Esempio n. 1
0
        public void AAS_Submodel_SerializedToAspectObject()
        {
            var aasEnvironment = new AasEnv();
            //var shell = aasEnvironment.AssetAdministrationShells.Elements.First( shell => shell.IdShort == "shellGlobalId");
            var submodel = aasEnvironment.Submodels.First(s => s.Identification.Text == "aspectModelSemanticId");

            var aspectModel    = AasImfMapper.ToAspectModel(submodel);
            var aspectObjects  = aspectModel.AspectObjects;
            var locationObject = aspectObjects.First(a => a.Id == "aspectObjectGlobalId");

            Assert.Equal("locationTypeUrl", locationObject.RDLType.Url);

            Assert.Equal(locationObject.RDLType.Aspect, locationObject.Aspect);
        }
Esempio n. 2
0
        public void AAS_Multiple_Submodel_Builds_Tree()
        {
            var aasEnvironment = new AasEnv();
            var shell          = aasEnvironment.AssetAdministrationShells.First(shell => shell.IdShort == "shellGlobalId");
            var submodels      = aasEnvironment.Submodels.Where(s => s.Identification.Text == "aspectModelSemanticId").Take(2);

            var aspectModels = new List <AspectModel>();

            foreach (var submodel in submodels)
            {
                var aspectModel = AasImfMapper.ToAspectModel(submodel);
                aspectModels.Add(aspectModel);
            }

            var mergedModel = ImfMerger.Merge(aspectModels); // params AspectModels[] models

            Assert.Equal(
                mergedModel.AspectObjects.First(a => a.Id == "childId").Parent,
                mergedModel.AspectObjects.First(a => a.Id == "parentId"));
        }
 public static string Serialize(AasEnv xml)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
        public ActionResult GenerateAAS()
        {
            try
            {
                string packagePath = Path.Combine(Directory.GetCurrentDirectory(), "DTDL.aasx");
                using (Package package = Package.Open(packagePath, FileMode.Create))
                {
                    // add package origin part
                    PackagePart origin = package.CreatePart(new Uri("/aasx/aasx-origin", UriKind.Relative), MediaTypeNames.Text.Plain, CompressionOption.Maximum);
                    using (Stream fileStream = origin.GetStream(FileMode.Create))
                    {
                        var bytes = Encoding.ASCII.GetBytes("Intentionally empty.");
                        fileStream.Write(bytes, 0, bytes.Length);
                    }
                    package.CreateRelationship(origin.Uri, TargetMode.Internal, "http://www.admin-shell.io/aasx/relationships/aasx-origin");

                    // create package spec part
                    string packageSpecPath = Path.Combine(Directory.GetCurrentDirectory(), "aasenv-with-no-id.aas.xml");
                    using (StringReader reader = new StringReader(System.IO.File.ReadAllText(packageSpecPath)))
                    {
                        XmlSerializer aasSerializer = new XmlSerializer(typeof(AasEnv));
                        AasEnv        aasEnv        = (AasEnv)aasSerializer.Deserialize(reader);

                        aasEnv.AssetAdministrationShells.AssetAdministrationShell.SubmodelRefs.Clear();
                        aasEnv.Submodels.Clear();

                        foreach (string filenamePath in Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "JSON"), "*.dtdl.json"))
                        {
                            string submodelPath = Path.Combine(Directory.GetCurrentDirectory(), "submodel.adt.xml");
                            using (StringReader reader2 = new StringReader(System.IO.File.ReadAllText(submodelPath)))
                            {
                                XmlSerializer aasSubModelSerializer = new XmlSerializer(typeof(AASSubModel));
                                AASSubModel   aasSubModel           = (AASSubModel)aasSubModelSerializer.Deserialize(reader2);

                                SubmodelRef nodesetReference = new SubmodelRef();
                                nodesetReference.Keys     = new Keys();
                                nodesetReference.Keys.Key = new Key
                                {
                                    IdType = "URI",
                                    Local  = true,
                                    Type   = "Submodel",
                                    Text   = "http://www.microsoft.com/type/dtdl/" + Path.GetFileNameWithoutExtension(filenamePath).Replace(".", "").ToLower()
                                };

                                aasEnv.AssetAdministrationShells.AssetAdministrationShell.SubmodelRefs.Add(nodesetReference);

                                aasSubModel.Identification.Text += Path.GetFileNameWithoutExtension(filenamePath).Replace(".", "").ToLower();
                                aasSubModel.SubmodelElements.SubmodelElement.SubmodelElementCollection.Value.SubmodelElement.File.Value =
                                    aasSubModel.SubmodelElements.SubmodelElement.SubmodelElementCollection.Value.SubmodelElement.File.Value.Replace("TOBEREPLACED", Path.GetFileNameWithoutExtension(filenamePath));
                                aasEnv.Submodels.Add(aasSubModel);
                            }
                        }

                        XmlTextWriter aasWriter = new XmlTextWriter(packageSpecPath, Encoding.UTF8);
                        aasSerializer.Serialize(aasWriter, aasEnv);
                        aasWriter.Close();
                    }

                    // add package spec part
                    PackagePart spec = package.CreatePart(new Uri("/aasx/aasenv-with-no-id/aasenv-with-no-id.aas.xml", UriKind.Relative), MediaTypeNames.Text.Xml);
                    using (FileStream fileStream = new FileStream(packageSpecPath, FileMode.Open, FileAccess.Read))
                    {
                        CopyStream(fileStream, spec.GetStream());
                    }
                    origin.CreateRelationship(spec.Uri, TargetMode.Internal, "http://www.admin-shell.io/aasx/relationships/aas-spec");

                    // add DTDL files
                    foreach (string filenamePath in Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "JSON"), "*.dtdl.json"))
                    {
                        PackagePart supplementalDoc = package.CreatePart(new Uri("/aasx/" + Path.GetFileNameWithoutExtension(filenamePath), UriKind.Relative), MediaTypeNames.Application.Json);
                        using (FileStream fileStream = new FileStream(filenamePath, FileMode.Open, FileAccess.Read))
                        {
                            CopyStream(fileStream, supplementalDoc.GetStream());
                        }
                        package.CreateRelationship(supplementalDoc.Uri, TargetMode.Internal, "http://www.admin-shell.io/aasx/relationships/aas-suppl");
                    }
                }

                return(File(new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "DTDL.aasx"), FileMode.Open, FileAccess.Read), "APPLICATION/octet-stream", "DTDL.aasx"));
            }
            catch (Exception ex)
            {
                ADTModel model = new ADTModel
                {
                    StatusMessage = HttpUtility.HtmlDecode(ex.Message)
                };

                return(View("Index", model));
            }
        }