void NormalizeAppUpdates(AppUpdate update) { KeyIndexer ndxer = AppContext.AccessPath.GetKeyIndexer(InternalTablesID.APP_UPDATE); var seq = from AppUpdate up in ndxer.Source.Enumerate() where up.AppArchitecture == update.AppArchitecture && up.Version.CompareTo(update.Version) > 0 select up; if (seq.Any()) { update.DeployTime = AppUpdate.NEVER; } else { seq = from AppUpdate up in ndxer.Source.Enumerate() where up.AppArchitecture == update.AppArchitecture && up.Version.CompareTo(update.Version) <= 0 && up.DeployTime == AppUpdate.NOT_YET select up; foreach (AppUpdate up in seq.ToArray()) { var datum = new AppUpdate(up.ID, up.Version, up.AppArchitecture, up.CreationTime); datum.DeployTime = AppUpdate.NEVER; int ndx = ndxer.IndexOf(up.ID); ndxer.Source.Replace(ndx, datum); } } }
private void AddPackage_Click(object sender, EventArgs e) { using (var dlg = new AppUpdateDialog()) if (dlg.ShowDialog(this) == DialogResult.OK) { IDatumProvider dp = null; var waitDlg = new Jobs.ProcessingDialog(); Action buildUpdate = () => { var bag = new FilesBag(); foreach (string file in dlg.Files) { waitDlg.Message = $"Préparation de {file}"; string relDir = Path.GetDirectoryName(file.Remove(0, dlg.RootFolder.Length + 1)); if (relDir.Length > 0) { bag.Add(file, relDir); } else { bag.Add(file); } } waitDlg.Message = "Compression en cours..."; dp = AppContext.TableManager.AppUpdates.DataProvider; dp.Connect(); var update = new AppUpdate(AppContext.TableManager.AppUpdates.CreateUniqID(), dlg.Version, dlg.AppArchitecture); bag.Compress(Path.Combine(AppPaths.AppUpdateFolder, update.ID.ToString("X"))); NormalizeAppUpdates(update); dp.Insert(update); }; Action <Task> onErr = t => { TextLogger.Error(t.Exception.InnerException.Message); this.ShowError(t.Exception.InnerException.Message); dp?.Dispose(); waitDlg.Dispose(); }; Action onSuccess = () => { dp?.Dispose(); waitDlg.Dispose(); }; var task = new Task(buildUpdate, TaskCreationOptions.LongRunning); task.OnSuccess(onSuccess); task.OnError(onErr); task.Start(); waitDlg.ShowDialog(this); } }