Esempio n. 1
0
        public void DoAuto2(SetupOperation task)
        {
            var errorLogFile = Path.Combine(Program.logsDir, "error.log");

            try {
                SetupOperation.DeleteFile(errorLogFile);

                if (!task.ConfigurationDialog())
                {
                    return;
                }

                if (!task.StartupWarning())
                {
                    return;
                }

                try {
                    task.Run();

                    if (cancelSource.IsCancellationRequested)
                    {
                        throw new OperationCanceledException();
                    }
                }
                catch (OperationCanceledException e) {
                    return;
                }

                if (task.Failed() || task.Warnings())
                {
                    task.FinishedDialog();
                }
            }
            catch (Exception e) {
                SetStatus(e.Message);
                Environment.Exit(1);
                var status = "";

                SetupOperation.CreateDirectory(Program.logsDir);
                File.WriteAllText(errorLogFile, status + "\r\n" + e);
            }
        }
Esempio n. 2
0
        private void RunTaskThread(SetupOperation task)
        {
            var errorLogFile = Path.Combine(Program.logsDir, "error.log");

            try
            {
                SetupOperation.DeleteFile(errorLogFile);

                if (!task.ConfigurationDialog())
                {
                    return;
                }

                if (!task.StartupWarning())
                {
                    return;
                }

                try
                {
                    task.Run();

                    if (cancelSource.IsCancellationRequested)
                    {
                        throw new OperationCanceledException();
                    }
                }
                catch (OperationCanceledException e)
                {
                    Invoke(new Action(() =>
                    {
                        labelStatus.Text = "Cancelled";
                        if (e.Message != new OperationCanceledException().Message)
                        {
                            labelStatus.Text += ": " + e.Message;
                        }
                    }));
                    return;
                }

                if (task.Failed() || task.Warnings())
                {
                    task.FinishedDialog();
                }

                Invoke(new Action(() =>
                {
                    labelStatus.Text = task.Failed() ? "Failed" : "Done";
                }));
            }
            catch (Exception e)
            {
                var status = "";
                Invoke(new Action(() =>
                {
                    status           = labelStatus.Text;
                    labelStatus.Text = "Error: " + e.Message.Trim();
                }));

                SetupOperation.CreateDirectory(Program.logsDir);
                File.WriteAllText(errorLogFile, status + "\r\n" + e);
            }
            finally
            {
                Invoke(new Action(() =>
                {
                    foreach (var b in taskButtons.Keys)
                    {
                        b.Enabled = true;
                    }
                    buttonCancel.Enabled = false;
                    progressBar.Value    = 0;
                    if (closeOnCancel)
                    {
                        Close();
                    }
                }));
            }
        }