Exemple #1
0
 static void Main(string[] args)
 {
     using (var guard = new SingleInstanceGuard(ProgramId, SingleInstanceGuard.Scope.CurrentUser))
     {
         if (guard.IsPrimaryInstance)
         {
             RunApp(args);
         }
         else
         {
             User32Messages.BroadcastMessage(Constants.OpenWindowMessage);
         }
     }
 }
Exemple #2
0
        static void RunApp(string[] args)
        {
            var shouldStartService = args.Any(x => "-StartService".Equals(x, StringComparison.InvariantCultureIgnoreCase));

            var settingsStore = new InMemoryKeyValueCache(new RegistryKeyValueStore(AppName));

            var logBuffer = new RotatingBufferSink();

            InitializeLogging(logBuffer, settingsStore, defaultLogLevel: LogLevel.Info);
            Log.Info($"Running version: {AppVersion}");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var retryLogic          = new ExponentialBackoffLogic(min: TimeSpan.FromMilliseconds(10), max: TimeSpan.FromHours(1));
            var startupRegistration = new StartupFolderRegistration(
                AppName.ToLowerInvariant(),
                new ShortcutOptions {
                Arguments = "-StartService", Target = AppPath
            },
                WindowsScriptHostWrapper.CreateShortcut,
                ShellifyWrapper.ReadShortcut);

            using (var scheduler = new WorkScheduler(retryLogic.CalculateRetryAfter))
            {
                var service = new WatchForFilesToDelete <string>(
                    subjectFactory: () => CreateSubject(settingsStore),
                    delete: Shell32Delete.DeleteFile,
                    scheduler: scheduler);

                RunForm(new MainForm(
                            showSettingsForm: !shouldStartService,
                            appPath: AppPath,
                            logEntries: logBuffer,
                            openWindowMessage: (int)User32Messages.GetMessage(Constants.OpenWindowMessage),
                            settingsStore: settingsStore,
                            startService: service.Run,
                            startupRegistration: startupRegistration));
            }
        }