private void LiveUpdateUpdateToolStripMenuItemClick(object sender, EventArgs e) { BackupAndUpdateModule("JeepService.LiveUpdate", Settings.Default.LiveUpdatePath); var promptValue = Prompt.ShowDialog("Nome del file:", "Inserire il nome del file che deve essere eseguito"); var returnMessage = LiveUpdateClient.ExecuteFile(new ActionMessage { Message = promptValue }).Message; var exit = false; while (!String.IsNullOrEmpty(returnMessage) && !exit) { if ( MessageBox.Show(String.Format("{0} Riprovare?", returnMessage), "Errore in esecuzione file", MessageBoxButtons.YesNo) == DialogResult.Yes) { promptValue = Prompt.ShowDialog("Nome del file:", "Inserire il nome del file che deve essere eseguito"); returnMessage = LiveUpdateClient.ExecuteFile(new ActionMessage { Message = promptValue }).Message; } else { exit = true; } } }
private void JeepServiceStop() { if (LiveUpdateClient != null) { LiveUpdateClient.StopService(Settings.Default.ServiceName); } else { var service = new ServiceController(Settings.Default.ServiceName); service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(60000)); } JeepServiceCheck(); }
public InstallModule() { InitializeComponent(); // Connessione al service var liveUpdateServiceClient = new LiveUpdateClient(); Releases = liveUpdateServiceClient.GetLastVersions().ToDictionary(updateDefinition => updateDefinition.ModuleId, updateDefinition => updateDefinition); ddlModule.DataSource = new BindingSource(Releases.ToDictionary(release => release.Key, release => release.Value.ModuleName), null); ddlModule.DisplayMember = "Value"; ddlModule.ValueMember = "Key"; ModuleDefinitionUpdate(Releases.First().Key); }
/// <summary> /// Effettua l'aggiornamento di un modulo /// </summary> /// <param name="moduleName">Nome del modulo che deve essere aggiornato</param> /// <param name="workingFile">Path del file di riferimento da aggiornare (dll/exe)</param> private void BackupAndUpdateModule(string moduleName, string workingFile) { var openDialog = new OpenFileDialog { Title = "Selezionare il pacchetto di aggiornamento", RestoreDirectory = false, CheckFileExists = true, Filter = String.Format("{0}.zip|*.zip", moduleName) }; openDialog.ShowDialog(); if (string.IsNullOrEmpty(openDialog.FileName)) { return; } // ReSharper disable AssignNullToNotNullAttribute var updateZipFilePath = Path.Combine(Path.GetDirectoryName(workingFile), "UpdateTemp", openDialog.SafeFileName); // ReSharper restore AssignNullToNotNullAttribute using (Stream uploadStream = new FileStream(openDialog.FileName, FileMode.Open)) { LiveUpdateClient.PutFile(new FileUploadMessage { VirtualPath = updateZipFilePath, DataStream = uploadStream }); } // Effettua l'effettivo aggiornamento var backupPath = LiveUpdateClient.Update(moduleName, updateZipFilePath, ZipExtraction.FullInternalDirectionExtraction, "UpdateTemp", Path.GetDirectoryName(workingFile), true, "BackupUpdate", String.Empty).Message; // Scarica il backup se è stato generato if (String.IsNullOrEmpty(backupPath)) { return; } var saveDialog = new SaveFileDialog { RestoreDirectory = false, OverwritePrompt = false, Title = String.Format("Salvare il backup del modulo {0}", moduleName), FileName = Path.GetFileName(backupPath), Filter = String.Format("{0}.zip|*.zip", Path.GetFileName(backupPath)) }; // Se premo OK salvo il backup in locale e lo cancello da remoto, altrimenti lo lascio in remoto if (saveDialog.ShowDialog(this) != DialogResult.OK || string.IsNullOrEmpty(saveDialog.FileName)) { return; } // Get the file from the server using (var output = new FileStream(saveDialog.FileName, FileMode.Create)) { LiveUpdateClient.GetFile(backupPath).CopyTo(output); } // Elimina il backup in remoto LiveUpdateClient.DeleteFile(backupPath); }