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;
        }
Example #2
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);
            }
        }