//************************************************************** // AppUpdater Constructor //************************************************************** public AppDownloader(AppUpdater appMan) { AppMan = appMan; Log = new UpdateLog(); UpdateEventArgs = new UpdateCompleteEventArgs(); DownloadEventArgs = new DownloadProgressEventArgs(); }
//************************************************************** // AppUpdater Constructor //************************************************************** public AppDownloader(AppUpdater appMan) { AppMan = appMan; Log = new UpdateLog(); UpdateEventArgs = new UpdateCompleteEventArgs(); DownloadEventArgs = new DownloadProgressEventArgs(); }
//************************************************************** // OnDownloaderComplete() //************************************************************** private void Downloader_OnUpdateComplete(object sender, UpdateCompleteEventArgs e) { if (OnUpdateComplete != null) { foreach (UpdateCompleteEventHandler UC in OnUpdateComplete.GetInvocationList()) { EventControl.BeginInvoke(UC, new object[] { sender, e }); } } //EventControl.BeginInvoke(new UpdateCompleteEventHandler(UpdateCompleteOps),new object[] {sender, e}); }
//************************************************************** // UpdateCompleteOps() //************************************************************** private void UpdateCompleteOps(object sender, UpdateCompleteEventArgs args) { if (ShowDefaultUI) { if (args.UpdateSucceeded) { UpdateForm F = new UpdateForm(); if (F.ShowDialog() == DialogResult.Yes) { RestartApp(); } } else { string ErrorMessage; ErrorMessage = "The auto-update of this application failed with the following error message: \r\n\r\n" + args.ErrorMessage + "\r\n\r\n" + "To correct this problem, try rebooting the computer & re-launching this application."; MessageBox.Show(ErrorMessage, "Application Update Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
//************************************************************** // This event if fired whenever a new update is complete. // shutdown the app //************************************************************** public void updater_OnUpdateComplete(object sender, UpdateCompleteEventArgs e) { string serviceName = null; //If the udpate succeeded... if (e.UpdateSucceeded) { logger.Info("Update succeeded."); //need to restart the service. //for now, this works only for ONE service. //refresh the config. config = ServiceUpdaterConfig.getUpdaterConfig(configFile); if (config.ClientMode == UpdaterClientMode.Service) { if (config.ClientType == UpdaterClientType.Executor) { serviceName = "Alchemi Executor Service"; } else if (config.ClientType == UpdaterClientType.Manager) { serviceName = "Alchemi Manager Service"; } if (serviceName != null) { try { ServiceController sc = new ServiceController(serviceName); sc.Refresh(); if (sc.CanStop) { sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped); } sc = null; logger.Info("Stopped service: " + serviceName); //need to uninstall the old one, install-&-start the new one. //uninstall here can only be done using the cmd-line since we dont have the ProjectInstaller object with us. //first uninstall the old one. Process pOld = new Process(); pOld.StartInfo = new ProcessStartInfo(currentServiceExePath, " /uninstall"); //using old service exe path pOld.Start(); logger.Info("Uninstall Process started : " + pOld.StartInfo.ToString()); pOld.WaitForExit(); pOld = null; Process pNew = new Process(); pNew.StartInfo = new ProcessStartInfo(config.AppExePath, " /install"); //using new service exe path pNew.Start(); logger.Info("Re-install Process started : " + pNew.StartInfo.ToString()); pNew.WaitForExit(); pNew = null; //now get the service controller again and try to start the service. sc = new ServiceController(serviceName); sc.Refresh(); sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running); sc = null; } catch (Exception ex) { handleUpdaterError("Error updating/restarting: " + serviceName, ex); } } } else { //currently we dont support updating an exec mode client. logger.Info("Updater service currently doesnt support App mode. It can update services only."); } } else //If the update failed.... { handleUpdaterError(e.ErrorMessage, e.FailureException); } }
//************************************************************** // UpdateCompleteOps() //************************************************************** private void UpdateCompleteOps(object sender, UpdateCompleteEventArgs args) { if (ShowDefaultUI) { if (args.UpdateSucceeded) { UpdateForm F = new UpdateForm(); if (F.ShowDialog()==DialogResult.Yes) RestartApp(); } else { string ErrorMessage; ErrorMessage = "The auto-update of this application failed with the following error message: \r\n\r\n" + args.ErrorMessage + "\r\n\r\n" + "To correct this problem, try rebooting the computer & re-launching this application."; MessageBox.Show(ErrorMessage,"Application Update Failed",MessageBoxButtons.OK,MessageBoxIcon.Warning); } } }
//************************************************************** // OnDownloaderComplete() //************************************************************** private void Downloader_OnUpdateComplete(object sender, UpdateCompleteEventArgs e) { if (OnUpdateComplete != null) { foreach ( UpdateCompleteEventHandler UC in OnUpdateComplete.GetInvocationList()) { EventControl.BeginInvoke(UC,new object[] {sender, e}); } } //EventControl.BeginInvoke(new UpdateCompleteEventHandler(UpdateCompleteOps),new object[] {sender, e}); }
//************************************************************** // This event if fired whenever a new update is complete. // shutdown the app //************************************************************** public void updater_OnUpdateComplete(object sender, UpdateCompleteEventArgs e) { string serviceName = null; //If the udpate succeeded... if (e.UpdateSucceeded) { logger.Info("Update succeeded."); //need to restart the service. //for now, this works only for ONE service. //refresh the config. config = ServiceUpdaterConfig.getUpdaterConfig(configFile); if (config.ClientMode == UpdaterClientMode.Service) { if (config.ClientType == UpdaterClientType.Executor) { serviceName = "Alchemi Executor Service"; } else if (config.ClientType == UpdaterClientType.Manager) { serviceName = "Alchemi Manager Service"; } if (serviceName!=null) { try { ServiceController sc = new ServiceController(serviceName); sc.Refresh(); if (sc.CanStop) { sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped); } sc = null; logger.Info("Stopped service: "+serviceName); //need to uninstall the old one, install-&-start the new one. //uninstall here can only be done using the cmd-line since we dont have the ProjectInstaller object with us. //first uninstall the old one. Process pOld = new Process(); pOld.StartInfo = new ProcessStartInfo(currentServiceExePath ," /uninstall"); //using old service exe path pOld.Start(); logger.Info("Uninstall Process started : "+pOld.StartInfo.ToString()); pOld.WaitForExit(); pOld = null; Process pNew = new Process(); pNew.StartInfo = new ProcessStartInfo(config.AppExePath ," /install"); //using new service exe path pNew.Start(); logger.Info("Re-install Process started : "+pNew.StartInfo.ToString()); pNew.WaitForExit(); pNew = null; //now get the service controller again and try to start the service. sc = new ServiceController(serviceName); sc.Refresh(); sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running); sc = null; } catch (Exception ex) { handleUpdaterError("Error updating/restarting: "+ serviceName,ex); } } } else { //currently we dont support updating an exec mode client. logger.Info("Updater service currently doesnt support App mode. It can update services only."); } } else //If the update failed.... { handleUpdaterError(e.ErrorMessage,e.FailureException); } }