Exemplo n.º 1
0
        private void BtnEiUpdate_Click(object sender, EventArgs e)
        {
            Enabled = false;
            var tmp = btnEiUpdate.Text;

            btnEiUpdate.Text = "Updating ...";
            btnEiUpdate.Update();
            DialogResult res         = DialogResult.OK;
            var          progressBar = new LoadingBar("EI Update", (ct, invok, progress) =>
            {
                do
                {
                    try
                    {
                        EliteInsights.Update(initState,
                                             new Progress <double>(p => progress.Report(new ProgressMessage(p, "Update EI"))),
                                             ct).Wait();
                    }
                    catch (OperationCanceledException ex)
                    {
                        Logger.Error("Manual EI update failed");
                        Logger.LogException(ex);
                        res = MessageBox.Show("EI uppdate failed.\nMessage:\n" + ex.Message, "Error - EI Update", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    }
                } while (res == DialogResult.Retry);
            });

            progressBar.ShowDialog(this);
            btnEiUpdate.Text = tmp;
            Enabled          = true;
        }
Exemplo n.º 2
0
        private static async Task InitEliteInsights(IEliteInsightsSettings settings, IProxySettings proxySettings, IProgress <ProgressMessage> progress = null, CancellationToken cancellationToken = default)
        {
            progress?.Report(new ProgressMessage(0, "Init"));
            EliteInsights.Init(settings);
            await EliteInsights.UpdateNewestVersion(proxySettings, new Progress <double>(p => progress?.Report(new ProgressMessage((p * 0.2) + 0.05, "Checking for Update"))));

            var newVersion = EliteInsights.UpdateAviable();

            if (EliteInsights.IsInstalled())
            {
                Logger.Message($"Installed EI Version: {EliteInsights.LocalVersion}");
            }
            else
            {
                Logger.Warn("EI not installed");
            }
            if (newVersion)
            {
                Logger.Message("EI update available. New version: " + EliteInsights.NewestVersion);
                Logger.Message("Auto update EI: " + settings.AutoUpdateEI);
                if (settings.AutoUpdateEI || MessageBox.Show("New Version of EliteInsights is aviable\nUpdate now?", "EliteInsights Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    progress?.Report(new ProgressMessage(0.25, "Starting Update"));
                    try
                    {
                        await EliteInsights.Update(proxySettings, new Progress <double>(p => progress?.Report(new ProgressMessage((p * 0.70) + 0.25, $"Updating {p*100:.}%"))), cancellationToken);

                        Logger.Message("Update EI completed");
                    }
                    catch (OperationCanceledException e)
                    {
                        Logger.Warn("EI update failed");
                        Logger.LogException(e);
                        if (!EliteInsights.IsInstalled())
                        {
                            MessageBox.Show("Faild to install EliteInsights", "Missing EliteInsights installation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            //TODO really crash here?
                            Exit(ExitCode.EI_UPDATE_FATAL_ERROR);
                        }
                    }

                    progress?.Report(new ProgressMessage(1, "Update Done"));
                }
            }
        }