private void DoDetect(OperationResult <bool> DetectionResult)
        {
            this.TxtStatus.Foreground = Brushes.White;

            try
            {
                if (DetectionResult.WasSuccessful)
                {
                    this.TxtStatus.Background = Brushes.Green;
                    this.TxtStatus.Text       = "Detection complete.";

                    var VersionFileText = General.FileToString(ProductDirector.VersioningSourceLocal);
                    this.VersionFileLines      = General.ToStrings(VersionFileText);
                    this.TxtNewestVersion.Text = this.VersionFileLines[0].Substring(1).Trim();
                    this.TxbChanges.Text       = VersionFileText;

                    if (ProductDirector.ProductUpdateIsNeeded(this.VersionFileLines))
                    {
                        this.BrdUpdate.SetVisible(true);
                        this.TxtStatus.Text = "There is a new version available!  Update when ready.";
                    }
                    else
                    {
                        this.TxtStatus.Text = "You are using the latest version available. No update required.";
                    }
                }
                else
                {
                    this.TxtStatus.Background = Brushes.Red;
                    this.TxtStatus.Text       = "Detection failed. Try again later.";
                }
            }
            catch (Exception Problem)
            {
                this.TxtStatus.Background = Brushes.Red;
                this.TxtStatus.Text       = "Detection failed. Cannot process request.";
                Display.DialogMessage("Error!", "Detection failed.\n\nProblem: " + Problem.Message);
            }

            this.PgsStatus.Value = 0;
            this.IsWorking       = false;
        }
        private void BtnUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (!ProductDirector.AppTerminationConfirmation())
            {
                return;
            }

            this.IsCancelled = false;
            this.IsWorking   = true;
            this.BrdUpdate.SetVisible(false, false);
            this.PgsStatus.Value = 0;

            this.TxtStatus.Background = Brushes.Blue;
            this.TxtStatus.Foreground = Brushes.White;
            this.TxtStatus.Text       = "Downloading new version";

            ProductDirector.LaunchNewVersionSetupOnExit = false;

            try
            {
                if (File.Exists(ProductDirector.VersioningSourceLocal))
                {
                    File.Delete(ProductDirector.VersioningSourceLocal);
                }

                General.DownloadFileAsync(new Uri(ProductDirector.SetupSourceRemote, UriKind.Absolute),
                                          ProductDirector.SetupSourceLocal,
                                          evargs =>
                {
                    this.PgsStatus.Value = evargs.ProgressPercentage;
                    return(!this.IsCancelled);
                },
                                          result =>
                {
                    this.TxtStatus.Foreground = Brushes.White;
                    this.IsWorking            = false;

                    if (result.WasSuccessful)
                    {
                        this.TxtStatus.Background = Brushes.Green;
                        this.TxtStatus.Text       = "Download complete.";

                        /* var Result = Display.DialogMessage("Attention", "Now the application will be closed and the installer will be started.",
                         *                                 EMessageType.Information, MessageBoxButton.OKCancel, MessageBoxResult.OK);
                         * if (Result != MessageBoxResult.OK)
                         *  return; */

                        ProductDirector.LaunchNewVersionSetupOnExit = true;
                        Application.Current.MainWindow.PostCall(wnd => wnd.Close());
                    }
                    else
                    {
                        this.TxtStatus.Background = Brushes.Red;
                        this.TxtStatus.Text       = "Download failed. Try again later.";
                        Display.DialogMessage("Error!", "Download failed.\n\nProblem: " + result.Message);
                    }
                });
            }
            catch (Exception Problem)
            {
                Display.DialogMessage("Error!", "Cannot start download and update of new version.\n\nProblem: " + Problem.Message);
            }
        }
Beispiel #3
0
        public static void ProductUpdateDaylyDetection()
        {
            // Pending: As in Paint.NET, force to be execute only once per day (not per execution).
            try
            {
                var LastDetection = AppExec.GetConfiguration <DateTime>("Application", "LastUpdateCheck");
                if (LastDetection.Date >= DateTime.Now.Date)
                {
                    return;
                }

                if (File.Exists(ProductDirector.LocalVersioningSource))
                {
                    File.Delete(ProductDirector.LocalVersioningSource);
                }

                General.DownloadFileAsync(new Uri(ProductDirector.VERSIONING_SOURCE, UriKind.Absolute),
                                          ProductDirector.LocalVersioningSource, evargs => true,
                                          result =>
                {
                    try
                    {
                        if (result.WasSuccessful)
                        {
                            AppExec.SetConfiguration <DateTime>("Application", "LastUpdateCheck", DateTime.Now.Date, true);

                            var VersionFileText  = General.FileToString(ProductDirector.LocalVersioningSource);
                            var VersionFileLines = General.StringToStrings(VersionFileText);

                            if (ProductDirector.ProductUpdateIsNeeded(VersionFileLines))
                            {
                                Console.WriteLine("There is a new version available: " + VersionFileLines[0]);

                                /*- var Result = Display.DialogMessage("Attention!", "There is a new version available for update this application.\n" +
                                 *                                                   "Do you want to download and install it now?", EMessageType.Question,
                                 *                                                   System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxResult.Yes); */

                                var Result = Display.DialogPersistableMultiOption("Attention!", "There is a new version available for update this application.\n" +
                                                                                  "Do you want to download and install it now?", null,
                                                                                  "Application", "AskForUpdateOnStart", "Cancel",
                                                                                  new SimplePresentationElement("OK", "OK", "Proceed, and apply changes directly.", Display.GetAppImage("accept.png")),
                                                                                  new SimplePresentationElement("Cancel", "Cancel", "Do not edit.", Display.GetAppImage("cancel.png")));

                                if (Result != null && Result == "OK")
                                {
                                    ;
                                }
                                AppVersionUpdate.ShowAppVersionUpdate(VersionFileText);
                            }
                            else
                            {
                                Console.WriteLine("You are using the latest version available. No update required.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Unable to detect new application version.");
                        }
                    }
                    catch (Exception Problem)
                    {
                        Console.WriteLine("Cannot detect new application version. Problem: " + Problem.Message);
                    }
                });
            }
            catch (Exception Problem)
            {
                Console.WriteLine("Error: Cannot start detection of new version.\n\nProblem: " + Problem.Message);
            }
        }