diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs index aa1b13de..1eaeb875 100644 --- a/ConsoleApp1/Program.cs +++ b/ConsoleApp1/Program.cs @@ -1,105 +1,17 @@ using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using AsbCloudDb.Model; -using AsbCloudDb; -using Google.Apis.Drive.v3.Data; -using Microsoft.EntityFrameworkCore; -using System.Net.Mail; -using System.Text.RegularExpressions; -using AsbCloudInfrastructure.Services.WellOperationService; -using AsbCloudInfrastructure.Services.Cache; -using AsbCloudInfrastructure.Services; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Primitives; namespace ConsoleApp1 { - //var options = new DbContextOptionsBuilder() - // .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") - // .Options; - //var context = new AsbCloudDbContext(options); - - class ConfigurationService : IConfigurationSection - { - public string this[string key] { get => "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"; - set{} } - - public string Key => ""; - - public string Path => ""; - - public string Value { get; set; } = "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"; - - public IEnumerable GetChildren() - { - return null; - } - - public IChangeToken GetReloadToken() - { - return null; - } - - public IConfigurationSection GetSection(string key) => this; - - } class Program { - - static void Main(/*string[] args*/) { - var options = new DbContextOptionsBuilder() - .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") - .Options; - var db = new AsbCloudDbContext(options); - var cacheDb = new CacheDb(); + // use ServiceFactory to make services - AsbCloudInfrastructure.DependencyInjection.MapsterSetup(); - var configService = new ConfigurationService(); - var telemetryTracker = new TelemetryTracker(cacheDb, configService); - var timeZoneService = new TimezoneService(); - var telemetryService = new TelemetryService(db, telemetryTracker, timeZoneService, cacheDb); - var wellService = new WellService(db, cacheDb, telemetryService, timeZoneService); - var operationService = new OperationsStatService(db, cacheDb, wellService); - var scheduleReportService = new ScheduleReportService(operationService, wellService); - var stream = scheduleReportService.MakeReportAsync(44).Result; - var outStream = System.IO.File.OpenWrite(@"c:\temp\1.xlsx"); - stream.CopyTo(outStream); - outStream.Flush(); - outStream.Close(); - return; - //SendMail.Main(); - - //DbDemoDataService.AddDemoData(); - //.GetAwaiter().GetResult(); Console.WriteLine("End of Test"); Console.ReadLine(); - //var options = new DbContextOptionsBuilder() - // .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") - // .Options; - //var context = new AsbCloudDbContext(options); - - //var sett = context.Set(); - //var r = context.Database.ExecInsertOrUpdateAsync(sett, new List { - // new TelemetryDataSaub - // { - // Date = DateTime.Now, - // IdTelemetry = 3, - // AxialLoad = 100.1f, - // }, - // new TelemetryDataSaub - // { - // Date = DateTime.Now.AddSeconds(2), - // IdTelemetry = 3, - // AxialLoad = 100.2f, - // }, - //}, System.Threading.CancellationToken.None).Result; } } } diff --git a/ConsoleApp1/ServiceFactory.cs b/ConsoleApp1/ServiceFactory.cs new file mode 100644 index 00000000..3fb9f1f6 --- /dev/null +++ b/ConsoleApp1/ServiceFactory.cs @@ -0,0 +1,73 @@ +using AsbCloudDb.Model; +using AsbCloudInfrastructure.Services; +using AsbCloudInfrastructure.Services.Cache; +using AsbCloudInfrastructure.Services.SAUB; +using AsbCloudInfrastructure.Services.WellOperationService; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Primitives; +using System.Collections.Generic; + +namespace ConsoleApp1 +{ + class ConfigurationService : IConfigurationSection + { + public string this[string key] + { + get => "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"; + set { } + } + + public string Key => ""; + + public string Path => ""; + + public string Value { get; set; } = "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"; + + public IEnumerable GetChildren() + { + return null; + } + + public IChangeToken GetReloadToken() + { + return null; + } + + public IConfigurationSection GetSection(string key) => this; + + } + + internal static class ServiceFactory + { + + private static DbContextOptions options = new DbContextOptionsBuilder() + .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") + .Options; + + static CacheDb CacheDb { get; } = new CacheDb(); + static ConfigurationService ConfigurationService { get; } = new ConfigurationService(); + static TimezoneService TimezoneService { get; } = new TimezoneService(); + public static AsbCloudDbContext Context { get; } = MakeContext(); + public static AsbCloudDbContext MakeContext() + => new AsbCloudDbContext(options); + + public static void MapsterSetup() + => AsbCloudInfrastructure.DependencyInjection.MapsterSetup(); + + public static TelemetryTracker MakeTelemetryTracker() + => new TelemetryTracker(CacheDb, ConfigurationService); + + public static TelemetryService MakeTelemetryService() + => new TelemetryService(Context, MakeTelemetryTracker(), TimezoneService, CacheDb); + + public static WellService MakeWellService() + => new WellService(Context, CacheDb, MakeTelemetryService(), TimezoneService); + + public static OperationsStatService MakeOperationsStatService() + => new OperationsStatService(Context, CacheDb, MakeWellService()); + + public static ScheduleReportService MakeScheduleReportService() + => new ScheduleReportService(MakeOperationsStatService(), MakeWellService()); + } +}