Free cookie consent management tool by TermsFeed Policy Generator

Changeset 417


Ignore:
Timestamp:
08/01/08 14:43:10 (16 years ago)
Author:
gkronber
Message:

worked on #211 (Full operator-graphs are stored multiple times in the database even though most of it is static anyway)

  • created a new type of operator library that is connected to the CEDMA db and a view for it
Location:
trunk/sources
Files:
3 added
7 edited

Legend:

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

    r383 r417  
    3333  public class Console : ItemBase, IEditable {
    3434    private AgentList agentList;
     35    private DatabaseOperatorLibrary operatorLibary;
    3536    private ChannelFactory<IDatabase> factory;
    3637    private IDatabase database;
     
    4445    }
    4546
     47    public IOperatorLibrary OperatorLibrary {
     48      get { return operatorLibary; }
     49    }
     50
    4651    public Console()
    4752      : base() {
    4853      agentList = new AgentList();
     54      operatorLibary = new DatabaseOperatorLibrary();
    4955    }
    5056
     
    8288      database = factory.CreateChannel(new EndpointAddress(serverUri));
    8389      agentList.Database = database;
     90      operatorLibary.Database = database;
    8491    }
    8592    #endregion
  • trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.cs

    r393 r417  
    2727using System.Windows.Forms;
    2828using System.ServiceModel;
     29using HeuristicLab.PluginInfrastructure;
    2930
    3031namespace HeuristicLab.CEDMA.Core {
     
    4041    private Timer refreshTimer;
    4142    private System.ComponentModel.IContainer components;
     43    private Button opLibButton;
     44    private Label label1;
    4245    private Console console;
    4346
     
    5861      this.newButton = new System.Windows.Forms.Button();
    5962      this.refreshTimer = new System.Windows.Forms.Timer(this.components);
     63      this.opLibButton = new System.Windows.Forms.Button();
     64      this.label1 = new System.Windows.Forms.Label();
    6065      this.tabControl.SuspendLayout();
    6166      this.SuspendLayout();
     
    6368      // uriTextBox
    6469      //
    65       this.uriTextBox.Location = new System.Drawing.Point(91, 3);
     70      this.uriTextBox.Location = new System.Drawing.Point(94, 3);
    6671      this.uriTextBox.Name = "uriTextBox";
    6772      this.uriTextBox.Size = new System.Drawing.Size(205, 20);
     
    8489      this.tabControl.Controls.Add(this.agentsPage);
    8590      this.tabControl.Enabled = false;
    86       this.tabControl.Location = new System.Drawing.Point(6, 56);
     91      this.tabControl.Location = new System.Drawing.Point(6, 85);
    8792      this.tabControl.Name = "tabControl";
    8893      this.tabControl.SelectedIndex = 0;
    89       this.tabControl.Size = new System.Drawing.Size(506, 407);
     94      this.tabControl.Size = new System.Drawing.Size(506, 378);
    9095      this.tabControl.TabIndex = 2;
    9196      //
     
    95100      this.agentsPage.Name = "agentsPage";
    96101      this.agentsPage.Padding = new System.Windows.Forms.Padding(3);
    97       this.agentsPage.Size = new System.Drawing.Size(498, 381);
     102      this.agentsPage.Size = new System.Drawing.Size(498, 352);
    98103      this.agentsPage.TabIndex = 1;
    99104      this.agentsPage.Text = "Agents";
     
    102107      // connectButton
    103108      //
    104       this.connectButton.Location = new System.Drawing.Point(302, 1);
     109      this.connectButton.Location = new System.Drawing.Point(305, 1);
    105110      this.connectButton.Name = "connectButton";
    106111      this.connectButton.Size = new System.Drawing.Size(75, 23);
     
    114119      this.comboBox1.Enabled = false;
    115120      this.comboBox1.FormattingEnabled = true;
    116       this.comboBox1.Location = new System.Drawing.Point(91, 29);
     121      this.comboBox1.Location = new System.Drawing.Point(94, 29);
    117122      this.comboBox1.Name = "comboBox1";
    118123      this.comboBox1.Size = new System.Drawing.Size(121, 21);
     
    132137      //
    133138      this.newButton.Enabled = false;
    134       this.newButton.Location = new System.Drawing.Point(218, 27);
     139      this.newButton.Location = new System.Drawing.Point(221, 27);
    135140      this.newButton.Name = "newButton";
    136141      this.newButton.Size = new System.Drawing.Size(75, 23);
     
    144149      this.refreshTimer.Tick += new System.EventHandler(this.refreshTimer_Tick);
    145150      //
     151      // opLibButton
     152      //
     153      this.opLibButton.Enabled = false;
     154      this.opLibButton.Location = new System.Drawing.Point(94, 56);
     155      this.opLibButton.Name = "opLibButton";
     156      this.opLibButton.Size = new System.Drawing.Size(75, 23);
     157      this.opLibButton.TabIndex = 7;
     158      this.opLibButton.Text = "&Open";
     159      this.opLibButton.UseVisualStyleBackColor = true;
     160      this.opLibButton.Click += new System.EventHandler(this.opLibButton_Click);
     161      //
     162      // label1
     163      //
     164      this.label1.AutoSize = true;
     165      this.label1.Location = new System.Drawing.Point(3, 61);
     166      this.label1.Name = "label1";
     167      this.label1.Size = new System.Drawing.Size(85, 13);
     168      this.label1.TabIndex = 8;
     169      this.label1.Text = "Operator Library:";
     170      //
    146171      // ConsoleEditor
    147172      //
    148173      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     174      this.Controls.Add(this.label1);
     175      this.Controls.Add(this.opLibButton);
    149176      this.Controls.Add(this.newButton);
    150177      this.Controls.Add(this.projectLabel);
     
    171198        agentsPage.Controls[0].Dock = DockStyle.Fill;
    172199        refreshTimer.Enabled = true;
     200        opLibButton.Enabled = true;
     201        opLibButton.Enabled = true;
    173202      } catch(CommunicationException ex) {
    174203        // TASK create helper class for error reporting
     
    182211      refreshTimer.Enabled = true;
    183212    }
     213
     214    private void opLibButton_Click(object sender, EventArgs e) {
     215      IOperatorLibrary opLib = console.OperatorLibrary;
     216      if(opLib != null) {
     217        IView view = opLib.CreateView();
     218        if(view != null)
     219          PluginManager.ControlManager.ShowControl(view);
     220      }
     221    }
    184222  }
    185223}
  • trunk/sources/HeuristicLab.CEDMA.Core/DatabaseOperatorLibrary.cs

    r416 r417  
    44using System.Text;
    55using HeuristicLab.Core;
     6using HeuristicLab.CEDMA.DB.Interfaces;
    67
    78namespace HeuristicLab.CEDMA.Core {
     
    1314    }
    1415
    15     private string dbUri;
    16 
    17     public DatabaseOperatorLibrary(string dbUri)
    18       : base() {
    19       this.dbUri = dbUri;
    20       group = new OperatorGroup();
     16    private IDatabase database;
     17    public IDatabase Database {
     18      get { return database; }
     19      set { this.database = value; }
    2120    }
    2221
     22    private Dictionary<IOperator, long> knownOperators;
     23
     24    public DatabaseOperatorLibrary()
     25      : base() {
     26      group = new OperatorGroup();
     27      knownOperators = new Dictionary<IOperator, long>();
     28    }
     29
     30    public void Save() {
     31      Dictionary<IOperator, long> newKnownOperators = new Dictionary<IOperator,long>();
     32      foreach(IOperator op in group.Operators) {
     33        if(knownOperators.ContainsKey(op)) {
     34          // update
     35          long id =knownOperators[op];
     36          Database.UpdateOperator(id, op.Name, PersistenceManager.SaveToGZip(op));
     37          knownOperators.Remove(op);
     38          newKnownOperators.Add(op, id);
     39        } else {
     40          // create new
     41          long id = Database.InsertOperator(op.Name, PersistenceManager.SaveToGZip(op));
     42          newKnownOperators.Add(op, id);
     43        }
     44      }
     45      // delete operators from the table that are not present in the group anymore (remaining entries)
     46      foreach(long id in knownOperators.Values) {
     47        Database.DeleteOperator(id);
     48      }
     49     
     50      knownOperators = newKnownOperators;
     51    }
     52
     53    public void Restore() {
     54      foreach(IOperator op in knownOperators.Keys) {
     55        group.RemoveOperator(op);
     56      }
     57      knownOperators.Clear();
     58      if(database == null) return;
     59      foreach(OperatorEntry e in Database.GetOperators()) {
     60        IOperator op = (IOperator)PersistenceManager.RestoreFromGZip(e.RawData);
     61        knownOperators.Add(op, e.Id);
     62        group.AddOperator(op);
     63      }
     64    }
    2365
    2466    public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
     
    3577
    3678    public override IView CreateView() {
    37       // return new DatabaseOperatorLibraryView(this);
    38       return null;
     79      Restore();
     80      return new DatabaseOperatorLibraryView(this);
    3981    }
    4082  }
  • trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj

    r416 r417  
    6363    </Compile>
    6464    <Compile Include="DatabaseOperatorLibrary.cs" />
     65    <Compile Include="DatabaseOperatorLibraryView.cs">
     66      <SubType>UserControl</SubType>
     67    </Compile>
     68    <Compile Include="DatabaseOperatorLibraryView.Designer.cs">
     69      <DependentUpon>DatabaseOperatorLibraryView.cs</DependentUpon>
     70    </Compile>
    6571    <Compile Include="Result.cs" />
    6672    <Compile Include="IResult.cs" />
     
    113119      <SubType>Designer</SubType>
    114120    </EmbeddedResource>
     121    <EmbeddedResource Include="DatabaseOperatorLibraryView.resx">
     122      <DependentUpon>DatabaseOperatorLibraryView.cs</DependentUpon>
     123      <SubType>Designer</SubType>
     124    </EmbeddedResource>
    115125  </ItemGroup>
    116126  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs

    r416 r417  
    4949
    5050    [OperationContract]
    51     long InsertOperator(string name, string rawData);
     51    long InsertOperator(string name, byte[] rawData);
     52
     53    [OperationContract]
     54    void UpdateOperator(long id, string name, byte[] rawData);
     55
     56    [OperationContract]
     57    void DeleteOperator(long id);
    5258
    5359    // should be replaced by more powerful querying interface (LINQ provider?)
  • trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/OperatorEntry.cs

    r416 r417  
    3535    public string Name { get; set; }
    3636    [DataMember]
    37     public string RawData { get; set; }
     37    public byte[] RawData { get; set; }
    3838  }
    3939}
  • trunk/sources/HeuristicLab.CEDMA.DB/Database.cs

    r416 r417  
    6565            }
    6666            using(DbCommand cmd = cnn.CreateCommand()) {
    67               cmd.CommandText = "CREATE TABLE Operator (ID integer primary key autoincrement, Name text, RawData text)";
     67              cmd.CommandText = "CREATE TABLE Operator (ID integer primary key autoincrement, Name text, RawData Blob)";
    6868              cmd.Transaction = t;
    6969              cmd.ExecuteNonQuery();
     
    200200    }
    201201
    202     public long InsertOperator(string name, string rawData) {
     202    public long InsertOperator(string name, byte[] rawData) {
    203203      rwLock.EnterWriteLock();
    204204      try {
     
    230230    #endregion
    231231
    232     #region update agent/run
     232    #region update agent, run, operator
    233233    public void UpdateAgent(long id, string name) {
    234234      rwLock.EnterWriteLock();
     
    312312    }
    313313
     314    public void UpdateOperator(long id, string name, byte[] rawData) {
     315      rwLock.EnterWriteLock();
     316      try {
     317        using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
     318          cnn.Open();
     319          using(SQLiteTransaction t = cnn.BeginTransaction()) {
     320            using(SQLiteCommand c = cnn.CreateCommand()) {
     321              c.Transaction = t;
     322              c.CommandText = "Update Operator set Name=@Name, RawData=@RawData where id=@Id";
     323              DbParameter rawDataParam = c.CreateParameter();
     324              DbParameter nameParam = c.CreateParameter();
     325              DbParameter idParam = c.CreateParameter();
     326              rawDataParam.ParameterName = "@RawData";
     327              rawDataParam.Value = rawData;
     328              idParam.ParameterName = "@Id";
     329              idParam.Value = id;
     330              nameParam.ParameterName = "@Name";
     331              nameParam.Value = name;
     332              c.Parameters.Add(rawDataParam);
     333              c.Parameters.Add(nameParam);
     334              c.Parameters.Add(idParam);
     335              c.ExecuteNonQuery();
     336            }
     337            t.Commit();
     338          }
     339        }
     340      } finally {
     341        rwLock.ExitWriteLock();
     342      }
     343    }
     344
    314345    #endregion
    315346
    316     #region get agent/result/sub-result
     347    #region get agent/result/sub-result/operator
    317348
    318349    public ICollection<AgentEntry> GetAgents(ProcessStatus status) {
     
    481512                op.Id = r.GetInt32(0);
    482513                op.Name = r.IsDBNull(1) ? "-" : r.GetString(1);
    483                 op.RawData = r.GetString(2);
     514                op.RawData = (byte[])r.GetValue(2);
    484515                operators.Add(op);
    485516              }
     
    491522      }
    492523      return operators;
     524    }
     525    #endregion
     526
     527    #region delete operator
     528    public void DeleteOperator(long id) {
     529      rwLock.EnterWriteLock();
     530      try {
     531        using(DbConnection cnn = new SQLiteConnection(connectionString)) {
     532          cnn.Open();
     533          using(DbTransaction t = cnn.BeginTransaction()) {
     534            using(DbCommand c = cnn.CreateCommand()) {
     535              c.Transaction = t;
     536              c.CommandText = "Delete from Operator where id=@Id";
     537              DbParameter idParam = c.CreateParameter();
     538              idParam.ParameterName = "@Id";
     539              idParam.Value = id;
     540              c.Parameters.Add(idParam);
     541              c.ExecuteNonQuery();
     542            }
     543            t.Commit();
     544          }
     545        }
     546      } finally {
     547        rwLock.ExitWriteLock();
     548      }
    493549    }
    494550    #endregion
Note: See TracChangeset for help on using the changeset viewer.