Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/07/19 15:38:16 (6 years ago)
Author:
gkronber
Message:

#2994: merged r16839:16910 from trunk to branch

Location:
branches/2994-AutoDiffForIntervals
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals

  • branches/2994-AutoDiffForIntervals/HeuristicLab.Clients.Hive

  • branches/2994-AutoDiffForIntervals/HeuristicLab.Clients.Hive/3.3/HiveAdminClient.cs

    r16565 r16911  
    2121
    2222using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2325using System.Threading;
     26using HeuristicLab.Clients.Access;
    2427using HeuristicLab.Common;
    2528using HeuristicLab.Core;
    26 using System.Collections.Generic;
    27 using System.Linq;
    28 using HeuristicLab.Clients.Access;
    2929
    3030namespace HeuristicLab.Clients.Hive {
     
    7777        if (value != jobs)
    7878          jobs = value;
    79         }
     79      }
    8080    }
    8181
     
    166166          if (projectIds.Any()) {
    167167            service.GetAssignedResourcesForProjectsAdministration(projectIds)
    168               .ForEach(a => projectResourceAssignments.Add(a));
    169             projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<RefreshableJob>()));
     168                   .ForEach(a => projectResourceAssignments.Add(a));
     169
    170170            var unsortedJobs = service.GetJobsByProjectIds(projectIds)
    171               .OrderBy(x => x.DateCreated).ToList();
    172 
    173             unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j)));
    174             unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j)));
    175             unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j)));
    176 
    177             foreach (var job in jobs.SelectMany(x => x.Value))
    178               LoadLightweightJob(job);
     171                                      .OrderBy(x => x.DateCreated).ToList();
    179172
    180173            projectNames = service.GetProjectNames();
     
    187180        RefreshDisabledParentProjects();
    188181        RefreshDisabledParentResources();
    189       }
    190       catch {
     182      } catch {
    191183        throw;
    192       }
    193       finally {
     184      } finally {
    194185        OnRefreshed();
    195186      }
    196187    }
    197 
    198     //public void UpdateResourceGenealogy(IItemList<Resource> resources) {
    199     //  resourceAncestors.Clear();
    200     //  resourceDescendants.Clear();
    201 
    202     //  foreach (var r in resources) {
    203     //    resourceAncestors.Add(r.Id, new HashSet<Resource>());
    204     //    resourceDescendants.Add(r.Id, new HashSet<Resource>());
    205     //  }
    206 
    207     //  foreach (var r in resources) {
    208     //    var parentResourceId = r.ParentResourceId;
    209     //    while (parentResourceId != null) {
    210     //      var parent = resources.SingleOrDefault(x => x.Id == parentResourceId);
    211     //      if (parent != null) {
    212     //        resourceAncestors[r.Id].Add(parent);
    213     //        resourceDescendants[parent.Id].Add(r);
    214     //        parentResourceId = parent.ParentResourceId;
    215     //      } else {
    216     //        parentResourceId = null;
    217     //      }
    218     //    }
    219     //  }
    220     //}
    221 
    222     //public void UpdateProjectGenealogy(IItemList<Project> projects) {
    223     //  projectAncestors.Clear();
    224     //  projectDescendants.Clear();
    225 
    226     //  foreach (var p in projects) {
    227     //    projectAncestors.Add(p.Id, new HashSet<Project>());
    228     //    projectDescendants.Add(p.Id, new HashSet<Project>());
    229     //  }
    230 
    231     //  foreach (var p in projects) {
    232     //    var parentProjectId = p.ParentProjectId;
    233     //    while (parentProjectId != null) {
    234     //      var parent = projects.SingleOrDefault(x => x.Id == parentProjectId);
    235     //      if (parent != null) {
    236     //        projectAncestors[p.Id].Add(parent);
    237     //        projectDescendants[parent.Id].Add(p);
    238     //        parentProjectId = parent.ParentProjectId;
    239     //      } else {
    240     //        parentProjectId = null;
    241     //      }
    242     //    }
    243     //  }
    244     //}
    245188
    246189    private void UpdateResourceGenealogy() {
     
    314257    }
    315258
    316     public void RefreshJobs() {
    317       var projectIds = new List<Guid>();
    318       jobs = new Dictionary<Guid, HiveItemCollection<RefreshableJob>>();
    319       tasks = new Dictionary<Guid, List<LightweightTask>>();
    320 
     259    public void RefreshJobs(Guid projectId) {
    321260      HiveServiceLocator.Instance.CallHiveService(service => {
    322         service.GetProjectsForAdministration().ForEach(p => projectIds.Add(p.Id));
    323         if(projectIds.Any()) {
    324           projectIds.ForEach(p => jobs.Add(p, new HiveItemCollection<RefreshableJob>()));
    325           var unsortedJobs = service.GetJobsByProjectIds(projectIds)
    326             .OrderBy(x => x.DateCreated).ToList();
    327          
     261        var projectIds = new HashSet<Guid>(service.GetProjectsForAdministration().Select(x => x.Id));
     262        if (projectIds.Contains(projectId)) {
     263          jobs.Add(projectId, new HiveItemCollection<RefreshableJob>());
     264
     265          var unsortedJobs = service.GetJobsByProjectId(projectId)
     266                                    .OrderBy(x => x.DateCreated).ToList();
     267
    328268          unsortedJobs.Where(j => j.State == JobState.DeletionPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j)));
    329269          unsortedJobs.Where(j => j.State == JobState.StatisticsPending).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j)));
    330270          unsortedJobs.Where(j => j.State == JobState.Online).ToList().ForEach(j => jobs[j.ProjectId].Add(new RefreshableJob(j)));
    331271
    332           foreach(var job in jobs.SelectMany(x => x.Value))
     272          foreach (var job in jobs.SelectMany(x => x.Value))
    333273            LoadLightweightJob(job);
    334274        }
     
    344284        tasks[job.Id].AddRange(lightweightTasks);
    345285      } else {
    346         tasks.Add(job.Id, new List<LightweightTask>(lightweightTasks));       
     286        tasks.Add(job.Id, new List<LightweightTask>(lightweightTasks));
    347287      }
    348288
    349289      if (lightweightTasks != null && lightweightTasks.Count > 0 && lightweightTasks.All(x => x.Id != Guid.Empty)) {
    350290        if (lightweightTasks.All(x =>
    351           x.State == TaskState.Finished 
    352           || x.State == TaskState.Aborted 
     291          x.State == TaskState.Finished
     292          || x.State == TaskState.Aborted
    353293          || x.State == TaskState.Failed)) {
    354294          refreshableJob.ExecutionState = ExecutionState.Stopped;
     
    366306          refreshableJob.ExecutionState = ExecutionState.Paused;
    367307          refreshableJob.RefreshAutomatically = false;
    368         } else if (lightweightTasks.Any(x => x.State == TaskState.Calculating 
    369                                   || x.State == TaskState.Transferring 
     308        } else if (lightweightTasks.Any(x => x.State == TaskState.Calculating
     309                                  || x.State == TaskState.Transferring
    370310                                  || x.State == TaskState.Waiting)) {
    371311          refreshableJob.ExecutionState = ExecutionState.Started;
     
    377317
    378318    public void SortJobs() {
    379       for(int i = 0; i < jobs.Count; i++) {
     319      for (int i = 0; i < jobs.Count; i++) {
    380320        var projectId = jobs.Keys.ElementAt(i);
    381321        var unsortedJobs = jobs.Values.ElementAt(i);
     
    403343            service.GetDowntimesForResource(downtimeForResourceId).ForEach(d => downtimes.Add(d));
    404344          });
    405         }
    406         catch {
     345        } catch {
    407346          throw;
    408         }
    409         finally {
     347        } finally {
    410348          OnRefreshed();
    411349        }
     
    521459
    522460    public IEnumerable<Project> GetAvailableProjectDescendants(Guid id) {
    523       if(projectDescendants.ContainsKey(id)) return projects.Where(x => projectDescendants[id].Contains(x.Id));
     461      if (projectDescendants.ContainsKey(id)) return projects.Where(x => projectDescendants[id].Contains(x.Id));
    524462      else return Enumerable.Empty<Project>();
    525463    }
     
    545483
    546484    public bool CheckAccessToAdminAreaGranted() {
    547       if(projects != null) {
     485      if (projects != null) {
    548486        return projects.Count > 0;
    549487      } else {
     
    561499      if (res.OwnerUserId == userId) {
    562500        return true;
    563       } else if(resourceAncestors.ContainsKey(res.Id)) {
     501      } else if (resourceAncestors.ContainsKey(res.Id)) {
    564502        return GetAvailableResourceAncestors(res.Id).Where(x => x.OwnerUserId == userId).Any();
    565503      }
     
    583521      if (pro == null || userId == Guid.Empty) return false;
    584522
    585       if(projectAncestors.ContainsKey(pro.Id)) {
     523      if (projectAncestors.ContainsKey(pro.Id)) {
    586524        return GetAvailableProjectAncestors(pro.Id).Any(x => x.OwnerUserId == userId);
    587525      }
     
    613551        // ... if the user is no admin nor owner of the new parent or grand..grandparents
    614552        changePossible = false;
    615       } else if(parent != null && projectDescendants.ContainsKey(child.Id)) {
     553      } else if (parent != null && projectDescendants.ContainsKey(child.Id)) {
    616554        // ... if the new parent is among the moved project's descendants
    617555        changePossible = !GetAvailableProjectDescendants(child.Id).Where(x => x.Id == parent.Id).Any();
     
    630568      // ... or the new parent is a slave
    631569      // ... or there is not parental change
    632       if (child == null 
     570      if (child == null
    633571        || child == parent
    634572        || (parent != null && parent.Id == Guid.Empty)
     
    645583
    646584    public IEnumerable<Resource> GetAssignedResourcesForJob(Guid jobId) {
    647       var assignedJobResource =  HiveServiceLocator.Instance.CallHiveService(service => service.GetAssignedResourcesForJob(jobId));
     585      var assignedJobResource = HiveServiceLocator.Instance.CallHiveService(service => service.GetAssignedResourcesForJob(jobId));
    648586      return Resources.Where(x => assignedJobResource.Select(y => y.ResourceId).Contains(x.Id));
    649587    }
Note: See TracChangeset for help on using the changeset viewer.