forked from ddrilling/AsbCloudServer
refactor ConsoleApp1
This commit is contained in:
parent
fa9486e44d
commit
9d1cbd2482
@ -1,105 +1,17 @@
|
|||||||
using System;
|
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
|
namespace ConsoleApp1
|
||||||
{
|
{
|
||||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
|
||||||
// .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<IConfigurationSection> GetChildren()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IChangeToken GetReloadToken()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IConfigurationSection GetSection(string key) => this;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
static void Main(/*string[] args*/)
|
static void Main(/*string[] args*/)
|
||||||
{
|
{
|
||||||
var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
// use ServiceFactory to make services
|
||||||
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
|
||||||
.Options;
|
|
||||||
var db = new AsbCloudDbContext(options);
|
|
||||||
var cacheDb = new CacheDb();
|
|
||||||
|
|
||||||
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.WriteLine("End of Test");
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
|
||||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
|
||||||
// .Options;
|
|
||||||
//var context = new AsbCloudDbContext(options);
|
|
||||||
|
|
||||||
//var sett = context.Set<TelemetryDataSaub>();
|
|
||||||
//var r = context.Database.ExecInsertOrUpdateAsync(sett, new List<TelemetryDataSaub> {
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
ConsoleApp1/ServiceFactory.cs
Normal file
73
ConsoleApp1/ServiceFactory.cs
Normal file
@ -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<IConfigurationSection> GetChildren()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IChangeToken GetReloadToken()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IConfigurationSection GetSection(string key) => this;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class ServiceFactory
|
||||||
|
{
|
||||||
|
|
||||||
|
private static DbContextOptions<AsbCloudDbContext> options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||||
|
.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());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user