Example #1
0
    public static void LoadJob(RefreshableJob refreshableJob) {
      var hiveExperiment = refreshableJob.Job;
      refreshableJob.IsProgressing = true;
      TaskDownloader downloader = null;

      try {
        int totalJobCount = 0;
        IEnumerable<LightweightTask> allTasks;

        // fetch all task objects to create the full tree of tree of HiveTask objects
        refreshableJob.Progress.Start("Downloading list of tasks...");
        allTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(hiveExperiment.Id));
        totalJobCount = allTasks.Count();

        refreshableJob.Progress.Status = "Downloading tasks...";
        downloader = new TaskDownloader(allTasks.Select(x => x.Id));
        downloader.StartAsync();

        while (!downloader.IsFinished) {
          refreshableJob.Progress.ProgressValue = downloader.FinishedCount / (double)totalJobCount;
          refreshableJob.Progress.Status = string.Format("Downloading/deserializing tasks... ({0}/{1} finished)", downloader.FinishedCount, totalJobCount);
          Thread.Sleep(500);

          if (downloader.IsFaulted) {
            throw downloader.Exception;
          }
        }
        IDictionary<Guid, HiveTask> allHiveTasks = downloader.Results;
        var parents = allHiveTasks.Values.Where(x => !x.Task.ParentTaskId.HasValue);

        refreshableJob.Progress.Status = "Downloading/deserializing complete. Displaying tasks...";
        // build child-task tree
        foreach (HiveTask hiveTask in parents) {
          BuildHiveJobTree(hiveTask, allTasks, allHiveTasks);
        }

        refreshableJob.HiveTasks = new ItemCollection<HiveTask>(parents);
        if (refreshableJob.IsFinished()) {
          refreshableJob.ExecutionState = Core.ExecutionState.Stopped;
        } else {
          refreshableJob.ExecutionState = Core.ExecutionState.Started;
        }
        refreshableJob.OnLoaded();
      }
      finally {
        refreshableJob.IsProgressing = false;
        refreshableJob.Progress.Finish();
        if (downloader != null) {
          downloader.Dispose();
        }
      }
    }