public void Run() { List <TableUpdate> tablesUpdate = BuildTablesUpdate(); Opts.AppSettings opt = AppContext.Settings.AppSettings; var inc = new UpdateIncrement(AppContext.TableManager.DataUpdates.CreateUniqID(), opt.DataGeneration); string incFileName = inc.ID.ToString("X"); string incFilePath = System.IO.Path.Combine(AppPaths.DataUpdateFolder, incFileName); UpdateEngin.SaveTablesUpdate(tablesUpdate, incFilePath); AppContext.AccessPath.GetDataProvider(InternalTablesID.INCREMENT).Insert(inc); foreach (TableUpdate tu in tablesUpdate) { AppContext.TableManager.SetTableGeneration(tu.TableID, tu.PostGeneration); } AppContext.TableManager.Transactions.Reset(); string dataMainfest = AppPaths.DataManifestPath; UpdateEngin.UpdateDataManifest(dataMainfest, new UpdateURI(incFileName, opt.DataGeneration)); if (opt.DataGeneration++ == 0) { opt.UpdateKey = (uint)DateTime.Now.Ticks; } AppContext.Settings.Save(); string manifestFile = AppPaths.ManifestPath; try { IUpdateManifest oldManifest = UpdateEngin.ReadUpdateManifest(manifestFile); var newManifest = new UpdateManifest(opt.UpdateKey, opt.DataGeneration, oldManifest.Versions); UpdateEngin.WriteUpdateManifest(newManifest, manifestFile); } catch { UpdateEngin.WriteUpdateManifest(new UpdateManifest(opt.UpdateKey, opt.DataGeneration), manifestFile); } }
private void UploadAppUpdates_Click(object sender, EventArgs e) { var filesNames = new Dictionary <AppArchitecture_t, string> { { AppArchitecture_t.Win7SP1, WIN7SP1_UPDATE_FILENAME }, { AppArchitecture_t.Win7SP1X64, WIN7SP1X64_UPADTE_FILENAME }, { AppArchitecture_t.WinXP, WINXP_UPADTE_FILENAME } }; var waitDlg = new Jobs.ProcessingDialog(); Action run = () => { KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE); var seq = (from AppUpdate up in ndxer.Source.Enumerate() where up.DeployTime == AppUpdate.NOT_YET select up).ToArray(); //maj app manifest + manifest global Dictionary <AppArchitecture_t, string> appManifest; try { appManifest = UpdateEngin.ReadAppManifest(AppPaths.AppManifestPath); } catch (Exception ex) { TextLogger.Warning(ex.Message); appManifest = new Dictionary <AppArchitecture_t, string>(); } IUpdateManifest gManifest; try { gManifest = UpdateEngin.ReadUpdateManifest(AppPaths.ManifestPath); } catch (Exception ex) { TextLogger.Warning(ex.Message); gManifest = new UpdateManifest(0, 0); } var netEngin = new NetEngin(AppContext.Settings.NetworkSettings); foreach (AppUpdate up in seq) { gManifest.Versions[up.AppArchitecture] = up.Version; appManifest[up.AppArchitecture] = filesNames[up.AppArchitecture]; string srcFileName = up.ID.ToString("X"); string destFileName = filesNames[up.AppArchitecture]; string dst = Urls.AppUpdateDirURL + destFileName; waitDlg.Message = $"Transfert du fichier {destFileName}. Cette opération peut durer plusieurs minutes."; netEngin.Upload(dst, Path.Combine(AppPaths.AppUpdateFolder, srcFileName)); up.DeployTime = DateTime.Now; ndxer.Source.Replace(ndxer.IndexOf(up.ID), up); } waitDlg.Message = "Transfert du manifest des applications..."; UpdateEngin.WriteAppManifest(AppPaths.AppManifestPath, appManifest); netEngin.Upload(Urls.AppManifestURL, AppPaths.AppManifestPath); waitDlg.Message = "Transfert du manifest global..."; UpdateEngin.WriteUpdateManifest(gManifest, AppPaths.ManifestPath); netEngin.Upload(Urls.ManifestURL, AppPaths.ManifestPath); }; Action onSucces = () => { m_tsbUploadAppUpdates.Enabled = false; waitDlg.Dispose(); }; Action <Task> onErr = t => { waitDlg.Dispose(); this.ShowError(t.Exception.InnerException.Message); TextLogger.Error(t.Exception.InnerException.Message); }; var task = new Task(run, TaskCreationOptions.LongRunning); task.OnSuccess(onSucces); task.OnError(onErr); task.Start(); waitDlg.ShowDialog(this); }
public static bool UpdateData() { /* * telecharger le fichier manifest * si DataGeneration > manifest.DataGeneration * signaler l'erreur a HubGovernor * sortir * si DataGeneration < manifest.DataGeneration * telecharger manifest.data * pour chaque entrées E dans manifest.data et tant que DataGeneration < manifest.DataGeneration * si DataGeneration == E.PreDataGeneration * Appliquer les maj des tables * mettre a jours DataGeneration */ string manifest = Path.GetTempFileName(); using (new AutoReleaser(() => File.Delete(manifest))) try { var netEngin = new NetEngin(Program.NetworkSettings); netEngin.Download(manifest, Urls.ManifestURL); IUpdateManifest updateManifest = UpdateEngin.ReadUpdateManifest(manifest); string log = "Recherche de mise à jour des données. Version actulle des données: " + $"{Program.Settings.DataGeneration}. "; if (updateManifest.DataGeneration == Program.Settings.DataGeneration) { Program.DialogManager.PostLog(log + " Les données sont à jour", false); return(true); } if (Program.Settings.UpdateKey != updateManifest.UpdateKey) { if (Program.Settings.UpdateKey == 0) { Program.Settings.UpdateKey = updateManifest.UpdateKey; } else { Log.LogEngin.PushFlash(AppText.ERR_UPDATEKEY); Dbg.Log("Update key mismatch!"); Program.DialogManager.PostLog(log + AppText.ERR_UPDATEKEY, true); return(false); } } //TODO: signaler l'erreur si DataGeneration < manifest.DataGeneration string dataManifest = Path.GetTempFileName(); using (Log.LogEngin.PushMessage("Installation des mises à jour...")) using (new AutoReleaser(() => File.Delete(dataManifest))) { netEngin.Download(dataManifest, Urls.DataManifestURL); var uris = new List <UpdateURI>(UpdateEngin.ReadDataManifest(dataManifest, Program.Settings.DataGeneration)); foreach (UpdateURI uu in uris.OrderBy(u => u.DataPreGeneration)) { if (uu.DataPreGeneration == Program.Settings.DataGeneration) { string updateFile = Path.GetTempFileName(); using (new AutoReleaser(() => File.Delete(updateFile))) { netEngin.Download(updateFile, Urls.DataUpdateDirURL + uu.FileURI); ApplyUpdate(updateFile); Program.Settings.DataGeneration = uu.DataPostGeneration; } } } DataUpdated?.Invoke(); } Program.DialogManager.PostLog(log + "Mises à jour installées. " + $"Nouvelle version des données: {Program.Settings.DataGeneration}", false); Assert(Program.Settings.DataGeneration == updateManifest.DataGeneration); } catch (Exception ex) { Dbg.Log("Data update: " + ex.Message); } return(true); }
public static void UpdateApp() { //dl global manifest Log.LogEngin.PushFlash("Rechercher d'une mise à jour de l'application..."); const string logTxt = "Rechercher d'une mise à jour de l'application. "; string tmpFile = Path.GetTempFileName(); using (new AutoReleaser(() => File.Delete(tmpFile))) try { var netEngin = new NetEngin(Program.NetworkSettings); netEngin.Download(tmpFile, Urls.ManifestURL); IUpdateManifest updateManifest = UpdateEngin.ReadUpdateManifest(tmpFile); Version curVer = Assembly.GetExecutingAssembly().GetName().Version; Version ver = updateManifest.GetAppVersion(Program.AppArchitecture); if (ver == null || curVer.CompareTo(ver) >= 0) { Log.LogEngin.PushFlash("Vous disposez déjà de la dernière version de l’application."); Program.DialogManager.PostLog(logTxt + "Pas de nouvelle mise à jour", false); return; } Log.LogEngin.PushFlash($"Une nouvelle version de l'application est disponible ({ver})."); Program.DialogManager.PostLog(logTxt + $"Une nouvelle version de l'application est disponible, version: ({ver})", false); const string setupTxtLog = "L'utilsateur a refuser d'installer la nouvelle version du HUB"; if (CanDownlaodAppUpdate?.Invoke() != true) { Program.DialogManager.PostLog(setupTxtLog, false); return; } Log.LogEngin.PushFlash($"Téléchargement de la mise à jour..."); //dl app manifest netEngin.Download(tmpFile, Urls.AppManifestURL); Dictionary <AppArchitecture_t, string> upFiles = UpdateEngin.ReadAppManifest(tmpFile); string fileName = upFiles[Program.AppArchitecture]; //dl update file var url = Urls.AppUpdateDirURL + fileName; netEngin.Download(tmpFile, url); if (CanRunAppUpdate?.Invoke() != true) { Program.DialogManager.PostLog(setupTxtLog, false); return; } string tmpDir = Path.GetTempPath(); new FilesBag().Decompress(tmpFile, tmpDir); System.Diagnostics.Process.Start(Path.Combine(tmpDir, "setup.exe")); Program.DialogManager.PostLog("Lancement du programme d'installation de la mise à jour du HUB", false); System.Windows.Forms.Application.Exit(); } catch (Exception ex) { Dbg.Log("App update: " + ex.Message); } }