Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/10 10:57:21 (15 years ago)
Author:
kgrading
Message:

changed the complete DAL to LINQ 2 SQL (with the exception of the job streaming), did a lot of refactoring, Introduced DTOs (that are named DTOs for better understanding), added the spring.NET Interceptor, reintroduced transactions and cleaned up the whole JobResult thing and updated a part of the config merger (#830)

Location:
trunk/sources/HeuristicLab.Hive.Server.Console/3.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Console/3.2/AddJobForm.cs

    r2092 r3011  
    1 #region License Information
     1#region License Information
    22/* HeuristicLab
    33 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    4343    public event addDelegate addJobEvent;
    4444
    45     ResponseList<Project> projects = null;
     45    ResponseList<ProjectDto> projects = null;
    4646    IJobManager jobManager;
    4747    IClientManager clientManager;
    48     ResponseList<ClientGroup> clientGroups;
     48    ResponseList<ClientGroupDto> clientGroups;
    4949
    5050    Dictionary<Guid, string> clients = null;
     
    6969      cbProject.Items.Add("none");
    7070      cbProject.SelectedIndex = 0;
    71       foreach (Project project in projects.List) {
     71      foreach (ProjectDto project in projects.List) {
    7272        cbProject.Items.Add(project.Name);
    7373      }
     
    8686
    8787    private void AddClientGroups() {
    88      foreach (ClientGroup cg in clientGroups.List) {
     88     foreach (ClientGroupDto cg in clientGroups.List) {
    8989       if (cg.Id != Guid.Empty)
    9090       clients.Add(cg.Id, cg.Name);
     
    9393    }
    9494
    95     private void AddClientOrGroup(ClientGroup clientGroup) {
    96       foreach (Resource resource in clientGroup.Resources) {
    97         if (resource is ClientGroup) {
     95    private void AddClientOrGroup(ClientGroupDto clientGroup) {
     96      foreach (ResourceDto resource in clientGroup.Resources) {
     97        if (resource is ClientGroupDto) {
    9898          if (resource.Id != Guid.Empty)
    9999          clients.Add(resource.Id, resource.Name);
    100           AddClientOrGroup(resource as ClientGroup);
     100          AddClientOrGroup(resource as ClientGroupDto);
    101101        }
    102102      }
     
    110110        if (numJobs > 0) {
    111111          for (int i = 0; i < numJobs; i++) {
    112             Job job = new Job { State = State.offline, CoresNeeded = 1 };
     112            JobDto job = new JobDto { State = State.offline, CoresNeeded = 1 };
    113113           
    114114            // if project selected (0 -> none)
  • trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerManagementConsole.cs

    r2118 r3011  
    4848
    4949    #region private variables
    50     private ResponseList<Job> jobs = null;
     50    private ResponseList<JobDto> jobs = null;
    5151
    5252    List<ListViewGroup> jobGroup;
     
    5454    private List<Changes> changes = new List<Changes>();
    5555
    56     private Job currentJob = null;
    57     private ClientInfo currentClient = null;
     56    private JobDto currentJob = null;
     57    private ClientDto currentClient = null;
    5858
    5959    private TreeNode currentGroupNode = null;
     
    9393        IJobManager jobManager = ServiceLocator.GetJobManager();
    9494        if (lvJobControl.SelectedItems.Count == 1) {
    95           jobManager.AbortJob(((Job)(lvJobControl.SelectedItems[0].Tag)).Id);
     95          jobManager.AbortJob(((JobDto)(lvJobControl.SelectedItems[0].Tag)).Id);
    9696        }
    9797      };
     
    101101        IJobManager jobManager = ServiceLocator.GetJobManager();
    102102        if (lvJobControl.SelectedItems.Count == 1) {
    103           jobManager.RequestSnapshot(((Job)(lvJobControl.SelectedItems[0].Tag)).Id);
     103          jobManager.RequestSnapshot(((JobDto)(lvJobControl.SelectedItems[0].Tag)).Id);
    104104        }
    105105      };
     
    109109        AddGroup addgroup = new AddGroup();
    110110        parentgroup = Guid.Empty;
    111         if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
    112           parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
     111        if ((tvClientControl.SelectedNode != null) && (((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
     112          parentgroup = ((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id;
    113113        }
    114114        addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
     
    120120        IClientManager clientManager = ServiceLocator.GetClientManager();
    121121        if (tvClientControl.SelectedNode != null) {
    122           Response resp = clientManager.DeleteClientGroup(((ClientGroup)tvClientControl.SelectedNode.Tag).Id);
     122          Response resp = clientManager.DeleteClientGroup(((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id);
    123123          if (tvClientControl.SelectedNode == currentGroupNode) {
    124124            currentGroupNode = null;
     
    147147        Point mouseLocation = tvClientControl.PointToClient(new Point(e.X, e.Y));
    148148        TreeNode node = tvClientControl.GetNodeAt(mouseLocation);
    149         if (node != null && ((ClientGroup)node.Tag).Id != Guid.Empty) {
     149        if (node != null && ((ClientGroupDto)node.Tag).Id != Guid.Empty) {
    150150          e.Effect = DragDropEffects.Move;
    151151          if (hoverNode == null) {
     
    170170          Point dropLocation = (sender as TreeView).PointToClient(new Point(e.X, e.Y));
    171171          TreeNode dropNode = (sender as TreeView).GetNodeAt(dropLocation);
    172           if (((ClientGroup)dropNode.Tag).Id != Guid.Empty) {
    173             Dictionary<ClientInfo, Guid> clients = new Dictionary<ClientInfo, Guid>();
     172          if (((ClientGroupDto)dropNode.Tag).Id != Guid.Empty) {
     173            Dictionary<ClientDto, Guid> clients = new Dictionary<ClientDto, Guid>();
    174174            foreach (ListViewItem lvi in lvClientControl.SelectedItems) {
    175175              Guid groupId = Guid.Empty;
    176176              foreach (ListViewGroup lvg in lvClientGroups) {
    177                 if (lvi.Group.Header == ((ClientGroup)lvg.Tag).Name) {
    178                   groupId = ((ClientGroup)lvg.Tag).Id;
     177                if (lvi.Group.Header == ((ClientGroupDto)lvg.Tag).Name) {
     178                  groupId = ((ClientGroupDto)lvg.Tag).Id;
    179179                }
    180180              }
    181               clients.Add((ClientInfo)lvi.Tag, groupId);
    182             }
    183             ChangeGroup(clients, ((ClientGroup)dropNode.Tag).Id);
     181              clients.Add((ClientDto)lvi.Tag, groupId);
     182            }
     183            ChangeGroup(clients, ((ClientGroupDto)dropNode.Tag).Id);
    184184          }
    185185          tvClientControl_DragLeave(null, EventArgs.Empty);
     
    194194    /// <param name="clients">list of clients</param>
    195195    /// <param name="clientgroupID">group of clients</param>
    196     private void ChangeGroup(Dictionary<ClientInfo, Guid> clients, Guid clientgroupID) {
     196    private void ChangeGroup(Dictionary<ClientDto, Guid> clients, Guid clientgroupID) {
    197197      IClientManager clientManager = ServiceLocator.GetClientManager();
    198       foreach (KeyValuePair<ClientInfo, Guid> client in clients) {
     198      foreach (KeyValuePair<ClientDto, Guid> client in clients) {
    199199        if (client.Key.Id != Guid.Empty) {
    200200          Response resp = clientManager.DeleteResourceFromGroup(client.Value, client.Key.Id);
     
    224224      changes.Clear();
    225225
    226       ResponseList<Job> jobsOld = jobs;
     226      ResponseList<JobDto> jobsOld = jobs;
    227227      try {
    228228        IJobManager jobManager =
     
    231231        jobs = jobManager.GetAllJobs();
    232232
    233         IDictionary<int, Job> jobsOldHelp;
     233        IDictionary<int, JobDto> jobsOldHelp;
    234234        CloneList(jobsOld, out jobsOldHelp);
    235235
     
    269269        if (jobs != null && jobs.List != null) {
    270270
    271           foreach (Job job in jobs.List) {
     271          foreach (JobDto job in jobs.List) {
    272272            if (job.State == State.calculating) {
    273273              ListViewItem lvi = new ListViewItem(job.Id.ToString(), 1, lvJobCalculating);
     
    312312      tvClientControl.Nodes.Clear();
    313313      try {
    314         ResponseList<ClientGroup> clientGroups = ClientManager.GetAllClientGroups();
     314        ResponseList<ClientGroupDto> clientGroups = ClientManager.GetAllClientGroups();
    315315
    316316        if (clientGroups != null && clientGroups.List != null) {
    317           foreach (ClientGroup cg in clientGroups.List) {
     317          foreach (ClientGroupDto cg in clientGroups.List) {
    318318            AddClientOrGroup(cg, null);
    319319          }
     
    333333    }
    334334
    335     private void AddClientOrGroup(ClientGroup clientGroup, TreeNode currentNode) {
     335    private void AddClientOrGroup(ClientGroupDto clientGroup, TreeNode currentNode) {
    336336      currentNode = CreateTreeNode(clientGroup, currentNode);
    337337      List<ListViewItem> clientGroupList = new List<ListViewItem>();
     
    345345      lvg.Tag = clientGroup;
    346346      lvClientGroups.Add(lvg);
    347       foreach (Resource resource in clientGroup.Resources) {
    348         if (resource is ClientInfo) {
    349           int percentageUsage = CapacityRam(((ClientInfo)resource).NrOfCores, ((ClientInfo)resource).NrOfFreeCores);
     347      foreach (ResourceDto resource in clientGroup.Resources) {
     348        if (resource is ClientDto) {
     349          int percentageUsage = CapacityRam(((ClientDto)resource).NrOfCores, ((ClientDto)resource).NrOfFreeCores);
    350350          int usage = 3;
    351           if ((((ClientInfo)resource).State != State.offline) &&
    352             (((ClientInfo)resource).State != State.nullState)) {
     351          if ((((ClientDto)resource).State != State.offline) &&
     352            (((ClientDto)resource).State != State.nullState)) {
    353353            if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
    354354              usage = 0;
     
    360360          }
    361361          ListViewItem lvi = new ListViewItem(resource.Name, usage, lvg);
    362           lvi.Tag = resource as ClientInfo;
     362          lvi.Tag = resource as ClientDto;
    363363          clientGroupList.Add(lvi);
    364         } else if (resource is ClientGroup) {
    365           AddClientOrGroup(resource as ClientGroup, currentNode);
     364        } else if (resource is ClientGroupDto) {
     365          AddClientOrGroup(resource as ClientGroupDto, currentNode);
    366366        }
    367367      }
     
    369369    }
    370370
    371     private TreeNode CreateTreeNode(ClientGroup clientGroup, TreeNode currentNode) {
     371    private TreeNode CreateTreeNode(ClientGroupDto clientGroup, TreeNode currentNode) {
    372372      TreeNode tn;
    373373      if (string.IsNullOrEmpty(clientGroup.Name)) {
     
    390390        lvClientControl.Groups.Add(lvg);
    391391        lvg.Tag = node.Tag;
    392         foreach (ListViewItem item in clientList[((ClientGroup)node.Tag).Id]) {
     392        foreach (ListViewItem item in clientList[((ClientGroupDto)node.Tag).Id]) {
    393393          item.Group = lvg;
    394394          lvClientControl.Items.Add(item);
     
    475475          IJobManager jobManager =
    476476            ServiceLocator.GetJobManager();
    477           ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id);
     477          ResponseObject<JobResult> jobRes = null;
     478          //Todo: jobManager.GetLastJobResultOf(currentJob.Id);
    478479
    479480          if (jobRes != null && jobRes.Obj != null) {
     
    532533        for (int i = 0; i < lvJobControl.Items.Count; i++) {
    533534          if (lvJobControl.Items[i].Text == change.ID.ToString()) {
    534             foreach (Job job in jobs.List) {
     535            foreach (JobDto job in jobs.List) {
    535536              if (job.Id == change.ID) {
    536537                lvJobControl.Items[i].Tag = job;
     
    562563        ListViewItem lvi = new ListViewItem(
    563564          change.ID.ToString(), 2, jobGroup[2]);
    564         foreach (Job job in jobs.List) {
     565        foreach (JobDto job in jobs.List) {
    565566          if (job.Id == change.ID) {
    566567            lvi.Tag = job;
     
    612613
    613614    private void OnLVJobControlClicked(object sender, EventArgs e) {
    614       currentJob = (Job)lvJobControl.SelectedItems[0].Tag;
     615      currentJob = (JobDto)lvJobControl.SelectedItems[0].Tag;
    615616      JobClicked();
    616617    }
     
    629630      ListViewHitTestInfo hitTestInfo = lvJobControl.HitTest(e.Location);
    630631      if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && lvJobControl.SelectedItems.Count == 1) {
    631         Job selectedJob = (Job)lvJobControl.SelectedItems[0].Tag;
     632        JobDto selectedJob = (JobDto)lvJobControl.SelectedItems[0].Tag;
    632633
    633634        if (selectedJob != null && selectedJob.State == State.calculating) {
     
    649650      AddGroup addgroup = new AddGroup();
    650651      parentgroup = Guid.Empty;
    651       if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
    652         parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
     652      if ((tvClientControl.SelectedNode != null) && (((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
     653        parentgroup = ((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id;
    653654      }
    654655      addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
     
    663664
    664665    private void OnLVClientClicked(object sender, EventArgs e) {
    665       currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag;
     666      currentClient = (ClientDto)lvClientControl.SelectedItems[0].Tag;
    666667      ClientClicked();
    667668    }
     
    675676      if (e.Button != MouseButtons.Right) return;
    676677      if (hitTestInfo.Node != null) {
    677         Resource selectedGroup = (Resource)tvClientControl.SelectedNode.Tag;
     678        ResourceDto selectedGroup = (ResourceDto)tvClientControl.SelectedNode.Tag;
    678679
    679680        if (selectedGroup != null) {
     
    690691      IJobManager jobManager = ServiceLocator.GetJobManager();
    691692
    692       Project pg = new Project() { Name = name };
     693      ProjectDto pg = new ProjectDto() { Name = name };
    693694      jobManager.CreateProject(pg);
    694695
     
    699700
    700701      if (parentgroup != Guid.Empty) {
    701         ClientGroup cg = new ClientGroup() { Name = name };
    702         ResponseObject<ClientGroup> respcg = clientManager.AddClientGroup(cg);
     702        ClientGroupDto cg = new ClientGroupDto() { Name = name };
     703        ResponseObject<ClientGroupDto> respcg = clientManager.AddClientGroup(cg);
    703704        Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj);
    704705        if (res != null && !res.Success) {
     
    706707        }
    707708      } else {
    708         ClientGroup cg = new ClientGroup() { Name = name };
     709        ClientGroupDto cg = new ClientGroupDto() { Name = name };
    709710        clientManager.AddClientGroup(cg);
    710711      }
     
    762763    #region Helper methods
    763764
    764     private void CloneList(ResponseList<Job> oldList, out IDictionary<int, Job> newList) {
    765       newList = new Dictionary<int, Job>();
     765    private void CloneList(ResponseList<JobDto> oldList, out IDictionary<int, JobDto> newList) {
     766      newList = new Dictionary<int, JobDto>();
    766767      for (int i = 0; i < oldList.List.Count; i++) {
    767768        newList.Add(i, oldList.List[i]);
     
    769770    }
    770771
    771     private bool IsEqual(ClientInfo ci1, ClientInfo ci2) {
     772    private bool IsEqual(ClientDto ci1, ClientDto ci2) {
    772773      if (ci2 == null) {
    773774        return false;
     
    786787    }
    787788
    788     private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) {
     789    private void GetDelta(IList<JobDto> oldJobs, IDictionary<int, JobDto> helpJobs) {
    789790      bool found = false;
    790791      for (int i = 0; i < jobs.List.Count; i++) {
    791         Job job = jobs.List[i];
     792        JobDto job = jobs.List[i];
    792793        for (int j = 0; j < oldJobs.Count; j++) {
    793794
    794           Job jobold = oldJobs[j];
     795          JobDto jobold = oldJobs[j];
    795796
    796797          if (job.Id.Equals(jobold.Id)) {
     
    814815
    815816            int removeAt = -1;
    816             foreach (KeyValuePair<int, Job> kvp in helpJobs) {
     817            foreach (KeyValuePair<int, JobDto> kvp in helpJobs) {
    817818              if (job.Id.Equals(kvp.Value.Id)) {
    818819                removeAt = kvp.Key;
     
    832833        found = false;
    833834      }
    834       foreach (KeyValuePair<int, Job> kvp in helpJobs) {
     835      foreach (KeyValuePair<int, JobDto> kvp in helpJobs) {
    835836        changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
    836837      }
     
    844845      ResponseList<JobResult> jobRes = jobManager.GetAllJobResults(currentJob.Id);
    845846
    846       if (jobRes.List != null) {
     847      if (jobRes != null && jobRes.List != null) {
    847848        foreach (JobResult jobresult in jobRes.List) {
    848849          ListViewItem curSnapshot = new ListViewItem(jobresult.ClientId.ToString());
     
    854855      }
    855856
    856       if ((jobRes.List == null) && (jobRes.List.Count == 0)) {
     857      if ((jobRes.List == null) || (jobRes.List.Count == 0)) {
    857858        lvSnapshots.Visible = false;
    858859      } else {
Note: See TracChangeset for help on using the changeset viewer.