Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1726 for trunk/sources


Ignore:
Timestamp:
04/30/09 15:18:28 (16 years ago)
Author:
gkronber
Message:

worked on HiveEngine and the HiveEngineEditor (#545 (Engine which can be executed in the Hive))

Location:
trunk/sources/HeuristicLab.Hive.Engine/3.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngine.cs

    r1651 r1726  
    3131using HeuristicLab.Hive.Contracts.BusinessObjects;
    3232using System.IO;
     33using System.Xml;
    3334
    3435namespace HeuristicLab.Hive.Engine {
     
    4647    }
    4748
    48 
    4949    #region IEngine Members
    5050
     
    7575    public void Execute() {
    7676      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
    77      
     77
    7878      DiscoveryService dService = new DiscoveryService();
    7979      PluginInfo depInfo = dService.GetDeclaringPlugin(typeof(HiveEngine));
     
    8989
    9090      foreach (PluginInfo info in dependentPlugins) {
    91         HivePluginInfo pluginInfo = 
     91        HivePluginInfo pluginInfo =
    9292          new HivePluginInfo();
    9393        pluginInfo.Name = info.Name;
     
    102102    }
    103103
    104     public void ExecuteStep() {
    105       throw new NotSupportedException();
    106     }
    107 
    108     public void ExecuteSteps(int steps) {
    109       throw new NotSupportedException();
    110     }
    111 
    112     public void Abort() {
     104    public void RequestSnapshot() {
    113105      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
    114      
    115      
    116       //This are just Stubs on the server right now. There won't be any effect right now...
    117       executionEngineFacade.AbortJob(jobId);     
    118       executionEngineFacade.RequestSnapshot(Guid);
    119      
     106
    120107      //Requests the last result.
    121108      //false: There will always be a result that is been sent back
     
    123110      //      the snapshot hasn't been submitted to the server (because the client needs
    124111      //      more time).
    125       executionEngineFacade.GetLastResult(jobId, false);
    126 
    127       throw new NotImplementedException();
     112      var result = executionEngineFacade.GetLastResult(jobId, false);
     113      if (result.Success) {
     114        JobResult jobResult = result.Obj;
     115        if (jobResult != null) {
     116          job = (Job)PersistenceManager.RestoreFromGZip(jobResult.Result);
     117          PluginManager.ControlManager.ShowControl(job.Engine.CreateView());
     118        }
     119      } else {
     120        Exception ex = new Exception(result.Obj.Exception.Message);
     121        ThreadPool.QueueUserWorkItem(delegate(object state) { OnExceptionOccurred(ex); });
     122      }
     123    }
     124
     125
     126    public void ExecuteStep() {
     127      throw new NotSupportedException();
     128    }
     129
     130    public void ExecuteSteps(int steps) {
     131      throw new NotSupportedException();
     132    }
     133
     134    public void Abort() {
     135      IExecutionEngineFacade executionEngineFacade = ServiceLocator.CreateExecutionEngineFacade(HiveServerUrl);
     136
     137      //This are just Stubs on the server right now. There won't be any effect right now...
     138      executionEngineFacade.AbortJob(jobId);
     139      OnFinished();
    128140    }
    129141
    130142    public void Reset() {
    131       throw new NotImplementedException();
     143      job.Engine.Reset();
     144      jobId = Guid.NewGuid();
     145      OnInitialized();
    132146    }
    133147
    134148    public event EventHandler Initialized;
     149    /// <summary>
     150    /// Fires a new <c>Initialized</c> event.
     151    /// </summary>
     152    protected virtual void OnInitialized() {
     153      if (Initialized != null)
     154        Initialized(this, new EventArgs());
     155    }
    135156
    136157    public event EventHandler<OperationEventArgs> OperationExecuted;
     158    /// <summary>
     159    /// Fires a new <c>OperationExecuted</c> event.
     160    /// </summary>
     161    /// <param name="operation">The operation that has been executed.</param>
     162    protected virtual void OnOperationExecuted(IOperation operation) {
     163      if (OperationExecuted != null)
     164        OperationExecuted(this, new OperationEventArgs(operation));
     165    }
    137166
    138167    public event EventHandler<ExceptionEventArgs> ExceptionOccurred;
     168    /// <summary>
     169    /// Aborts the execution and fires a new <c>ExceptionOccurred</c> event.
     170    /// </summary>
     171    /// <param name="exception">The exception that was thrown.</param>
     172    protected virtual void OnExceptionOccurred(Exception exception) {
     173      Abort();
     174      if (ExceptionOccurred != null)
     175        ExceptionOccurred(this, new ExceptionEventArgs(exception));
     176    }
    139177
    140178    public event EventHandler ExecutionTimeChanged;
     179    /// <summary>
     180    /// Fires a new <c>ExecutionTimeChanged</c> event.
     181    /// </summary>
     182    protected virtual void OnExecutionTimeChanged() {
     183      if (ExecutionTimeChanged != null)
     184        ExecutionTimeChanged(this, new EventArgs());
     185    }
    141186
    142187    public event EventHandler Finished;
     188    /// <summary>
     189    /// Fires a new <c>Finished</c> event.
     190    /// </summary>
     191    protected virtual void OnFinished() {
     192      if (Finished != null)
     193        Finished(this, new EventArgs());
     194    }
    143195
    144196    #endregion
    145 
    146     public void RequestSnapshot() {
    147       throw new NotImplementedException();
    148     }
    149197
    150198    public override IView CreateView() {
     
    158206    }
    159207    #endregion
     208
     209    public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     210      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     211      XmlAttribute attr = document.CreateAttribute("HiveServerUrl");
     212      attr.Value = HiveServerUrl;
     213      node.Attributes.Append(attr);
     214      node.AppendChild(PersistenceManager.Persist("Job", job, document, persistedObjects));
     215      return node;
     216    }
     217
     218    public override void Populate(System.Xml.XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     219      base.Populate(node, restoredObjects);
     220      HiveServerUrl = node.Attributes["HiveServerUrl"].Value;
     221      job = (Job)PersistenceManager.Restore(node.SelectSingleNode("Job"), restoredObjects);
     222    }
    160223  }
    161224}
  • trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.Designer.cs

    r1530 r1726  
    8787      //
    8888      this.snapshotButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     89      this.snapshotButton.Enabled = false;
    8990      this.snapshotButton.Location = new System.Drawing.Point(294, 457);
    9091      this.snapshotButton.Name = "snapshotButton";
     
    9394      this.snapshotButton.Text = "Snapshot";
    9495      this.snapshotButton.UseVisualStyleBackColor = true;
     96      this.snapshotButton.Click += new System.EventHandler(this.snapshotButton_Click);
    9597      //
    9698      // urlTextBox
  • trunk/sources/HeuristicLab.Hive.Engine/3.2/HiveEngineEditor.cs

    r1530 r1726  
    4242      get { return (HiveEngine)Engine; }
    4343      set {
     44        if (base.Engine != null) RemoveItemEvents();
    4445        base.Engine = value;
     46        AddItemEvents();
    4547        SetDataBinding();
    4648      }
     
    6163      : this() {
    6264      HiveEngine = hiveEngine;
     65      base.executeButton.Click += new EventHandler(executeButton_Click);
     66    }
     67
     68    void executeButton_Click(object sender, EventArgs e) {
     69      snapshotButton.Enabled = true;
    6370    }
    6471
     
    6673      urlTextBox.DataBindings.Add("Text", HiveEngine, "HiveServerUrl");
    6774    }
     75
     76    protected override void RemoveItemEvents() {
     77      Engine.Initialized -= new EventHandler(Engine_Initialized);
     78      Engine.Finished -= new EventHandler(Engine_Finished);
     79      base.RemoveItemEvents();
     80    }
     81
     82    protected override void AddItemEvents() {
     83      base.AddItemEvents();
     84      Engine.Finished += new EventHandler(Engine_Finished);
     85      Engine.Initialized += new EventHandler(Engine_Initialized);
     86    }
     87
     88    void Engine_Initialized(object sender, EventArgs e) {
     89      snapshotButton.Enabled = false;
     90    }
     91
     92    void Engine_Finished(object sender, EventArgs e) {
     93      snapshotButton.Enabled = false;
     94    }
     95
     96    private void snapshotButton_Click(object sender, EventArgs e) {
     97      HiveEngine.RequestSnapshot();
     98    }
    6899  }
    69100}
Note: See TracChangeset for help on using the changeset viewer.