public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { services.AddSingleton(typeof(ILoggerAdapter <>), typeof(LoggerAdapter <>)); services.AddSingleton <IEntryPointService, EntryPointService>(); services.AddSingleton <IServiceLocator, ServiceScopeFactoryLocator>(); // Infrastructure.ContainerSetup services.AddMessageQueues(); services.AddDbContext(hostContext.Configuration); services.AddRepositories(); services.AddUrlCheckingServices(); var workerSettings = new WorkerSettings(); hostContext.Configuration.Bind(nameof(WorkerSettings), workerSettings); services.AddSingleton(workerSettings); var entryPointSettings = new EntryPointSettings(); hostContext.Configuration.Bind(nameof(EntryPointSettings), entryPointSettings); services.AddSingleton(entryPointSettings); // examples of different ways to add instances and lifetimes services.AddTransient <IOrderService, OrderService>(); services.AddScoped <IOrderRepository, OrderRepository>(); services.AddSingleton <IConnectionManager, ConnectionManager>(); services.AddSingleton <SomeInstance>(new SomeInstance()); services.AddHostedService <Worker>(); });
public EntryPointService(ILoggerAdapter <EntryPointService> logger, EntryPointSettings settings, IQueueReceiver queueReceiver, IQueueSender queueSender) { _logger = logger; this.settings = settings; _queueReceiver = queueReceiver; _queueSender = queueSender; }
public EntryPointService(ILoggerAdapter <EntryPointService> logger, EntryPointSettings settings, IQueueReceiver queueReceiver, IQueueSender queueSender, IServiceLocator serviceScopeFactoryLocator, IUrlStatusChecker urlStatusChecker) { _logger = logger; _settings = settings; _queueReceiver = queueReceiver; _queueSender = queueSender; _serviceScopeFactoryLocator = serviceScopeFactoryLocator; _urlStatusChecker = urlStatusChecker; }
public EntryPointService(ILoggerAdapter <EntryPointService> logger, EntryPointSettings settings, IUpload upload, ICapture capture, IServiceLocator serviceScopeFactoryLocator, IUrlStatusChecker urlStatusChecker) { _logger = logger; _settings = settings; _capture = capture; _upload = upload; _serviceScopeFactoryLocator = serviceScopeFactoryLocator; _urlStatusChecker = urlStatusChecker; }
private static (EntryPointService, Mock <ILoggerAdapter <EntryPointService> >, Mock <IQueueReceiver>, Mock <IServiceLocator>, Mock <IRepository>) Factory() { var logger = new Mock <ILoggerAdapter <EntryPointService> >(); var settings = new EntryPointSettings { ReceivingQueueName = "testQueue" }; var queueReceiver = new Mock <IQueueReceiver>(); var serviceLocator = new Mock <IServiceLocator>(); // maybe a tuple later on var repository = SetupCreateScope(serviceLocator); var service = new EntryPointService(logger.Object, settings, queueReceiver.Object, null, serviceLocator.Object, null); return(service, logger, queueReceiver, serviceLocator, repository); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { services.AddSingleton(typeof(ILoggerAdapter <>), typeof(LoggerAdapter <>)); services.AddSingleton <IEntryPointService, EntryPointService>(); services.AddSingleton <IQueueReceiver, InMemoryQueueReceiver>(); services.AddSingleton <IQueueSender, InMemoryQueueSender>(); var workerSettings = new WorkerSettings(); hostContext.Configuration.Bind(nameof(WorkerSettings), workerSettings); services.AddSingleton(workerSettings); var entryPointSettings = new EntryPointSettings(); hostContext.Configuration.Bind(nameof(EntryPointSettings), entryPointSettings); services.AddSingleton(entryPointSettings); services.AddHostedService <Worker>(); });
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { services.AddSingleton(typeof(ILoggerAdapter <>), typeof(LoggerAdapter <>)); services.AddSingleton <IEntryPointService, EntryPointService>(); services.AddSingleton <IQueueReceiver, InMemoryQueueReceiver>(); services.AddSingleton <IQueueSender, InMemoryQueueSender>(); // https://weblog.west-wind.com/posts/2017/Dec/12/Easy-Configuration-Binding-in-ASPNET-Core-revisited var workerSettings = new WorkerSettings(); hostContext.Configuration.Bind(nameof(WorkerSettings), workerSettings); services.AddSingleton(workerSettings); var entryPointSettings = new EntryPointSettings(); hostContext.Configuration.Bind(nameof(EntryPointSettings), entryPointSettings); services.AddSingleton(entryPointSettings); services.AddHostedService <Worker>(); });
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureServices((hostContext, services) => { services.AddSingleton(typeof(ILoggerAdapter <>), typeof(LoggerAdapter <>)); services.AddSingleton <IEntryPointService, EntryPointService>(); services.AddSingleton <IServiceLocator, ServiceScopeFactoryLocator>(); // Infrastructure.ContainerSetup services.AddImages(); services.AddUrlCheckingServices(); var entryPointSettings = new EntryPointSettings(); hostContext.Configuration.Bind(nameof(EntryPointSettings), entryPointSettings); services.AddSingleton(entryPointSettings); var workerSettings = new WorkerSettings(); hostContext.Configuration.Bind(nameof(WorkerSettings), workerSettings); services.AddSingleton(workerSettings); services.AddHostedService <Worker>(); });
public void CaptueImage(EntryPointSettings entryPoint) { //Method 1 //ScreenCapture sc = new ScreenCapture(); //Image img = sc.CaptureScreen(); //string imageName = $"{entryPoint.UserID}-{DateTime.Now.ToFileTime()}.png"; //img.Save("img.png", System.Drawing.Imaging.ImageFormat.Png); //Method 2 ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"\root\wmi", @"SELECT * FROM WmiMonitorBasicDisplayParams"); //Calculate and output size for each monitor foreach (ManagementObject managementObject in searcher.Get()) { string imageName = $"{entryPoint.UserID}-{DateTime.Now.ToFileTime()}.png"; double width = (byte)managementObject["MaxHorizontalImageSize"]; double height = (byte)managementObject["MaxVerticalImageSize"]; Bitmap bmp = new Bitmap(Convert.ToInt32(width * width), Convert.ToInt32(height * height)); Graphics gr = Graphics.FromImage(bmp); gr.CopyFromScreen(0, 0, 0, 0, bmp.Size); bmp.Save(imageName, System.Drawing.Imaging.ImageFormat.Png); } }