Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            AssetAdministrationShell aas = SimpleAssetAdministrationShell.GetAssetAdministrationShell();
            ISubmodel testSubmodel       = aas.Submodels["TestSubmodel"];

            ServerSettings submodelServerSettings = ServerSettings.CreateSettings();

            submodelServerSettings.ServerConfig.Hosting.ContentPath = "Content";
            submodelServerSettings.ServerConfig.Hosting.Urls.Add("http://localhost:5222");

            SubmodelHttpServer       submodelServer          = new SubmodelHttpServer(submodelServerSettings);
            ISubmodelServiceProvider submodelServiceProvider = testSubmodel.CreateServiceProvider();

            submodelServer.SetServiceProvider(submodelServiceProvider);
            submodelServiceProvider.UseAutoEndpointRegistration(submodelServerSettings.ServerConfig);
            Task runSubmodelTask = submodelServer.RunAsync();

            ServerSettings aasServerSettings = ServerSettings.CreateSettings();

            aasServerSettings.ServerConfig.Hosting.ContentPath = "Content";
            aasServerSettings.ServerConfig.Hosting.Urls.Add("http://localhost:5111");

            IAssetAdministrationShellServiceProvider serviceProvider = aas.CreateServiceProvider(true);

            serviceProvider.SubmodelRegistry.RegisterSubmodelServiceProvider(testSubmodel.IdShort, submodelServiceProvider);
            serviceProvider.UseAutoEndpointRegistration(aasServerSettings.ServerConfig);

            AssetAdministrationShellHttpServer aasServer = new AssetAdministrationShellHttpServer(aasServerSettings);

            aasServer.SetServiceProvider(serviceProvider);
            aasServer.Run();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            logger.Info("Starting Asset Administration Shell's HTTP-REST interface...");

            //Loading server configurations settings from ServerSettings.xml;
            ServerSettings serverSettings = ServerSettings.LoadSettingsFromFile("ServerSettings.xml");

            //Initialize generic HTTP-REST interface passing previously loaded server configuration
            AssetAdministrationShellHttpServer aasServer = new AssetAdministrationShellHttpServer(serverSettings);

            //Instantiate Asset Administration Shell Service
            HelloAssetAdministrationShellService shellService = new HelloAssetAdministrationShellService();

            //Dictate Asset Administration Shell service to use provided endpoints from the server configuration
            shellService.UseAutoEndpointRegistration(serverSettings.ServerConfig);

            //Assign Asset Administration Shell Service to the generic HTTP-REST interface
            aasServer.SetServiceProvider(shellService);

            //Run HTTP-REST interface
            aasServer.Run();
        }
Exemplo n.º 3
0
        private static void LoadSingleShell()
        {
            AssetAdministrationShell aas = SimpleAssetAdministrationShell.SimpleAssetAdministrationShell.GetAssetAdministrationShell();
            ISubmodel testSubmodel       = aas.Submodels["TestSubmodel"];

            ServerSettings submodelServerSettings = ServerSettings.CreateSettings();

            submodelServerSettings.ServerConfig.Hosting.ContentPath = "Content";
            submodelServerSettings.ServerConfig.Hosting.Urls.Add("http://localhost:5222");

            SubmodelHttpServer       submodelServer          = new SubmodelHttpServer(submodelServerSettings);
            ISubmodelServiceProvider submodelServiceProvider = testSubmodel.CreateServiceProvider();

            submodelServer.SetServiceProvider(submodelServiceProvider);
            submodelServiceProvider.UseAutoEndpointRegistration(submodelServerSettings.ServerConfig);
            submodelServer.RunAsync();

            ServerSettings aasServerSettings = ServerSettings.CreateSettings();

            aasServerSettings.ServerConfig.Hosting.ContentPath = "Content";
            aasServerSettings.ServerConfig.Hosting.Urls.Add("http://localhost:5111");

            IAssetAdministrationShellServiceProvider aasServiceProvider = aas.CreateServiceProvider(true);

            aasServiceProvider.SubmodelRegistry.RegisterSubmodelServiceProvider(testSubmodel.IdShort, submodelServiceProvider);
            aasServiceProvider.UseAutoEndpointRegistration(aasServerSettings.ServerConfig);

            AssetAdministrationShellHttpServer aasServer = new AssetAdministrationShellHttpServer(aasServerSettings);

            aasServer.SetServiceProvider(aasServiceProvider);
            aasServer.ApplicationStopping = () => { registryClient.DeleteAssetAdministrationShell(aas.Identification.Id); };
            aasServer.RunAsync();

            registryClient.CreateAssetAdministrationShell(new AssetAdministrationShellDescriptor(aas, aasServiceProvider.ServiceDescriptor.Endpoints));
            registryClient.CreateSubmodel(aas.Identification.Id, new SubmodelDescriptor(testSubmodel, submodelServiceProvider.ServiceDescriptor.Endpoints));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            logger.Info("Starting AASX Hoster...");

            if (args?.Length == 0)
            {
                logger.Error("No arguments provided --> Application is shutting down...");
                return;
            }
            if (!string.IsNullOrEmpty(args[0]) && File.Exists(args[0]))
            {
                IAssetAdministrationShell          shell;
                AssetAdministrationShellHttpServer server = new AssetAdministrationShellHttpServer();

                using (BaSyx.Models.Export.AASX aasx = new BaSyx.Models.Export.AASX(args[0]))
                {
                    AssetAdministrationShellEnvironment_V2_0 environment = aasx.GetEnvironment_V2_0();
                    shell = environment.AssetAdministrationShells.FirstOrDefault();
                    if (shell == null)
                    {
                        logger.Error("Asset Administration Shell cannot be obtained from AASX-Package " + args[0]);
                        return;
                    }
                    else
                    {
                        logger.Info("AASX-Package successfully loaded");

                        var service = shell.CreateServiceProvider(true);
                        List <HttpEndpoint> endpoints;
                        if (args.Length == 2 && !string.IsNullOrEmpty(args[1]))
                        {
                            logger.Info("Using " + args[1] + " as host url");
                            endpoints = new List <HttpEndpoint>()
                            {
                                new HttpEndpoint(args[1])
                            };
                        }
                        else
                        {
                            endpoints = server.Settings.ServerConfig.Hosting.Urls.ConvertAll(c =>
                            {
                                string address = c.Replace("+", "127.0.0.1");
                                logger.Info("Using " + address + " as host url");
                                return(new HttpEndpoint(address));
                            });
                        }
                        service.UseDefaultEndpointRegistration(endpoints);
                        server.SetServiceProvider(service);

                        server.ConfigureServices(services =>
                        {
                            Assembly controllerAssembly = Assembly.Load("BaSyx.API.Http.Controllers.AASX");
                            services.AddMvc()
                            .AddApplicationPart(controllerAssembly)
                            .AddControllersAsServices();
                        });

                        foreach (var file in aasx.SupplementaryFiles)
                        {
                            using (Stream stream = file.GetStream())
                            {
                                logger.Info("Providing content on server: " + file.Uri);
                                server.ProvideContent(file.Uri, stream);
                            }
                        }
                        logger.Info("Server is starting up...");
                        server.Run();
                    }
                }
            }
            logger.Info("Application shut down");
        }