Free cookie consent management tool by TermsFeed Policy Generator

Changeset 372 for trunk


Ignore:
Timestamp:
07/09/08 10:34:10 (16 years ago)
Author:
gkronber
Message:

worked on #187 - code is still a mess

Location:
trunk/sources
Files:
7 added
1 deleted
19 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Console/Agent.cs

    r357 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    526using HeuristicLab.Core;
    627using System.Xml;
     28using HeuristicLab.CEDMA.DB.Interfaces;
    729
    830namespace HeuristicLab.CEDMA.Console {
    931  public class Agent : ItemBase, IAgent {
    10     private string name;
     32    public IDatabase Database { get; set; }
     33    public long Id { get; set; }
     34    public string Name { get; set; }
     35    public AgentStatus Status { get; set; }
    1136    private OperatorGraph operatorGraph;
    12     public string Name {
    13       get { return name; }
    14       set { name = value; }
    15     }
    1637
    1738    public IOperatorGraph OperatorGraph {
     
    1940    }
    2041
    21     public Agent() : base() {
     42    public Agent()
     43      : base() {
    2244      operatorGraph = new OperatorGraph();
    2345    }
     46
     47    public Agent(IDatabase database, long id) : this() {
     48      Database = database;
     49      Id = id;
     50    }
     51
     52    public void Save() {
     53      AgentEntry entry = new AgentEntry(Id, Name, Status, DbPersistenceManager.Save(this));
     54      Database.Update(entry);
     55    }
     56
     57    public void Activate() {
     58      Status = AgentStatus.Waiting;
     59      Save();
     60    }
     61
     62    #region persistence
     63    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     64      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
     65      node.AppendChild(PersistenceManager.Persist("OperatorGraph", operatorGraph, document, persistedObjects));
     66      return node;
     67    }
     68
     69    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
     70      base.Populate(node, restoredObjects);
     71      operatorGraph = (OperatorGraph)PersistenceManager.Restore(node.SelectSingleNode("OperatorGraph"), restoredObjects);
     72    }
     73    #endregion
     74
    2475  }
    2576}
  • trunk/sources/HeuristicLab.CEDMA.Console/AgentList.cs

    r357 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    627using System.Collections;
    728using HeuristicLab.CEDMA.DB.Interfaces;
     29using System.Xml;
     30using System.Runtime.Serialization;
     31using System.IO;
    832
    933namespace HeuristicLab.CEDMA.Console {
    10   public class AgentList: ItemBase, IAgentList {
     34  public class AgentList : ItemBase, IAgentList {
    1135    private string serverUri;
    1236    private List<IAgent> agentList;
     
    2246    private void ReloadList() {
    2347      agentList.Clear();
    24       foreach(HeuristicLab.CEDMA.DB.Interfaces.IAgent a in database.GetAgents()) {
    25         Agent newAgent = new Agent();
     48      foreach(AgentEntry a in database.GetAgentEntries()) {
     49        Agent newAgent = (Agent)DbPersistenceManager.Restore(a.RawData);
     50        newAgent.Database = database;
     51        newAgent.Id = a.Id;
    2652        newAgent.Name = a.Name;
     53        newAgent.Status = a.Status;
    2754        agentList.Add(newAgent);
    2855      }
     
    3461      agentList = new List<IAgent>();
    3562    }
    36    
    37     public void Add(IAgent agent) {
     63
     64    public void CreateAgent() {
     65      long id = database.CreateAgent();
     66      Agent agent = new Agent(database, id);
     67      agent.Name = DateTime.Now.ToString();
     68      agent.Save();
    3869      agentList.Add(agent);
    3970    }
  • trunk/sources/HeuristicLab.CEDMA.Console/AgentListView.cs

    r357 r372  
    9494    #region Button Events
    9595    private void addButton_Click(object sender, EventArgs e) {
    96       Agent agent = new Agent();
    97       string name = DateTime.Now.ToString();
    98       agent.Name = name;
    99       AgentList.Add(agent);
     96      AgentList.CreateAgent();
     97      UpdateControls();
    10098    }
    10199    #endregion
  • trunk/sources/HeuristicLab.CEDMA.Console/AgentView.Designer.cs

    r357 r372  
    4848      this.saveButton = new System.Windows.Forms.Button();
    4949      this.activateButton = new System.Windows.Forms.Button();
    50       this.stopButton = new System.Windows.Forms.Button();
    5150      this.SuspendLayout();
    5251      //
     
    7271      this.saveButton.Text = "&Save";
    7372      this.saveButton.UseVisualStyleBackColor = true;
     73      this.saveButton.Click += new System.EventHandler(this.saveButton_Click);
    7474      //
    7575      // activateButton
     
    8282      this.activateButton.Text = "&Activate";
    8383      this.activateButton.UseVisualStyleBackColor = true;
    84       //
    85       // stopButton
    86       //
    87       this.stopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    88       this.stopButton.Location = new System.Drawing.Point(166, 128);
    89       this.stopButton.Name = "stopButton";
    90       this.stopButton.Size = new System.Drawing.Size(75, 23);
    91       this.stopButton.TabIndex = 3;
    92       this.stopButton.Text = "S&top";
    93       this.stopButton.UseVisualStyleBackColor = true;
     84      this.activateButton.Click += new System.EventHandler(this.activateButton_Click);
    9485      //
    9586      // AgentView
     
    9788      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    9889      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    99       this.Controls.Add(this.stopButton);
    10090      this.Controls.Add(this.activateButton);
    10191      this.Controls.Add(this.saveButton);
     
    112102    private System.Windows.Forms.Button saveButton;
    113103    private System.Windows.Forms.Button activateButton;
    114     private System.Windows.Forms.Button stopButton;
    115104  }
    116105}
  • trunk/sources/HeuristicLab.CEDMA.Console/AgentView.cs

    r357 r372  
    2828using System.Windows.Forms;
    2929using HeuristicLab.Core;
     30using HeuristicLab.CEDMA.DB.Interfaces;
    3031
    3132namespace HeuristicLab.CEDMA.Console {
     
    5657          editorGroupBox.Enabled = true;
    5758        }
     59
     60        if(Agent.Status == AgentStatus.Unkown) activateButton.Enabled = true;
     61        else activateButton.Enabled = false;
    5862      }
     63    }
     64
     65    private void saveButton_Click(object sender, EventArgs e) {
     66      Agent.Save();
     67    }
     68
     69    private void activateButton_Click(object sender, EventArgs e) {
     70      Agent.Activate();
     71      activateButton.Enabled = false;
    5972    }
    6073  }
  • trunk/sources/HeuristicLab.CEDMA.Console/Console.cs

    r359 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
  • trunk/sources/HeuristicLab.CEDMA.Console/ConsoleEditor.cs

    r359 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    1637    private System.Windows.Forms.TabPage resultsPage;
    1738    private Button connectButton;
     39    private ComboBox comboBox1;
     40    private Label projectLabel;
     41    private Button newButton;
    1842    private Console console;
    1943
     
    3155      this.resultsPage = new System.Windows.Forms.TabPage();
    3256      this.connectButton = new System.Windows.Forms.Button();
     57      this.comboBox1 = new System.Windows.Forms.ComboBox();
     58      this.projectLabel = new System.Windows.Forms.Label();
     59      this.newButton = new System.Windows.Forms.Button();
    3360      this.tabControl.SuspendLayout();
    3461      this.SuspendLayout();
     
    5986      this.tabControl.Controls.Add(this.resultsPage);
    6087      this.tabControl.Enabled = false;
    61       this.tabControl.Location = new System.Drawing.Point(6, 29);
     88      this.tabControl.Location = new System.Drawing.Point(6, 56);
    6289      this.tabControl.Name = "tabControl";
    6390      this.tabControl.SelectedIndex = 0;
    64       this.tabControl.Size = new System.Drawing.Size(407, 242);
     91      this.tabControl.Size = new System.Drawing.Size(506, 407);
    6592      this.tabControl.TabIndex = 2;
    6693      //
     
    7097      this.overviewPage.Name = "overviewPage";
    7198      this.overviewPage.Padding = new System.Windows.Forms.Padding(3);
    72       this.overviewPage.Size = new System.Drawing.Size(399, 216);
     99      this.overviewPage.Size = new System.Drawing.Size(498, 381);
    73100      this.overviewPage.TabIndex = 0;
    74101      this.overviewPage.Text = "Overview";
     
    80107      this.agentsPage.Name = "agentsPage";
    81108      this.agentsPage.Padding = new System.Windows.Forms.Padding(3);
    82       this.agentsPage.Size = new System.Drawing.Size(399, 216);
     109      this.agentsPage.Size = new System.Drawing.Size(498, 381);
    83110      this.agentsPage.TabIndex = 1;
    84111      this.agentsPage.Text = "Agents";
     
    90117      this.resultsPage.Name = "resultsPage";
    91118      this.resultsPage.Padding = new System.Windows.Forms.Padding(3);
    92       this.resultsPage.Size = new System.Drawing.Size(399, 216);
     119      this.resultsPage.Size = new System.Drawing.Size(498, 381);
    93120      this.resultsPage.TabIndex = 2;
    94121      this.resultsPage.Text = "Results";
     
    105132      this.connectButton.Click += new System.EventHandler(this.connectButton_Click);
    106133      //
     134      // comboBox1
     135      //
     136      this.comboBox1.Enabled = false;
     137      this.comboBox1.FormattingEnabled = true;
     138      this.comboBox1.Location = new System.Drawing.Point(91, 29);
     139      this.comboBox1.Name = "comboBox1";
     140      this.comboBox1.Size = new System.Drawing.Size(121, 21);
     141      this.comboBox1.TabIndex = 4;
     142      //
     143      // projectLabel
     144      //
     145      this.projectLabel.AutoSize = true;
     146      this.projectLabel.Enabled = false;
     147      this.projectLabel.Location = new System.Drawing.Point(42, 32);
     148      this.projectLabel.Name = "projectLabel";
     149      this.projectLabel.Size = new System.Drawing.Size(43, 13);
     150      this.projectLabel.TabIndex = 5;
     151      this.projectLabel.Text = "Project:";
     152      //
     153      // newButton
     154      //
     155      this.newButton.Enabled = false;
     156      this.newButton.Location = new System.Drawing.Point(218, 27);
     157      this.newButton.Name = "newButton";
     158      this.newButton.Size = new System.Drawing.Size(75, 23);
     159      this.newButton.TabIndex = 6;
     160      this.newButton.Text = "New...";
     161      this.newButton.UseVisualStyleBackColor = true;
     162      //
    107163      // ConsoleEditor
    108164      //
    109165      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     166      this.Controls.Add(this.newButton);
     167      this.Controls.Add(this.projectLabel);
     168      this.Controls.Add(this.comboBox1);
    110169      this.Controls.Add(this.connectButton);
    111170      this.Controls.Add(this.tabControl);
     
    113172      this.Controls.Add(this.uriTextBox);
    114173      this.Name = "ConsoleEditor";
    115       this.Size = new System.Drawing.Size(416, 274);
     174      this.Size = new System.Drawing.Size(515, 466);
    116175      this.tabControl.ResumeLayout(false);
    117176      this.ResumeLayout(false);
     
    125184        connectButton.Enabled = false;
    126185        tabControl.Enabled = true;
     186        agentsPage.Controls.Clear();
    127187        agentsPage.Controls.Add((Control)console.AgentList.CreateView());
     188        agentsPage.Controls[0].Dock = DockStyle.Fill;
    128189      } catch(CommunicationException ex) {
    129190        // TASK create helper class for error reporting
  • trunk/sources/HeuristicLab.CEDMA.Console/HeuristicLab.CEDMA.Console.csproj

    r357 r372  
    6666      <SubType>UserControl</SubType>
    6767    </Compile>
     68    <Compile Include="DbPersistenceManager.cs" />
    6869    <Compile Include="HeuristicLabCedmaConsolePlugin.cs" />
    6970    <Compile Include="IAgent.cs" />
    7071    <Compile Include="IAgentList.cs" />
     72    <Compile Include="IDatabaseItem.cs" />
    7173    <Compile Include="Properties\AssemblyInfo.cs" />
    7274    <Compile Include="AgentListView.cs">
  • trunk/sources/HeuristicLab.CEDMA.Console/IAgent.cs

    r357 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
    425using System.Text;
    526using HeuristicLab.Core;
     27using HeuristicLab.CEDMA.DB.Interfaces;
    628
    729namespace HeuristicLab.CEDMA.Console {
    8   public interface IAgent : IItem {
     30  public interface IAgent : IDatabaseItem {
    931    string Name { get; }
     32    AgentStatus Status { get; }
    1033    IOperatorGraph OperatorGraph { get; }
     34    void Save();
     35    void Activate();
    1136  }
    1237}
  • trunk/sources/HeuristicLab.CEDMA.Console/IAgentList.cs

    r357 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    728namespace HeuristicLab.CEDMA.Console {
    829  public interface IAgentList : IItem, IEnumerable<IAgent> {
    9     void Add(IAgent agent);
     30    void CreateAgent();
    1031  }
    1132}
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentStatus.cs

    r357 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    526
    627namespace HeuristicLab.CEDMA.DB.Interfaces {
    7   public enum AgentStatus { Aktive, Finished, Error, Waiting }
     28  public enum AgentStatus { Unkown, Active, Finished, Error, Waiting}
    829}
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/HeuristicLab.CEDMA.DB.Interfaces.csproj

    r357 r372  
    4242      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    4343    </Reference>
     44    <Reference Include="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
     45      <RequiredTargetFramework>3.0</RequiredTargetFramework>
     46    </Reference>
    4447    <Reference Include="System.ServiceModel">
    4548      <RequiredTargetFramework>3.0</RequiredTargetFramework>
     
    5558  </ItemGroup>
    5659  <ItemGroup>
     60    <Compile Include="AgentEntry.cs" />
    5761    <Compile Include="AgentStatus.cs" />
     62    <Compile Include="ResultEntry.cs" />
    5863    <Compile Include="HeuristicLabCedmaDbInterfacesPlugin.cs" />
    59     <Compile Include="IAgent.cs" />
    6064    <Compile Include="IDatabase.cs" />
    6165    <Compile Include="Properties\AssemblyInfo.cs" />
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs

    r357 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
    425using System.Text;
    526using System.ServiceModel;
     27using System.Data;
    628
    729namespace HeuristicLab.CEDMA.DB.Interfaces {
    8   [ServiceContract(Namespace = "http://HeuristicLab.Cedma")]
     30  [ServiceContract(Namespace = "http://HeuristicLab.CEDMA.DB")]
    931  public interface IDatabase {
    1032    [OperationContract]
    11     IList<IAgent> GetAgents();
     33    ICollection<AgentEntry> GetAgentEntries();
    1234
    1335    [OperationContract]
    14     IAgent CreateAgent();
     36    long CreateAgent();
     37
     38    [OperationContract(Name="UpdateAgent")]
     39    void Update(AgentEntry entry);
     40
     41    [OperationContract(Name ="UpdateResult")]
     42    void Update(ResultEntry result);
    1543  }
    1644}
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r357 r372  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    627using HeuristicLab.CEDMA.DB.Interfaces;
    728using System.ServiceModel;
     29using System.Data;
     30using System.Data.SQLite;
     31using System.Data.Common;
    832
    933namespace HeuristicLab.CEDMA.DB {
    10   [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
    11   public class Database : DataContext, IDatabase {
    12     Table<Agent> Agents;
    13 
    14     public Database() : this("c:\\cedma.mdf") { }
    15 
    16     public Database(string connection) : base(connection) {
     34  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, UseSynchronizationContext = true)]
     35  public class Database : IDatabase {
     36    private string connectionString;
     37    public Database(string connectionString) {
     38      this.connectionString = connectionString;
    1739    }
    1840
    19     public IList<IAgent> GetAgents() {
    20       List<IAgent> result = new List<IAgent>();
    21       foreach(Agent a in Agents) {
    22         result.Add(a);
     41    public void CreateNew() {
     42      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     43        cnn.ConnectionString = connectionString;
     44        cnn.Open();
     45
     46        SQLiteCommand cAgent = cnn.CreateCommand();
     47        cAgent.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, Name text, Status text default 'Unknown', RawData Blob)";
     48        SQLiteCommand cProject = cnn.CreateCommand();
     49        cProject.CommandText = "CREATE TABLE Project (ID integer primary key autoincrement, Name text, Description text, CreationDate DateTime)";
     50        SQLiteCommand cResult = cnn.CreateCommand();
     51        cResult.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, AgentId integer, ParentResultId integer, CreationDate DateTime, RawData Blob)";
     52        cAgent.ExecuteNonQuery();
     53        cProject.ExecuteNonQuery();
     54        cResult.ExecuteNonQuery();
    2355      }
    24       return result;
    2556    }
    2657
    27     public IAgent CreateAgent() {
    28       Agent newAgent = new Agent();
    29       newAgent.Name = DateTime.Now.ToString();
    30       newAgent.Status = AgentStatus.Waiting;
    31       newAgent.RawData = null;
    32       Agents.InsertOnSubmit(newAgent);
    33       this.SubmitChanges();
    34       return newAgent;
     58    public long CreateAgent() {
     59      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     60        cnn.Open();
     61        SQLiteCommand c = cnn.CreateCommand();
     62        c.CommandText = "Insert into Agent (Name) values (@Name); select last_insert_rowid()";
     63        DbParameter nameParam = c.CreateParameter();
     64        nameParam.ParameterName = "@Name";
     65        nameParam.Value = DateTime.Now.ToString();
     66        c.Parameters.Add(nameParam);
     67        long id = (long)c.ExecuteScalar();
     68        return id;
     69      }
     70    }
     71
     72    public ICollection<AgentEntry> GetAgentEntries() {
     73      List<AgentEntry> agents = new List<AgentEntry>();
     74      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     75        cnn.Open();
     76        SQLiteCommand c = cnn.CreateCommand();
     77        c.CommandText = "Select id, name, status, rawdata from Agent";
     78        SQLiteDataReader r = c.ExecuteReader();
     79        while(r.Read()) {
     80          AgentEntry agent = new AgentEntry(r.GetInt32(0), r.GetString(1), (AgentStatus)Enum.Parse(typeof(AgentStatus), r.GetString(2)), (byte[])r.GetValue(3));
     81          agents.Add(agent);
     82        }
     83      }
     84      return agents;
     85    }
     86
     87    public ICollection<AgentEntry> GetAgentEntries(AgentStatus status) {
     88      List<AgentEntry> agents = new List<AgentEntry>();
     89      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     90        cnn.Open();
     91        SQLiteCommand c = cnn.CreateCommand();
     92        c.CommandText = "Select id, name, status, rawdata from Agent where Status=@Status";
     93        DbParameter statusParameter = c.CreateParameter();
     94        statusParameter.ParameterName = "@Status";
     95        statusParameter.Value = (int)status;
     96        c.Parameters.Add(statusParameter);
     97
     98        SQLiteDataReader r = c.ExecuteReader();
     99        while(r.Read()) {
     100          AgentEntry agent = new AgentEntry(r.GetInt32(0), r.GetString(1), (AgentStatus)Enum.Parse(typeof(AgentStatus), r.GetString(2)), (byte[])r.GetValue(3));
     101          agents.Add(agent);
     102        }
     103      }
     104      return agents;
     105    }
     106
     107    public void Update(AgentEntry entry) {
     108      using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     109        cnn.Open();
     110        SQLiteCommand c = cnn.CreateCommand();
     111        c.CommandText = "Update Agent set Name=@Name, Status=@Status, RawData=@RawData where id=@Id";
     112        DbParameter nameParam = c.CreateParameter();
     113        DbParameter statusParam = c.CreateParameter();
     114        DbParameter rawDataParam = c.CreateParameter();
     115        DbParameter idParam = c.CreateParameter();
     116        nameParam.ParameterName = "@Name";
     117        nameParam.Value = entry.Name;
     118        statusParam.ParameterName = "@Status";
     119        statusParam.Value = entry.Status;
     120        rawDataParam.ParameterName = "@RawData";
     121        rawDataParam.Value = entry.RawData;
     122        idParam.ParameterName = "@Id";
     123        idParam.Value = entry.Id;
     124        c.Parameters.Add(nameParam);
     125        c.Parameters.Add(statusParam);
     126        c.Parameters.Add(rawDataParam);
     127        c.Parameters.Add(idParam);
     128        c.ExecuteNonQuery();
     129      }
     130    }
     131
     132    public void Update(ResultEntry result) {
     133      throw new NotImplementedException();
    35134    }
    36135  }
  • trunk/sources/HeuristicLab.CEDMA.DB/HeuristicLab.CEDMA.DB.csproj

    r357 r372  
    1515    <SignAssembly>true</SignAssembly>
    1616    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
     17    <StartupObject>
     18    </StartupObject>
    1719  </PropertyGroup>
    1820  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     
    6264  </ItemGroup>
    6365  <ItemGroup>
    64     <Compile Include="Agent.cs" />
    6566    <Compile Include="Database.cs" />
    6667    <Compile Include="HeuristicLabCedmaDbPlugin.cs" />
    6768    <Compile Include="Properties\AssemblyInfo.cs" />
     69    <Compile Include="Properties\Settings.Designer.cs">
     70      <AutoGen>True</AutoGen>
     71      <DesignTimeSharedInput>True</DesignTimeSharedInput>
     72      <DependentUpon>Settings.settings</DependentUpon>
     73    </Compile>
    6874  </ItemGroup>
    6975  <ItemGroup>
    7076    <None Include="HeuristicLab.snk" />
     77    <None Include="Properties\Settings.settings">
     78      <Generator>SettingsSingleFileGenerator</Generator>
     79      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
     80    </None>
    7181  </ItemGroup>
    7282  <ItemGroup>
  • trunk/sources/HeuristicLab.CEDMA.Server/HeuristicLab.CEDMA.Server.csproj

    r357 r372  
    5959  </ItemGroup>
    6060  <ItemGroup>
     61    <Compile Include="AgentScheduler.cs" />
     62    <Compile Include="DbPersistenceManager.cs" />
    6163    <Compile Include="ServerApplication.cs" />
    6264    <Compile Include="HeuristicLabCedmaServerPlugin.cs" />
     
    7072  </ItemGroup>
    7173  <ItemGroup>
     74    <ProjectReference Include="..\HeuristicLab.CEDMA.Console\HeuristicLab.CEDMA.Console.csproj">
     75      <Project>{F8880599-F224-4EC7-9288-5C4A6853E7BE}</Project>
     76      <Name>HeuristicLab.CEDMA.Console</Name>
     77    </ProjectReference>
    7278    <ProjectReference Include="..\HeuristicLab.CEDMA.DB.Interfaces\HeuristicLab.CEDMA.DB.Interfaces.csproj">
    7379      <Project>{4F9BB789-D561-436B-B226-2BF44B7D0804}</Project>
     
    7884      <Name>HeuristicLab.CEDMA.DB</Name>
    7985    </ProjectReference>
     86    <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj">
     87      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
     88      <Name>HeuristicLab.Core</Name>
     89    </ProjectReference>
    8090    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    8191      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
    8292      <Name>HeuristicLab.PluginInfrastructure</Name>
     93    </ProjectReference>
     94    <ProjectReference Include="..\HeuristicLab.SequentialEngine\HeuristicLab.SequentialEngine.csproj">
     95      <Project>{B4BE8E53-BA06-4237-9A01-24255F880201}</Project>
     96      <Name>HeuristicLab.SequentialEngine</Name>
    8397    </ProjectReference>
    8498  </ItemGroup>
  • trunk/sources/HeuristicLab.CEDMA.Server/ServerForm.cs

    r357 r372  
    3434using HeuristicLab.CEDMA.DB;
    3535using HeuristicLab.CEDMA.DB.Interfaces;
     36using System.Data.Common;
     37using System.Threading;
    3638
    3739namespace HeuristicLab.CEDMA.Server {
    3840  public partial class ServerForm : Form {
    3941    private ServiceHost host;
    40     private Database database = new Database();
    41 
     42    private Database database;
     43    private static readonly string dbFile = AppDomain.CurrentDomain.BaseDirectory + "/test.db3";
     44    private static readonly string connectionString = "Data Source=\""+dbFile+"\";Pooling=False";
    4245    public ServerForm() {
    4346      InitializeComponent();
     47      InitDatabase();
     48      InitAgentScheduler();
    4449
    4550      // windows XP returns the external ip on index 0 while windows vista returns the external ip on index 2
    4651      if (System.Environment.OSVersion.Version.Major >= 6) {
    47         addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8000/CEDMA/World";
     52        addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[2] + ":8002/CEDMA/World";
    4853      } else {
    49         addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8000/CEDMA/World";
     54        addressTextBox.Text = "net.tcp://" + Dns.GetHostAddresses(Dns.GetHostName())[0] + ":8002/CEDMA/World";
    5055      }
    5156      Start();
     57    }
     58
     59    private void InitAgentScheduler() {
     60      AgentScheduler scheduler = new AgentScheduler(database);
     61      ThreadPool.QueueUserWorkItem(delegate(object status) { scheduler.Run(); });
     62    }
     63
     64    private void InitDatabase() {
     65      DbProviderFactory fact;
     66      fact = DbProviderFactories.GetFactory("System.Data.SQLite");
     67      if(!System.IO.File.Exists(dbFile)) {
     68        database = new Database(connectionString);
     69        database.CreateNew();
     70      } else {
     71        database = new Database(connectionString);
     72      }
    5273    }
    5374
  • trunk/sources/HeuristicLab.DistributedEngine/HeuristicLab.DistributedEngine.csproj

    r219 r372  
    4949  </ItemGroup>
    5050  <ItemGroup>
     51    <Compile Include="OnGridProcessor.cs" />
    5152    <Compile Include="HeuristicLabDistributedEnginePlugin.cs" />
    52     <Compile Include="JobManager.cs" />
    5353    <Compile Include="Properties\AssemblyInfo.cs" />
    5454    <Compile Include="DistributedEngine.cs" />
     
    6464      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
    6565      <Name>HeuristicLab.Core</Name>
     66    </ProjectReference>
     67    <ProjectReference Include="..\HeuristicLab.Data\HeuristicLab.Data.csproj">
     68      <Project>{F473D9AF-3F09-4296-9F28-3C65118DAFFA}</Project>
     69      <Name>HeuristicLab.Data</Name>
    6670    </ProjectReference>
    6771    <ProjectReference Include="..\HeuristicLab.Grid\HeuristicLab.Grid.csproj">
  • trunk/sources/HeuristicLab.Grid/HeuristicLab.Grid.csproj

    r247 r372  
    6565    <Compile Include="IEngineStore.cs" />
    6666    <Compile Include="IGridServer.cs" />
     67    <Compile Include="JobManager.cs" />
    6768    <Compile Include="ProcessingEngine.cs" />
    6869    <Compile Include="Properties\AssemblyInfo.cs" />
  • trunk/sources/HeuristicLab.Grid/JobManager.cs

    r371 r372  
    3232using System.Windows.Forms;
    3333
    34 namespace HeuristicLab.DistributedEngine {
    35   class JobManager {
     34namespace HeuristicLab.Grid {
     35  public class JobManager {
    3636    private IGridServer server;
    3737    private string address;
     
    5454    }
    5555
    56     internal void Reset() {
     56    public void Reset() {
    5757      ResetConnection();
    5858      lock(dictionaryLock) {
Note: See TracChangeset for help on using the changeset viewer.