public static void Main(string[] args) { try { int workerThreads; int completionPortThreads; System.Threading.ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads); if (workerThreads < 16) { workerThreads = 16; System.Threading.ThreadPool.SetMinThreads(workerThreads, completionPortThreads); } IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .AddCommandLine(args); IConfigurationRoot configuration = builder.Build(); ServiceConfiguration.LoadConfig(configuration.GetSection("ServiceConfiguration")); Version version = Assembly.GetExecutingAssembly().GetName().Version; Console.Write("Subscription ("); Console.Write(version.ToString()); Console.WriteLine(")"); ServiceConfiguration.DisplayConfig(); BusinessLogicFactory.Subscriptions.StartListening(); ApplicationEventLog.LogLevel = System.Diagnostics.EventLogEntryType.Information; _ShutdownEvent = new ManualResetEvent(false); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { _ShutdownEvent.Set(); e.Cancel = true; }; Console.WriteLine("Press Ctrl+C to stop the server."); _ShutdownEvent.WaitOne(); Console.WriteLine("Exiting."); BusinessLogicFactory.ServiceMessages.Stop(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <JwtBearerOptions> authOptions) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseJwtBearerAuthentication(authOptions.Value); #if DEBUG app.UseCors("allowEveryThingPolicy"); #endif app.UseStaticFiles(); app.UseMvc(); ServiceConfiguration.DisplayConfig(); }
public static void Main(string[] args) { try { int workerThreads; int completionPortThreads; System.Threading.ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads); if (workerThreads < 16) { workerThreads = 16; System.Threading.ThreadPool.SetMinThreads(workerThreads, completionPortThreads); } IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .AddCommandLine(args); IConfigurationRoot configuration = builder.Build(); ServiceConfiguration.LoadConfig(configuration.GetSection("ServiceConfiguration")); int port = 15683; bool secureOnly = true; IConfigurationSection section = configuration.GetSection("LWM2MBootstrap"); if (section != null) { section = section.GetSection("Port"); if (section != null) { if (!int.TryParse(section.Value, out port)) { port = 15683; } } section = section.GetSection("SecureOnly"); if (section != null) { if (!bool.TryParse(section.Value, out secureOnly)) { secureOnly = true; } } } Version version = Assembly.GetExecutingAssembly().GetName().Version; Console.Write("LWM2M Bootstrap ("); Console.Write(version.ToString()); Console.WriteLine(")"); if (ServiceConfiguration.ExternalUri == null) { ServiceConfiguration.ExternalUri = new Uri(string.Concat("coaps://", ServiceConfiguration.Hostname, ":", (port + 1).ToString())); } ServiceConfiguration.DisplayConfig(); BusinessLogicFactory.Initialise(); BootstrapServer bootstrapServer = new BootstrapServer(); //bootstrapServer.PSKIdentities.LoadFromFile("PSKIdentities.xml"); bootstrapServer.Port = port; bootstrapServer.SecureOnly = secureOnly; bootstrapServer.Start(); ServiceEventMessage message = new ServiceEventMessage(); Imagination.Model.BootstrapServer bootstrap = new Imagination.Model.BootstrapServer(); bootstrap.Url = ServiceConfiguration.ExternalUri.ToString(); //PSKIdentity pskIdentity = new PSKIdentity(); //pskIdentity.Identity = "Test1"; //pskIdentity.Secret = "TestSecret"; //bootstrap.AddServerIdentity(pskIdentity); message.AddParameter("BootstrapServer", bootstrap); BusinessLogicFactory.ServiceMessages.Publish("Bootstrap.Start", message, TMessagePublishMode.Confirms); _ShutdownEvent = new ManualResetEvent(false); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { _ShutdownEvent.Set(); e.Cancel = true; }; Console.Write("Listening on port "); Console.WriteLine(port.ToString()); Console.WriteLine("Press Ctrl+C to stop the server."); _ShutdownEvent.WaitOne(); Console.WriteLine("Exiting."); bootstrapServer.Stop(); BusinessLogicFactory.ServiceMessages.Stop(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void Main(string[] args) { try { int workerThreads; int completionPortThreads; System.Threading.ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads); if (workerThreads < 16) { workerThreads = 16; System.Threading.ThreadPool.SetMinThreads(workerThreads, completionPortThreads); } IConfigurationBuilder builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .AddCommandLine(args); IConfigurationRoot configuration = builder.Build(); ServiceConfiguration.LoadConfig(configuration.GetSection("ServiceConfiguration")); int port = 5683; bool secureOnly = true; IConfigurationSection sectionServer = configuration.GetSection("LWM2MServer"); if (sectionServer != null) { IConfigurationSection sectionPort = sectionServer.GetSection("Port"); if (sectionPort != null) { if (!int.TryParse(sectionPort.Value, out port)) { port = 5683; } } IConfigurationSection sectionSecure = sectionServer.GetSection("SecureOnly"); if (sectionSecure != null) { if (!bool.TryParse(sectionSecure.Value, out secureOnly)) { secureOnly = true; } } } if (ServiceConfiguration.ExternalUri == null) { ServiceConfiguration.ExternalUri = new Uri(string.Concat("coaps://", ServiceConfiguration.Hostname, ":", (port + 1).ToString())); } Version version = Assembly.GetExecutingAssembly().GetName().Version; Console.Write("LWM2M server ("); Console.Write(version.ToString()); Console.WriteLine(")"); ServiceConfiguration.DisplayConfig(); ApplicationEventLog.LogLevel = System.Diagnostics.EventLogEntryType.Information; Server server = new Server(); //server.PSKIdentities.LoadFromFile("PSKIdentities.xml"); server.Port = port; server.SecureOnly = secureOnly; server.Start(); _ShutdownEvent = new ManualResetEvent(false); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { _ShutdownEvent.Set(); e.Cancel = true; }; Console.Write("Listening on port "); Console.WriteLine(port.ToString()); Console.WriteLine("Press Ctrl+C to stop the server."); _ShutdownEvent.WaitOne(); Console.WriteLine("Exiting."); server.Stop(); BusinessLogicFactory.Clients.Stop(); BusinessLogicFactory.ServiceMessages.Stop(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }