Example #1
0
        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);
            }
        }
Example #2
0
        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);
        }