Exemple #1
0
        static void Main(string[] args)
        {
            ServerSettings aasRepositorySettings = ServerSettings.CreateSettings();

            aasRepositorySettings.ServerConfig.Hosting.ContentPath = "Content";
            aasRepositorySettings.ServerConfig.Hosting.Urls.Add("http://+:5999");

            MultiAssetAdministrationShellHttpServer           server            = new MultiAssetAdministrationShellHttpServer(aasRepositorySettings);
            AssetAdministrationShellRepositoryServiceProvider repositoryService = new AssetAdministrationShellRepositoryServiceProvider();

            for (int i = 0; i < 10; i++)
            {
                AssetAdministrationShell aas = new AssetAdministrationShell()
                {
                    IdShort        = "MultiAAS_" + i,
                    Identification = new Identifier("http://basys40.de/shells/MultiAAS/" + Guid.NewGuid().ToString(), KeyType.IRI),
                    Description    = new LangStringSet()
                    {
                        new LangString("de-DE", i + ". VWS"),
                        new LangString("en-US", i + ". AAS")
                    },
                    Administration = new AdministrativeInformation()
                    {
                        Version  = "1.0",
                        Revision = "120"
                    },
                    Asset = new Asset()
                    {
                        IdShort        = "Asset_" + i,
                        Identification = new Identifier("http://basys40.de/assets/MultiAsset/" + Guid.NewGuid().ToString(), KeyType.IRI),
                        Kind           = AssetKind.Instance,
                        Description    = new LangStringSet()
                        {
                            new LangString("de-DE", i + ". Asset"),
                            new LangString("en-US", i + ". Asset")
                        }
                    }
                };

                aas.Submodels.Create(new Submodel()
                {
                    Identification   = new Identifier("http://basys40.de/submodels/" + Guid.NewGuid().ToString(), KeyType.IRI),
                    IdShort          = "TestSubmodel",
                    SubmodelElements = new ElementContainer <ISubmodelElement>()
                    {
                        new Property <string>()
                        {
                            IdShort = "Property_" + i
                        }
                    }
                });

                var aasServiceProvider = aas.CreateServiceProvider(true);
                repositoryService.RegisterAssetAdministrationShellServiceProvider(aas.IdShort, aasServiceProvider);
            }

            List <HttpEndpoint> endpoints = server.Settings.ServerConfig.Hosting.Urls.ConvertAll(c => new HttpEndpoint(c.Replace("+", "127.0.0.1")));

            repositoryService.UseDefaultEndpointRegistration(endpoints);

            server.SetServiceProvider(repositoryService);
            server.Run();
        }
Exemple #2
0
        private static void LoadMultipleShells()
        {
            ServerSettings aasRepositorySettings = ServerSettings.CreateSettings();

            aasRepositorySettings.ServerConfig.Hosting.ContentPath = "Content";
            aasRepositorySettings.ServerConfig.Hosting.Urls.Add("http://+:5999");

            MultiAssetAdministrationShellHttpServer           multiServer       = new MultiAssetAdministrationShellHttpServer(aasRepositorySettings);
            AssetAdministrationShellRepositoryServiceProvider repositoryService = new AssetAdministrationShellRepositoryServiceProvider();

            for (int i = 0; i < 3; i++)
            {
                AssetAdministrationShell aas = new AssetAdministrationShell()
                {
                    IdShort        = "MultiAAS_" + i,
                    Identification = new Identifier("http://basyx.de/shells/MultiAAS/" + i, KeyType.IRI),
                    Description    = new LangStringSet()
                    {
                        new LangString("de-DE", i + ". VWS"),
                        new LangString("en-US", i + ". AAS")
                    },
                    Administration = new AdministrativeInformation()
                    {
                        Version  = "1.0",
                        Revision = "120"
                    },
                    Asset = new Asset()
                    {
                        IdShort        = "Asset_" + i,
                        Identification = new Identifier("http://basyx.de/assets/MultiAsset/" + i, KeyType.IRI),
                        Kind           = AssetKind.Instance,
                        Description    = new LangStringSet()
                        {
                            new LangString("de-DE", i + ". Asset"),
                            new LangString("en-US", i + ". Asset")
                        }
                    }
                };

                aas.Submodels.Create(new Submodel()
                {
                    Identification   = new Identifier("http://basyx.de/submodels/" + i, KeyType.IRI),
                    IdShort          = "TestSubmodel",
                    SubmodelElements = new ElementContainer <ISubmodelElement>()
                    {
                        new Property <string>()
                        {
                            IdShort = "Property_" + i,
                            Value   = "TestValue_" + i
                        },
                        new SubmodelElementCollection()
                        {
                            IdShort = "Coll_" + i,
                            Value   = new ElementContainer <ISubmodelElement>()
                            {
                                new Property <string>()
                                {
                                    IdShort = "SubProperty_" + i,
                                    Value   = "TestSubValue_" + i
                                }
                            }
                        }
                    }
                });

                var aasServiceProvider = aas.CreateServiceProvider(true);
                repositoryService.RegisterAssetAdministrationShellServiceProvider(aas.IdShort, aasServiceProvider);
            }

            List <HttpEndpoint> endpoints = multiServer.Settings.ServerConfig.Hosting.Urls.ConvertAll(c => new HttpEndpoint(c.Replace("+", "127.0.0.1")));

            repositoryService.UseDefaultEndpointRegistration(endpoints);

            multiServer.SetServiceProvider(repositoryService);
            multiServer.ApplicationStopping = () =>
            {
                foreach (var aasDescriptor in repositoryService.ServiceDescriptor.AssetAdministrationShellDescriptors)
                {
                    registryClient.DeleteAssetAdministrationShell(aasDescriptor.Identification.Id);
                }
            };

            multiServer.RunAsync();

            foreach (var aasDescriptor in repositoryService.ServiceDescriptor.AssetAdministrationShellDescriptors)
            {
                registryClient.CreateAssetAdministrationShell(aasDescriptor);
            }
        }