private void CheckForUpdateCompleted(Action postUpdateAction, IUpdateManager updater, VersionInfo versionInfo, bool isNewVersion) { try { if (versionInfo == null) { MessageBox.Show( "There was an error verifying your version of HSDL-TigerIDM. Please check your network connection or contact your System Administrator.", "HSDL-TigerIDM", MessageBoxButton.OK, MessageBoxImage.Error); logger.Error("Version Information is missing in server."); hasError = true; postUpdateAction(); return; } if (isNewVersion) // New version detected { MessageBoxResult confirmDownload = MessageBox.Show( "A new version of HSDL-TigerIDM is available for download. The process may take a few minutes. Do you want to download it now?", "HSDL-TigerIDM", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes); if (confirmDownload == MessageBoxResult.No) // user cannot run the application without installing available UPDATE { logger.Error("User refused to download new version."); userRefusedToAccept = true; postUpdateAction(); return; } } else // Installation is up-to-date { logger.Info("Current version is up-to-date."); userRefusedToAccept = false; hasError = false; postUpdateAction(); return; } /* Download update (if there is any) */ //logger.Info("UpdateProgressView starting."); UpdateProgressView dlProgressWindow = new UpdateProgressView(); dlProgressWindow.Show(); dlProgressWindow.Cancelled += (sender, e) => { updater.CancelDownloadMsi(); }; //logger.Info("UpdateProgressView closed."); Action <AsyncCompletedEventArgs> postDownloadAction = (e) => { string localMsiFilePath = (string)e.UserState; newMsiFilePath = localMsiFilePath; if (e.Cancelled) { //MessageBox.Show( // "Download cancelled.", // ""HSDL Admin Portal", // MessageBoxButton.OK, // MessageBoxImage.Error); } else if (e.Error != null) { logger.Error(Util.GetExceptionMessageWithStackTrace(e.Error)); MessageBox.Show( "There was an error downloading the latest version of HSDL-TigerIDM. Please check your network connection or contact your System Administrator.", "HSDL-TigerIDM", MessageBoxButton.OK, MessageBoxImage.Error); } // Download cancelled by user or error occurred while downloading update if (e.Error != null) { hasError = true; postUpdateAction(); return; } MessageBoxResult confirmInstall = MessageBox.Show( "\nThe new version of HSDL-TigerIDM has been successfully downloaded. Do you want to install it now?", "HSDL-TigerIDM", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes); if (confirmInstall == MessageBoxResult.No) { logger.Error("User refused to install new version after downloaded."); userRefusedToAccept = true; postUpdateAction(); return; } if (postUpdateAction != null) { postUpdateAction(); } }; updater.DownloadProgressChanged += (sender, e) => { Dispatcher.Invoke((Action)( () => { string bytes = GetHumanReadbleByte(e.BytesReceived); dlProgressWindow.txtMessage.Text = "Downloading update... " + bytes + " of " + versionInfo.fileSize; dlProgressWindow.progressBar.Value = e.ProgressPercentage; } )); }; updater.DownloadFileCompleted += (sender, e) => { Dispatcher.Invoke((Action)( () => { dlProgressWindow.txtMessage.Text = "Downloading complete."; dlProgressWindow.Close(); postDownloadAction(e); } )); }; //string localMsiFilePath = null; ThreadPool.QueueUserWorkItem( new WaitCallback(obj => { updater.DownloadMsiAsync(new Uri(GetFormattedFtpPath(versionInfo.relativePath, versionInfo.SetupFileName)), versionInfo.SetupFileName); }) ); } catch (Exception ex) { hasError = true; logger.Error(Util.GetExceptionMessageWithStackTrace(ex)); MessageBox.Show( "There was an error verifying your version of HSDL-TigerIDM. Please check your network connection or contact your System Administrator.", "HSDL-TigerIDM", MessageBoxButton.OK, MessageBoxImage.Error); StartApplication(); return; } }