private static void KillOtherWorkers(ILogger <Program> logger, int processId)
        {
            logger.LogDebug($"Killing other workers except process id = '{processId}'");

            var executingFile    = WorkerHelper.GetExecutingFile();
            var workerFileName   = WorkerHelper.GetWorkerFileName(executingFile);
            var currentProcessId = Process.GetCurrentProcess().Id;
            var processes        = Process.GetProcesses();

            foreach (var process in processes)
            {
                logger.LogDebug($"Process id = '{process.Id}', name = '{process.ProcessName}'");

                try
                {
                    if (process.Id == currentProcessId ||
                        process.Id == processId ||
                        process.ProcessName.IndexOf("HstWbInstaller.Imager.GuiApp",
                                                    StringComparison.OrdinalIgnoreCase) < 0 ||
                        process.MainModule == null ||
                        process.MainModule.FileName == null ||
                        process.MainModule.FileName.IndexOf(workerFileName, StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        continue;
                    }
                }
                catch (Exception)
                {
                    continue;
                }

                logger.LogDebug($"Killing worker process id '{process.Id}', name '{process.ProcessName}'");
                process.Kill();
            }
        }
Beispiel #2
0
        private static void SetupDebugLogging()
        {
            var logFilePath = Path.Combine(Path.GetDirectoryName(WorkerHelper.GetExecutingFile()), "logs",
                                           "log-imager.txt");

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                         .WriteTo.File(
                logFilePath,
                rollingInterval: RollingInterval.Day,
                outputTemplate:
                "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] ({SourceContext}) {Message}{NewLine}{Exception}")
                         .CreateLogger();
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSignalR(o =>
            {
                o.EnableDetailedErrors      = ApplicationDataHelper.HasDebugEnabled(Constants.AppName);
                o.MaximumReceiveMessageSize = 1024 * 1024;
            });

            services.AddControllersWithViews().AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
            });

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });

            services.AddHostedService <QueuedHostedService>();
            services.AddSingleton <IBackgroundTaskQueue>(new BackgroundTaskQueue(100));

            services.AddHostedService <BackgroundTaskService>();
            services.AddSingleton <IActiveBackgroundTaskList>(new ActiveBackgroundTaskList());
            services.AddSingleton(new AppState
            {
                AppPath          = AppContext.BaseDirectory,
                ExecutingFile    = WorkerHelper.GetExecutingFile(),
                IsLicenseAgreed  = ApplicationDataHelper.IsLicenseAgreed(Constants.AppName),
                IsAdministrator  = OperatingSystem.IsAdministrator(),
                IsElectronActive = HybridSupport.IsElectronActive,
                UseFake          = Debugger.IsAttached,
                IsWindows        = OperatingSystem.IsWindows(),
                IsMacOs          = OperatingSystem.IsMacOs(),
                IsLinux          = OperatingSystem.IsLinux()
            });
            services.AddSingleton <PhysicalDriveManagerFactory>();
            services.AddSingleton <WorkerService>();
        }