[372] | 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 |
|
---|
| 22 | using System;
|
---|
[357] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using System.Data.Linq;
|
---|
| 27 | using HeuristicLab.CEDMA.DB.Interfaces;
|
---|
| 28 | using System.ServiceModel;
|
---|
[372] | 29 | using System.Data;
|
---|
| 30 | using System.Data.SQLite;
|
---|
| 31 | using System.Data.Common;
|
---|
[380] | 32 | using System.Threading;
|
---|
[357] | 33 |
|
---|
| 34 | namespace HeuristicLab.CEDMA.DB {
|
---|
[375] | 35 | [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
|
---|
[372] | 36 | public class Database : IDatabase {
|
---|
| 37 | private string connectionString;
|
---|
[380] | 38 | private ReaderWriterLockSlim rwLock;
|
---|
[372] | 39 | public Database(string connectionString) {
|
---|
| 40 | this.connectionString = connectionString;
|
---|
[380] | 41 | rwLock = new ReaderWriterLockSlim();
|
---|
[372] | 42 | }
|
---|
[357] | 43 |
|
---|
[375] | 44 | #region create empty database
|
---|
[372] | 45 | public void CreateNew() {
|
---|
[380] | 46 | rwLock.EnterWriteLock();
|
---|
| 47 | try {
|
---|
[375] | 48 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 49 | cnn.Open();
|
---|
| 50 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 51 | using(DbCommand cmd = cnn.CreateCommand()) {
|
---|
| 52 | cmd.CommandText = "CREATE TABLE Project (ID integer primary key autoincrement, Name text, Description text, CreationTime DateTime)";
|
---|
| 53 | cmd.Transaction = t;
|
---|
| 54 | cmd.ExecuteNonQuery();
|
---|
| 55 | }
|
---|
| 56 | using(DbCommand cmd = cnn.CreateCommand()) {
|
---|
| 57 | cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, Name text, Status text default 'Unknown', RawData Blob)";
|
---|
| 58 | cmd.Transaction = t;
|
---|
| 59 | cmd.ExecuteNonQuery();
|
---|
| 60 | }
|
---|
| 61 | using(DbCommand cmd = cnn.CreateCommand()) {
|
---|
| 62 | cmd.CommandText = "CREATE TABLE Run (ID integer primary key autoincrement, AgentId integer, CreationTime DateTime, StartTime DateTime, FinishedTime DateTime, Status text default 'Unknown', RawData Blob)";
|
---|
| 63 | cmd.Transaction = t;
|
---|
| 64 | cmd.ExecuteNonQuery();
|
---|
| 65 | }
|
---|
| 66 | using(DbCommand cmd = cnn.CreateCommand()) {
|
---|
| 67 | cmd.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, RunId integer, ResultId integer, CreationTime DateTime, RawData Blob)";
|
---|
| 68 | cmd.Transaction = t;
|
---|
| 69 | cmd.ExecuteNonQuery();
|
---|
| 70 | }
|
---|
| 71 | t.Commit();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
[380] | 74 | } finally {
|
---|
| 75 | rwLock.ExitWriteLock();
|
---|
[375] | 76 | }
|
---|
| 77 | }
|
---|
| 78 | #endregion
|
---|
[357] | 79 |
|
---|
[375] | 80 | #region insert agent/run/result/sub-result
|
---|
| 81 | public long InsertAgent(string name, byte[] rawData) {
|
---|
[380] | 82 | rwLock.EnterWriteLock();
|
---|
| 83 | try {
|
---|
[375] | 84 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 85 | cnn.Open();
|
---|
| 86 | long id;
|
---|
| 87 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 88 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 89 | c.Transaction = t;
|
---|
| 90 | c.CommandText = "Insert into Agent (Name, RawData) values (@Name, @RawData); select last_insert_rowid()";
|
---|
| 91 | DbParameter nameParam = c.CreateParameter();
|
---|
| 92 | nameParam.ParameterName = "@Name";
|
---|
| 93 | nameParam.Value = name;
|
---|
| 94 | c.Parameters.Add(nameParam);
|
---|
| 95 | DbParameter dataParam = c.CreateParameter();
|
---|
| 96 | dataParam.ParameterName = "@RawData";
|
---|
| 97 | dataParam.Value = rawData;
|
---|
| 98 | c.Parameters.Add(dataParam);
|
---|
| 99 | id = (long)c.ExecuteScalar();
|
---|
| 100 | }
|
---|
| 101 | t.Commit();
|
---|
| 102 | return id;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
[380] | 105 | } finally {
|
---|
| 106 | rwLock.ExitWriteLock();
|
---|
[372] | 107 | }
|
---|
[357] | 108 | }
|
---|
| 109 |
|
---|
[375] | 110 | public long InsertRun(long agentId, byte[] rawData) {
|
---|
[380] | 111 | rwLock.EnterWriteLock();
|
---|
| 112 | try {
|
---|
[375] | 113 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 114 | cnn.Open();
|
---|
| 115 | long id;
|
---|
| 116 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 117 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 118 | c.Transaction = t;
|
---|
| 119 | c.CommandText = "Insert into Run (AgentId, CreationTime, RawData) values (@AgentId, @CreationTime, @RawData); select last_insert_rowid()";
|
---|
| 120 | DbParameter agentIdParam = c.CreateParameter();
|
---|
| 121 | agentIdParam.ParameterName = "@AgentId";
|
---|
| 122 | agentIdParam.Value = agentId;
|
---|
| 123 | c.Parameters.Add(agentIdParam);
|
---|
| 124 | DbParameter creationParam = c.CreateParameter();
|
---|
| 125 | creationParam.ParameterName = "@CreationTime";
|
---|
| 126 | DateTime now = DateTime.Now;
|
---|
| 127 | creationParam.Value = now;
|
---|
| 128 | c.Parameters.Add(creationParam);
|
---|
| 129 | DbParameter rawDataParam = c.CreateParameter();
|
---|
| 130 | rawDataParam.ParameterName = "@RawData";
|
---|
| 131 | rawDataParam.Value = rawData;
|
---|
| 132 | c.Parameters.Add(rawDataParam);
|
---|
| 133 | id = (long)c.ExecuteScalar();
|
---|
| 134 | }
|
---|
| 135 | t.Commit();
|
---|
| 136 | return id;
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
[380] | 139 | } finally {
|
---|
| 140 | rwLock.ExitWriteLock();
|
---|
[357] | 141 | }
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[375] | 144 | public long InsertResult(long runId, byte[] rawData) {
|
---|
[380] | 145 | rwLock.EnterWriteLock();
|
---|
| 146 | try {
|
---|
[375] | 147 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 148 | cnn.Open();
|
---|
| 149 | long id;
|
---|
| 150 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 151 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 152 | c.Transaction = t;
|
---|
| 153 | c.CommandText = "Insert into Result (RunId, CreationTime, RawData) values (@RunId, @CreationTime, @RawData); select last_insert_rowid()";
|
---|
| 154 | DbParameter runIdParam = c.CreateParameter();
|
---|
| 155 | runIdParam.ParameterName = "@RunId";
|
---|
| 156 | runIdParam.Value = runId;
|
---|
| 157 | c.Parameters.Add(runIdParam);
|
---|
| 158 | DbParameter creationParam = c.CreateParameter();
|
---|
| 159 | creationParam.ParameterName = "@CreationTime";
|
---|
| 160 | DateTime now = DateTime.Now;
|
---|
| 161 | creationParam.Value = now;
|
---|
| 162 | c.Parameters.Add(creationParam);
|
---|
| 163 | DbParameter rawDataParam = c.CreateParameter();
|
---|
| 164 | rawDataParam.ParameterName = "@RawData";
|
---|
| 165 | rawDataParam.Value = rawData;
|
---|
| 166 | c.Parameters.Add(rawDataParam);
|
---|
| 167 | id = (long)c.ExecuteScalar();
|
---|
| 168 | }
|
---|
| 169 | t.Commit();
|
---|
| 170 | return id;
|
---|
| 171 | }
|
---|
[372] | 172 | }
|
---|
[380] | 173 | } finally {
|
---|
| 174 | rwLock.ExitWriteLock();
|
---|
[372] | 175 | }
|
---|
[357] | 176 | }
|
---|
[372] | 177 |
|
---|
[375] | 178 | public long InsertSubResult(long resultId, byte[] rawData) {
|
---|
[380] | 179 | rwLock.EnterWriteLock();
|
---|
| 180 | try {
|
---|
[375] | 181 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 182 | cnn.Open();
|
---|
| 183 | long id;
|
---|
| 184 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 185 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 186 | c.Transaction = t;
|
---|
| 187 | c.CommandText = "Insert into Result (ResultId, CreationTime, RawData) values (@ResultId, @CreationTime, @RawData); select last_insert_rowid()";
|
---|
| 188 | DbParameter resultIdParam = c.CreateParameter();
|
---|
| 189 | resultIdParam.ParameterName = "@ResultId";
|
---|
| 190 | resultIdParam.Value = resultId;
|
---|
| 191 | c.Parameters.Add(resultIdParam);
|
---|
| 192 | DbParameter creationParam = c.CreateParameter();
|
---|
| 193 | creationParam.ParameterName = "@CreationTime";
|
---|
| 194 | DateTime now = DateTime.Now;
|
---|
| 195 | creationParam.Value = now;
|
---|
| 196 | c.Parameters.Add(creationParam);
|
---|
| 197 | DbParameter rawDataParam = c.CreateParameter();
|
---|
| 198 | rawDataParam.ParameterName = "@RawData";
|
---|
| 199 | rawDataParam.Value = rawData;
|
---|
| 200 | c.Parameters.Add(rawDataParam);
|
---|
| 201 | id = (long)c.ExecuteScalar();
|
---|
| 202 | }
|
---|
| 203 | t.Commit();
|
---|
| 204 | return id;
|
---|
| 205 | }
|
---|
[372] | 206 | }
|
---|
[380] | 207 | } finally {
|
---|
| 208 | rwLock.ExitWriteLock();
|
---|
[372] | 209 | }
|
---|
| 210 | }
|
---|
[375] | 211 | #endregion
|
---|
[372] | 212 |
|
---|
[375] | 213 | #region update agent/run
|
---|
| 214 | public void UpdateAgent(long id, string name) {
|
---|
[380] | 215 | rwLock.EnterWriteLock();
|
---|
| 216 | try {
|
---|
[375] | 217 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 218 | cnn.Open();
|
---|
| 219 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 220 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 221 | c.Transaction = t;
|
---|
| 222 | c.CommandText = "Update Agent set Name=@Name where id=@Id";
|
---|
| 223 | DbParameter nameParam = c.CreateParameter();
|
---|
| 224 | DbParameter idParam = c.CreateParameter();
|
---|
| 225 | nameParam.ParameterName = "@Name";
|
---|
| 226 | nameParam.Value = name;
|
---|
| 227 | idParam.ParameterName = "@Id";
|
---|
| 228 | idParam.Value = id;
|
---|
| 229 | c.Parameters.Add(nameParam);
|
---|
| 230 | c.Parameters.Add(idParam);
|
---|
| 231 | c.ExecuteNonQuery();
|
---|
| 232 | }
|
---|
| 233 | t.Commit();
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
[380] | 236 | } finally {
|
---|
| 237 | rwLock.ExitWriteLock();
|
---|
[372] | 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[375] | 241 | public void UpdateAgent(long id, ProcessStatus status) {
|
---|
[380] | 242 | rwLock.EnterWriteLock();
|
---|
| 243 | try {
|
---|
[375] | 244 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 245 | cnn.Open();
|
---|
| 246 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 247 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 248 | c.Transaction = t;
|
---|
| 249 | c.CommandText = "Update Agent set Status=@Status where id=@Id";
|
---|
| 250 | DbParameter statusParam = c.CreateParameter();
|
---|
| 251 | DbParameter idParam = c.CreateParameter();
|
---|
| 252 | statusParam.ParameterName = "@Status";
|
---|
| 253 | statusParam.Value = status;
|
---|
| 254 | idParam.ParameterName = "@Id";
|
---|
| 255 | idParam.Value = id;
|
---|
| 256 | c.Parameters.Add(statusParam);
|
---|
| 257 | c.Parameters.Add(idParam);
|
---|
| 258 | c.ExecuteNonQuery();
|
---|
| 259 | }
|
---|
| 260 | t.Commit();
|
---|
| 261 | }
|
---|
| 262 | }
|
---|
[380] | 263 | } finally {
|
---|
| 264 | rwLock.ExitWriteLock();
|
---|
[375] | 265 | }
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | public void UpdateAgent(long id, byte[] rawData) {
|
---|
[380] | 269 | rwLock.EnterWriteLock();
|
---|
| 270 | try {
|
---|
[375] | 271 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 272 | cnn.Open();
|
---|
| 273 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 274 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 275 | c.Transaction = t;
|
---|
| 276 | c.CommandText = "Update Agent set RawData=@RawData where id=@Id";
|
---|
| 277 | DbParameter rawDataParam = c.CreateParameter();
|
---|
| 278 | DbParameter idParam = c.CreateParameter();
|
---|
| 279 | rawDataParam.ParameterName = "@RawData";
|
---|
| 280 | rawDataParam.Value = rawData;
|
---|
| 281 | idParam.ParameterName = "@Id";
|
---|
| 282 | idParam.Value = id;
|
---|
| 283 | c.Parameters.Add(rawDataParam);
|
---|
| 284 | c.Parameters.Add(idParam);
|
---|
| 285 | c.ExecuteNonQuery();
|
---|
| 286 | }
|
---|
| 287 | t.Commit();
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
[380] | 290 | } finally {
|
---|
| 291 | rwLock.ExitWriteLock();
|
---|
[375] | 292 | }
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | public void UpdateRunStart(long runId, DateTime startTime) {
|
---|
[380] | 296 | rwLock.EnterWriteLock();
|
---|
| 297 | try {
|
---|
[375] | 298 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 299 | cnn.Open();
|
---|
| 300 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 301 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 302 | c.Transaction = t;
|
---|
| 303 | c.CommandText = "Update Run set StartTime=@StartTime where id=@Id";
|
---|
| 304 | DbParameter startTimeParam = c.CreateParameter();
|
---|
| 305 | DbParameter idParam = c.CreateParameter();
|
---|
| 306 | startTimeParam.ParameterName = "@StartTime";
|
---|
| 307 | startTimeParam.Value = startTime;
|
---|
| 308 | idParam.ParameterName = "@Id";
|
---|
| 309 | idParam.Value = runId;
|
---|
| 310 | c.Parameters.Add(startTimeParam);
|
---|
| 311 | c.Parameters.Add(idParam);
|
---|
| 312 | c.ExecuteNonQuery();
|
---|
| 313 | }
|
---|
| 314 | t.Commit();
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
[380] | 317 | } finally {
|
---|
| 318 | rwLock.ExitWriteLock();
|
---|
[375] | 319 | }
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | public void UpdateRunFinished(long runId, DateTime finishedTime) {
|
---|
[380] | 323 | rwLock.EnterWriteLock();
|
---|
| 324 | try {
|
---|
[375] | 325 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 326 | cnn.Open();
|
---|
| 327 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 328 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 329 | c.Transaction = t;
|
---|
| 330 | c.CommandText = "Update Run set FinishedTime=@FinishedTime where id=@Id";
|
---|
| 331 | DbParameter finishedTimeParam = c.CreateParameter();
|
---|
| 332 | DbParameter idParam = c.CreateParameter();
|
---|
| 333 | finishedTimeParam.ParameterName = "@FinishedTime";
|
---|
| 334 | finishedTimeParam.Value = finishedTime;
|
---|
| 335 | idParam.ParameterName = "@Id";
|
---|
| 336 | idParam.Value = runId;
|
---|
| 337 | c.Parameters.Add(finishedTimeParam);
|
---|
| 338 | c.Parameters.Add(idParam);
|
---|
| 339 | c.ExecuteNonQuery();
|
---|
| 340 | }
|
---|
| 341 | t.Commit();
|
---|
| 342 | }
|
---|
| 343 | }
|
---|
[380] | 344 | } finally {
|
---|
| 345 | rwLock.ExitWriteLock();
|
---|
[375] | 346 | }
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | public void UpdateRunStatus(long runId, ProcessStatus status) {
|
---|
[380] | 350 | rwLock.EnterWriteLock();
|
---|
| 351 | try {
|
---|
[375] | 352 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 353 | cnn.Open();
|
---|
| 354 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 355 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 356 | c.Transaction = t;
|
---|
| 357 | c.CommandText = "Update Run set Status=@Status where id=@Id";
|
---|
| 358 | DbParameter statusParam = c.CreateParameter();
|
---|
| 359 | DbParameter idParam = c.CreateParameter();
|
---|
| 360 | statusParam.ParameterName = "@Status";
|
---|
| 361 | statusParam.Value = status;
|
---|
| 362 | idParam.ParameterName = "@Id";
|
---|
| 363 | idParam.Value = runId;
|
---|
| 364 | c.Parameters.Add(statusParam);
|
---|
| 365 | c.Parameters.Add(idParam);
|
---|
| 366 | c.ExecuteNonQuery();
|
---|
| 367 | }
|
---|
| 368 | t.Commit();
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
[380] | 371 | } finally {
|
---|
| 372 | rwLock.ExitWriteLock();
|
---|
[375] | 373 | }
|
---|
| 374 | }
|
---|
| 375 | #endregion
|
---|
| 376 |
|
---|
| 377 | #region get agent/run/result/sub-result
|
---|
| 378 |
|
---|
| 379 | public ICollection<AgentEntry> GetAgents(ProcessStatus status) {
|
---|
[380] | 380 | rwLock.EnterReadLock();
|
---|
| 381 | List<AgentEntry> agents = new List<AgentEntry>();
|
---|
| 382 | try {
|
---|
[375] | 383 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 384 | cnn.Open();
|
---|
| 385 | SQLiteCommand c = cnn.CreateCommand();
|
---|
| 386 | c.CommandText = "Select id, name, status, rawdata from Agent where Status=@Status";
|
---|
| 387 | DbParameter statusParameter = c.CreateParameter();
|
---|
| 388 | statusParameter.ParameterName = "@Status";
|
---|
| 389 | statusParameter.Value = status;
|
---|
| 390 | c.Parameters.Add(statusParameter);
|
---|
| 391 |
|
---|
| 392 | SQLiteDataReader r = c.ExecuteReader();
|
---|
| 393 | while(r.Read()) {
|
---|
| 394 | AgentEntry agent = new AgentEntry();
|
---|
| 395 | agent.Id = r.GetInt32(0);
|
---|
| 396 | agent.Name = r.GetString(1);
|
---|
| 397 | agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
|
---|
| 398 | agent.RawData = (byte[])r.GetValue(3);
|
---|
| 399 | agents.Add(agent);
|
---|
| 400 | }
|
---|
| 401 | }
|
---|
[380] | 402 | } finally {
|
---|
| 403 | rwLock.ExitReadLock();
|
---|
[375] | 404 | }
|
---|
[380] | 405 | return agents;
|
---|
[375] | 406 | }
|
---|
| 407 |
|
---|
| 408 | public ICollection<AgentEntry> GetAgents() {
|
---|
[380] | 409 | rwLock.EnterReadLock();
|
---|
| 410 | List<AgentEntry> agents = new List<AgentEntry>();
|
---|
| 411 | try {
|
---|
[375] | 412 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 413 | cnn.Open();
|
---|
| 414 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 415 | c.CommandText = "Select id, name, status, rawdata from Agent";
|
---|
| 416 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 417 | while(r.Read()) {
|
---|
| 418 | AgentEntry agent = new AgentEntry();
|
---|
| 419 | agent.Id = r.GetInt32(0);
|
---|
| 420 | agent.Name = r.GetString(1);
|
---|
| 421 | agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
|
---|
| 422 | agent.RawData = (byte[])r.GetValue(3);
|
---|
| 423 | agents.Add(agent);
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
[380] | 428 | } finally {
|
---|
| 429 | rwLock.ExitReadLock();
|
---|
[375] | 430 | }
|
---|
[380] | 431 | return agents;
|
---|
[375] | 432 | }
|
---|
| 433 |
|
---|
| 434 | public ICollection<RunEntry> GetRuns() {
|
---|
[380] | 435 | List<RunEntry> runs = new List<RunEntry>();
|
---|
| 436 | rwLock.EnterReadLock();
|
---|
| 437 | try {
|
---|
[375] | 438 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 439 | cnn.Open();
|
---|
| 440 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 441 | c.CommandText = "Select Id, AgentId, CreationTime, StartTime, FinishedTime, Status, Rawdata from Run";
|
---|
| 442 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 443 | while(r.Read()) {
|
---|
| 444 | RunEntry run = new RunEntry();
|
---|
| 445 | run.Id = r.GetInt32(0);
|
---|
| 446 | run.AgentId = r.GetInt32(1);
|
---|
| 447 | run.CreationTime = r.GetDateTime(2);
|
---|
| 448 | run.StartTime = r.GetDateTime(3);
|
---|
| 449 | run.FinishedTime = r.GetDateTime(4);
|
---|
| 450 | run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(5));
|
---|
| 451 | run.RawData = (byte[])r.GetValue(6);
|
---|
| 452 | runs.Add(run);
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
[380] | 457 | } finally {
|
---|
| 458 | rwLock.ExitReadLock();
|
---|
[375] | 459 | }
|
---|
[380] | 460 | return runs;
|
---|
[375] | 461 | }
|
---|
| 462 |
|
---|
| 463 | public ICollection<RunEntry> GetRuns(ProcessStatus status) {
|
---|
[380] | 464 | List<RunEntry> runs = new List<RunEntry>();
|
---|
| 465 | rwLock.EnterReadLock();
|
---|
| 466 | try {
|
---|
[375] | 467 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 468 | cnn.Open();
|
---|
| 469 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 470 | c.CommandText = "Select Id, AgentId, CreationTime, StartTime, FinishedTime, Status, Rawdata from Run where Status=@Status";
|
---|
| 471 | DbParameter statusParameter = c.CreateParameter();
|
---|
| 472 | statusParameter.ParameterName = "@Status";
|
---|
| 473 | statusParameter.Value = status;
|
---|
| 474 | c.Parameters.Add(statusParameter);
|
---|
| 475 |
|
---|
| 476 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 477 | while(r.Read()) {
|
---|
| 478 | RunEntry run = new RunEntry();
|
---|
| 479 | run.Id = r.GetInt32(0);
|
---|
| 480 | run.AgentId = r.GetInt32(1);
|
---|
| 481 | run.CreationTime = r.GetDateTime(2);
|
---|
[380] | 482 | run.StartTime = r.IsDBNull(3) ? null : new Nullable<DateTime>(r.GetDateTime(3));
|
---|
| 483 | run.FinishedTime = r.IsDBNull(4) ? null : new Nullable<DateTime>(r.GetDateTime(4));
|
---|
[375] | 484 | run.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(5));
|
---|
| 485 | run.RawData = (byte[])r.GetValue(6);
|
---|
| 486 | runs.Add(run);
|
---|
| 487 | }
|
---|
| 488 | }
|
---|
| 489 | }
|
---|
| 490 | }
|
---|
[380] | 491 | } finally {
|
---|
| 492 | rwLock.ExitReadLock();
|
---|
[375] | 493 | }
|
---|
[380] | 494 | return runs;
|
---|
[375] | 495 | }
|
---|
| 496 |
|
---|
| 497 | public ICollection<ResultEntry> GetResults(long runId) {
|
---|
[380] | 498 | List<ResultEntry> results = new List<ResultEntry>();
|
---|
| 499 | rwLock.EnterReadLock();
|
---|
| 500 | try {
|
---|
[375] | 501 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 502 | cnn.Open();
|
---|
| 503 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 504 | c.CommandText = "Select Id, RunId, CreationTime, Rawdata from Result";
|
---|
| 505 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 506 | while(r.Read()) {
|
---|
| 507 | ResultEntry result = new ResultEntry();
|
---|
| 508 | result.Id = r.GetInt32(0);
|
---|
| 509 | result.RunId = r.GetInt32(1);
|
---|
| 510 | result.CreationTime = r.GetDateTime(2);
|
---|
| 511 | result.RawData = (byte[])r.GetValue(3);
|
---|
| 512 | results.Add(result);
|
---|
| 513 | }
|
---|
| 514 | }
|
---|
| 515 | }
|
---|
| 516 | }
|
---|
[380] | 517 | } finally {
|
---|
| 518 | rwLock.ExitReadLock();
|
---|
[375] | 519 | }
|
---|
[380] | 520 | return results;
|
---|
[375] | 521 | }
|
---|
| 522 |
|
---|
| 523 | public ICollection<ResultEntry> GetSubResults(long resultId) {
|
---|
[372] | 524 | throw new NotImplementedException();
|
---|
| 525 | }
|
---|
[375] | 526 | #endregion
|
---|
[357] | 527 | }
|
---|
| 528 | } |
---|