示例#1
0
        public IActionResult GetAASXPackage()
        {
            string filename = shellServiceProvider.AssetAdministrationShell.IdShort + ".aasx";

            using (AASX aasx = new AASX(filename))
            {
                AssetAdministrationShellEnvironment_V2_0 env = new AssetAdministrationShellEnvironment_V2_0(shellServiceProvider.AssetAdministrationShell);
                aasx.AddEnvironment(shellServiceProvider.AssetAdministrationShell.Identification, env, ExportType.Xml);

                if (aasx != null)
                {
                    IFileProvider fileProvider = hostingEnvironment.ContentRootFileProvider;
                    foreach (var item in fileProvider.GetDirectoryContents("Content/aasx"))
                    {
                        if (item.IsDirectory)
                        {
                            foreach (var subItem in fileProvider.GetDirectoryContents("Content/aasx/" + item.Name))
                            {
                                if (subItem.Exists)
                                {
                                    aasx.AddFileToAASX("/aasx/" + item.Name + "/" + subItem.Name, subItem.PhysicalPath);
                                }
                            }
                        }
                        else
                        {
                            if (item.Exists)
                            {
                                aasx.AddFileToAASX("/aasx/" + item.Name, item.PhysicalPath);
                            }
                        }
                    }

                    var fileInfo   = fileProvider.GetFileInfo(filename);
                    var fileResult = new PhysicalFileResult(fileInfo.PhysicalPath, "application/asset-administration-shell-package")
                    {
                        FileDownloadName = filename
                    };
                    return(fileResult);
                }
            }
            return(new BadRequestResult());
        }
示例#2
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");
        }