コード例 #1
0
ファイル: JobExecutor.cs プロジェクト: rzio/flywheel-backup
        private void DoBackupJob(BackupJob job)
        {
            XElement rootElement = new XElement("BackupSet"
                    , new XAttribute("folder", job.AbsolutePath)
                    , new XAttribute("date", DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ")));
            List<Task> tasks = new List<Task>();

            foreach (var fileTask in enumerateFileBackupTasks(job.AbsolutePath,job.Recursive))
            {
                Task task = Task<ResultType<BackupItem>>.Factory.StartNew(() =>
                   {
                       lock (syncRoot)
                       {
                           totalTasks++;
                           fireProgressEvent();
                       }
                       var res = job.ProcessChain.Process(fileTask);
                       if (res is ErrorResultType<BackupItem>)
                       {
                           return res;
                       }
                       else if (res is FinishedResultType<BackupItem>)
                       {
                           var typedResult = res as FinishedResultType<BackupItem>;
                           lock (syncRoot)
                           {
                               rootElement.Add(new XElement("file",
                                   new XAttribute("local", typedResult.LocalFilePath.Replace(job.AbsolutePath, "")),
                                   new XAttribute("remote", typedResult.RemoteFileName)));
                           }
                           return res;
                       }
                       return null;
                   }).ContinueWith((t) =>
                   {
                       lock (syncRoot)
                       {
                           doneTasks++;
                           fireProgressEvent();
                       }
                   });

                tasks.Add(task);
            }
            Task.WaitAll(tasks.ToArray());
            XDocument x = new XDocument(rootElement);
            x.Save(job.MetadataFilePath);
            if (JobDone != null)
            {
                JobDone(this, new JobDoneEventArgs());
            }
            return;// BackupResult.Finished("Finished backing up" + job.Task.AbsolutePath);
        }
コード例 #2
0
ファイル: JobExecutor.cs プロジェクト: rzio/flywheel-backup
 public void SubmitBackupJob(BackupJob job)
 {
     jobExecution = Task.Factory.StartNew(() => DoBackupJob(job));
 }