Ejemplo 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();
        }
 public void SetServiceProvider(IAssetAdministrationShellServiceProvider aasServiceProvider)
 {
     WebHostBuilder.ConfigureServices(services =>
     {
         services.AddSingleton <IAssetAdministrationShellServiceProvider>(aasServiceProvider);
     });
 }
Ejemplo n.º 3
0
        public static void UseDefaultEndpointRegistration(this IAssetAdministrationShellServiceProvider serviceProvider, IEnumerable <IEndpoint> endpoints)
        {
            List <IEndpoint> aasEndpoints = new List <IEndpoint>();

            foreach (var endpoint in endpoints)
            {
                string epAddress = endpoint.Address;
                if (!epAddress.EndsWith("/aas"))
                {
                    epAddress = epAddress + (epAddress.EndsWith("/") ? "" : "/") + "aas";
                }

                aasEndpoints.Add(EndpointFactory.CreateEndpoint(endpoint.Type, epAddress, endpoint.Security));
            }

            serviceProvider.ServiceDescriptor.AddEndpoints(aasEndpoints);
            var aasDescriptor = serviceProvider.ServiceDescriptor;

            foreach (var submodel in aasDescriptor.SubmodelDescriptors)
            {
                List <IEndpoint> spEndpoints = new List <IEndpoint>();
                foreach (var endpoint in aasEndpoints)
                {
                    var ep = EndpointFactory.CreateEndpoint(endpoint.Type, GetSubmodelEndpoint(endpoint, submodel.IdShort), endpoint.Security);
                    spEndpoints.Add(ep);
                }
                submodel.AddEndpoints(spEndpoints);
            }
        }
 public void RegisterAssetAdministrationShellServiceProvider(string id, IAssetAdministrationShellServiceProvider assetAdministrationShellServiceProvider)
 {
     if (!AssetAdministrationShellServiceProviders.ContainsKey(id))
     {
         AssetAdministrationShellServiceProviders.Add(id, assetAdministrationShellServiceProvider);
     }
 }
        public IResult <IAssetAdministrationShell> RetrieveAssetAdministrationShell(string aasId)
        {
            IAssetAdministrationShellServiceProvider serviceProvider = GetAssetAdministrationShellServiceProvider(aasId);

            if (serviceProvider != null && serviceProvider.GetBinding() != null)
            {
                IAssetAdministrationShell binding = serviceProvider.GetBinding();
                return(new Result <IAssetAdministrationShell>(true, binding));
            }
            return(new Result <IAssetAdministrationShell>(false, new NotFoundMessage("Asset Administration Shell Service Provider")));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Starts mDNS dicovery for an Asset Administration Shell Service Provider with a list of given IP-addresses and a port
 /// </summary>
 /// <param name="serviceProvider">The Asset Administration Shell Service Provider</param>
 /// <param name="port">The port to advertise</param>
 /// <param name="iPAddresses">A list of IP-addresses to advertise, if empty uses locally dicoverable multicast IP addresses</param>
 public static void StartDiscovery(this IAssetAdministrationShellServiceProvider serviceProvider, int port, IEnumerable <IPAddress> iPAddresses)
 {
     discoveryClient = new DiscoveryClient(serviceProvider.ServiceDescriptor.IdShort, (ushort)port, ServiceTypes.AAS_SERVICE_TYPE, iPAddresses);
     discoveryClient.AddProperty(ASSETADMINISTRATIONSHELL_ID, serviceProvider.ServiceDescriptor.Identification.Id);
     discoveryClient.AddProperty(ASSETADMINISTRATIONSHELL_IDSHORT, serviceProvider.ServiceDescriptor.IdShort);
     foreach (var endpoint in serviceProvider.ServiceDescriptor.Endpoints)
     {
         discoveryClient.AddProperty(ASSETADMINISTRATIONSHELL_ENDPOINT + "." + endpoint.Type, endpoint.Address + "aas");
     }
     discoveryClient.Start();
 }
Ejemplo n.º 7
0
        public static void UseAutoEndpointRegistration(this IAssetAdministrationShellServiceProvider serviceProvider, ServerConfiguration serverConfiguration)
        {
            string multiUrl = serverConfiguration.Hosting.Urls.Find(u => u.Contains("+"));

            if (!string.IsNullOrEmpty(multiUrl))
            {
                Uri uri = new Uri(multiUrl.Replace("+", "localhost"));
                List <IEndpoint> endpoints = GetNetworkInterfaceBasedEndpoints(uri.Scheme, uri.Port);
                serviceProvider.UseDefaultEndpointRegistration(endpoints);
            }
            else
            {
                List <IEndpoint> endpoints = serverConfiguration.Hosting.Urls.ConvertAll(EndpointConverter);
                serviceProvider.UseDefaultEndpointRegistration(endpoints);
            }
        }
        public IResult <IAssetAdministrationShell> CreateAssetAdministrationShell(IAssetAdministrationShell aas)
        {
            if (aas == null)
            {
                return(new Result <IAssetAdministrationShell>(new ArgumentNullException(nameof(aas))));
            }
            RegisterAssetAdministrationShellServiceProvider(aas.IdShort, aas.CreateServiceProvider(true));

            IAssetAdministrationShellServiceProvider serviceProvider = GetAssetAdministrationShellServiceProvider(aas.IdShort);

            if (serviceProvider != null && serviceProvider.GetBinding() != null)
            {
                return(new Result <IAssetAdministrationShell>(true, serviceProvider.GetBinding()));
            }
            else
            {
                return(new Result <IAssetAdministrationShell>(false, new Message(MessageType.Error, "Could not retrieve Asset Administration Shell Service Provider")));
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Starts mDNS dicovery for an Asset Administration Shell Service Provider with included endpoints in its Service Descriptor
        /// </summary>
        /// <param name="serviceProvider">The Asset Administration Shell Service Provider</param>
        public static void StartDiscovery(this IAssetAdministrationShellServiceProvider serviceProvider)
        {
            List <IPAddress> ipAddresses = new List <IPAddress>();
            int port = -1;

            foreach (var endpoint in serviceProvider.ServiceDescriptor.Endpoints)
            {
                Uri uriEndpoint = new Uri(endpoint.Address);
                if (port == -1)
                {
                    port = uriEndpoint.Port;
                }

                if (IPAddress.TryParse(uriEndpoint.Host, out IPAddress address))
                {
                    ipAddresses.Add(address);
                }
            }
            StartDiscovery(serviceProvider, port, ipAddresses);
        }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        public static IResult <IAssetAdministrationShellDescriptor> RegisterAssetAdministrationShell(this IAssetAdministrationShellServiceProvider serviceProvider, RegistryClientSettings settings)
        {
            RegistryHttpClient registryHttpClient = new RegistryHttpClient(settings);

            if (registryHttpClient.Settings?.RegistryConfig?.RepeatRegistration != null)
            {
                registryHttpClient.RepeatRegistration(serviceProvider.ServiceDescriptor, new CancellationTokenSource());
            }

            IResult <IAssetAdministrationShellDescriptor> result = registryHttpClient.CreateAssetAdministrationShell(serviceProvider.ServiceDescriptor);

            return(result);
        }
Ejemplo n.º 12
0
 public static IResult <IAssetAdministrationShellDescriptor> RegisterAssetAdministrationShell(this IAssetAdministrationShellServiceProvider serviceProvider) => RegisterAssetAdministrationShell(serviceProvider, null);
Ejemplo n.º 13
0
 public IndexModel(IAssetAdministrationShellServiceProvider provider, ServerSettings serverSettings)
 {
     ServiceProvider = provider;
     Settings        = serverSettings;
 }
Ejemplo n.º 14
0
 public static void StopDiscovery(this IAssetAdministrationShellServiceProvider serviceProvider)
 {
     discoveryClient.Stop();
 }
Ejemplo n.º 15
0
 public PackageService(IAssetAdministrationShellServiceProvider aasServiceProvider, IHostingEnvironment environment)
 {
     shellServiceProvider = aasServiceProvider;
     hostingEnvironment   = environment;
 }
Ejemplo n.º 16
0
 public void RegisterAssetAdministrationShellServiceProvider(string id, IAssetAdministrationShellServiceProvider assetAdministrationShellServiceProvider)
 {
     repository.RegisterAssetAdministrationShellServiceProvider(id, assetAdministrationShellServiceProvider);
 }
Ejemplo n.º 17
0
 public AssetAdministrationShellServices(IAssetAdministrationShellServiceProvider assetAdministrationShellServiceProvider)
 {
     this.assetAdministrationShellServiceProvider = assetAdministrationShellServiceProvider;
     ServiceDescriptor = assetAdministrationShellServiceProvider.ServiceDescriptor;
 }
Ejemplo n.º 18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddStandardImplementation();

            Assembly controllerAssembly = Assembly.Load(ControllerAssemblyName);

            services.AddCors();
            services.AddMvc()
            .AddApplicationPart(controllerAssembly)
            .AddControllersAsServices()
            .AddNewtonsoftJson(options => options.GetDefaultMvcJsonOptions(services));

            services.AddRazorPages(options =>
            {
                string pageName = ServerSettings.ServerConfig?.DefaultRoute ?? "/Index";
                options.Conventions.AddPageRoute(pageName, "");
            });

            //Check whether Asset Administration Shell Service Provider exists and bind it to the AssetAdministrationShell-Services-Controller
            services.AddTransient <IAssetAdministrationShellServiceProvider>(ctx =>
            {
                IAssetAdministrationShellServiceProvider aasServiceProvider = ctx
                                                                              .GetRequiredService <IAssetAdministrationShellRepositoryServiceProvider>()
                                                                              .GetAssetAdministrationShellServiceProvider(aasId);

                return(new AssetAdministrationShellServices(aasServiceProvider));
            });


            //Check whether Submodel Service Provider exists and bind it to the Submodel-Services-Controller
            services.AddTransient <ISubmodelServiceProvider>(ctx =>
            {
                IAssetAdministrationShellServiceProvider aasServiceProvider = ctx
                                                                              .GetRequiredService <IAssetAdministrationShellRepositoryServiceProvider>()
                                                                              .GetAssetAdministrationShellServiceProvider(aasId);

                var submodelServiceProvider = aasServiceProvider.SubmodelRegistry.GetSubmodelServiceProvider(submodelId);
                if (!submodelServiceProvider.Success || submodelServiceProvider.Entity == null)
                {
                    SubmodelServiceProvider cssp = new SubmodelServiceProvider();
                    return(new SubmodelServices(cssp));
                }
                else
                {
                    return(new SubmodelServices(submodelServiceProvider.Entity));
                }
            });

            // Register the Swagger generator, defining one or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version     = "v1",
                    Title       = "BaSyx Asset Administration Shell Repository HTTP REST-API",
                    Description = "The full description of the generic BaSyx Asset Administration Shell Repository HTTP REST-API",
                    Contact     = new OpenApiContact {
                        Name = "Constantin Ziesche", Email = "*****@*****.**", Url = new Uri("https://www.bosch.com/de/")
                    },
                    License = new OpenApiLicense {
                        Name = "EPL-2.0", Url = new Uri("https://www.eclipse.org/legal/epl-2.0/")
                    }
                });

                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{controllerAssembly.GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                if (ResourceChecker.CheckResourceAvailability(controllerAssembly, ControllerAssemblyName, xmlFile, true))
                {
                    c.IncludeXmlComments(xmlPath);
                }
            });
            services.AddSwaggerGenNewtonsoftSupport();
        }