public ProcessSingletonService(
     IConfiguration config,
     IHostLifetime hostLifetime)
 {
     _config       = NamedNullException.Assert(config, nameof(config));
     _hostLifetime = NamedNullException.Assert(hostLifetime, nameof(hostLifetime));
 }
Exemplo n.º 2
0
        public Host(IServiceProvider services,
                    IHostEnvironment hostEnvironment,
                    PhysicalFileProvider defaultProvider,
                    IHostApplicationLifetime applicationLifetime,
                    ILogger <Host> logger,
                    IHostLifetime hostLifetime,
                    IOptions <HostOptions> options)
        {
            ThrowHelper.ThrowIfNull(services);
            ThrowHelper.ThrowIfNull(applicationLifetime);
            ThrowHelper.ThrowIfNull(logger);
            ThrowHelper.ThrowIfNull(hostLifetime);

            Services             = services;
            _applicationLifetime = (applicationLifetime as ApplicationLifetime) !;
            _hostEnvironment     = hostEnvironment;
            _defaultProvider     = defaultProvider;

            if (_applicationLifetime is null)
            {
                throw new ArgumentException(SR.IHostApplicationLifetimeReplacementNotSupported, nameof(applicationLifetime));
            }
            _logger       = logger;
            _hostLifetime = hostLifetime;
            _options      = options?.Value ?? throw new ArgumentNullException(nameof(options));
        }
Exemplo n.º 3
0
 internal Host(IServiceProvider services)
 {
     Services             = services ?? throw new ArgumentNullException(nameof(services));
     _applicationLifetime = Services.GetRequiredService <IApplicationLifetime>() as ApplicationLifetime;
     _logger       = Services.GetRequiredService <ILogger <Host> >();
     _hostLifetime = Services.GetRequiredService <IHostLifetime>();
 }
Exemplo n.º 4
0
 public Worker(ILogger <Worker> logger,
               IHostApplicationLifetime appLifetime,
               IHostLifetime hostLifetime,
               IHostEnvironment hostEnvironment)
 {
     this._logger = logger;
 }
 public Worker(IHostApplicationLifetime hostApplicationLifetime, ILogger <Worker> logger,
               IHostLifetime hostLifetime)
 {
     _hostApplicationLifetime = hostApplicationLifetime;
     _logger       = logger;
     _hostLifetime = hostLifetime;
 }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="hostApplicationLifetime"></param>
 /// <param name="hostLifetime"></param>
 /// <param name="timer"></param>
 /// <param name="timerCallback"></param>
 /// <param name="executionCount"></param>
 /// <param name="config"></param>
 /// <param name="dbContext"></param>
 public ExampleHostedService(ILogger <ExampleHostedService> logger, IHostApplicationLifetime hostApplicationLifetime, IHostLifetime hostLifetime, IConfiguration config, ApplicationDbContext dbContext)
 {
     _logger = logger;
     _hostApplicationLifetime = hostApplicationLifetime;
     _hostLifetime            = hostLifetime;
     _config    = config;
     _dbContext = dbContext;
 }
Exemplo n.º 7
0
 public MycoHost(IServiceProvider services, IHostApplicationLifetime applicationLifetime, ILogger <MycoHost> logger,
                 IHostLifetime hostLifetime, IOptions <HostOptions> options)
 {
     this.Services            = services ?? throw new ArgumentNullException(nameof(services));
     this.applicationLifetime = (applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime))) as ApplicationLifetime;
     this.logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     this.hostLifetime = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime));
     this.options      = options?.Value ?? throw new ArgumentNullException(nameof(options));
 }
Exemplo n.º 8
0
 public Host(IServiceProvider services, IApplicationLifetime applicationLifetime, ILogger <Host> logger,
             IHostLifetime hostLifetime, IOptions <HostOptions> options)
 {
     Services             = services ?? throw new ArgumentNullException(nameof(services));
     _applicationLifetime = (applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime))) as ApplicationLifetime;
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     _hostLifetime = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime));
     _options      = options?.Value ?? throw new ArgumentNullException(nameof(options));
 }
Exemplo n.º 9
0
 public HostLifetimeEvents(
     ILogger <HostLifetimeEvents> logger,
     IHostApplicationLifetime appLifetime,
     IRedisCacheProvider redis,
     IHostLifetime host)
 {
     _logger      = logger;
     _appLifetime = appLifetime;
     _redis       = redis;
 }
Exemplo n.º 10
0
 public ServiceHost(ContainerBuilder builder,
                    IServiceProvider hostingServiceProvider,
                    IHostLifetime hostLifetime,
                    List <Action <IContainer> > mapServicesDelegate)
 {
     _builder = builder;
     _hostingServiceProvider = hostingServiceProvider;
     _hostLifetime           = hostLifetime;
     _mapServicesDelegates   = mapServicesDelegate;
 }
Exemplo n.º 11
0
        public HostedJobService(IServiceProvider serviceProvider, ILoggerFactory loggerFactory,
                                IHostLifetime lifetime)
        {
            _serviceProvider = serviceProvider;
            _loggerFactory   = loggerFactory;
            _logger          = loggerFactory.CreateLogger <T>();
            var hostedJobServiceLifetime = lifetime as JobHostLifetime;

            hostedJobServiceLifetime?.RegisterHostedJobInstance(this);
        }
Exemplo n.º 12
0
        public TestJob(
            IOptionsMonitor <TestJobOptions> options,
            ILogger <TestJob> logger,
            IHostLifetime lifetime)
        {
            _options = options.Get(Name);

            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            // _logger.LogInformation("IsSystemd: {isSystemd}", lifetime.GetType() == typeof(SystemdLifetime));
            _logger.LogInformation("IHostLifetime: {hostLifetime}", lifetime.GetType());
        }
Exemplo n.º 13
0
 public Host(IServiceProvider services, IHostApplicationLifetime applicationLifetime, ILogger <Host> logger,
             IHostLifetime hostLifetime, IOptions <HostOptions> options)
 {
     Services             = services ?? throw new ArgumentNullException(nameof(services));
     _applicationLifetime = (applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime))) as ApplicationLifetime;
     if (_applicationLifetime is null)
     {
         throw new ArgumentException("Replacing IHostApplicationLifetime is not supported.", nameof(applicationLifetime));
     }
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     _hostLifetime = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime));
     _options      = options?.Value ?? throw new ArgumentNullException(nameof(options));
 }
Exemplo n.º 14
0
 public ClientHost(IServiceProvider services, IHostApplicationLifetime applicationLifetime, ILogger <ClientHost> logger, IHostLifetime hostLifetime, IOptions <HostOptions> options)
 {
     Guard.Throw.ArgumentNullException(services == null, nameof(services));
     Guard.Throw.ArgumentNullException(applicationLifetime == null, nameof(applicationLifetime));
     Guard.Throw.ArgumentNullException(logger == null, nameof(logger));
     Guard.Throw.ArgumentNullException(hostLifetime == null, nameof(hostLifetime));
     this.Services            = services;
     this.applicationLifetime = (ApplicationLifetime)applicationLifetime;
     this.logger         = logger;
     this.hostLifetime   = hostLifetime;
     this.hostedServices = this.Services.GetService <IEnumerable <IHostedService> >() ?? new Collection <IHostedService>();
     Guard.Throw.ArgumentNullException(options?.Value == null, nameof(options));
     this.options = options !.Value;
 }
Exemplo n.º 15
0
        public RuntimeInfo(Logger logger, IHostLifetime hostLifetime = null)
        {
            _logger = logger;

            IsWindowsService = hostLifetime is WindowsServiceLifetime;

            //Guarded to avoid issues when running in a non-managed process
            var entry = Process.GetCurrentProcess().MainModule;

            if (entry != null)
            {
                ExecutingApplication = entry.FileName;
                IsWindowsTray        = OsInfo.IsWindows && entry.ModuleName == $"{ProcessProvider.READARR_PROCESS_NAME}.exe";
            }
        }
 public LabBackgroundService(ILogger <LabBackgroundService> logger,
                             IHostApplicationLifetime appLifetime,
                             IHostLifetime hostLifetime,
                             IHostEnvironment hostEnvironment)
 {
     this._logger = logger;
     appLifetime.ApplicationStarted.Register(this.OnStarted);
     appLifetime.ApplicationStopping.Register(this.OnStopping);
     appLifetime.ApplicationStopped.Register(this.OnStopped);
     this._logger.LogInformation($"主機環境:" +
                                 $"ApplicationName = {hostEnvironment.ApplicationName}\r\n" +
                                 $"EnvironmentName = {hostEnvironment.EnvironmentName}\r\n" +
                                 $"RootPath = {hostEnvironment.ContentRootPath}\r\n" +
                                 $"Root File Provider = {hostEnvironment.ContentRootFileProvider}\r\n");
 }
Exemplo n.º 17
0
        public RuntimeInfo(Logger logger, IHostLifetime hostLifetime = null)
        {
            _logger = logger;

            IsWindowsService = hostLifetime is WindowsServiceLifetime;

            // net6.0 will return Radarr.dll for entry assembly, we need the actual
            // executable name (Radarr on linux).  On mono this will return the location of
            // the mono executable itself, which is not what we want.
            var entry = Process.GetCurrentProcess().MainModule;

            if (entry != null)
            {
                ExecutingApplication = entry.FileName;
                IsWindowsTray        = OsInfo.IsWindows && entry.ModuleName == $"{ProcessProvider.PROWLARR_PROCESS_NAME}.exe";
            }
        }
 public ConsoleSinkHostedService(ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IHostEnvironment hostEnvironment,
                                 IConfiguration hostConfiguration, IHostLifetime hostLifetime, IHostApplicationLifetime hostApplicationLifetime
                                 // Can the external CTS go here instead of in StartAsync?
                                 )
 {
     this.stringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory));
     //exceptionLocalizer = stringLocalizerFactory.Create(typeof(ATAP.Utilities.HostedServices.ConsoleSinkHostedService.ExceptionResources);
     //debugLocalizer = stringLocalizerFactory.Create(typeof(ATAP.Utilities.HostedServices.ConsoleSinkHostedService.DebugResources));
     this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.logger        = loggerFactory.CreateLogger <ConsoleSinkHostedService>();
     //logger.LogDebug(this.debugLocalizer["{0} {1}: Starting"],"ConsoleSinkHostedService", ".ctor");  // ToDo Fody for tracing constructors, via an optional switch
     logger.LogDebug("{0} {1}: Starting", "ConsoleSinkHostedService", ".ctor"); // ToDo Fody for tracing constructors, via an optional switch
     this.hostEnvironment         = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
     this.hostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime));
     this.hostLifetime            = hostLifetime ?? throw new ArgumentNullException(nameof(hostEnvironment));
     this.hostConfiguration       = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration));
     internalCancellationToken    = internalCancellationTokenSource.Token;
 }
Exemplo n.º 19
0
 public ObservableResetableTimersHostedService(
     // This service gets all the default injected services
     ILogger <ObservableResetableTimersHostedService> logger,
     // todo: inject localizer
     IHostEnvironment hostEnvironment,
     IConfiguration hostConfiguration,
     IHostLifetime hostLifetime,
     IHostApplicationLifetime hostApplicationLifetime
     // Can the external CTS go here instead of in StartAsync?
     )
 {
     this.logger                  = logger ?? throw new ArgumentNullException(nameof(logger));
     this.stringLocalizer         = null; // new StringLocalizer<ObservableResetableTimersHostedService>();
     this.hostEnvironment         = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
     this.hostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime));
     this.hostLifetime            = hostLifetime ?? throw new ArgumentNullException(nameof(hostEnvironment));
     this.hostConfiguration       = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration));
 }
        public Worker(ILogger <Worker> logger, SettingsBase settings,
                      PowerManagementStateMachine powerManagementStateMachine, Lid lid,
                      NetworkAdapters networkAdapters, ServiceRunningStatus serviceRunningStatus,
                      IHostLifetime hostLifetime)
        {
            _logger   = logger;
            _settings = settings;
            _powerManagementStateMachine = powerManagementStateMachine;
            _lid                   = lid;
            _networkAdapters       = networkAdapters;
            _serviceRunningStatus  = serviceRunningStatus;
            _serviceControlHandler = HandleServiceControlEvents;

            // Check if lifetime is a windows service
            if (!(hostLifetime is WindowsServiceLifetime windowsServiceLifetime))
            {
                throw new NotSupportedException(
                          $"Current Lifetime isn't supported: {_windowsServiceLifetime}. Require WindowsServiceLifetime");
            }
            _windowsServiceLifetime = windowsServiceLifetime;

            // Retrieve service handle
            _serviceHandle = GetServiceHandle();

            // Get access to service control handler of the ServiceBase class
            MethodInfo?baseServiceControlHandlerMethod = windowsServiceLifetime.GetType().BaseType?.GetMethod(
                "ServiceCommandCallbackEx",
                BindingFlags.Instance | BindingFlags.NonPublic);

            if (baseServiceControlHandlerMethod == null)
            {
                throw new ApplicationException("Could not find ServiceCommandCallbackEx method in ServiceBase class.");
            }

            _baseServiceControlHandler = (control, type, data, context) =>
            {
                return((int)(baseServiceControlHandlerMethod.Invoke(windowsServiceLifetime,
                                                                    new object[] { control, type, data, context }) ??
                             throw new ApplicationException("Unexpected return value from ServiceCommandCallbackEx.")));
            };
        }
Exemplo n.º 21
0
 public FileSystemWatchersHostedService(
     // This service gets all the default injected services
     ILogger <FileSystemWatchersHostedService> logger,
     // todo: inject localizer
     IHostEnvironment hostEnvironment,
     IConfiguration hostConfiguration,
     IHostLifetime hostLifetime,
     IHostApplicationLifetime hostApplicationLifetime
     // Can the external CTS go here insteaad of in StartAsync?
     )
 {
     this.logger          = logger ?? throw new ArgumentNullException(nameof(logger));
     this.stringLocalizer = null; // new StringLocalizer<FileSystemWatchersHostedService>();
     this.logger.LogInformation("{@ .ctor}{FileSystemWatchersHostedService} in .ctor");
     this.hostEnvironment         = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
     this.hostApplicationLifetime = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime));
     this.hostLifetime            = hostLifetime ?? throw new ArgumentNullException(nameof(hostEnvironment));
     this.hostConfiguration       = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration));
     this.logger.LogInformation("{@ .ctor}{FileSystemWatchersHostedService} leaving .ctor");
     // Initialize the Data structure
     fileSystemWatchersHostedServiceData = (IFileSystemWatchersHostedServiceData) new FileSystemWatchersHostedServiceData();
 }
Exemplo n.º 22
0
        public XamarinHost(IServiceProvider services,
                           IHostApplicationLifetime applicationLifetime,
                           IHostLifetime hostLifetime,
                           IOptions <HostOptions> options,
                           IXamarinHostingPlatform platform,
                           XamarinApplicationDelegate applicationDelegate)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            if (applicationLifetime == null)
            {
                throw new ArgumentNullException(nameof(applicationLifetime));
            }
            if (hostLifetime == null)
            {
                throw new ArgumentNullException(nameof(hostLifetime));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (platform == null)
            {
                throw new ArgumentNullException(nameof(platform));
            }
            if (applicationDelegate == null)
            {
                throw new ArgumentNullException(nameof(applicationDelegate));
            }

            Services             = services;
            _applicationLifetime = applicationLifetime as ApplicationLifetime;
            _hostLifetime        = hostLifetime;
            _options             = options.Value;
            _platform            = platform;
            _application         = applicationDelegate();
        }
        }                        // ToDo: utilize a much more powerful 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 the injected services specific to this program that are needed by this HostedService (or derivative like BackgroundService)
        /// </summary>
        /// <param name="loggerFactory"></param>
        /// <param name="hostEnvironment"></param>
        /// <param name="hostConfiguration"></param>
        /// <param name="hostLifetime"></param>
        /// <param name="hostApplicationLifetime"></param>
        public GenerateProgramHostedService(ILoggerFactory loggerFactory, IStringLocalizerFactory stringLocalizerFactory, IHostEnvironment hostEnvironment, IConfiguration hostConfiguration, IHostLifetime hostLifetime, IConfiguration hostedServiceConfiguration, IHostApplicationLifetime hostApplicationLifetime)
        {
            StringLocalizerFactory = stringLocalizerFactory ?? throw new ArgumentNullException(nameof(stringLocalizerFactory));
            ExceptionLocalizer     = StringLocalizerFactory.Create(typeof(ATAP.Services.GenerateProgram.ExceptionResources));
            DebugLocalizer         = StringLocalizerFactory.Create(typeof(ATAP.Services.GenerateProgram.DebugResources));
            UiLocalizer            = StringLocalizerFactory.Create(typeof(ATAP.Services.GenerateProgram.UIResources));
            LoggerFactory          = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            Logger = loggerFactory.CreateLogger <GenerateProgramHostedService>();
            // Logger = (Logger<GenerateProgramHostedService>) ATAP.Utilities.Logging.LogProvider.GetLogger("GenerateProgramHostedService");
            Logger.LogDebug(DebugLocalizer["{0} {1}: Starting"], "GenerateProgramHostedService", ".ctor"); // ToDo Fody for tracing constructors, via an optional switch
            HostEnvironment            = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
            HostConfiguration          = hostConfiguration ?? throw new ArgumentNullException(nameof(hostConfiguration));
            HostLifetime               = hostLifetime ?? throw new ArgumentNullException(nameof(hostLifetime));
            HostedServiceConfiguration = hostedServiceConfiguration ?? throw new ArgumentNullException(nameof(hostedServiceConfiguration));
            HostApplicationLifetime    = hostApplicationLifetime ?? throw new ArgumentNullException(nameof(hostApplicationLifetime));
            InternalCancellationToken  = InternalCancellationTokenSource.Token;
            Stopwatch = new Stopwatch();
            #region Create the serviceData and initialize it from the StringConstants or this service's ConfigRoot
            Logger.LogDebug(DebugLocalizer["{0} {1}: Creating the ServiceData"], "GenerateProgramHostedService", ".ctor");

            ServiceData = new GenerateProgramHostedServiceData();
            // populate the servicedata tasks list with a single tuple for development

            // The following parameters are for each invocation of a InvokeGenerateProgramAsync call
            // invoking a GenerateProgram call may override any of these values, but absent an override, these are the
            //  default values that will be used for every InvokeGenerateProgramAsync call.
            //  the default values come from the IConfiguration HostedServiceConfiguration that is DI injected at service startup
            /// ToDo: Security: ensure the paths do not go above their Base directory

            // var gInvokeGenerateCodeSignilDefault = new GInvokeGenerateCodeSignil(
            //   new GAssemblyGroupSignil(), new GGlobalSettingsSignil(), new GSolutionSignil(),
            //   artifactsDirectoryBase: hostedServiceConfiguration.GetValue<string>(hostedServiceStringConstants.ArtifactsDirectoryBaseConfigRootKey, hostedServiceStringConstants.ArtifactsDirectoryBaseDefault), // ToDo: should validate in case the hostedServiceStringConstants assembly is messed up?
            //   artifactsFileRelativePath: hostedServiceConfiguration.GetValue<string>(hostedServiceStringConstants.ArtifactsFileRelativePathConfigRootKey, hostedServiceStringConstants.ArtifactsFileRelativePathDefault),
            //   enablePersistence: hostedServiceConfiguration.GetValue<bool>(hostedServiceStringConstants.EnablePersistenceBoolConfigRootKey, bool.Parse(hostedServiceStringConstants.EnablePersistenceBoolDefault)), // ToDo: should validate in case the hostedServiceStringConstants assembly is messed up?
            //   enablePickAndSave: hostedServiceConfiguration.GetValue<bool>(hostedServiceStringConstants.EnablePickAndSaveBoolConfigRootKey, bool.Parse(hostedServiceStringConstants.EnablePickAndSaveBoolDefault)), // 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?
            //   temporaryDirectoryBase: hostedServiceConfiguration.GetValue<string>(hostedServiceStringConstants.TemporaryDirectoryBaseConfigRootKey, hostedServiceStringConstants.TemporaryDirectoryBaseDefault),
            //   persistenceMessageFileRelativePath: hostedServiceConfiguration.GetValue<string>(hostedServiceStringConstants.PersistenceMessageFileRelativePathConfigRootKey, hostedServiceStringConstants.PersistenceMessageFileRelativePathDefault),
            //   pickAndSaveMessageFileRelativePath: hostedServiceConfiguration.GetValue<string>(hostedServiceStringConstants.PickAndSaveMessageFileRelativePathConfigRootKey, hostedServiceStringConstants.PickAndSaveMessageFileRelativePathDefault),
            //   dBConnectionString: hostedServiceConfiguration.GetValue<string>(hostedServiceStringConstants.DBConnectionStringConfigRootKey, hostedServiceStringConstants.DBConnectionStringDefault),
            //   ormLiteDialectProviderStringDefault: hostedServiceConfiguration.GetValue<string>(hostedServiceStringConstants.OrmLiteDialectProviderConfigRootKey, hostedServiceStringConstants.OrmLiteDialectProviderDefault)
            // );
            // // Every invocation to GenerateProgram needs an instance of an EntryPoint class
            // gInvokeGenerateCodeSignilDefault.EntryPoints = new ATAP.Utilities.GenerateProgram.EntryPoints();
            // gInvokeGenerateCodeSignilDefault.ArtifactsFilePaths = new string[1] { gInvokeGenerateCodeSignilDefault.ArtifactsDirectoryBase + gInvokeGenerateCodeSignilDefault.ArtifactsFileRelativePath };
            // gInvokeGenerateCodeSignilDefault.PersistenceFilePaths = new string[1] { gInvokeGenerateCodeSignilDefault.TemporaryDirectoryBase + gInvokeGenerateCodeSignilDefault.PersistenceMessageFileRelativePath };
            // gInvokeGenerateCodeSignilDefault.PickAndSaveFilePaths = new string[1] { gInvokeGenerateCodeSignilDefault.TemporaryDirectoryBase + gInvokeGenerateCodeSignilDefault.PickAndSaveMessageFileRelativePath };
            // // ToDo ?: setup placeholders for the ProgressReport object
            // // ToDo ?: setup placeholders for the Persistence(File)
            // // ToDo ?: setup placeholders for the PickAndSave object
            #endregion
        }
Exemplo n.º 24
0
 }                        // 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
 }
Exemplo n.º 25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime, IHostLifetime hostLifetime, ILifetimeScope autofacContainer)
        {
            AppLifetime      = appLifetime;
            AutofacContainer = autofacContainer;

            appLifetime.ApplicationStarted.Register(OnStarted);
            appLifetime.ApplicationStopping.Register(OnStopping);
            appLifetime.ApplicationStopped.Register(OnStopped);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseSerilogRequestLogging();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGrpcService <Behavior.Biz.Biz>();
                endpoints.MapGrpcService <BizAsync>();

                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
                });
            });
        }
 public TerminateCommandHandler(IHostLifetime hostLifetime)
 {
     _hostLifetime = hostLifetime;
 }
 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
 }
Exemplo n.º 29
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime, IHostLifetime hostLifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });


            // Graceful shutdown
            applicationLifetime.ApplicationStopping.Register(() =>
            {
            });
        }
Exemplo n.º 30
0
        //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;
        }