Changeset 417
- Timestamp:
- 08/01/08 14:43:10 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Core/Console.cs
r383 r417 33 33 public class Console : ItemBase, IEditable { 34 34 private AgentList agentList; 35 private DatabaseOperatorLibrary operatorLibary; 35 36 private ChannelFactory<IDatabase> factory; 36 37 private IDatabase database; … … 44 45 } 45 46 47 public IOperatorLibrary OperatorLibrary { 48 get { return operatorLibary; } 49 } 50 46 51 public Console() 47 52 : base() { 48 53 agentList = new AgentList(); 54 operatorLibary = new DatabaseOperatorLibrary(); 49 55 } 50 56 … … 82 88 database = factory.CreateChannel(new EndpointAddress(serverUri)); 83 89 agentList.Database = database; 90 operatorLibary.Database = database; 84 91 } 85 92 #endregion -
trunk/sources/HeuristicLab.CEDMA.Core/ConsoleEditor.cs
r393 r417 27 27 using System.Windows.Forms; 28 28 using System.ServiceModel; 29 using HeuristicLab.PluginInfrastructure; 29 30 30 31 namespace HeuristicLab.CEDMA.Core { … … 40 41 private Timer refreshTimer; 41 42 private System.ComponentModel.IContainer components; 43 private Button opLibButton; 44 private Label label1; 42 45 private Console console; 43 46 … … 58 61 this.newButton = new System.Windows.Forms.Button(); 59 62 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(); 60 65 this.tabControl.SuspendLayout(); 61 66 this.SuspendLayout(); … … 63 68 // uriTextBox 64 69 // 65 this.uriTextBox.Location = new System.Drawing.Point(9 1, 3);70 this.uriTextBox.Location = new System.Drawing.Point(94, 3); 66 71 this.uriTextBox.Name = "uriTextBox"; 67 72 this.uriTextBox.Size = new System.Drawing.Size(205, 20); … … 84 89 this.tabControl.Controls.Add(this.agentsPage); 85 90 this.tabControl.Enabled = false; 86 this.tabControl.Location = new System.Drawing.Point(6, 56);91 this.tabControl.Location = new System.Drawing.Point(6, 85); 87 92 this.tabControl.Name = "tabControl"; 88 93 this.tabControl.SelectedIndex = 0; 89 this.tabControl.Size = new System.Drawing.Size(506, 407);94 this.tabControl.Size = new System.Drawing.Size(506, 378); 90 95 this.tabControl.TabIndex = 2; 91 96 // … … 95 100 this.agentsPage.Name = "agentsPage"; 96 101 this.agentsPage.Padding = new System.Windows.Forms.Padding(3); 97 this.agentsPage.Size = new System.Drawing.Size(498, 3 81);102 this.agentsPage.Size = new System.Drawing.Size(498, 352); 98 103 this.agentsPage.TabIndex = 1; 99 104 this.agentsPage.Text = "Agents"; … … 102 107 // connectButton 103 108 // 104 this.connectButton.Location = new System.Drawing.Point(30 2, 1);109 this.connectButton.Location = new System.Drawing.Point(305, 1); 105 110 this.connectButton.Name = "connectButton"; 106 111 this.connectButton.Size = new System.Drawing.Size(75, 23); … … 114 119 this.comboBox1.Enabled = false; 115 120 this.comboBox1.FormattingEnabled = true; 116 this.comboBox1.Location = new System.Drawing.Point(9 1, 29);121 this.comboBox1.Location = new System.Drawing.Point(94, 29); 117 122 this.comboBox1.Name = "comboBox1"; 118 123 this.comboBox1.Size = new System.Drawing.Size(121, 21); … … 132 137 // 133 138 this.newButton.Enabled = false; 134 this.newButton.Location = new System.Drawing.Point(2 18, 27);139 this.newButton.Location = new System.Drawing.Point(221, 27); 135 140 this.newButton.Name = "newButton"; 136 141 this.newButton.Size = new System.Drawing.Size(75, 23); … … 144 149 this.refreshTimer.Tick += new System.EventHandler(this.refreshTimer_Tick); 145 150 // 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 // 146 171 // ConsoleEditor 147 172 // 148 173 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 174 this.Controls.Add(this.label1); 175 this.Controls.Add(this.opLibButton); 149 176 this.Controls.Add(this.newButton); 150 177 this.Controls.Add(this.projectLabel); … … 171 198 agentsPage.Controls[0].Dock = DockStyle.Fill; 172 199 refreshTimer.Enabled = true; 200 opLibButton.Enabled = true; 201 opLibButton.Enabled = true; 173 202 } catch(CommunicationException ex) { 174 203 // TASK create helper class for error reporting … … 182 211 refreshTimer.Enabled = true; 183 212 } 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 } 184 222 } 185 223 } -
trunk/sources/HeuristicLab.CEDMA.Core/DatabaseOperatorLibrary.cs
r416 r417 4 4 using System.Text; 5 5 using HeuristicLab.Core; 6 using HeuristicLab.CEDMA.DB.Interfaces; 6 7 7 8 namespace HeuristicLab.CEDMA.Core { … … 13 14 } 14 15 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; } 21 20 } 22 21 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 } 23 65 24 66 public override System.Xml.XmlNode GetXmlNode(string name, System.Xml.XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { … … 35 77 36 78 public override IView CreateView() { 37 // return new DatabaseOperatorLibraryView(this);38 return n ull;79 Restore(); 80 return new DatabaseOperatorLibraryView(this); 39 81 } 40 82 } -
trunk/sources/HeuristicLab.CEDMA.Core/HeuristicLab.CEDMA.Core.csproj
r416 r417 63 63 </Compile> 64 64 <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> 65 71 <Compile Include="Result.cs" /> 66 72 <Compile Include="IResult.cs" /> … … 113 119 <SubType>Designer</SubType> 114 120 </EmbeddedResource> 121 <EmbeddedResource Include="DatabaseOperatorLibraryView.resx"> 122 <DependentUpon>DatabaseOperatorLibraryView.cs</DependentUpon> 123 <SubType>Designer</SubType> 124 </EmbeddedResource> 115 125 </ItemGroup> 116 126 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs
r416 r417 49 49 50 50 [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); 52 58 53 59 // should be replaced by more powerful querying interface (LINQ provider?) -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/OperatorEntry.cs
r416 r417 35 35 public string Name { get; set; } 36 36 [DataMember] 37 public stringRawData { get; set; }37 public byte[] RawData { get; set; } 38 38 } 39 39 } -
trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
r416 r417 65 65 } 66 66 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)"; 68 68 cmd.Transaction = t; 69 69 cmd.ExecuteNonQuery(); … … 200 200 } 201 201 202 public long InsertOperator(string name, stringrawData) {202 public long InsertOperator(string name, byte[] rawData) { 203 203 rwLock.EnterWriteLock(); 204 204 try { … … 230 230 #endregion 231 231 232 #region update agent /run232 #region update agent, run, operator 233 233 public void UpdateAgent(long id, string name) { 234 234 rwLock.EnterWriteLock(); … … 312 312 } 313 313 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 314 345 #endregion 315 346 316 #region get agent/result/sub-result 347 #region get agent/result/sub-result/operator 317 348 318 349 public ICollection<AgentEntry> GetAgents(ProcessStatus status) { … … 481 512 op.Id = r.GetInt32(0); 482 513 op.Name = r.IsDBNull(1) ? "-" : r.GetString(1); 483 op.RawData = r.GetString(2);514 op.RawData = (byte[])r.GetValue(2); 484 515 operators.Add(op); 485 516 } … … 491 522 } 492 523 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 } 493 549 } 494 550 #endregion
Note: See TracChangeset
for help on using the changeset viewer.