Exemplo n.º 1
0
        //public static void InstallUpdateSyncWithInfo(MainWindowViewModel mainWindowViewModel)
        public static bool InstallUpdateSyncWithInfo(MainWindowViewModel mainWindowViewModel)
        {
            return false;

            var updateAvailable = false;
            UpdateCheckInfo info = null;

            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

                try
                {
                    info = ad.CheckForDetailedUpdate();

                }
                catch (DeploymentDownloadException dde)
                {
                    RepOperation.LogError(new SSCTechException(dde));
                    MsgUtility.ShowMessageBox("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message, MessageType.Info);
                    return updateAvailable;
                    //return;
                }
                catch (InvalidDeploymentException ide)
                {
                    RepOperation.LogError(new SSCTechException(ide));
                    MsgUtility.ShowMessageBox("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message, MessageType.Info);
                    return updateAvailable;
                    //return;
                }
                catch (InvalidOperationException ioe)
                {
                    RepOperation.LogError(new SSCTechException(ioe));
                    MsgUtility.ShowMessageBox("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message, MessageType.Info);
                    return updateAvailable;
                    //return;
                }

                if (info.UpdateAvailable)
                {
                    updateAvailable = true;
                    Boolean doUpdate = true;

                    //if (!info.IsUpdateRequired)
                    //{
                    //    MessageBoxResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButton.OKCancel);
                    //    if (!(MessageBoxResult.OK == dr))
                    //    {
                    //        doUpdate = false;
                    //    }
                    //}
                    //else
                    //{
                    //    // Display a message that the app MUST reboot. Display the minimum required version.
                    //    MessageBox.Show("This application has detected a mandatory update from your current " +
                    //        "version to version " + info.MinimumRequiredVersion.ToString() +
                    //        ". The application will now install the update and restart.",
                    //        "Update Available", MessageBoxButton.OK,
                    //        MessageBoxImage.Information);
                    //}

                    MsgUtility.ShowMessageBox("An update is available. The application will now install the update.", MessageType.Info);

                    if (doUpdate)
                    {
                        try
                        {
                            //using (BackgroundWorker worker = new BackgroundWorker())
                            //{
                            //    mainWindowViewModel.ProgressBarMsg = "Updating Application";
                            //    mainWindowViewModel.IsProgressBarVisible = true;

                            //    worker.DoWork += (s, e) =>
                            //    {
                            //        ad.Update();
                            //    };

                            //    worker.RunWorkerCompleted += (s, e) =>
                            //    {
                            //        if (e.Error != null)
                            //        {
                            //            mainWindowViewModel.IsBusy = false;
                            //            SSCLog.HandleError(e.Error);
                            //        }
                            //        else
                            //        {
                            //            //MsgUtility.ShowMessageBox("The application has been upgraded, and will now restart.", MessageType.Info);
                            //            MsgUtility.ShowMessageBox("The application has been upgraded, you have to restart the application.", MessageType.Info);
                            //        }
                            //        mainWindowViewModel.IsBusy = false;
                            //        mainWindowViewModel.IsProgressBarVisible = false;
                            //        RestartApp();
                            //    };

                            //    //mainWindowViewModel.IsBusy = true;
                            //    worker.RunWorkerAsync();
                            //}

                            //mainWindowViewModel.IsBusy = true;
                            //mainWindowViewModel.ProgressBarMsg = "Updating Application";
                            //mainWindowViewModel.IsProgressBarVisible = true;

                            //ad.Update();

                            //mainWindowViewModel.IsBusy = false;
                            //mainWindowViewModel.IsProgressBarVisible = false;

                            //MsgUtility.ShowMessageBox("The application has been upgraded, you have to restart the application.", MessageType.Info);

                        }
                        catch (DeploymentDownloadException dde)
                        {
                            RepOperation.LogError(new SSCTechException(dde));
                            MsgUtility.ShowMessageBox("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde, MessageType.Info);
                            return updateAvailable;
                            //return;
                        }
                    }
                }
            }

            return updateAvailable;
        }
Exemplo n.º 2
0
        public static void UpdateApp(MainWindowViewModel mainWindowViewModel)
        {
            using (BackgroundWorker worker = new BackgroundWorker())
            {
                mainWindowViewModel.ProgressBarMsg = "Updating Application";
                mainWindowViewModel.IsProgressBarVisible = true;

                worker.DoWork += (s, e) =>
                {
                    ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
                    ad.Update();
                };

                worker.RunWorkerCompleted += (s, e) =>
                {
                    if (e.Error != null)
                    {
                        mainWindowViewModel.IsBusy = false;
                        SSCLog.HandleError(e.Error);
                    }
                    else
                    {
                        //MsgUtility.ShowMessageBox("The application has been upgraded, and will now restart.", MessageType.Info);
                        MsgUtility.ShowMessageBox("The application has been upgraded, you have to restart the application.", MessageType.Info);
                    }
                    mainWindowViewModel.IsBusy = false;
                    mainWindowViewModel.IsProgressBarVisible = false;
                    RestartApp();
                };

                mainWindowViewModel.IsBusy = true;
                worker.RunWorkerAsync();
            }
        }