Exemplo n.º 1
0
        public override bool ExecuteOffer(AdminShellPackageEnv package, AdminShell.Referable currentReferable,
                                          ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs)
        {
            // access
            var offer = offerBase as ConvertOfferDocumentationSg2ToV11;

            if (package == null || package.AasEnv == null || currentReferable == null || offer == null)
            {
                return(false);
            }

            // use pre-definitions
            var defsSg2 = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770(
                new AasxPredefinedConcepts.DefinitionsVDI2770());
            var defsV11 = AasxPredefinedConcepts.VDI2770v11.Static;

            // access Submodel (again)
            var sm = currentReferable as AdminShell.Submodel;

            if (sm == null || sm.submodelElements == null ||
                true != sm.GetSemanticKey()?.Matches(defsSg2.SM_VDI2770_Documentation.GetSemanticKey()))
            {
                /* disable line above to allow more models, such as MCAD/ECAD */
                return(false);
            }

            // convert in place: detach old SMEs, change semanticId
            var smcOldSg2 = sm.submodelElements;

            sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection();
            sm.semanticId       = new AdminShell.SemanticId(defsV11.SM_ManufacturerDocumentation.GetSemanticKey());

            // delete (old) CDs
            if (deleteOldCDs)
            {
                smcOldSg2.RecurseOnSubmodelElements(null, null, (state, parents, current) =>
                {
                    var sme = current;
                    if (sme != null && sme.semanticId != null)
                    {
                        var cd = package.AasEnv.FindConceptDescription(sme.semanticId);
                        if (cd != null)
                        {
                            if (package.AasEnv.ConceptDescriptions.Contains(cd))
                            {
                                package.AasEnv.ConceptDescriptions.Remove(cd);
                            }
                        }
                    }
                });
            }

            // add (all) new CDs?
            if (addNewCDs)
            {
                foreach (var rf in defsV11.GetAllReferables())
                {
                    if (rf is AdminShell.ConceptDescription)
                    {
                        package.AasEnv.ConceptDescriptions.AddIfNew(new AdminShell.ConceptDescription(
                                                                        rf as AdminShell.ConceptDescription));
                    }
                }
            }

            // ok, go thru the old == SG2 records
            foreach (var smcDoc in smcOldSg2.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsSg2.CD_VDI2770_Document.GetSingleKey()))
            {
                // access
                if (smcDoc == null || smcDoc.value == null)
                {
                    continue;
                }

                // look immediately for DocumentVersion, as only with this there is a valid List item
                foreach (var smcVer in smcDoc.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                             defsSg2.CD_VDI2770_DocumentVersion.GetSingleKey()))
                {
                    // access
                    if (smcVer == null || smcVer.value == null)
                    {
                        continue;
                    }

                    // make new V11 Document
                    // Document Item
                    using (var smcV11Doc = AdminShell.SubmodelElementCollection.CreateNew("" + smcDoc.idShort,
                                                                                          smcDoc.category,
                                                                                          AdminShell.Key.GetFromRef(defsV11.CD_Document.GetCdReference())))
                    {
                        // Document itself
                        smcV11Doc.description = smcDoc.description;
                        sm.submodelElements.Add(smcV11Doc);

                        // Domain?
                        var s1 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsSg2.CD_VDI2770_DomainId.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed)?.value;
                        var s2 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsSg2.CD_VDI2770_DocumentId.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed)?.value;
                        if (s1 != null || s2 != null)
                        {
                            var smcV11Dom = smcV11Doc.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                                defsV11.CD_DocumentIdDomain, addSme: true);

                            smcV11Dom.value.CreateSMEForCD <AdminShell.Property>(
                                defsV11.CD_DocumentDomainId, addSme: true)?.Set("string", "" + s1);
                            smcV11Dom.value.CreateSMEForCD <AdminShell.Property>(
                                defsV11.CD_DocumentId, addSme: true)?.Set("string", "" + s2);
                        }

                        // Classification (3 properties)
                        s1 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsSg2.CD_VDI2770_DocumentClassificationSystem.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed)?.value;
                        s2 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsSg2.CD_VDI2770_DocumentClassId.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed)?.value;
                        var s3 = smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsSg2.CD_VDI2770_DocumentClassName.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed)?.value;
                        if (s2 != null || s3 != null)
                        {
                            var smcV11Cls = smcV11Doc.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                                defsV11.CD_DocumentClassification, addSme: true);

                            smcV11Cls.value.CreateSMEForCD <AdminShell.Property>(
                                defsV11.CD_DocumentClassificationSystem, addSme: true)?.Set("string", "" + s1);
                            smcV11Cls.value.CreateSMEForCD <AdminShell.Property>(
                                defsV11.CD_DocumentClassId, addSme: true)?.Set("string", "" + s2);
                            smcV11Cls.value.CreateSMEForCD <AdminShell.Property>(
                                defsV11.CD_DocumentClassName, addSme: true)?.Set("string", "" + s3);
                        }

                        // Document Version
                        var smcV11Ver = smcV11Doc.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                            defsV11.CD_DocumentVersion, addSme: true);

                        foreach (var o in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(
                                     defsSg2.CD_VDI2770_Language.GetSingleKey(),
                                     AdminShellV20.Key.MatchMode.Relaxed))
                        {
                            smcV11Ver.value.CreateSMEForCD <AdminShell.Property>(
                                defsV11.CD_Language, addSme: true)?.Set("string", "" + o);
                        }

                        smcV11Ver.value.CreateSMEForCD <AdminShell.Property>(
                            defsV11.CD_DocumentVersionIdValue, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_DocumentVersionIdValue.GetSingleKey(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value);

                        var mlp1 = smcVer.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>(
                            defsSg2.CD_VDI2770_Title.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed);
                        if (mlp1 != null)
                        {
                            smcV11Ver.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>(
                                defsV11.CD_Title, addSme: true).value = mlp1.value;
                        }

                        mlp1 = smcVer.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>(
                            defsSg2.CD_VDI2770_Summary.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed);
                        if (mlp1 != null)
                        {
                            smcV11Ver.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>(
                                defsV11.CD_Summary, addSme: true).value = mlp1.value;
                        }

                        mlp1 = smcVer.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>(
                            defsSg2.CD_VDI2770_Keywords.GetSingleKey(),
                            AdminShellV20.Key.MatchMode.Relaxed);
                        if (mlp1 != null)
                        {
                            smcV11Ver.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>(
                                defsV11.CD_KeyWords, addSme: true).value = mlp1.value;
                        }

                        smcV11Ver.value.CreateSMEForCD <AdminShell.Property>(
                            defsV11.CD_Date, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_Date.GetSingleKey(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value);

                        smcV11Ver.value.CreateSMEForCD <AdminShell.Property>(
                            defsV11.CD_LifeCycleStatusValue, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_StatusValue.GetSingleKey(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value);

                        smcV11Ver.value.CreateSMEForCD <AdminShell.Property>(
                            defsV11.CD_Role, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_Role.GetSingleKey(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value);

                        smcV11Ver.value.CreateSMEForCD <AdminShell.Property>(
                            defsV11.CD_OrganizationName, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_OrganizationName.GetSingleKey(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value);

                        smcV11Ver.value.CreateSMEForCD <AdminShell.Property>(
                            defsV11.CD_OrganizationOfficialName, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_OrganizationOfficialName.GetSingleKey(),
                                AdminShellV20.Key.MatchMode.Relaxed)?.value);

                        foreach (var o in smcVer.value.FindAllSemanticIdAs <AdminShell.File>(
                                     defsSg2.CD_VDI2770_DigitalFile.GetSingleKey(),
                                     AdminShellV20.Key.MatchMode.Relaxed))
                        {
                            smcV11Ver.value.CreateSMEForCD <AdminShell.File>(
                                defsV11.CD_DigitalFile, addSme: true)?.Set(o.mimeType, o.value);
                        }
                    }
                }
            }

            // obviously well
            return(true);
        }
Exemplo n.º 2
0
 public virtual bool ExecuteOffer(
     AdminShellPackageEnv package, AdminShell.Referable currentReferable, ConvertOfferBase offer,
     bool deleteOldCDs, bool addNewCDs)
 {
     return(true);
 }
        public override bool ExecuteOffer(
            AdminShellPackageEnv package, AdminShell.Referable currentReferable, ConvertOfferBase offerBase,
            bool deleteOldCDs, bool addNewCDs)
        {
            // access
            var offer = offerBase as ConvertOfferDocumentationHsuToSg2;

            if (package == null || package.AasEnv == null || currentReferable == null || offer == null)
            {
                return(false);
            }

            // use pre-definitions
            var defsHsu = new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate.SetOfDocumentation(
                new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate());
            var defsSg2 = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770(
                new AasxPredefinedConcepts.DefinitionsVDI2770());

            // access Submodel (again)
            var sm = currentReferable as AdminShell.Submodel;

            if (sm == null || sm.submodelElements == null ||
                true != sm.GetSemanticKey()?.Matches(defsHsu.SM_Document.GetSemanticKey()))
            {
                return(false);
            }

            // convert in place: detach old SMEs, change semanticId
            var smcOldHsu = sm.submodelElements;

            sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection();
            sm.semanticId       = new AdminShell.SemanticId(defsSg2.SM_VDI2770_Documentation.GetSemanticKey());

            // delete (old) CDs
            if (deleteOldCDs)
            {
                smcOldHsu.RecurseOnSubmodelElements(null, null, (state, parents, current) =>
                {
                    var sme = current;
                    if (sme != null && sme.semanticId != null)
                    {
                        var cd = package.AasEnv.FindConceptDescription(sme.semanticId);
                        if (cd != null)
                        {
                            if (package.AasEnv.ConceptDescriptions.Contains(cd))
                            {
                                package.AasEnv.ConceptDescriptions.Remove(cd);
                            }
                        }
                    }
                });
            }

            // add (all) new CDs?
            if (addNewCDs)
            {
                foreach (var rf in defsSg2.GetAllReferables())
                {
                    if (rf is AdminShell.ConceptDescription)
                    {
                        package.AasEnv.ConceptDescriptions.AddIfNew(
                            new AdminShell.ConceptDescription(rf as AdminShell.ConceptDescription));
                    }
                }
            }

            // ok, go thru the old == HSU records
            foreach (var smcSource in smcOldHsu.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsHsu.CD_DocumentationItem.GetSingleKey(), AdminShell.Key.MatchMode.Relaxed))
            {
                // access
                if (smcSource == null || smcSource.value == null)
                {
                    continue;
                }

                // make new SG2 Document + DocumentItem
                // Document Item
                using (var smcDoc = AdminShell.SubmodelElementCollection.CreateNew("" + smcSource.idShort,
                                                                                   smcSource.category,
                                                                                   AdminShell.Key.GetFromRef(defsSg2.CD_VDI2770_Document.GetReference())))
                    using (var smcDocVersion = AdminShell.SubmodelElementCollection.CreateNew("DocumentVersion",
                                                                                              smcSource.category,
                                                                                              AdminShell.Key.GetFromRef(defsSg2.CD_VDI2770_DocumentVersion.GetReference())))
                    {
                        // Document itself
                        smcDoc.description = smcSource.description;

                        // classification
                        var clid = smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsHsu.CD_DocumentClassification_ClassId.GetSingleKey())?.value;
                        var clname = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsHsu.CD_VDI2770_ClassName.GetSingleKey())?.value;
                        var clsys = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsHsu.CD_VDI2770_ClassificationSystem.GetSingleKey())?.value;

#if future_structure
                        // as described in the VDI 2770 Submodel template document
                        if (clid.HasContent())
                        {
                            using (var smcClass = AdminShell.SubmodelElementCollection.CreateNew("DocumentClassification",
                                                                                                 smcSource.category, AdminShell.Key.GetFromRef(defsSg2.CD_XXX.GetReference())))
                            {
                                smcDoc.Add(smcClass);

                                smcClass.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassId,
                                                                                    addSme: true)?.Set("string", "" + clid);
                                smcClass.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassName,
                                                                                    addSme: true)?.Set("string", "" + clname);
                                smcClass.value.CreateSMEForCD <AdminShell.Property>(
                                    defsSg2.CD_VDI2770_DocumentClassificationSystem, addSme: true)?
                                .Set("string", "" + clsys);
                            }
                        }
#else
                        // current state of code
                        smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassId,
                                                                          addSme: true)?.Set("string", "" + clid);
                        smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassName,
                                                                          addSme: true)?.Set("string", "" + clname);
                        smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentClassificationSystem,
                                                                          addSme: true)?.Set("string", "" + clsys);
#endif

                        // items ..
                        smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentId, addSme: true)?.
                        Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsHsu.CD_DocumentId.GetSingleKey())?.value);

                        var idt = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsHsu.CD_VDI2770_IdType.GetSingleKey())?.IsTrue();
                        smcDoc.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_IsPrimaryDocumentId,
                                                                          addSme: true)?.Set("boolean", (idt.Trim().ToLower() == "primary") ? "True" : "False");

                        smcDoc.value.CreateSMEForCD <AdminShell.ReferenceElement>(defsSg2.CD_VDI2770_ReferencedObject,
                                                                                  addSme: true)?.
                        Set(new AdminShell.Reference());

                        // DocumentVersion

                        // languages
                        var lcs = "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsHsu.CD_DocumentVersion_LanguageCode.GetSingleKey())?.value;
                        var lcsa = lcs.Trim().Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                        //ReSharper disable ConditionIsAlwaysTrueOrFalse
                        if (lcsa != null && lcsa.Length > 0)
                        {
                            int i = 0;
                            foreach (var lc in lcsa)
                            {
                                var lcc = "" + lc;
                                if (lcc.IndexOf('-') > 0)
                                {
                                    lcc = lc.Substring(0, lcc.IndexOf('-'));
                                }
                                smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_Language,
                                                                                         idShort: $"Language{(i++):00}", addSme: true)?.
                                Set("string", "" + lcc);
                            }
                        }
                        //ReSharper enable ConditionIsAlwaysTrueOrFalse

                        smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_DocumentVersionId,
                                                                                 addSme: true)?.
                        Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsHsu.CD_DocumentVersionId.GetSingleKey())?.value);

                        var cdSrc = new[] { defsHsu.CD_VDI2770_Title, defsHsu.CD_VDI2770_Summary,
                                            defsHsu.CD_VDI2770_Keywords };
                        var cdDst = new[] { defsSg2.CD_VDI2770_Title, defsSg2.CD_VDI2770_Summary,
                                            defsSg2.CD_VDI2770_Keywords };
                        for (int i = 0; i < 3; i++)
                        {
                            var target = smcDocVersion.value.CreateSMEForCD <AdminShell.MultiLanguageProperty>(cdDst[i],
                                                                                                               addSme: true);
                            if (target == null)
                            {
                                continue;
                            }

                            var asProp = smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                cdSrc[i].GetSingleKey());
                            if (asProp != null)
                            {
                                target.Set("en?", "" + asProp.value);
                            }

                            var asMLP = smcSource.value.FindFirstSemanticIdAs <AdminShell.MultiLanguageProperty>(
                                cdSrc[i].GetSingleKey());
                            if (asMLP != null)
                            {
                                target.value = asMLP.value;
                            }
                        }

                        smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_Date, addSme: true)?.
                        Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsHsu.CD_VDI2770_SetDate.GetSingleKey())?.value);

                        smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_Role, addSme: true)?.
                        Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsHsu.CD_VDI2770_Role.GetSingleKey())?.value);

                        smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(defsSg2.CD_VDI2770_OrganizationName,
                                                                                 addSme: true)?.Set("string", "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                        defsHsu.CD_VDI2770_OrganisationName.GetSingleKey())?.value);

                        smcDocVersion.value.CreateSMEForCD <AdminShell.Property>(
                            defsSg2.CD_VDI2770_OrganizationOfficialName, addSme: true)?.Set("string",
                                                                                            "" + smcSource.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                defsHsu.CD_VDI2770_OrganisationOfficialName.GetSingleKey())?.value);

                        // 1 file?
                        var fl = smcSource.value.FindFirstSemanticIdAs <AdminShell.File>(defsHsu.CD_File.GetSingleKey());
                        smcDocVersion.value.CreateSMEForCD <AdminShell.File>(defsSg2.CD_VDI2770_DigitalFile, addSme: true)?.
                        Set("" + fl?.mimeType, "" + fl?.value);

                        // finally, add
                        smcDoc.Add(smcDocVersion);
                        sm.submodelElements.Add(smcDoc);
                    }
            }

            // obviously well
            return(true);
        }
        public override bool ExecuteOffer(AdminShellPackageEnv package, AdminShell.Referable currentReferable,
                                          ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs)
        {
            // access
            var offer = offerBase as ConvertOfferTechnicalDataV10ToV11;

            if (package == null || package.AasEnv == null || currentReferable == null || offer == null)
            {
                return(false);
            }

            // use pre-definitions
            var defsV10 = new AasxPredefinedConcepts.DefinitionsZveiTechnicalData.SetOfDefs(
                new AasxPredefinedConcepts.DefinitionsZveiTechnicalData());
            var defsV11 = AasxPredefinedConcepts.ZveiTechnicalDataV11.Static;

            // access Submodel (again)
            var sm = currentReferable as AdminShell.Submodel;

            if (sm == null || sm.submodelElements == null ||
                true != sm.GetSemanticKey()?.Matches(defsV10.SM_TechnicalData.GetSemanticKey()))
            {
                /* disable line above to allow more models, such as MCAD/ECAD */
                return(false);
            }

            // convert in place: detach old SMEs, change semanticId
            var smcV10 = sm.submodelElements;

            sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection();
            sm.semanticId       = new AdminShell.SemanticId(defsV11.SM_TechnicalData.GetSemanticKey());

            // delete (old) CDs
            if (deleteOldCDs)
            {
                smcV10.RecurseOnSubmodelElements(null, null, (state, parents, current) =>
                {
                    var sme = current;
                    if (sme != null && sme.semanticId != null)
                    {
                        var cd = package.AasEnv.FindConceptDescription(sme.semanticId);
                        if (cd != null)
                        {
                            if (package.AasEnv.ConceptDescriptions.Contains(cd))
                            {
                                package.AasEnv.ConceptDescriptions.Remove(cd);
                            }
                        }
                    }
                });
            }

            // add (all) new CDs?
            if (addNewCDs)
            {
                foreach (var rf in defsV11.GetAllReferables())
                {
                    if (rf is AdminShell.ConceptDescription)
                    {
                        package.AasEnv.ConceptDescriptions.AddIfNew(new AdminShell.ConceptDescription(
                                                                        rf as AdminShell.ConceptDescription));
                    }
                }
            }

            // General Info (target cardinality: 1)
            foreach (var smcV10gi in smcV10.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsV10.CD_GeneralInformation.GetSingleKey()))
            {
                // make a new one
                var smcV11gi = sm.submodelElements.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                    defsV11.CD_GeneralInformation, addSme: true);

                // SME
                smcV11gi.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV11.CD_ManufacturerName,
                                                                      smcV10gi.value, defsV10.CD_ManufacturerName,
                                                                      createDefault: true, addSme: true);

                smcV11gi.value.CopyOneSMEbyCopy <AdminShell.File>(defsV11.CD_ManufacturerLogo,
                                                                  smcV10gi.value, defsV10.CD_ManufacturerLogo,
                                                                  createDefault: true, addSme: true);

                smcV11gi.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV11.CD_ManufacturerPartNumber,
                                                                      smcV10gi.value, defsV10.CD_ManufacturerPartNumber,
                                                                      createDefault: true, addSme: true);

                smcV11gi.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV11.CD_ManufacturerOrderCode,
                                                                      smcV10gi.value, defsV10.CD_ManufacturerOrderCode,
                                                                      createDefault: true, addSme: true);

                smcV11gi.value.CopyManySMEbyCopy <AdminShell.File>(defsV11.CD_ProductImage,
                                                                   smcV10gi.value, defsV10.CD_ProductImage,
                                                                   createDefault: true);
            }

            // Product Classifications (target cardinality: 1)
            foreach (var smcV10pcs in smcV10.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsV10.CD_ProductClassifications.GetSingleKey()))
            {
                // make a new one
                var smcV11pcs = sm.submodelElements.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                    defsV11.CD_ProductClassifications, addSme: true);

                // Product Classification Items (target cardinality: 1..n)
                foreach (var smcV10pci in smcV10pcs.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                             defsV10.CD_ProductClassificationItem.GetSingleKey()))
                {
                    // make a new one
                    var smcV11pci = smcV11pcs.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                        defsV11.CD_ProductClassificationItem, addSme: true);

                    // SME
                    smcV11pci.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV11.CD_ProductClassificationSystem,
                                                                           smcV10pci.value, defsV10.CD_ClassificationSystem,
                                                                           createDefault: true, addSme: true);

                    smcV11pci.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV11.CD_ClassificationSystemVersion,
                                                                           smcV10pci.value, defsV10.CD_SystemVersion,
                                                                           createDefault: true, addSme: true);

                    smcV11pci.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV11.CD_ProductClassId,
                                                                           smcV10pci.value, defsV10.CD_ProductClass,
                                                                           createDefault: true, addSme: true);
                }
            }

            // TechnicalProperties (target cardinality: 1)
            foreach (var smcV10prop in smcV10.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsV10.CD_TechnicalProperties.GetSingleKey()))
            {
                // make a new one
                var smcV11prop = sm.submodelElements.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                    defsV11.CD_TechnicalProperties, addSme: true);

                // use recursion
                RecurseToCopyTechnicalProperties(defsV11, defsV10, smcV11prop, smcV10prop);
            }

            // Further Info (target cardinality: 1)
            foreach (var smcV10fi in smcV10.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsV10.CD_FurtherInformation.GetSingleKey()))
            {
                // make a new one
                var smcV11fi = sm.submodelElements.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                    defsV11.CD_FurtherInformation, addSme: true);

                // SME
                smcV11fi.value.CopyManySMEbyCopy <AdminShell.MultiLanguageProperty>(defsV11.CD_TextStatement,
                                                                                    smcV10fi.value, defsV10.CD_TextStatement,
                                                                                    createDefault: true);

                smcV11fi.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV11.CD_ValidDate,
                                                                      smcV10fi.value, defsV10.CD_ValidDate,
                                                                      createDefault: true, addSme: true);
            }

            // obviously well
            return(true);
        }
Exemplo n.º 5
0
        public override bool ExecuteOffer(AdminShellPackageEnv package, AdminShell.Referable currentReferable,
                                          ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs)
        {
            // access
            var offer = offerBase as ConvertOfferDocumentationSg2ToHsu;

            if (package == null || package.AasEnv == null || currentReferable == null || offer == null)
            {
                return(false);
            }

            // use pre-definitions
            var defsSg2 = new AasxPredefinedConcepts.DefinitionsVDI2770.SetOfDefsVDI2770(
                new AasxPredefinedConcepts.DefinitionsVDI2770());
            var defsHsu = new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate.SetOfDocumentation(
                new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate());

            // access Submodel (again)
            var sm = currentReferable as AdminShell.Submodel;

            if (sm == null || sm.submodelElements == null ||
                true != sm.GetSemanticKey()?.Matches(defsSg2.SM_VDI2770_Documentation.GetSemanticKey()))
            {
                /* disable line above to allow more models, such as MCAD/ECAD */
                return(false);
            }

            // convert in place: detach old SMEs, change semanticId
            var smcOldSg2 = sm.submodelElements;

            sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection();
            sm.semanticId       = new AdminShell.SemanticId(defsHsu.SM_Document.GetSemanticKey());

            // delete (old) CDs
            if (deleteOldCDs)
            {
                sm.RecurseOnSubmodelElements(null, (state, parents, current) =>
                {
                    var sme = current;
                    if (sme != null && sme.semanticId != null)
                    {
                        var cd = package.AasEnv.FindConceptDescription(sme.semanticId);
                        if (cd != null)
                        {
                            if (package.AasEnv.ConceptDescriptions.Contains(cd))
                            {
                                package.AasEnv.ConceptDescriptions.Remove(cd);
                            }
                        }
                    }
                    // recurse
                    return(true);
                });
            }

            // add (all) new CDs?
            if (addNewCDs)
            {
                foreach (var rf in defsHsu.GetAllReferables())
                {
                    if (rf is AdminShell.ConceptDescription)
                    {
                        package.AasEnv.ConceptDescriptions.AddIfNew(new AdminShell.ConceptDescription(
                                                                        rf as AdminShell.ConceptDescription));
                    }
                }
            }

            // ok, go thru the old == SG2 records
            foreach (var smcDoc in smcOldSg2.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsSg2.CD_VDI2770_Document.GetSingleKey()))
            {
                // access
                if (smcDoc == null || smcDoc.value == null)
                {
                    continue;
                }

                // look immediately for DocumentVersion, as only with this there is a valid List item
                foreach (var smcVer in smcDoc.value.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                             defsSg2.CD_VDI2770_DocumentVersion.GetSingleKey()))
                {
                    // access
                    if (smcVer == null || smcVer.value == null)
                    {
                        continue;
                    }

                    // make new HSU Document
                    // ReSharper disable once ConvertToUsingDeclaration
                    // Document Item
                    using (var smcHsuDoc = AdminShell.SubmodelElementCollection.CreateNew("" + smcDoc.idShort,
                                                                                          smcDoc.category,
                                                                                          AdminShell.Key.GetFromRef(defsHsu.CD_DocumentationItem.GetCdReference())))
                    {
                        // Document itself
                        smcHsuDoc.description = smcDoc.description;
                        sm.submodelElements.Add(smcHsuDoc);

                        // items ..
                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentType, addSme: true)?.
                        Set("string", "Single");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_DomainId,
                                                                             addSme: true)?.Set("string", "");

                        var b = true == smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                            defsSg2.CD_VDI2770_IsPrimaryDocumentId.GetSingleKey())?.IsTrue();
                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_IdType, addSme: true)?.
                        Set("string", b ? "Primary" : "Secondary");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentId, addSme: true)?.
                        Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentDomainId,
                                                                             addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Role, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_Role.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_OrganisationId,
                                                                             addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_OrganisationName,
                                                                             addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                    defsSg2.CD_VDI2770_OrganizationName.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(
                            defsHsu.CD_VDI2770_OrganisationOfficialName, addSme: true)?.Set("string",
                                                                                            "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                defsSg2.CD_VDI2770_OrganizationOfficialName.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Description,
                                                                             addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentPartId, addSme: true)?.
                        Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentClassification_ClassId,
                                                                             addSme: true)?.Set("string", "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                    defsSg2.CD_VDI2770_DocumentClassId.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_ClassName,
                                                                             addSme: true)?.Set("string", "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                    defsSg2.CD_VDI2770_DocumentClassName.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_ClassificationSystem,
                                                                             addSme: true)?.Set("string", "" + smcDoc.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                    defsSg2.CD_VDI2770_DocumentClassificationSystem.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentVersionId,
                                                                             addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                    defsSg2.CD_VDI2770_DocumentVersionId.GetSingleKey())?.value);

                        var lcs = "";
                        foreach (var lcp in smcVer.value.FindAllSemanticIdAs <AdminShell.Property>(
                                     defsSg2.CD_VDI2770_Language.GetSingleKey()))
                        {
                            lcs += "" + lcp?.value + ",";
                        }
                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_DocumentVersion_LanguageCode,
                                                                             addSme: true)?.Set("string", lcs.TrimEnd(','));

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Title, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticId(
                                defsSg2.CD_VDI2770_Title.GetSingleKey(),
                                new[] {
                            typeof(AdminShell.Property),
                            typeof(AdminShell.MultiLanguageProperty)
                        })?.submodelElement?.ValueAsText());

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Summary, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticId(
                                defsSg2.CD_VDI2770_Summary.GetSingleKey(),
                                new[] {
                            typeof(AdminShell.Property),
                            typeof(AdminShell.MultiLanguageProperty)
                        })?.submodelElement?.ValueAsText());

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Keywords,
                                                                             addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticId(
                                                                                                    defsSg2.CD_VDI2770_Keywords.GetSingleKey(),
                                                                                                    new[] {
                            typeof(AdminShell.Property),
                            typeof(AdminShell.MultiLanguageProperty)
                        })?.submodelElement?.ValueAsText());

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_StatusValue,
                                                                             addSme: true)?.Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                                                                                    defsSg2.CD_VDI2770_StatusValue.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_SetDate, addSme: true)?.
                        Set("string", "" + smcVer.value.FindFirstSemanticIdAs <AdminShell.Property>(
                                defsSg2.CD_VDI2770_Date.GetSingleKey())?.value);

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Purpose, addSme: true)?.
                        Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_BasedOnProcedure,
                                                                             addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_Comments,
                                                                             addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_ReferencedObject_Type,
                                                                             addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(
                            defsHsu.CD_VDI2770_ReferencedObject_RefType, addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(
                            defsHsu.CD_VDI2770_ReferencedObject_ObjectId, addSme: true)?.Set("string", "");

                        smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_FileId, addSme: true)?.
                        Set("string", "");

                        var fl = smcVer.value.FindFirstSemanticIdAs <AdminShell.File>(
                            defsSg2.CD_VDI2770_DigitalFile.GetSingleKey());
                        if (fl != null)
                        {
                            smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_FileName,
                                                                                 addSme: true)?.Set("string", System.IO.Path.GetFileName("" + fl.value));

                            smcHsuDoc.value.CreateSMEForCD <AdminShell.Property>(defsHsu.CD_VDI2770_FileFormat,
                                                                                 addSme: true)?.Set("string", "" + fl.mimeType);

                            smcHsuDoc.value.CreateSMEForCD <AdminShell.File>(defsHsu.CD_File, addSme: true)?.
                            Set("" + fl.mimeType, "" + fl.value);
                        }
                    }
                }
            }

            // obviously well
            return(true);
        }
        public override bool ExecuteOffer(
            AdminShellPackageEnv package, AdminShell.Referable currentReferable,
            ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs)
        {
            // access
            var offer = offerBase as ConvertOfferTechnicalDataToFlat;

            if (package == null || package.AasEnv == null || currentReferable == null || offer == null)
            {
                return(false);
            }

            // use pre-definitions
            var defsTD = new AasxPredefinedConcepts.DefinitionsZveiTechnicalData.SetOfDefs(
                new AasxPredefinedConcepts.DefinitionsZveiTechnicalData());

            // access Submodel (again)
            var sm = currentReferable as AdminShell.Submodel;

            if (sm == null || sm.submodelElements == null ||
                true != sm.GetSemanticKey()?.Matches(defsTD.SM_TechnicalData.GetSemanticKey()))
            {
                return(false);
            }

            // convert in place: detach old SMEs, change semanticId
            var smcOldTD = sm.submodelElements;

            sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection();
            sm.semanticId       = new AdminShell.SemanticId(
                AdminShell.Key.CreateNew(
                    AdminShell.Key.Submodel, false, AdminShell.Identification.IRI,
                    "http://admin-shell.io/sandbox/technical-data-flat/sm"));

            // find all technical properties
            foreach (var smcTDP in smcOldTD.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsTD.CD_TechnicalProperties.GetSingleKey()))
            {
                // access
                if (smcTDP == null || smcTDP.value == null)
                {
                    continue;
                }

                // now, take this as root for a recurse find ..
                foreach (var oldSme in smcTDP.value.FindDeep <AdminShell.SubmodelElement>((o) => true))
                {
                    // no collections!
                    if (oldSme is AdminShell.SubmodelElementCollection)
                    {
                        continue;
                    }

                    // simply add to new
                    sm.submodelElements.Add(oldSme);
                }
            }

            // obviously well
            return(true);
        }
        public override bool ExecuteOffer(AdminShellPackageEnv package, AdminShell.Referable currentReferable,
                                          ConvertOfferBase offerBase, bool deleteOldCDs, bool addNewCDs)
        {
            // access
            var offer = offerBase as ConvertOfferNameplateHsuToZveiV10;

            if (package == null || package.AasEnv == null || currentReferable == null || offer == null)
            {
                return(false);
            }

            // use pre-definitions
            var defsHSU = new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate.SetOfNameplate(
                new AasxPredefinedConcepts.DefinitionsZveiDigitalTypeplate());
            var defsV10 = AasxPredefinedConcepts.ZveiNameplateV10.Static;

            // access Submodel (again)
            var sm = currentReferable as AdminShell.Submodel;

            if (sm == null || sm.submodelElements == null ||
                true != sm.GetSemanticKey()?.Matches(defsHSU.SM_Nameplate.GetSemanticKey()))
            {
                /* disable line above to allow more models, such as MCAD/ECAD */
                return(false);
            }

            // convert in place: detach old SMEs, change semanticId
            var smHSU = sm.submodelElements;

            sm.submodelElements = new AdminShell.SubmodelElementWrapperCollection();
            sm.semanticId       = new AdminShell.SemanticId(defsV10.SM_Nameplate.GetSemanticKey());

            // delete (old) CDs
            if (deleteOldCDs)
            {
                sm.RecurseOnSubmodelElements(null, (state, parents, current) =>
                {
                    var sme = current;
                    if (sme != null && sme.semanticId != null)
                    {
                        var cd = package.AasEnv.FindConceptDescription(sme.semanticId);
                        if (cd != null)
                        {
                            if (package.AasEnv.ConceptDescriptions.Contains(cd))
                            {
                                package.AasEnv.ConceptDescriptions.Remove(cd);
                            }
                        }
                    }
                    // recurse
                    return(true);
                });
            }

            // add (all) new CDs?
            if (addNewCDs)
            {
                foreach (var rf in defsV10.GetAllReferables())
                {
                    if (rf is AdminShell.ConceptDescription)
                    {
                        package.AasEnv.ConceptDescriptions.AddIfNew(new AdminShell.ConceptDescription(
                                                                        rf as AdminShell.ConceptDescription));
                    }
                }
            }

            // Submodel level

            sm.submodelElements.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_ManNam,
                                                                       smHSU, defsHSU.CD_ManufacturerName,
                                                                       createDefault: true, addSme: true, idShort: "ManufacturerName");

            sm.submodelElements.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_ManProDes,
                                                                       smHSU, defsHSU.CD_ManufacturerProductDesignation,
                                                                       createDefault: true, addSme: true, idShort: "ManufacturerProductDesignation");

            // Address (target cardinality: 1)
            foreach (var smcHSUadd in smHSU.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsHSU.CD_PhysicalAddress.GetSingleKey()))
            {
                // make a new one
                var smcV10add = sm.submodelElements.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                    defsV10.CD_Add, idShort: "Address", addSme: true);

                // SME
                smcV10add.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_Str,
                                                                       smcHSUadd.value, new[] {
                    defsHSU.CD_Street.GetSingleKey(),
                    new AdminShell.Key(AdminShell.Key.ConceptDescription, true, AdminShell.Identification.IRI,
                                       "https://www.hsu-hh.de/aut/aas/street")
                },
                                                                       createDefault: true, addSme: true, idShort: "Street");

                smcV10add.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_ZipCod,
                                                                       smcHSUadd.value, new[] {
                    defsHSU.CD_Zip.GetSingleKey(),
                    new AdminShell.Key(AdminShell.Key.ConceptDescription, true, AdminShell.Identification.IRI,
                                       "https://www.hsu-hh.de/aut/aas/postalcode")
                },
                                                                       createDefault: true, addSme: true, idShort: "Zipcode");

                smcV10add.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_CitTow,
                                                                       smcHSUadd.value, new[] {
                    defsHSU.CD_CityTown.GetSingleKey(),
                    new AdminShell.Key(AdminShell.Key.ConceptDescription, true, AdminShell.Identification.IRI,
                                       "https://www.hsu-hh.de/aut/aas/city")
                },
                                                                       createDefault: true, addSme: true, idShort: "CityTown");

                smcV10add.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_StaCou,
                                                                       smcHSUadd.value, new[] {
                    defsHSU.CD_StateCounty.GetSingleKey(),
                    new AdminShell.Key(AdminShell.Key.ConceptDescription, true, AdminShell.Identification.IRI,
                                       "https://www.hsu-hh.de/aut/aas/statecounty")
                },
                                                                       createDefault: true, addSme: true, idShort: "StateCounty");

                smcV10add.value.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_NatCod,
                                                                       smcHSUadd.value, defsHSU.CD_CountryCode,
                                                                       createDefault: true, addSme: true, idShort: "NationalCode");
            }

            // Submodel level - continued

            sm.submodelElements.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_ManProFam,
                                                                       smHSU, defsHSU.CD_ManufacturerProductFamily,
                                                                       createDefault: true, addSme: true, idShort: "ManufacturerProductFamily");

            sm.submodelElements.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_SerNum,
                                                                       smHSU, defsHSU.CD_SerialNumber,
                                                                       createDefault: true, addSme: true, idShort: "SerialNumber");

            sm.submodelElements.CopyOneSMEbyCopy <AdminShell.Property>(defsV10.CD_YeaOfCon,
                                                                       smHSU, defsHSU.CD_YearOfConstruction,
                                                                       createDefault: true, addSme: true, idShort: "YearOfConstruction");

            // Markings
            var smcV10mks = sm.submodelElements.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                defsV10.CD_Markings, idShort: "Markings", addSme: true);

            // each Marking
            foreach (var smcHSUmk in smHSU.FindAllSemanticIdAs <AdminShell.SubmodelElementCollection>(
                         defsHSU.CD_ProductMarking.GetSingleKey()))
            {
                // make a new one
                var smcV10mk = smcV10mks.value.CreateSMEForCD <AdminShell.SubmodelElementCollection>(
                    defsV10.CD_Marking, idShort: "" + smcHSUmk.idShort, addSme: true);

                // take over the name of the old collection in the distinct Property
                var mkName = "" + smcHSUmk.idShort;
                if (mkName.StartsWith("Marking_"))
                {
                    mkName = mkName.Substring(8);
                }
                var mkNameProp = smcV10mk.value.CreateSMEForCD <AdminShell.Property>(
                    defsV10.CD_MarkingName, idShort: "MarkingName", addSme: true)?
                                 .Set(AdminShell.DataElement.ValueType_STRING, "" + mkName);

                // file
                smcV10mk.value.CopyOneSMEbyCopy <AdminShell.File>(defsV10.CD_MarkingFile,
                                                                  smcHSUmk.value, defsHSU.CD_File,
                                                                  createDefault: true, addSme: true, idShort: "ManufacturerName");

                // if there a other Property inside, assume, that their semantic ids shall
                // go into the valueId of the Name

                foreach (var other in smcHSUmk.value.FindAll((smw) => smw?.submodelElement is AdminShell.Property))
                {
                    if (mkNameProp != null &&
                        other?.submodelElement?.semanticId != null &&
                        !other.submodelElement.semanticId.IsEmpty &&
                        other.submodelElement.semanticId[0].IsIdType(AdminShell.Identification.IRDI))
                    {
                        mkNameProp.valueId = other.submodelElement.semanticId;
                    }
                }
            }

            // obviously well
            return(true);
        }