public ValuesController(IOptions <MyAppConfig> optionsAccessor) { if (optionsAccessor == null) { throw new ArgumentNullException(nameof(optionsAccessor)); } _appConfig = optionsAccessor.Value; }
void Initialize() { try { myappconfig = new MyAppConfig(); var offset = System.Configuration.ConfigurationManager.AppSettings.Get("offset"); myappconfig.DesktopLocation = (Point) new PointConverter().ConvertFromString(offset); var filename = System.Configuration.ConfigurationManager.AppSettings.Get("filename_img"); myappconfig.Filename = filename; } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } //myappconfig.ImageAlign = ContentAlignment.MiddleCenter; //myappconfig.Offset = Point.Empty; //1920/2 - 64/2==928 //1080/2 - 64/2==508 this.propertyGrid1.SelectedObject = myappconfig; try { frmCrosshair = new FormDesktopCrosshair(); var rect = Screen.PrimaryScreen.Bounds; frmCrosshair.Size = rect.Size; var b = new Binding("DesktopLocation", myappconfig, "DesktopLocation"); frmCrosshair.DataBindings.Add(b); //var offset = myappconfig.DesktopLocation; //(frmCrosshair as FormDesktopCrosshair).SetDesktopLocation(offset.X, offset.Y); var fs = new System.IO.FileStream(myappconfig.Filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); //this.textBox1.Text = filename; streamImg = fs; var img = new Bitmap(streamImg); frmCrosshair.BackgroundImage = img; frmCrosshair.DataBindings.Add("Visible", myappconfig, "Visible", false, DataSourceUpdateMode.OnPropertyChanged); //this.checkBox1.DataBindings.Add("Checked", frmCrosshair, "Visible", false, DataSourceUpdateMode.OnPropertyChanged); this.checkBox1.DataBindings.Add("Checked", myappconfig, "Visible", false, DataSourceUpdateMode.OnPropertyChanged); frmCrosshair?.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); throw; } }
void CleanUp() { myappconfig = null; frmCrosshair?.Close(); frmCrosshair?.Dispose(); frmCrosshair = null; streamImg?.Close(); streamImg?.Dispose(); streamImg = null; }
private static void StartApp(string[] args) { MyAppConfig.SetEnvironmentVariables("consoleback"); var config = Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration)) .Build().Services.GetRequiredService <IConfiguration>(); var serlogger = config.CreateSerilogger(); Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .ConfigureServices((context, services) => { var sopiBuilder = services .AddSopi(context.Configuration, serlogger.Information) .AddPlatformServices() .AddSystemServicesByConfiguration() ; sopiBuilder .AddDomainServices(); services .AddSingleton <ISaga, MySaga>() .AddHostedService <SopiAppService>() ; }) .Build().Run() ; }
private static IHostBuilder CreateWebHostBuilder(string[] args) { MyAppConfig.SetEnvironmentVariables("fronthost"); MyAppConfig.SetWebSocketEnvironmentVariables(Constants.NotificationsBaseRouteAuth); var config = WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration)) .Configure(builder => { }) .Build().Services.GetRequiredService <IConfiguration>(); var serlogger = config.CreateSerilogger(); return(Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureServices((context, services) => { var sopiBuilder = services .AddSopi(context.Configuration, serlogger.Information) .AddAuthentication() .AddPlatformServices() .AddMvcServices(mvc => { mvc.AddNewtonsoftJson(); }) .AddSystemServicesByConfiguration() ; services.AddSopiSwaggerForMultipleServices(Constants.ApiTitle, Constants.ApiBaseRoute, "sample", new[] { Constants.ApiKey, "api", "api2", "cmd1", "qry1" }, false, options => { options.SchemaFilter <RemoveAllOffSchemaFilter>(); }, sopiBuilder.Log); services .AddTestClientOptions(c => { c.BaseAddress = "http://localhost:5097"; }) .AddTestSystemClient() .AddTestUserClient() ; services .AddSignalR(options => { options.EnableDetailedErrors = true; }) .AddJsonProtocol() .AddNewtonsoftJsonProtocol() .AddMessagePackProtocol() ; services .AddTransient <MyQueryService>() ; sopiBuilder.GetMvcBuilder().AddApplicationPart(typeof(HomeController).Assembly); }); webBuilder.Configure(app => { var logger = app.ApplicationServices.GetStartupLogger(); app.UseSerilogRequestLogging(); app.UseVersionInfo(Constants.ApiBaseRoute, s => logger.LogInformation(s)); app.UseSopiLifetimeEndpoint(Constants.ApiBaseRoute, s => logger.LogInformation(s)); app.UseRouting() .UseAuthentication() .UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); endpoints.MapHub <TestHub>(Constants.NotificationsBaseRoute); endpoints.MapHub <TestHubAuth>(Constants.NotificationsBaseRouteAuth); }) .UseSopiSwagger(); }); }) ); }
private static IHostBuilder CreateWebHostBuilder(string[] args) { var id = "backhost"; MyAppConfig.SetEnvironmentVariables(id); var config = WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration)) .Configure(builder => { }) .Build().Services.GetRequiredService <IConfiguration>(); var serlogger = config.CreateSerilogger(); return(Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureServices((context, services) => { var sopiBuilder = services .AddSopi(context.Configuration, serlogger.Information) .AddAuthentication() .AddPlatformServices() .AddMvcServices(mvc => { mvc.AddNewtonsoftJson(); }) .AddSystemServicesByConfiguration() ; sopiBuilder .AddDomainServices(); services .AddSingleton <ISaga, MySaga1>(); sopiBuilder .AddProjectionServices(); services .AddSingleton <MyProjector1>() .AddSingleton <IReadModelProjector, MyCompositeProjector1>() .AddHostedService <SopiAppService>() ; services.AddSopiSwaggerForMultipleServices(Constants.ApiTitle, Constants.ApiBaseRoute, "backhost", new[] { Constants.ApiKey, "api", "api2", "cmd1", "qry1" }, false, options => { options.SchemaFilter <RemoveAllOffSchemaFilter>(); }, sopiBuilder.Log); }); webBuilder.Configure(app => { var logger = app.ApplicationServices.GetStartupLogger(); app.UseSerilogRequestLogging(); app.UseVersionInfo(Constants.ApiBaseRoute, s => logger.LogInformation(s)); app.UseSopiLifetimeEndpoint(Constants.ApiBaseRoute, s => logger.LogInformation(s)); app.UseProjectionStatusEndpoint(Constants.ProjectionBaseRoute, s => logger.LogInformation(s)); app.UseRouting() .UseAuthentication() .UseAuthorization(); }); }) ); }
private static IHostBuilder CreateWebHostBuilder(string[] args) { var id = Environment.GetEnvironmentVariable("APPID"); if (string.IsNullOrEmpty(id)) { id = "app"; } MyAppConfig.SetEnvironmentVariables(id); MyAppConfig.SetWebSocketEnvironmentVariables(Constants.NotificationsBaseRouteAuth); var config = WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .ConfigureServices((context, collection) => collection.AddSingleton(context.Configuration)) .Configure(builder => { }) .Build().Services.GetRequiredService <IConfiguration>(); var serlogger = config.CreateSerilogger(); return(Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration(MyAppConfig.Configure) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureServices((context, services) => { var sopiBuilder = services .AddSopi(context.Configuration, serlogger.Information) .AddAuthentication() .AddPlatformServices() .AddMvcServices(mvc => { mvc.AddNewtonsoftJson(); }) .AddSystemServicesByConfiguration() ; var startDomainServices = Environment.GetEnvironmentVariable("DOMAIN_SERVICES"); if (string.IsNullOrEmpty(startDomainServices) || startDomainServices.ToLower() == "true") { sopiBuilder .AddDomainServices(); services .AddSingleton <ISaga, MySaga1>(); } var startProjectionServices = Environment.GetEnvironmentVariable("PROJECTION_SERVICES"); if (string.IsNullOrEmpty(startProjectionServices) || startProjectionServices.ToLower() == "true") { sopiBuilder .AddProjectionServices(); services .AddSingleton <MyProjector1>() .AddSingleton <IReadModelProjector, MyCompositeProjector1>(); } services.AddSopiSwaggerForMultipleServices(Constants.ApiTitle, Constants.ApiBaseRoute, "sample", new[] { Constants.ApiKey, "api", "api2", "cmd1", "qry1" }, false, options => { options.SchemaFilter <RemoveAllOffSchemaFilter>(); }, sopiBuilder.Log); services .AddTestClientOptions(c => { c.BaseAddress = "http://localhost:5099"; }) .AddTestSystemClient() .AddTestUserClient() .AddSingleton <IReadModelProjector, MyProjector1>() .AddSopiService <DelayStartService>() .AddHostedService <SopiAppService>() ; services.AddSignalR(options => { options.EnableDetailedErrors = true; }) ; var startQueryServices = Environment.GetEnvironmentVariable("QUERY_SERVICES"); if (string.IsNullOrEmpty(startQueryServices) || startQueryServices.ToLower() == "true") { services .AddTransient <MyQueryService>() ; } sopiBuilder.GetMvcBuilder().AddApplicationPart(typeof(HomeController).Assembly); }); webBuilder.Configure(app => { var logger = app.ApplicationServices.GetStartupLogger(); app.UseSerilogRequestLogging(); app.UseVersionInfo(Constants.ApiBaseRoute, s => logger.LogInformation(s)); app.UseSopiLifetimeEndpoint(Constants.ApiBaseRoute, s => logger.LogInformation(s)); app.UseProjectionStatusEndpoint(Constants.ProjectionBaseRoute, s => logger.LogInformation(s)); app.UseRouting() .UseAuthentication() .UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"); endpoints.MapHub <TestHub>(Constants.NotificationsBaseRoute); endpoints.MapHub <TestHubAuth>(Constants.NotificationsBaseRouteAuth); }) .UseSopiSwagger(); }); })); }