void ITask.Execute(TaskArgs args)
 {
     if (args.Action == TaskArgs.TaskAction.Installation)
     {
         DownloadAndInstallUpdatePackage(args);
     }
 }
 void ITask.Execute(TaskArgs args)
 {
     switch (args.Action)
     {
         case TaskArgs.TaskAction.Pre:
             BackupDatabase(args);
             break;
         default: break;
     }
 }
 void ITask.Execute(TaskArgs args)
 {
     switch (args.Action)
     {
         case TaskArgs.TaskAction.Pre:
             StopProcesses();
             break;
         default:
             break;
     }
 }
 void ITask.Execute(TaskArgs args)
 {
     switch (args.Action)
     {
         case TaskArgs.TaskAction.Pre:
             CheckAndMoveLegacyFiles();
             break;
         default:
             break;
     }
 }
 void ITask.Execute(TaskArgs args)
 {
     switch (args.Action)
     {
         case TaskArgs.TaskAction.Post:
             DownloadOcrSoftwarePackage();
             break;
         default:
             break;
     }
 }
 void ITask.Execute(TaskArgs args)
 {
     switch (args.Action)
     {
         case TaskArgs.TaskAction.Pre:
             StopSerivce();
             break;
         case TaskArgs.TaskAction.Post:
             InstallService();
             break;
         default:
             break;
     }
 }
Example #7
0
        private void bwUpdateProcess_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            TaskArgs args = new TaskArgs();
            args.Context["WorkingDirectory"] = Application.StartupPath;
            args.Context["InstalllOptions"] = _options;
            args.Context["LocalVersion"] = _localVersion;
            args.Context["ServerVersion"] = _serverVersion;

            args.Action = TaskArgs.TaskAction.Pre;
            ExecuteTasks(args);

            args.Action = TaskArgs.TaskAction.Installation;
            ExecuteTasks(args);

            args.Action = TaskArgs.TaskAction.Post;
            ExecuteTasks(args);
        }
        private void DownloadAndInstallUpdatePackage(TaskArgs args)
        {
            Version serverVersion = (Version)args.Context["ServerVersion"];

            using (WebClient client = new WebClient())
            {
                string serverVersionUri = string.Format("{0}/{1}/{2}", Properties.Settings.Default.UpdateServerName, Properties.Settings.Default.UpdateFilesDirectory, serverVersion + ".zip");

                Log.Write("Downloading update package, this may take a while...");

                byte[] buffer = client.DownloadData(new Uri(serverVersionUri));

                Log.Write("Update package downloaded. Begin unpacking...");

                ZipFile zipFile = ZipFile.Read(buffer);
                zipFile.ExtractAll(Application.StartupPath, ExtractExistingFileAction.OverwriteSilently);

                Log.Write("Unpacking download package succeeded.");
            }
        }
        private void BackupDatabase(TaskArgs args)
        {
            string wd = (string)args.Context["WorkingDirectory"];

            string dbOldPath = Path.Combine(wd, OperationStoreDatabaseName);

            if (File.Exists(dbOldPath))
            {
                string dbNewPath = Path.Combine(wd, OperationStoreDatabaseName + "." + new Random(DateTime.Now.Millisecond).Next().ToString() + ".bak");

                Log.Write("Starting backup database '{0}' to '{1}'...", dbOldPath, dbNewPath);

                File.Copy(dbOldPath, dbNewPath);

                Log.Write("Finished backup database.");
            }
            else
            {
                Log.Write("Database file did not exist, no backup needed.");
            }
        }
Example #10
0
        private void ExecuteTasks(TaskArgs args)
        {
            foreach (ITask task in _tasks)
            {
                Log.Write("");

                Stopwatch sw = Stopwatch.StartNew();
                string taskName = task.GetType().Name;
                try
                {
                    Log.Write("Executing task '{0}' (in phase '{1}')...", taskName, args.Action);

                    task.Execute(args);

                    sw.Stop();
                    Log.Write("Task finished in '{0}' milliseconds.", sw.ElapsedMilliseconds);
                }
                catch (Exception ex)
                {
                    // A failing task is always critical
                    Log.Write("Failed at task '{0}'! The error message was: '{1}'", taskName, ex.Message);

                    throw;
                }
            }
        }