Esempio n. 1
0
 public static bool ImportSubmodel(Window window, AdminShellV20.AdministrationShellEnv env,
                                   string defaultSourceDir, AdminShellV20.AdministrationShell?adminShell = null)
 {
     adminShell ??= CreateAdminShell(env);
     return(PerformImport(window, ImportMode.Submodels, defaultSourceDir,
                          e => e.ImportSubmodelInto(env, adminShell)));
 }
Esempio n. 2
0
        public static AdminShellV20.Submodel CreateSubmodel(
            AdminShellV20.AdministrationShellEnv env,
            AdminShellV20.AdministrationShell adminShell, Iec61360Data data)
        {
            // We need this to ensure that we don't use the same AAS ID twice when importing multiple submodels (as
            // GenerateIdAccordingTemplate uses the timestamp as part of the ID).
            Thread.Sleep(1000);
            var submodel = new AdminShellV20.Submodel()
            {
                identification = new AdminShellV20.Identification(
                    AdminShellV20.Identification.IRI,
                    AasxPackageExplorer.Options.Curr.GenerateIdAccordingTemplate(
                        AasxPackageExplorer.Options.Curr.TemplateIdSubmodelInstance)),
                idShort = data.IdShort,
                kind    = AdminShellV20.ModelingKind.CreateAsInstance(),
            };

            AddDescriptions(submodel, data);
            AddDataSpecification(env, submodel, data);

            adminShell.AddSubmodelRef(submodel.GetReference() as AdminShellV20.SubmodelRef);
            env.Submodels.Add(submodel);

            return(submodel);
        }
        /// <summary>
        /// De-serialize an open stream into AdministrationShellEnv. Does version/ compatibility management.
        /// </summary>
        /// <param name="s">Open for read stream</param>
        /// <returns></returns>
        public static AdminShell.AdministrationShellEnv DeserializeXmlFromStreamWithCompat(Stream s)
        {
            // not sure
            AdminShell.AdministrationShellEnv res = null;

            // try get first element
            var nsuri = TryReadXmlFirstElementNamespaceURI(s);

            // read V1.0?
            if (nsuri != null && nsuri.Trim() == "http://www.admin-shell.io/aas/1/0")
            {
#if UseAasxCompatibilityModels
                XmlSerializer serializer = new XmlSerializer(typeof(AasxCompatibilityModels.AdminShellV10.AdministrationShellEnv), "http://www.admin-shell.io/aas/1/0");
                var           v10        = serializer.Deserialize(s) as AasxCompatibilityModels.AdminShellV10.AdministrationShellEnv;
                res = new AdminShellV20.AdministrationShellEnv(v10);
                return(res);
#else
                throw (new Exception("Cannot handle AAS file format http://www.admin-shell.io/aas/1/0 !"));
#endif
            }

            // read V2.0?
            if (nsuri != null && nsuri.Trim() == "http://www.admin-shell.io/aas/2/0")
            {
                XmlSerializer serializer = new XmlSerializer(typeof(AdminShell.AdministrationShellEnv), "http://www.admin-shell.io/aas/2/0");
                res = serializer.Deserialize(s) as AdminShell.AdministrationShellEnv;
                return(res);
            }

            // nope!
            return(null);
        }
Esempio n. 4
0
        public static AdminShellV20.SubmodelElementCollection CreateCollection(
            AdminShellV20.AdministrationShellEnv env, Iec61360Data data)
        {
            var collection = new AdminShellV20.SubmodelElementCollection()
            {
                idShort = data.IdShort,
                kind    = AdminShellV20.ModelingKind.CreateAsInstance(),
            };

            InitSubmodelElement(env, collection, data);
            return(collection);
        }
Esempio n. 5
0
        private static AdminShellV20.AdministrationShell CreateAdminShell(AdminShellV20.AdministrationShellEnv env)
        {
            var adminShell = new AdminShellV20.AdministrationShell()
            {
                identification = new AdminShellV20.Identification(
                    AdminShellV20.Identification.IRI,
                    AdminShellUtil.GenerateIdAccordingTemplate(Options.Curr.TemplateIdAas))
            };

            env.AdministrationShells.Add(adminShell);
            return(adminShell);
        }
Esempio n. 6
0
        protected static AdminShellV20.AdministrationShell CreateAdminShell(AdminShellV20.AdministrationShellEnv env)
        {
            var adminShell = new AdminShellV20.AdministrationShell()
            {
                identification = new AdminShellV20.Identification(
                    AdminShellV20.Identification.IRI,
                    AasxPackageExplorer.Options.Curr.GenerateIdAccordingTemplate(
                        AasxPackageExplorer.Options.Curr.TemplateIdAas)),
            };

            env.AdministrationShells.Add(adminShell);
            return(adminShell);
        }
Esempio n. 7
0
        public static AdminShellV20.Property CreateProperty(
            AdminShellV20.AdministrationShellEnv env, Iec61360Data data, string valueType)
        {
            var property = new AdminShellV20.Property()
            {
                idShort   = data.IdShort,
                kind      = AdminShellV20.ModelingKind.CreateAsInstance(),
                valueType = valueType,
            };

            InitSubmodelElement(env, property, data);
            return(property);
        }
Esempio n. 8
0
        private static void AddDataSpecification(AdminShellV20.AdministrationShellEnv env,
                                                 AdminShellV20.SubmodelElement submodelElement, Iec61360Data data)
        {
            var cd = CreateConceptDescription(env, data);

            // cd should already contain IEC61360Spec; add data spec
            // TODO (Robin, 2020-09-03): MIHO is not sure, if the data spec reference is correct; please check
            var eds = cd.IEC61360DataSpec;

            if (eds != null)
            {
                eds.dataSpecification = new AdminShellV20.DataSpecificationRef(cd.GetReference());
            }

            submodelElement.semanticId = new AdminShellV20.SemanticId(cd.GetReference());
        }
Esempio n. 9
0
        public static AdminShellV20.Submodel CreateSubmodel(
            AdminShellV20.AdministrationShellEnv env,
            AdminShellV20.AdministrationShell adminShell, Iec61360Data data)
        {
            var submodel = new AdminShellV20.Submodel()
            {
                identification = new AdminShellV20.Identification(
                    AdminShellV20.Identification.IRI,
                    AasxPackageExplorer.Options.Curr.GenerateIdAccordingTemplate(
                        AasxPackageExplorer.Options.Curr.TemplateIdSubmodelInstance)),
                idShort = data.IdShort,
                kind    = AdminShellV20.ModelingKind.CreateAsInstance(),
            };

            AddDescriptions(submodel, data);
            AddDataSpecification(env, submodel, data);

            adminShell.AddSubmodelRef(submodel.GetReference() as AdminShellV20.SubmodelRef);
            env.Submodels.Add(submodel);

            return(submodel);
        }
Esempio n. 10
0
        private static AdminShellV20.ConceptDescription CreateConceptDescription(
            AdminShellV20.AdministrationShellEnv env, Iec61360Data data)
        {
            var cd = AdminShellV20.ConceptDescription.CreateNew(
                data.IdShort, AdminShellV20.Identification.IRDI, data.Irdi);

            // TODO (Robin, 2020-09-03): check this code
            cd.IEC61360Content = data.ToDataSpecification();
            // dead-csharp off
            //cd.embeddedDataSpecification = new AdminShellV20.EmbeddedDataSpecification()
            //{
            //    dataSpecificationContent = new AdminShellV20.DataSpecificationContent()
            //    {
            //        dataSpecificationIEC61360 = data.ToDataSpecification(),
            //    },
            //};
            // dead-csharp on

            cd.AddIsCaseOf(AdminShellV20.Reference.CreateIrdiReference(data.Irdi));
            env.ConceptDescriptions.Add(cd);
            return(cd);
        }
Esempio n. 11
0
 public override bool ImportSubmodelInto(AdminShellV20.AdministrationShellEnv env,
                                         AdminShellV20.AdministrationShell adminShell)
 {
     return(new Importer(env, Context).ImportSubmodel(this, adminShell));
 }
Esempio n. 12
0
 public static bool ImportSubmodel(AdminShellV20.AdministrationShellEnv env,
                                   AdminShellV20.AdministrationShell?adminShell = null)
 {
     adminShell ??= CreateAdminShell(env);
     return(PerformImport(ImportMode.Submodels, e => e.ImportSubmodelInto(env, adminShell)));
 }
Esempio n. 13
0
 private static void InitSubmodelElement(AdminShellV20.AdministrationShellEnv env,
                                         AdminShellV20.SubmodelElement submodelElement, Iec61360Data data)
 {
     AddDescriptions(submodelElement, data);
     AddDataSpecification(env, submodelElement, data);
 }
Esempio n. 14
0
 public Importer(AdminShellV20.AdministrationShellEnv env, Context context)
 {
     _env     = env;
     _context = context;
     _all     = context.DataSource.ImportAllAttributes;
 }
Esempio n. 15
0
        //Annotations
        //Almost every Method is build the same way:
        //1. Create UANode object and set its parameters
        //   Create a List of References and add a Reference to the Type (HasTypeDefinition)
        //   Increment masterId++, so the InformationModel will stay consistent and so there be no duplicate IDs
        //2. Set specific parameters of the mapped Object with properties
        //   createReference only needs the ReferenceType and a nodeId, that is why every method only returns a string
        //3. Create an array from the List
        //   Add the created Node to the root List

        public static string CreateAAS(string name, AdminShellV20.AdministrationShellEnv env)
        {
            UAObject sub = new UAObject();

            sub.NodeId     = "ns=1;i=" + masterID.ToString();
            sub.BrowseName = "1:AASAssetAdministrationShell";
            masterID++;
            List <Reference> refs = new List <Reference>();

            refs.Add(new Reference
            {
                Value         = "i=58",
                ReferenceType = "HasTypeDefinition"
            });
            refs.Add(new Reference
            {
                IsForward     = false,
                Value         = "i=85",
                ReferenceType = "Organizes"
            });

            //add ConceptDictionary
            refs.Add(CreateReference("HasComponent", CreateConceptDictionaryFolder(env.ConceptDescriptions)));

            //add Assets
            foreach (AdminShellV20.Asset asset in env.Assets)
            {
                refs.Add(CreateReference("HasComponent", CreateAASAsset(asset)));
            }

            //add Submodels
            foreach (AdminShellV20.Submodel submodel in env.Submodels)
            {
                string id = CreateAASSubmodel(submodel);
                refs.Add(CreateReference("HasComponent", id));
            }

            //map AAS Information
            foreach (AdminShellV20.AdministrationShell shell in env.AdministrationShells)
            {
                if (shell.views != null)
                {
                    foreach (AdminShellV20.View view in shell.views.views)
                    {
                        refs.Add(CreateReference("HasComponent", CreateView(view)));
                    }
                }

                if (shell.derivedFrom != null)
                {
                    refs.Add(CreateReference("HasComponent", CreateDerivedFrom(shell.derivedFrom.Keys)));
                }

                if (shell.idShort != null)
                {
                    refs.Add(
                        CreateReference(
                            "HasProperty",
                            CreateProperty(shell.idShort, "PropertyType", "idShort", "String")));
                }

                if (shell.identification != null)
                {
                    refs.Add(
                        CreateReference(
                            "HasComponent",
                            CreateIdentifiableIdentification(
                                shell.identification.id, shell.identification.idType)));
                }

                if (shell.hasDataSpecification != null)
                {
                    refs.Add(CreateReference("HasComponent", CreateHasDataSpecification(shell.hasDataSpecification)));
                }

                if (shell.assetRef != null)
                {
                    refs.Add(CreateReference("HasComponent", CreateAssetRef(shell.assetRef)));
                }
            }

            sub.References = refs.ToArray();
            root.Add((UANode)sub);
            return(sub.NodeId);
        }
Esempio n. 16
0
        public void Simple()
        {
            using var tempDir = TempDir.Create();
            CopyXls("simple-class.xls", Path.Combine(tempDir.Path, GetExportFileName("class", "simple")));
            CopyXls("simple-property.xls", Path.Combine(tempDir.Path, GetExportFileName("property", "simple")));

            var dataProvider = new DataProvider();
            var source       = dataProvider.OpenPath(tempDir.Path);
            var context      = source.Load();

            var submodels = context.LoadSubmodels();

            Assert.That(submodels.Select(c => new[] { c.Id, c.Name }), Is.EqualTo(new[] {
                new[] { "C1", "Main test class" },
                new[] { "C2", "Block 1" },
                new[] { "C3", "Block 2" },
            }));

            var submodelElements = context.LoadSubmodelElements();

            Assert.That(submodelElements.Select(c => new[] { c.Id, c.Name }), Is.EquivalentTo(new[] {
                new[] { "C1", "Main test class" },
                new[] { "C2", "Block 1" },
                new[] { "C3", "Block 2" },
                // P1: "Block reference 1 is resolved to:
                new[] { "C2", "Block 1" },
                // P2: "Block reference 2 is resolved to:
                new[] { "C3", "Block 2" },
                new[] { "P3", "Test property 1" },
                new[] { "P4", "Test property 2" },
            }));

            var env        = new AdminShellV20.AdministrationShellEnv();
            var adminShell = CreateAdminShell(env);

            var p3 = submodelElements.First(e => e.Id == "P3");

            p3.IsSelected = true;
            Assert.That(!p3.ImportSubmodelInto(env, adminShell));
            Assert.That(adminShell.submodelRefs, Has.Count.Zero);

            var c1       = submodels.First(e => e.Id == "C1");
            var children = c1.Children;

            Assert.That(children.Count, Is.EqualTo(2));

            SetSelected(c1, true);
            Assert.That(c1.ImportSubmodelInto(env, adminShell));
            Assert.That(adminShell.submodelRefs, Has.Count.EqualTo(1));
            var submodel = env.FindSubmodel(adminShell.submodelRefs[0]);

            Assert.That(submodel.idShort, Is.EqualTo("MainTestClass"));
            Assert.That(submodel.submodelElements, Is.Not.Null);
            Assert.That(submodel.submodelElements, Has.Count.EqualTo(2));

            var c2 = submodel.submodelElements[0].submodelElement;

            Assert.That(c2, Is.TypeOf <AdminShellV20.SubmodelElementCollection>());
            Assert.That(c2.idShort, Is.EqualTo("Block1"));
            if (!(c2 is AdminShellV20.SubmodelElementCollection c2Coll))
            {
                return;
            }
            Assert.That(c2Coll.value, Has.Count.EqualTo(1));

            var p3Element = c2Coll.value[0].submodelElement;

            Assert.That(p3Element, Is.TypeOf <AdminShellV20.Property>());
            Assert.That(p3Element.idShort, Is.EqualTo("TestProperty1"));
            // TODO (Robin, 2020-09-03): please check
            // dead-csharp off
            // Assert.That(p3Element.hasDataSpecification, Is.Not.Null);
            // Assert.That(p3Element.hasDataSpecification, Has.Count.EqualTo(1));
            // dead-csharp on

            var c3 = submodel.submodelElements[1].submodelElement;

            Assert.That(c3, Is.TypeOf <AdminShellV20.SubmodelElementCollection>());
            Assert.That(c3.idShort, Is.EqualTo("Block2"));
            if (!(c3 is AdminShellV20.SubmodelElementCollection c3Coll))
            {
                return;
            }
            Assert.That(c3Coll.value, Has.Count.EqualTo(1));

            var p4Element = c3Coll.value[0].submodelElement;

            Assert.That(p4Element, Is.TypeOf <AdminShellV20.Property>());
            Assert.That(p4Element.idShort, Is.EqualTo("TestProperty2"));
            // TODO (Robin, 2020-09-03): please check
            // dead-csharp off
            // Assert.That(p4Element.hasDataSpecification, Is.Not.Null);
            // Assert.That(p4Element.hasDataSpecification, Has.Count.EqualTo(1));
            // dead-csharp on
        }
Esempio n. 17
0
 public virtual bool ImportSubmodelInto(AdminShellV20.AdministrationShellEnv env,
                                        AdminShellV20.AdministrationShell adminShell) => false;