Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4145


Ignore:
Timestamp:
08/04/10 15:13:28 (14 years ago)
Author:
cneumuel
Message:

worked on "request snapshot" feature (#1115)

Location:
branches/3.3-HiveMigration/sources/HeuristicLab.Hive
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/JobItemView.cs

    r4144 r4145  
    4747      Content.LatestSnapshotChanged += new EventHandler(Content_LatestSnapshotChanged);
    4848      Content.JobDtoChanged += new EventHandler(Content_JobDtoChanged);
     49      Content.SnapshotRequestedStateChanged += new EventHandler(Content_SnapshotRequestedStateChanged);
    4950    }
    5051
     
    5253      Content.LatestSnapshotChanged -= new EventHandler(Content_LatestSnapshotChanged);
    5354      Content.JobDtoChanged -= new EventHandler(Content_JobDtoChanged);
     55      Content.SnapshotRequestedStateChanged -= new EventHandler(Content_SnapshotRequestedStateChanged);
    5456      base.DeregisterContentEvents();
    5557    }
     
    9294    protected override void SetEnabledStateOfControls() {
    9395      base.SetEnabledStateOfControls();
    94       openSnapshotButton.Enabled = Content != null && Content.LatestSnapshot != null;
     96      if (Content != null) {
     97        openSnapshotButton.Enabled = Content.SnapshotRequestedState == SnapshotRequestedState.Idle;
     98        requestSnapshotButton.Enabled = Content.SnapshotRequestedState == SnapshotRequestedState.Requested;
     99      }
    95100      this.jobIdTextBox.ReadOnly = this.ReadOnly;
    96101      this.stateTextBox.ReadOnly = this.ReadOnly;
     
    115120
    116121    private void requestSnapshotButton_Click(object sender, EventArgs e) {
    117      
     122      this.Content.RequestSnapshot();
     123    }
     124
     125    private void Content_SnapshotRequestedStateChanged(object sender, EventArgs e) {
     126      SetEnabledStateOfControls();
    118127    }
    119128  }
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs

    r4144 r4145  
    158158      isPollingResults = false;
    159159      resultPollingThreads = new Dictionary<Guid, Thread>();
     160      RegisterEvents();
    160161      InitTimer();
    161162    }
     
    191192      this.IsPollingResults = false;
    192193      this.stopResultsPollingPending = false;
     194      RegisterEvents();
    193195      LogMessage("I was deserialized.");
    194196    }
    195 
     197   
    196198    private void InitTimer() {
    197199      timer = new System.Timers.Timer(100);
     
    556558      lock (locker) {
    557559        log.LogMessage(message);
     560      }
     561    }
     562
     563    void JobItem_SnapshotRequestedStateChanged(object sender, EventArgs e) {
     564      JobItem jobItem = (JobItem)sender;
     565      if (jobItem.SnapshotRequestedState == SnapshotRequestedState.Requested) {
     566        RequestSnapshot(jobItem.JobDto.Id);
    558567      }
    559568    }
     
    588597          );
    589598      }
    590       SerializedJob jobResult = response.Obj;
    591       if (jobResult != null) {
    592         Logger.Debug("HiveEngine: Results-polling - Got result!");
    593 
    594         //job = XmlParser.Deserialize<Job>(new MemoryStream(jobResult.SerializedJobData));
    595 
    596         throw new NotImplementedException("[chn] how to create a view in 3.3 and why should i do this here? shouldnt the caller of this method receive a result and decide what to do?");
    597         //ControlManager.Manager.ShowControl(job.Engine.CreateView());
     599      if (response.Success) {
     600        GetJobItemById(jobId).LogMessage("Snapshot polling successfull for job " + jobId);
     601        GetJobItemById(jobId).LatestSnapshot = response;
     602      } else {
     603        GetJobItemById(jobId).LogMessage("Error: Polling of Snapshot failed for job " + jobId + ": " + response.StatusMessage);
    598604      }
    599605    }
     
    763769      if (handler != null) handler(this, EventArgs.Empty);
    764770    }
     771
     772    private void RegisterEvents() {
     773      jobItems.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_CollectionReset);
     774      jobItems.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_ItemsAdded);
     775      jobItems.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_ItemsRemoved);
     776      jobItems.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_ItemsReplaced);
     777    }
     778
     779    private void DeregisterEvents() {
     780      jobItems.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_CollectionReset);
     781      jobItems.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_ItemsAdded);
     782      jobItems.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_ItemsRemoved);
     783      jobItems.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<JobItem>>(jobItems_ItemsReplaced);
     784    }
     785
     786
     787    void jobItems_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<JobItem>> e) {
     788      UpdateSnapshotRequestedEvents(e);
     789    }
     790
     791    private void UpdateSnapshotRequestedEvents(CollectionItemsChangedEventArgs<IndexedItem<JobItem>> e) {
     792      foreach (var item in e.OldItems) {
     793        item.Value.SnapshotRequestedStateChanged -= new EventHandler(JobItem_SnapshotRequestedStateChanged);
     794      }
     795      foreach (var item in e.Items) {
     796        item.Value.SnapshotRequestedStateChanged += new EventHandler(JobItem_SnapshotRequestedStateChanged);
     797      }
     798    }
     799
     800    void jobItems_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<JobItem>> e) {
     801      UpdateSnapshotRequestedEvents(e);
     802    }
     803
     804    void jobItems_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<JobItem>> e) {
     805      UpdateSnapshotRequestedEvents(e);
     806    }
     807
     808    void jobItems_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<JobItem>> e) {
     809      foreach (var item in e.OldItems) {
     810        item.Value.SnapshotRequestedStateChanged -= new EventHandler(JobItem_SnapshotRequestedStateChanged);
     811      }
     812    }
    765813    #endregion
    766814  }
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/JobItem.cs

    r4144 r4145  
    1313
    1414namespace HeuristicLab.Hive.Experiment {
     15  public enum SnapshotRequestedState { Idle, Requested }
     16
    1517  [StorableClass]
    1618  public class JobItem : Item {
     
    5153          latestSnapshot = value;
    5254          latestSnapshotTime = DateTime.Now;
     55          SnapshotRequestedState = Experiment.SnapshotRequestedState.Idle;
    5356          OnLatestSnapshotChanged();
    5457        }
     
    7477      set { this.optimizer = value; }
    7578    }
    76    
     79
     80    [Storable]
     81    private SnapshotRequestedState snapshotRequestedState;
     82    public SnapshotRequestedState SnapshotRequestedState {
     83      get { return snapshotRequestedState; }
     84      private set {
     85        this.snapshotRequestedState = value;
     86        OnSnapshotRequestedStateChanged();
     87      }
     88    }
     89
    7790    public JobItem() {
    7891      log = new Log();
     
    117130      return clone;
    118131    }
     132
     133
     134    public event EventHandler SnapshotRequestedStateChanged;
     135    private void OnSnapshotRequestedStateChanged() {
     136      EventHandler handler = SnapshotRequestedStateChanged;
     137      if (handler != null) handler(this, EventArgs.Empty);
     138    }
     139
     140    public void RequestSnapshot() {
     141      this.SnapshotRequestedState = Experiment.SnapshotRequestedState.Requested;
     142    }
     143
    119144  }
    120145}
Note: See TracChangeset for help on using the changeset viewer.