} // ToDo: utilize a much more powerfull and ubiquitious timing and profiling tool than a stopwatch #endregion #region Constructor /// <summary> /// Constructor that populates all the injected services provided by a GenericHost, along with teh injected services specific to this program that are needed by this HostedService (or derivitive like BackgroundService) /// </summary> /// <param name="consoleSinkHostedService"></param> /// <param name="consoleSourceHostedService"></param> /// <param name="loggerFactory"></param> /// <param name="hostEnvironment"></param> /// <param name="hostConfiguration"></param> /// <param name="hostLifetime"></param> /// <param name="hostApplicationLifetime"></param> public FileSystemGraphToDBService(IConsoleSinkHostedService consoleSinkHostedService, IConsoleSourceHostedService consoleSourceHostedService, ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IHostEnvironment hostEnvironment, IConfiguration hostConfiguration, IHostLifetime hostLifetime, IConfiguration hostedServiceConfiguration, IHostApplicationLifetime hostApplicationLifetime) { this.stringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory)); exceptionLocalizer = stringLocalizerFactory.Create(nameof(AService01.Resources), "AService01"); debugLocalizer = stringLocalizerFactory.Create(nameof(AService01.Resources), "AService01"); uiLocalizer = stringLocalizerFactory.Create(nameof(AService01.Resources), "AService01"); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.logger = loggerFactory.CreateLogger <FileSystemGraphToDBService>(); // this.logger = (Logger<FileSystemGraphToDBService>) ATAP.Utilities.Logging.LogProvider.GetLogger("FileSystemGraphToDBService"); logger.LogDebug("FileSystemGraphToDBService", ".ctor"); // ToDo Fody for tracing constructors, via an optional switch this.hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); this.hostConfiguration = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration)); this.hostLifetime = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime)); this.hostedServiceConfiguration = hostedServiceConfiguration ?? throw new ArgumentNullException(nameof(hostedServiceConfiguration)); this.hostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime)); this.consoleSinkHostedService = consoleSinkHostedService ?? throw new ArgumentNullException(nameof(consoleSinkHostedService)); this.consoleSourceHostedService = consoleSourceHostedService ?? throw new ArgumentNullException(nameof(consoleSourceHostedService)); //internalCancellationToken = internalCancellationTokenSource.Token; Stopwatch = new Stopwatch(); #region Create the serviceData and initialize it from the StringConstants or this service's ConfigRoot this.serviceData = new FileSystemGraphToDBServiceData( // ToDo: Get the list from the StringConstants, and localize them choices: new List <string>() { "1. Run ConvertFileSystemGraphToDBAsyncTask", "2. Changeable", "99: Quit this service" }, stdInHandlerState: new StringBuilder(), mesg: new StringBuilder(), convertFileSystemGraphToDBDataAndResults: new ConvertFileSystemGraphToDBDataAndResults( convertFileSystemGraphToDBData: new ConvertFileSystemGraphToDBData( asyncFileReadBlockSize: hostedServiceConfiguration.GetValue <int>(hostedServiceStringConstants.AsyncFileReadBlockSizeConfigRootKey, int.Parse(hostedServiceStringConstants.AsyncFileReadBlockSizeDefault)), // ToDo: should validate in case the hostedServiceStringConstants assembly is messed up? enableProgress: hostedServiceConfiguration.GetValue <bool>(hostedServiceStringConstants.EnableProgressBoolConfigRootKey, bool.Parse(hostedServiceStringConstants.EnableProgressBoolDefault)), // ToDo: should validate in case the hostedServiceStringConstants assembly is messed up? convertFileSystemGraphToDBProgress: new ConvertFileSystemGraphToDBProgress(false), temporaryDirectoryBase: hostedServiceConfiguration.GetValue <string>(hostedServiceStringConstants.TemporaryDirectoryBaseConfigRootKey, hostedServiceStringConstants.TemporaryDirectoryBaseDefault), nodeFileRelativePath: hostedServiceConfiguration.GetValue <string>(hostedServiceStringConstants.NodeFileRelativePathConfigRootKey, hostedServiceStringConstants.NodeFileRelativePathDefault), edgeFileRelativePath: hostedServiceConfiguration.GetValue <string>(hostedServiceStringConstants.EdgeFileRelativePathConfigRootKey, hostedServiceStringConstants.EdgeFileRelativePathDefault), filePaths: null, dBConnectionString: "", ormLiteDialectProviderStringDefault: "" ), convertFileSystemGraphToDBResults: new ConvertFileSystemGraphToDBResults( success: false ) ), longRunningTasks: new List <Task <ConvertFileSystemGraphToDBResults> >() ); serviceData.ConvertFileSystemGraphToDBDataAndResults.ConvertFileSystemGraphToDBData.FilePaths = new string[2] { serviceData.ConvertFileSystemGraphToDBDataAndResults.ConvertFileSystemGraphToDBData.TemporaryDirectoryBase + serviceData.ConvertFileSystemGraphToDBDataAndResults.ConvertFileSystemGraphToDBData.NodeFileRelativePath, serviceData.ConvertFileSystemGraphToDBDataAndResults.ConvertFileSystemGraphToDBData.TemporaryDirectoryBase + serviceData.ConvertFileSystemGraphToDBDataAndResults.ConvertFileSystemGraphToDBData.EdgeFileRelativePath }; #endregion }
//Stopwatch stopWatch; // ToDo: utilize a much more powerfull and ubiquitious timing and profiling tool than a stopwatch #endregion /// <summary> /// Constructor that populates all the injected services provided by a GenericHost, along with teh injected services specific to this program that are needed by this HostedService (or derivitive like BackgroundService) /// </summary> /// <param name="consoleSinkHostedService"></param> /// <param name="consoleSourceHostedService"></param> /// <param name="loggerFactory"></param> /// <param name="hostEnvironment"></param> /// <param name="hostConfiguration"></param> /// <param name="hostLifetime"></param> /// <param name="hostApplicationLifetime"></param> //public ConsoleMonitorBackgroundService(IConsoleSinkHostedService hostedServiceConsoleSink, IConsoleSourceHostedService consoleSourceHostedService, ILoggerFactory loggerFactory, IStringLocalizer stringLocalizer, IHostEnvironment hostEnvironment, IConfiguration hostConfiguration, IHostLifetime hostLifetime, IHostApplicationLifetime hostApplicationLifetime) { //public ConsoleMonitorBackgroundService(IConsoleSinkHostedService hostedServiceConsoleSink, IConsoleSourceHostedService consoleSourceHostedService, ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IHostEnvironment hostEnvironment, IConfiguration hostConfiguration, IHostLifetime hostLifetime, IHostApplicationLifetime hostApplicationLifetime) { public ConsoleMonitorBackgroundService(IConsoleSinkHostedService consoleSinkHostedService, IConsoleSourceHostedService consoleSourceHostedService, ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IHostEnvironment hostEnvironment, IConfiguration hostConfiguration, IHostLifetime hostLifetime, IHostApplicationLifetime hostApplicationLifetime) { this.stringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory)); //this.exceptionLocalizer = stringLocalizerFactory.Create(nameof(Resources.ExceptionResources), "ATAP.Utilities.ConsoleMonitor"); //this.debugLocalizer = stringLocalizerFactory.Create(nameof(Resources.DebugResources), "ATAP.Utilities.HostedServices"); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.logger = loggerFactory.CreateLogger <ConsoleMonitorBackgroundService>(); this.logger.LogDebug("ConsoleMonitorBackgroundService", ".ctor"); // ToDo Fody for tracing constructors, via an optional switch this.stringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory)); this.hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); this.hostConfiguration = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration)); this.hostLifetime = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime)); this.hostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime)); this.consoleSinkHostedService = consoleSinkHostedService ?? throw new ArgumentNullException(nameof(consoleSinkHostedService)); this.consoleSourceHostedService = consoleSourceHostedService ?? throw new ArgumentNullException(nameof(consoleSourceHostedService)); internalCancellationToken = internalCancellationTokenSource.Token; }
Stopwatch stopWatch; // ToDo: utilize a much more powerfull and ubiquitous timing and profiling tool than a stopwatch #endregion #region Constructor /// <summary> /// Constructor that populates all the injected services provided by a GenericHost, along with teh injected services specific to this program that are needed by this HostedService (or derivitive like BackgroundService) /// </summary> /// <param name="consoleSinkHostedService"></param> /// <param name="consoleSourceHostedService"></param> /// <param name="loggerFactory"></param> /// <param name="hostEnvironment"></param> /// <param name="hostConfiguration"></param> /// <param name="hostLifetime"></param> /// <param name="hostApplicationLifetime"></param> public Console03BackgroundService(IConsoleSinkHostedService consoleSinkHostedService, IConsoleSourceHostedService consoleSourceHostedService, ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IHostEnvironment hostEnvironment, IConfiguration hostConfiguration, IHostLifetime hostLifetime, IConfiguration appConfiguration, IHostApplicationLifetime hostApplicationLifetime) { this.stringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory)); exceptionLocalizer = stringLocalizerFactory.Create(nameof(Resources), "ATAP.Console.Console03"); debugLocalizer = stringLocalizerFactory.Create(nameof(Resources), "ATAP.Console.Console03"); uiLocalizer = stringLocalizerFactory.Create(nameof(Resources), "ATAP.Console.Console03"); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.logger = loggerFactory.CreateLogger <Console03BackgroundService>(); // this.logger = (Logger<Console03BackgroundService>) ATAP.Utilities.Logging.LogProvider.GetLogger("Console03BackgroundService"); logger.LogDebug("Console03BackgroundService", ".ctor"); this.hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); this.hostConfiguration = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration)); this.hostLifetime = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime)); this.appConfiguration = appConfiguration ?? throw new ArgumentNullException(nameof(appConfiguration)); this.hostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime)); this.consoleSinkHostedService = consoleSinkHostedService ?? throw new ArgumentNullException(nameof(consoleSinkHostedService)); this.consoleSourceHostedService = consoleSourceHostedService ?? throw new ArgumentNullException(nameof(consoleSourceHostedService)); internalCancellationToken = internalCancellationTokenSource.Token; }
/// <summary> /// Constructor that populates all the injected services provided by a GenericHost, along with teh injected services specific to this program that are needed by this HostedService (or derivitive like BackgroundService) /// </summary> /// <param name="consoleSinkHostedService"></param> /// <param name="consoleSourceHostedService"></param> /// <param name="loggerFactory"></param> /// <param name="hostEnvironment"></param> /// <param name="hostConfiguration"></param> /// <param name="hostLifetime"></param> /// <param name="hostApplicationLifetime"></param> public StdInHandlerService(IFileSystemGraphToDBService fileSystemGraphToDBService, IFileSystemToObjectGraphService fileSystemToObjectGraphService, IConsoleSinkHostedService consoleSinkHostedService, IConsoleSourceHostedService consoleSourceHostedService, ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IHostEnvironment hostEnvironment, IConfiguration hostConfiguration, IHostLifetime hostLifetime, IConfiguration appConfiguration, IHostApplicationLifetime hostApplicationLifetime) { this.StringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory)); exceptionLocalizer = stringLocalizerFactory.Create(nameof(AService01.Resources), "AService01"); debugLocalizer = stringLocalizerFactory.Create(nameof(AService01.Resources), "AService01"); uiLocalizer = stringLocalizerFactory.Create(nameof(AService01.Resources), "AService01"); this.LoggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.logger = loggerFactory.CreateLogger <StdInHandlerService>(); // this.logger = (Logger<AService01StdInHandlerService>) ATAP.Utilities.Logging.LogProvider.GetLogger("AService01StdInHandlerService"); logger.LogDebug("StdInHandlerService", ".ctor"); // ToDo Fody for tracing constructors, via an optional switch this.HostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment)); this.HostConfiguration = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration)); this.HostLifetime = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime)); this.appConfiguration = appConfiguration ?? throw new ArgumentNullException(nameof(appConfiguration)); this.HostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime)); this.FileSystemGraphToDBService = fileSystemGraphToDBService ?? throw new ArgumentNullException(nameof(fileSystemGraphToDBService)); this.FileSystemToObjectGraphService = fileSystemToObjectGraphService ?? throw new ArgumentNullException(nameof(fileSystemToObjectGraphService)); this.consoleSinkHostedService = consoleSinkHostedService ?? throw new ArgumentNullException(nameof(consoleSinkHostedService)); this.consoleSourceHostedService = consoleSourceHostedService ?? throw new ArgumentNullException(nameof(consoleSourceHostedService)); //internalCancellationToken = internalCancellationTokenSource.Token; Stopwatch = new Stopwatch(); #region Create the serviceData and initialize it from the StringConstants or this service's ConfigRoot this.serviceData = new StdInHandlerServiceData( // ToDo: Get the list from the StringConstants, and localize them choices: new List <string>() { "1. Run FileSystemToObjectGraphAsyncTask", "2. Run FileSystemGraphToDBAsyncTask", "99: Quit this service" }, // Create a list of choices stdInHandlerState: new StringBuilder(), mesg: new StringBuilder()); FinishedWithStdInAction = () => EnableListeningToStdInAsync(); #endregion }