[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()) {
|
---|
[392] | 57 | cmd.CommandText = "CREATE TABLE Agent (ID integer primary key autoincrement, ProjectId integer, ParentAgentId integer, Name text, Status text default "+ProcessStatus.Unknown+", ControllerAgent integer, CreationTime DateTime, RawData Blob)";
|
---|
[375] | 58 | cmd.Transaction = t;
|
---|
| 59 | cmd.ExecuteNonQuery();
|
---|
| 60 | }
|
---|
| 61 | using(DbCommand cmd = cnn.CreateCommand()) {
|
---|
[390] | 62 | cmd.CommandText = "CREATE TABLE Result (ID integer primary key autoincrement, AgentId integer, ParentResultId integer, Summary text, Description text, CreationTime DateTime, RawData Blob)";
|
---|
[375] | 63 | cmd.Transaction = t;
|
---|
| 64 | cmd.ExecuteNonQuery();
|
---|
| 65 | }
|
---|
| 66 | t.Commit();
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
[380] | 69 | } finally {
|
---|
| 70 | rwLock.ExitWriteLock();
|
---|
[375] | 71 | }
|
---|
| 72 | }
|
---|
| 73 | #endregion
|
---|
[357] | 74 |
|
---|
[375] | 75 | #region insert agent/run/result/sub-result
|
---|
[390] | 76 | public long InsertAgent(long? parentAgentId, string name, bool controllerAgent, byte[] rawData) {
|
---|
[380] | 77 | rwLock.EnterWriteLock();
|
---|
| 78 | try {
|
---|
[375] | 79 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 80 | cnn.Open();
|
---|
| 81 | long id;
|
---|
| 82 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 83 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 84 | c.Transaction = t;
|
---|
[392] | 85 | c.CommandText = "Insert into Agent (Name, ParentAgentId, ControllerAgent, CreationTime, RawData) values (@Name, @ParentAgentId, @ControllerAgent, @CreationTime, @RawData); select last_insert_rowid()";
|
---|
[375] | 86 | DbParameter nameParam = c.CreateParameter();
|
---|
| 87 | nameParam.ParameterName = "@Name";
|
---|
| 88 | nameParam.Value = name;
|
---|
| 89 | c.Parameters.Add(nameParam);
|
---|
[390] | 90 | DbParameter parentParam = c.CreateParameter();
|
---|
| 91 | parentParam.ParameterName = "@ParentAgentId";
|
---|
| 92 | parentParam.Value = parentAgentId;
|
---|
| 93 | c.Parameters.Add(parentParam);
|
---|
| 94 | DbParameter controllerParam = c.CreateParameter();
|
---|
| 95 | controllerParam.ParameterName = "@ControllerAgent";
|
---|
| 96 | controllerParam.Value = controllerAgent;
|
---|
| 97 | c.Parameters.Add(controllerParam);
|
---|
[392] | 98 | DbParameter creationTimeParam = c.CreateParameter();
|
---|
| 99 | creationTimeParam.ParameterName = "@CreationTime";
|
---|
| 100 | creationTimeParam.Value = DateTime.Now;
|
---|
| 101 | c.Parameters.Add(creationTimeParam);
|
---|
[375] | 102 | DbParameter dataParam = c.CreateParameter();
|
---|
| 103 | dataParam.ParameterName = "@RawData";
|
---|
| 104 | dataParam.Value = rawData;
|
---|
| 105 | c.Parameters.Add(dataParam);
|
---|
| 106 | id = (long)c.ExecuteScalar();
|
---|
| 107 | }
|
---|
| 108 | t.Commit();
|
---|
| 109 | return id;
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
[380] | 112 | } finally {
|
---|
| 113 | rwLock.ExitWriteLock();
|
---|
[372] | 114 | }
|
---|
[357] | 115 | }
|
---|
| 116 |
|
---|
[390] | 117 | public long InsertResult(long agentId, string summary, string description, byte[] rawData) {
|
---|
[380] | 118 | rwLock.EnterWriteLock();
|
---|
| 119 | try {
|
---|
[375] | 120 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 121 | cnn.Open();
|
---|
| 122 | long id;
|
---|
| 123 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 124 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 125 | c.Transaction = t;
|
---|
[390] | 126 | c.CommandText = "Insert into Result (AgentId, CreationTime, Summary, Description, RawData) values (@AgentId, @CreationTime, @Summary, @Description, @RawData); select last_insert_rowid()";
|
---|
[375] | 127 | DbParameter agentIdParam = c.CreateParameter();
|
---|
| 128 | agentIdParam.ParameterName = "@AgentId";
|
---|
| 129 | agentIdParam.Value = agentId;
|
---|
| 130 | c.Parameters.Add(agentIdParam);
|
---|
| 131 | DbParameter creationParam = c.CreateParameter();
|
---|
| 132 | creationParam.ParameterName = "@CreationTime";
|
---|
| 133 | DateTime now = DateTime.Now;
|
---|
| 134 | creationParam.Value = now;
|
---|
| 135 | c.Parameters.Add(creationParam);
|
---|
[390] | 136 | DbParameter summaryParam = c.CreateParameter();
|
---|
| 137 | summaryParam.ParameterName = "@Summary";
|
---|
| 138 | summaryParam.Value = summary;
|
---|
| 139 | c.Parameters.Add(summaryParam);
|
---|
| 140 | DbParameter descParam = c.CreateParameter();
|
---|
| 141 | descParam.ParameterName = "@Description";
|
---|
| 142 | descParam.Value = description;
|
---|
| 143 | c.Parameters.Add(descParam);
|
---|
[375] | 144 | DbParameter rawDataParam = c.CreateParameter();
|
---|
| 145 | rawDataParam.ParameterName = "@RawData";
|
---|
| 146 | rawDataParam.Value = rawData;
|
---|
| 147 | c.Parameters.Add(rawDataParam);
|
---|
| 148 | id = (long)c.ExecuteScalar();
|
---|
| 149 | }
|
---|
| 150 | t.Commit();
|
---|
| 151 | return id;
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
[380] | 154 | } finally {
|
---|
| 155 | rwLock.ExitWriteLock();
|
---|
[357] | 156 | }
|
---|
| 157 | }
|
---|
| 158 |
|
---|
[390] | 159 | public long InsertSubResult(long resultId, string summary, string description, byte[] rawData) {
|
---|
[380] | 160 | rwLock.EnterWriteLock();
|
---|
| 161 | try {
|
---|
[375] | 162 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 163 | cnn.Open();
|
---|
| 164 | long id;
|
---|
| 165 | using(DbTransaction t = cnn.BeginTransaction()) {
|
---|
| 166 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
| 167 | c.Transaction = t;
|
---|
[390] | 168 | c.CommandText = "Insert into Result (ParentResultId, CreationTime, Summary, Description, RawData) values (@ParentResultId, @CreationTime, @Summary, @Description, @RawData); select last_insert_rowid()";
|
---|
[375] | 169 | DbParameter resultIdParam = c.CreateParameter();
|
---|
[390] | 170 | resultIdParam.ParameterName = "@ParentResultId";
|
---|
[375] | 171 | resultIdParam.Value = resultId;
|
---|
| 172 | c.Parameters.Add(resultIdParam);
|
---|
| 173 | DbParameter creationParam = c.CreateParameter();
|
---|
| 174 | creationParam.ParameterName = "@CreationTime";
|
---|
| 175 | DateTime now = DateTime.Now;
|
---|
| 176 | creationParam.Value = now;
|
---|
| 177 | c.Parameters.Add(creationParam);
|
---|
[390] | 178 | DbParameter summaryParam = c.CreateParameter();
|
---|
| 179 | summaryParam.ParameterName = "@Summary";
|
---|
| 180 | summaryParam.Value = summary;
|
---|
| 181 | c.Parameters.Add(summaryParam);
|
---|
| 182 | DbParameter descParam = c.CreateParameter();
|
---|
| 183 | descParam.ParameterName = "@Description";
|
---|
| 184 | descParam.Value = description;
|
---|
| 185 | c.Parameters.Add(descParam);
|
---|
[375] | 186 | DbParameter rawDataParam = c.CreateParameter();
|
---|
| 187 | rawDataParam.ParameterName = "@RawData";
|
---|
| 188 | rawDataParam.Value = rawData;
|
---|
| 189 | c.Parameters.Add(rawDataParam);
|
---|
| 190 | id = (long)c.ExecuteScalar();
|
---|
| 191 | }
|
---|
| 192 | t.Commit();
|
---|
| 193 | return id;
|
---|
| 194 | }
|
---|
[372] | 195 | }
|
---|
[380] | 196 | } finally {
|
---|
| 197 | rwLock.ExitWriteLock();
|
---|
[372] | 198 | }
|
---|
| 199 | }
|
---|
[375] | 200 | #endregion
|
---|
[372] | 201 |
|
---|
[375] | 202 | #region update agent/run
|
---|
| 203 | public void UpdateAgent(long id, string name) {
|
---|
[380] | 204 | rwLock.EnterWriteLock();
|
---|
| 205 | try {
|
---|
[375] | 206 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 207 | cnn.Open();
|
---|
| 208 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 209 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 210 | c.Transaction = t;
|
---|
| 211 | c.CommandText = "Update Agent set Name=@Name where id=@Id";
|
---|
| 212 | DbParameter nameParam = c.CreateParameter();
|
---|
| 213 | DbParameter idParam = c.CreateParameter();
|
---|
| 214 | nameParam.ParameterName = "@Name";
|
---|
| 215 | nameParam.Value = name;
|
---|
| 216 | idParam.ParameterName = "@Id";
|
---|
| 217 | idParam.Value = id;
|
---|
| 218 | c.Parameters.Add(nameParam);
|
---|
| 219 | c.Parameters.Add(idParam);
|
---|
| 220 | c.ExecuteNonQuery();
|
---|
| 221 | }
|
---|
| 222 | t.Commit();
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
[380] | 225 | } finally {
|
---|
| 226 | rwLock.ExitWriteLock();
|
---|
[372] | 227 | }
|
---|
| 228 | }
|
---|
| 229 |
|
---|
[375] | 230 | public void UpdateAgent(long id, ProcessStatus status) {
|
---|
[380] | 231 | rwLock.EnterWriteLock();
|
---|
| 232 | try {
|
---|
[375] | 233 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 234 | cnn.Open();
|
---|
| 235 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 236 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 237 | c.Transaction = t;
|
---|
| 238 | c.CommandText = "Update Agent set Status=@Status where id=@Id";
|
---|
| 239 | DbParameter statusParam = c.CreateParameter();
|
---|
| 240 | DbParameter idParam = c.CreateParameter();
|
---|
| 241 | statusParam.ParameterName = "@Status";
|
---|
[392] | 242 | statusParam.Value = status.ToString();
|
---|
[375] | 243 | idParam.ParameterName = "@Id";
|
---|
| 244 | idParam.Value = id;
|
---|
| 245 | c.Parameters.Add(statusParam);
|
---|
| 246 | c.Parameters.Add(idParam);
|
---|
| 247 | c.ExecuteNonQuery();
|
---|
| 248 | }
|
---|
| 249 | t.Commit();
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
[380] | 252 | } finally {
|
---|
| 253 | rwLock.ExitWriteLock();
|
---|
[375] | 254 | }
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | public void UpdateAgent(long id, byte[] rawData) {
|
---|
[380] | 258 | rwLock.EnterWriteLock();
|
---|
| 259 | try {
|
---|
[375] | 260 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 261 | cnn.Open();
|
---|
| 262 | using(SQLiteTransaction t = cnn.BeginTransaction()) {
|
---|
| 263 | using(SQLiteCommand c = cnn.CreateCommand()) {
|
---|
| 264 | c.Transaction = t;
|
---|
| 265 | c.CommandText = "Update Agent set RawData=@RawData where id=@Id";
|
---|
| 266 | DbParameter rawDataParam = c.CreateParameter();
|
---|
| 267 | DbParameter idParam = c.CreateParameter();
|
---|
| 268 | rawDataParam.ParameterName = "@RawData";
|
---|
| 269 | rawDataParam.Value = rawData;
|
---|
| 270 | idParam.ParameterName = "@Id";
|
---|
| 271 | idParam.Value = id;
|
---|
| 272 | c.Parameters.Add(rawDataParam);
|
---|
| 273 | c.Parameters.Add(idParam);
|
---|
| 274 | c.ExecuteNonQuery();
|
---|
| 275 | }
|
---|
| 276 | t.Commit();
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
[380] | 279 | } finally {
|
---|
| 280 | rwLock.ExitWriteLock();
|
---|
[375] | 281 | }
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | #endregion
|
---|
| 285 |
|
---|
| 286 | #region get agent/run/result/sub-result
|
---|
| 287 |
|
---|
| 288 | public ICollection<AgentEntry> GetAgents(ProcessStatus status) {
|
---|
[380] | 289 | rwLock.EnterReadLock();
|
---|
| 290 | List<AgentEntry> agents = new List<AgentEntry>();
|
---|
| 291 | try {
|
---|
[375] | 292 | using(SQLiteConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 293 | cnn.Open();
|
---|
| 294 | SQLiteCommand c = cnn.CreateCommand();
|
---|
[390] | 295 | c.CommandText = "Select id, name, ControllerAgent, rawdata from Agent where Status=@Status";
|
---|
[375] | 296 | DbParameter statusParameter = c.CreateParameter();
|
---|
| 297 | statusParameter.ParameterName = "@Status";
|
---|
[392] | 298 | statusParameter.Value = status.ToString();
|
---|
[375] | 299 | c.Parameters.Add(statusParameter);
|
---|
| 300 | SQLiteDataReader r = c.ExecuteReader();
|
---|
| 301 | while(r.Read()) {
|
---|
| 302 | AgentEntry agent = new AgentEntry();
|
---|
[390] | 303 | agent.ParentAgentId = null;
|
---|
| 304 | agent.Status = status;
|
---|
[375] | 305 | agent.Id = r.GetInt32(0);
|
---|
[390] | 306 | agent.Name = r.IsDBNull(1)?"":r.GetString(1);
|
---|
| 307 | agent.ControllerAgent = r.GetBoolean(2);
|
---|
[375] | 308 | agent.RawData = (byte[])r.GetValue(3);
|
---|
| 309 | agents.Add(agent);
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
[380] | 312 | } finally {
|
---|
| 313 | rwLock.ExitReadLock();
|
---|
[375] | 314 | }
|
---|
[380] | 315 | return agents;
|
---|
[375] | 316 | }
|
---|
| 317 |
|
---|
| 318 | public ICollection<AgentEntry> GetAgents() {
|
---|
[380] | 319 | rwLock.EnterReadLock();
|
---|
| 320 | List<AgentEntry> agents = new List<AgentEntry>();
|
---|
| 321 | try {
|
---|
[375] | 322 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 323 | cnn.Open();
|
---|
| 324 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
[394] | 325 | c.CommandText = "Select id, name, status, ControllerAgent, rawdata from Agent where ParentAgentId isnull";
|
---|
[375] | 326 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 327 | while(r.Read()) {
|
---|
| 328 | AgentEntry agent = new AgentEntry();
|
---|
[394] | 329 | agent.ParentAgentId = null;
|
---|
[375] | 330 | agent.Id = r.GetInt32(0);
|
---|
[394] | 331 | agent.Name = r.IsDBNull(1)?"-":r.GetString(1);
|
---|
| 332 | agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
|
---|
| 333 | agent.ControllerAgent = r.GetBoolean(3);
|
---|
| 334 | agent.RawData = (byte[])r.GetValue(4);
|
---|
[375] | 335 | agents.Add(agent);
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 | }
|
---|
| 339 | }
|
---|
[380] | 340 | } finally {
|
---|
| 341 | rwLock.ExitReadLock();
|
---|
[375] | 342 | }
|
---|
[380] | 343 | return agents;
|
---|
[375] | 344 | }
|
---|
| 345 |
|
---|
[390] | 346 | public ICollection<AgentEntry> GetSubAgents(long parentAgentId) {
|
---|
[380] | 347 | rwLock.EnterReadLock();
|
---|
[390] | 348 | List<AgentEntry> agents = new List<AgentEntry>();
|
---|
[380] | 349 | try {
|
---|
[375] | 350 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 351 | cnn.Open();
|
---|
| 352 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
[390] | 353 | c.CommandText = "Select id, name, status, controllerAgent, rawdata from Agent where ParentAgentId=@ParentAgentId";
|
---|
[393] | 354 | DbParameter parentParameter = c.CreateParameter();
|
---|
| 355 | parentParameter.ParameterName = "@ParentAgentId";
|
---|
| 356 | parentParameter.Value = parentAgentId;
|
---|
| 357 | c.Parameters.Add(parentParameter);
|
---|
| 358 |
|
---|
[375] | 359 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 360 | while(r.Read()) {
|
---|
[390] | 361 | AgentEntry agent = new AgentEntry();
|
---|
| 362 | agent.ParentAgentId = parentAgentId;
|
---|
| 363 | agent.Id = r.GetInt32(0);
|
---|
[393] | 364 | agent.Name = r.IsDBNull(1)?"-":r.GetString(1);
|
---|
[390] | 365 | agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2));
|
---|
| 366 | agent.ControllerAgent = r.GetBoolean(3);
|
---|
| 367 | agent.RawData = (byte[])r.GetValue(4);
|
---|
| 368 | agents.Add(agent);
|
---|
[375] | 369 | }
|
---|
| 370 | }
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
[380] | 373 | } finally {
|
---|
| 374 | rwLock.ExitReadLock();
|
---|
[375] | 375 | }
|
---|
[390] | 376 | return agents;
|
---|
[375] | 377 | }
|
---|
| 378 |
|
---|
[390] | 379 | public ICollection<ResultEntry> GetResults(long agentId) {
|
---|
| 380 | List<ResultEntry> results = new List<ResultEntry>();
|
---|
[380] | 381 | rwLock.EnterReadLock();
|
---|
| 382 | try {
|
---|
[375] | 383 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 384 | cnn.Open();
|
---|
| 385 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
[390] | 386 | c.CommandText = "Select Id, CreationTime, Summary, Description, Rawdata from Result where AgentId=@AgentId";
|
---|
| 387 | DbParameter agentParam = c.CreateParameter();
|
---|
| 388 | agentParam.ParameterName = "@AgentId";
|
---|
| 389 | agentParam.Value = agentId;
|
---|
| 390 | c.Parameters.Add(agentParam);
|
---|
[375] | 391 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 392 | while(r.Read()) {
|
---|
[390] | 393 | ResultEntry result = new ResultEntry();
|
---|
| 394 | result.AgentId = agentId;
|
---|
| 395 | result.Id = r.GetInt32(0);
|
---|
| 396 | result.CreationTime = r.GetDateTime(1);
|
---|
| 397 | result.Summary = r.GetString(2);
|
---|
| 398 | result.Description = r.GetString(3);
|
---|
| 399 | result.RawData = (byte[])r.GetValue(4);
|
---|
| 400 | results.Add(result);
|
---|
[375] | 401 | }
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 | }
|
---|
[380] | 405 | } finally {
|
---|
| 406 | rwLock.ExitReadLock();
|
---|
[375] | 407 | }
|
---|
[390] | 408 | return results;
|
---|
[375] | 409 | }
|
---|
| 410 |
|
---|
[390] | 411 | public ICollection<ResultEntry> GetSubResults(long resultId) {
|
---|
[380] | 412 | List<ResultEntry> results = new List<ResultEntry>();
|
---|
| 413 | rwLock.EnterReadLock();
|
---|
| 414 | try {
|
---|
[375] | 415 | using(DbConnection cnn = new SQLiteConnection(connectionString)) {
|
---|
| 416 | cnn.Open();
|
---|
| 417 | using(DbCommand c = cnn.CreateCommand()) {
|
---|
[390] | 418 | c.CommandText = "Select Id, CreationTime, Summary, Description, Rawdata from Result where ParentResultId=@ParentResultId";
|
---|
| 419 | DbParameter parentParam = c.CreateParameter();
|
---|
| 420 | parentParam.ParameterName = "@ParentResultId";
|
---|
| 421 | parentParam.Value = resultId;
|
---|
| 422 | c.Parameters.Add(parentParam);
|
---|
[375] | 423 | using(DbDataReader r = c.ExecuteReader()) {
|
---|
| 424 | while(r.Read()) {
|
---|
| 425 | ResultEntry result = new ResultEntry();
|
---|
[390] | 426 | result.ParentResultId = resultId;
|
---|
[375] | 427 | result.Id = r.GetInt32(0);
|
---|
[390] | 428 | result.CreationTime = r.GetDateTime(1);
|
---|
| 429 | result.Summary = r.GetString(2);
|
---|
| 430 | result.Description = r.GetString(3);
|
---|
| 431 | result.RawData = (byte[])r.GetValue(4);
|
---|
[375] | 432 | results.Add(result);
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 | }
|
---|
| 436 | }
|
---|
[380] | 437 | } finally {
|
---|
| 438 | rwLock.ExitReadLock();
|
---|
[375] | 439 | }
|
---|
[380] | 440 | return results;
|
---|
[375] | 441 | }
|
---|
| 442 | #endregion
|
---|
[357] | 443 | }
|
---|
| 444 | } |
---|