void CheckInstallation()
        {
            Thread.Sleep(200);

            var exit = SeqForwarderExeUtility.Run("install --setup", WriteOutput, WriteError);

            _dispatcher.Invoke(() =>
            {
                IsDone    = true;
                HasFailed = HasFailed || exit != 0;
            });
        }
        public ConfigurationViewModel(Dispatcher dispatcher)
        {
            _dispatcher = dispatcher;

            if (Environment.CommandLine.Contains("--setup") && SeqForwarderExeUtility.DefaultInstanceIsInstalled())
            {
                Page = "Execute";
                Task.Run(() => CheckInstallation());
            }
            else
            {
                _serverUrl   = "";
                _apiKey      = "";
                _storagePath = Path.GetFullPath(Path.Combine(
                                                    Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                                                    "Seq",
                                                    "Forwarder"));
            }
        }
        void Install()
        {
            Thread.Sleep(200);

            var exit = 0;

            if (SeqForwarderExeUtility.DefaultInstanceIsInstalled())
            {
                WriteOutput("An existing service instance was detected; removing the service entry...");
                SeqForwarderExeUtility.Run("stop", delegate { }, delegate { });
                exit = SeqForwarderExeUtility.Run("uninstall", WriteOutput, WriteError);
            }

            if (exit == 0)
            {
                exit = SeqForwarderExeUtility.Run($"install --storage=\"{_storagePath}\"", WriteOutput, WriteError);
            }

            if (exit == 0)
            {
                exit = SeqForwarderExeUtility.Run($"config -k output.serverUrl --value=\"{_serverUrl}\"", WriteOutput, WriteError);
            }

            if (exit == 0 && !string.IsNullOrWhiteSpace(_apiKey))
            {
                exit = SeqForwarderExeUtility.Run($"config -k output.apiKey --value=\"{_apiKey}\"", WriteOutput, WriteError);
            }

            if (exit == 0)
            {
                exit = SeqForwarderExeUtility.Run("start", WriteOutput, WriteError);
            }

            _dispatcher.Invoke(() =>
            {
                IsDone    = true;
                HasFailed = HasFailed || exit != 0;
            });
        }