Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/09 17:35:41 (15 years ago)
Author:
aleitner
Message:

find changes in backgroundworker (#508)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Hive_Management_Console_Refactoring_Ticket508/HeuristicLab.Hive.Server.Console/HiveServerManagementConsole.cs

    r1273 r1372  
    6363    private bool flagUser = false;
    6464
     65    private List<Changes> changes = new List<Changes>();
     66
    6567    private ToolTip tt = new ToolTip();
    6668    #endregion
     
    8082    /// <param name="e"></param>
    8183    private void TickSync(object obj, EventArgs e) {
    82       Refresh();
    83       //updaterWoker.RunWorkerAsync();
     84      //Refresh();
     85      if (!updaterWoker.IsBusy) {
     86        updaterWoker.RunWorkerAsync();
     87      }
    8488    }
    8589
     
    375379      AddJobForm newForm = new AddJobForm();
    376380      newForm.Show();
    377       newForm.addJobEvent += new addDelegate(Refresh);
     381      //newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
    378382    }
    379383
     
    481485
    482486    private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
    483       #region ClientInfo
    484       List<Changes> changes = new List<Changes>();
    485       ResponseList<ClientInfo> clientInfoOld = clientInfo;
     487
    486488      IClientManager clientManager =
    487489          ServiceLocator.GetClientManager();
     490     
     491      #region ClientInfo
     492      ResponseList<ClientInfo> clientInfoOld = clientInfo;
     493      clientInfo = clientManager.GetAllClients();
     494
     495      ResponseList<ClientInfo> clientInfoOldHelp;
     496
     497      CloneList(clientInfoOld, out clientInfoOldHelp);
     498
     499      GetDelta(clientInfoOld.List, clientInfoOldHelp.List);
     500      #endregion
     501
     502      #region Clients
     503      ResponseList<ClientGroup> clientsOld = clients;
     504     
     505      clients = clientManager.GetAllClientGroups();
     506
     507      ResponseList<ClientGroup> clientsOldHelp;
     508
     509      CloneList(clientsOld, out clientsOldHelp);
     510
     511      GetDelta(clientsOld.List, clientsOldHelp.List);
     512      #endregion
     513
     514      #region Job
     515      ResponseList<Job> jobsOld = jobs;
     516      IJobManager jobManager =
     517          ServiceLocator.GetJobManager();
     518
     519      jobs = jobManager.GetAllJobs();
     520
     521      ResponseList<Job> jobsOldHelp = new ResponseList<Job>();
     522      CloneList(jobsOld, out jobsOldHelp);
     523     
     524      //System.Diagnostics.Debug.WriteLine(jobsOldHelp.List[0].Id.ToString());
     525
     526      GetDelta(jobsOld.List, jobsOldHelp.List);
     527
     528      #endregion
     529
     530    }
     531    #endregion
     532
     533    #region Helper methods
     534
     535    private void CloneList(ResponseList<Job> oldList, out ResponseList<Job> newList) {
     536      newList = new ResponseList<Job>();
     537      newList.List = new List<Job>();
     538      foreach (Job item in oldList.List) {
     539        newList.List.Add(item);
     540      }
     541    }
     542
     543    private void CloneList(ResponseList<ClientInfo> oldList, out ResponseList<ClientInfo> newList) {
     544      newList = new ResponseList<ClientInfo>();
     545      newList.List = new List<ClientInfo>();
     546      foreach (ClientInfo item in oldList.List) {
     547        newList.List.Add(item);
     548      }
     549    }
     550
     551    private void CloneList(ResponseList<ClientGroup> oldList, out ResponseList<ClientGroup> newList) {
     552      newList = new ResponseList<ClientGroup>();
     553      newList.List = new List<ClientGroup>();
     554      foreach (ClientGroup item in oldList.List) {
     555        newList.List.Add(item);
     556      }
     557    }
     558
     559    private bool IsEqual(ClientInfo ci1, ClientInfo ci2) {
     560      if (ci1.ClientId.Equals(ci2.ClientId)) {
     561        return true;
     562      } else return false;
     563    }
     564
     565    private void GetDelta(IList<ClientInfo> oldClient, IList<ClientInfo> helpClients) {
    488566      bool found = false;
    489       clientInfo = clientManager.GetAllClients();
    490 
    491       ResponseList<ClientInfo> clientInfoOldHelp = clientInfoOld;
    492567
    493568      foreach (ClientInfo ci in clientInfo.List) {
    494         for (int i = 0; i < clientInfoOld.List.Count; i ++) {
    495           ClientInfo cio = clientInfoOld.List[i];
     569        for (int i = 0; i < oldClient.Count; i++) {
     570          ClientInfo cio = oldClient[i];
    496571          if (ci.Id.Equals(cio.Id)) {
    497572            found = true;
     
    499574              changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Update });
    500575            }
    501               for (int j = 0; j < clientInfoOldHelp.List.Count; j++) {
    502                 if (cio.Id.Equals(clientInfoOldHelp.List[i])) {
    503                   clientInfoOldHelp.List.RemoveAt(i);
    504                   break;
    505                 }
    506               }
     576            for (int j = 0; j < helpClients.Count; j++) {
     577              if (cio.Id.Equals(helpClients[j])) {
     578                helpClients.RemoveAt(j);
     579                break;
     580              }
     581            }
    507582            break;
    508583          }
     
    511586          changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Create });
    512587        }
    513       }
    514       foreach (ClientInfo ci in clientInfoOldHelp.List) {
     588        found = false;
     589      }
     590      foreach (ClientInfo ci in helpClients) {
    515591        changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Delete });
    516592      }
    517       #endregion
    518 
    519       #region Clients
    520       ResponseList<ClientGroup> clientsOld = clients;
    521       found = false;
    522       clients = clientManager.GetAllClientGroups();
    523 
    524       ResponseList<ClientGroup> clientsOldHelp = clientsOld;
    525 
     593
     594    }
     595
     596    private void GetDelta(IList<ClientGroup> oldClient, IList<ClientGroup> helpClients) {
     597
     598      bool found = false;
    526599      foreach (ClientGroup cg in clients.List) {
    527         for (int i = 0; i < clientInfoOld.List.Count; i++) {
    528           ClientGroup cgo = clientsOld.List[i];
     600        for (int i = 0; i < oldClient.Count; i++) {
     601          ClientGroup cgo = oldClient[i];
    529602          if (cg.Id.Equals(cgo.Id)) {
    530603            found = true;
     
    538611              }
    539612            }
    540             for (int j = 0; j < clientInfoOldHelp.List.Count; j++) {
    541               if (cgo.Id.Equals(clientInfoOldHelp.List[i])) {
    542                 clientInfoOldHelp.List.RemoveAt(i);
     613            for (int j = 0; j < helpClients.Count; j++) {
     614              if (cgo.Id.Equals(helpClients[j])) {
     615                helpClients.RemoveAt(j);
    543616                break;
    544617              }
     
    550623          changes.Add(new Changes { Types = Type.ClientGroup, ID = cg.Id, ChangeType = Change.Create });
    551624        }
    552       }
    553       foreach (ClientGroup cg in clientsOldHelp.List) {
     625        found = false;
     626      }
     627      foreach (ClientGroup cg in helpClients) {
    554628        changes.Add(new Changes { Types = Type.ClientGroup, ID = cg.Id, ChangeType = Change.Delete });
    555629      }
    556       #endregion
    557 
    558       #region job
    559       ResponseList<Job> jobsOld = jobs;
    560       IJobManager jobManager =
    561           ServiceLocator.GetJobManager();
    562       found = false;
    563       jobs = jobManager.GetAllJobs();
    564 
    565       ResponseList<Job> jobsOldHelp = jobsOld;
    566 
     630    }
     631     
     632    private void GetDelta(IList<Job> oldJobs, IList<Job> helpJobs) {
     633      bool found = false;
    567634      foreach (Job job in jobs.List) {
    568         for (int i = 0; i < jobsOld.List.Count; i++) {
    569           Job jobold = jobsOld.List[i];
     635       
     636        for (int i = 0; i < oldJobs.Count; i++) {
     637         
     638          Job jobold = oldJobs[i];
     639
    570640          if (job.Id.Equals(jobold.Id)) {
     641
    571642            found = true;
    572             if (job.Client != jobold.Client) {
     643            if (IsEqual(job.Client, jobold.Client)) {
    573644              changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update });
    574645            } else if (job.DateCalculated != jobold.DateCalculated) {
    575646              changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update });
    576647            }
    577             //for (int j = 0; j < clientInfoOldHelp.List.Count; j++) {
    578             //  if (job.Id.Equals(clientInfoOldHelp.List[i])) {
    579             //    clientInfoOldHelp.List.RemoveAt(i);
    580             //    break;
    581             //  }
    582             //}
     648
     649            for (int j = 0; j < helpJobs.Count; j++) {
     650              if (job.Id.Equals(helpJobs[j].Id)) {
     651                helpJobs.RemoveAt(j);
     652                break;
     653              }
     654            }
    583655            break;
    584656          }
     657
    585658        }
    586659        if (found == false) {
    587660          changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
    588         }
    589       }
    590       foreach (Job job in jobsOldHelp.List) {
     661          System.Diagnostics.Debug.WriteLine("new Job: " + job.Id);
     662        }
     663        found = false;
     664      }
     665      foreach (Job job in helpJobs) {
    591666        changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Delete });
    592       }
    593       #endregion
    594 
    595     }
     667        System.Diagnostics.Debug.WriteLine("delete Job: " + job.Id);
     668      }
     669    }
     670
     671
    596672    #endregion
     673
     674
    597675  }
    598676}
Note: See TracChangeset for help on using the changeset viewer.