Changeset 503
- Timestamp:
- 08/12/08 14:55:51 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Core/Agent.cs
r409 r503 27 27 using System.Xml; 28 28 using HeuristicLab.CEDMA.DB.Interfaces; 29 using HeuristicLab.Operators; 29 30 30 31 namespace HeuristicLab.CEDMA.Core { … … 70 71 newAgent.Name = entry.Name; 71 72 newAgent.Status = entry.Status; 72 IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(entry.RawData);73 newAgent.OperatorGraph.Clear();74 foreach(IOperator op in opGraph.Operators) newAgent.OperatorGraph.AddOperator(op);75 newAgent.OperatorGraph.InitialOperator = opGraph.InitialOperator;76 73 agents.Add(newAgent); 77 74 } … … 87 84 result.Summary = entry.Summary; 88 85 result.Description = entry.Description; 89 result.Item = (IItem)PersistenceManager.RestoreFromGZip(entry.RawData);90 86 results.Add(result); 91 87 } … … 95 91 96 92 public IView CreateView() { 93 if(OperatorGraph.Operators.Count == 0) { 94 byte[] rawData = Database.GetAgentRawData(Id); 95 IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(rawData); 96 DownloadOperators(opGraph, new Dictionary<long, IOperator>()); 97 foreach(IOperator op in opGraph.Operators) OperatorGraph.AddOperator(op); 98 OperatorGraph.InitialOperator = opGraph.InitialOperator; 99 } 97 100 return new AgentView(this); 101 } 102 103 private void DownloadOperators(IOperatorGraph opGraph, Dictionary<long, IOperator> downloaded) { 104 foreach(IOperator op in opGraph.Operators) { 105 DownloadOperators(op, downloaded); 106 } 107 } 108 109 private void DownloadOperators(IOperator op, Dictionary<long, IOperator> downloaded) { 110 if(op is OperatorLink) { 111 OperatorLink link = op as OperatorLink; 112 if(downloaded.ContainsKey(link.Id)) { 113 link.Operator = downloaded[link.Id]; 114 } else { 115 OperatorEntry targetEntry = Database.GetOperator(link.Id); 116 IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData); 117 downloaded.Add(link.Id, target); 118 DownloadOperators(target, downloaded); 119 link.Operator = target; 120 } 121 } else if(op is CombinedOperator) { 122 DownloadOperators(((CombinedOperator)op).OperatorGraph, downloaded); 123 } 98 124 } 99 125 } -
trunk/sources/HeuristicLab.CEDMA.Core/AgentList.cs
r420 r503 50 50 newAgent.Name = a.Name; 51 51 newAgent.Status = a.Status; 52 IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(a.RawData);53 54 DownloadOperators(opGraph, new Dictionary<long, IOperator>());55 56 foreach(IOperator op in opGraph.Operators) {57 newAgent.OperatorGraph.AddOperator(op);58 }59 newAgent.OperatorGraph.InitialOperator = opGraph.InitialOperator;60 52 agentList.Add(newAgent); 61 53 } … … 86 78 } 87 79 88 private void DownloadOperators(IOperatorGraph opGraph, Dictionary<long, IOperator> downloaded) {89 foreach(IOperator op in opGraph.Operators) {90 DownloadOperators(op, downloaded);91 }92 }93 94 private void DownloadOperators(IOperator op, Dictionary<long, IOperator> downloaded) {95 if(op is OperatorLink) {96 OperatorLink link = op as OperatorLink;97 if(downloaded.ContainsKey(link.Id)) {98 link.Operator = downloaded[link.Id];99 } else {100 OperatorEntry targetEntry = database.GetOperator(link.Id);101 IOperator target = (IOperator)PersistenceManager.RestoreFromGZip(targetEntry.RawData);102 downloaded.Add(link.Id, target);103 DownloadOperators(target, downloaded);104 link.Operator = target;105 }106 } else if(op is CombinedOperator) {107 DownloadOperators(((CombinedOperator)op).OperatorGraph, downloaded);108 }109 }110 111 80 public override IView CreateView() { 112 81 return new AgentListView(this); -
trunk/sources/HeuristicLab.CEDMA.Core/Result.cs
r403 r503 53 53 result.Summary = entry.Summary; 54 54 result.Description = entry.Description; 55 result.Item = (IItem)PersistenceManager.RestoreFromGZip(entry.RawData);56 55 results.Add(result); 57 56 } … … 61 60 62 61 public IView CreateView() { 62 if(Item == null) { 63 byte[] rawData = Database.GetResultRawData(Id); 64 Item = (IItem)PersistenceManager.RestoreFromGZip(rawData); 65 } 63 66 return Item.CreateView(); 64 67 } -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/AgentEntry.cs
r398 r503 40 40 [DataMember] 41 41 public ProcessStatus Status { get; set; } 42 [DataMember]43 public byte[] RawData { get; set; }44 42 } 45 43 } -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/IDatabase.cs
r420 r503 65 65 66 66 [OperationContract] 67 byte[] GetAgentRawData(long id); 68 69 [OperationContract] 67 70 ICollection<ResultEntry> GetResults(long agentId); 68 71 69 72 [OperationContract] 70 73 ICollection<ResultEntry> GetSubResults(long parentResultId); 74 75 [OperationContract] 76 byte[] GetResultRawData(long id); 71 77 72 78 [OperationContract] -
trunk/sources/HeuristicLab.CEDMA.DB.Interfaces/ResultEntry.cs
r390 r503 42 42 [DataMember] 43 43 public DateTime CreationTime { get; set; } 44 [DataMember]45 public byte[] RawData { get; set; }46 44 } 47 45 } -
trunk/sources/HeuristicLab.CEDMA.DB/Database.cs
r419 r503 354 354 cnn.Open(); 355 355 SQLiteCommand c = cnn.CreateCommand(); 356 c.CommandText = "Select id, name , rawdatafrom Agent where Status=@Status";356 c.CommandText = "Select id, name from Agent where Status=@Status"; 357 357 DbParameter statusParameter = c.CreateParameter(); 358 358 statusParameter.ParameterName = "@Status"; … … 366 366 agent.Id = r.GetInt32(0); 367 367 agent.Name = r.IsDBNull(1) ? "" : r.GetString(1); 368 agent.RawData = (byte[])r.GetValue(2);369 368 agents.Add(agent); 370 369 } … … 383 382 cnn.Open(); 384 383 using(DbCommand c = cnn.CreateCommand()) { 385 c.CommandText = "Select id, name, status , rawdatafrom Agent where ParentAgentId isnull";384 c.CommandText = "Select id, name, status from Agent where ParentAgentId isnull"; 386 385 using(DbDataReader r = c.ExecuteReader()) { 387 386 while(r.Read()) { … … 391 390 agent.Name = r.IsDBNull(1) ? "-" : r.GetString(1); 392 391 agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2)); 393 agent.RawData = (byte[])r.GetValue(3);394 392 agents.Add(agent); 395 393 } … … 410 408 cnn.Open(); 411 409 using(DbCommand c = cnn.CreateCommand()) { 412 c.CommandText = "Select id, name, status , rawdatafrom Agent where ParentAgentId=@ParentAgentId";410 c.CommandText = "Select id, name, status from Agent where ParentAgentId=@ParentAgentId"; 413 411 DbParameter parentParameter = c.CreateParameter(); 414 412 parentParameter.ParameterName = "@ParentAgentId"; … … 423 421 agent.Name = r.IsDBNull(1) ? "-" : r.GetString(1); 424 422 agent.Status = (ProcessStatus)Enum.Parse(typeof(ProcessStatus), r.GetString(2)); 425 agent.RawData = (byte[])r.GetValue(3);426 423 agents.Add(agent); 427 424 } … … 435 432 } 436 433 434 public byte[] GetAgentRawData(long id) { 435 rwLock.EnterReadLock(); 436 try { 437 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 438 cnn.Open(); 439 using(DbCommand c = cnn.CreateCommand()) { 440 c.CommandText = "Select RawData from Agent where Id=@Id"; 441 DbParameter idParameter = c.CreateParameter(); 442 idParameter.ParameterName = "@Id"; 443 idParameter.Value = id; 444 c.Parameters.Add(idParameter); 445 using(DbDataReader r = c.ExecuteReader()) { 446 if(r.HasRows) { 447 r.Read(); 448 return (byte[])r.GetValue(0); 449 } 450 } 451 } 452 } 453 } finally { 454 rwLock.ExitReadLock(); 455 } 456 return null; // agent with the given id not found 457 } 458 437 459 public ICollection<ResultEntry> GetResults(long agentId) { 438 460 List<ResultEntry> results = new List<ResultEntry>(); … … 442 464 cnn.Open(); 443 465 using(DbCommand c = cnn.CreateCommand()) { 444 c.CommandText = "Select Id, CreationTime, Summary, Description , Rawdatafrom Result where AgentId=@AgentId";466 c.CommandText = "Select Id, CreationTime, Summary, Description from Result where AgentId=@AgentId"; 445 467 DbParameter agentParam = c.CreateParameter(); 446 468 agentParam.ParameterName = "@AgentId"; … … 455 477 result.Summary = r.GetString(2); 456 478 result.Description = r.GetString(3); 457 result.RawData = (byte[])r.GetValue(4);458 479 results.Add(result); 459 480 } … … 474 495 cnn.Open(); 475 496 using(DbCommand c = cnn.CreateCommand()) { 476 c.CommandText = "Select Id, CreationTime, Summary, Description , Rawdatafrom Result where ParentResultId=@ParentResultId";497 c.CommandText = "Select Id, CreationTime, Summary, Description from Result where ParentResultId=@ParentResultId"; 477 498 DbParameter parentParam = c.CreateParameter(); 478 499 parentParam.ParameterName = "@ParentResultId"; … … 487 508 result.Summary = r.GetString(2); 488 509 result.Description = r.GetString(3); 489 result.RawData = (byte[])r.GetValue(4);490 510 results.Add(result); 491 511 } … … 497 517 } 498 518 return results; 519 } 520 521 public byte[] GetResultRawData(long id) { 522 rwLock.EnterReadLock(); 523 try { 524 using(DbConnection cnn = new SQLiteConnection(connectionString)) { 525 cnn.Open(); 526 using(DbCommand c = cnn.CreateCommand()) { 527 c.CommandText = "Select RawData from Result where Id=@Id"; 528 DbParameter idParameter = c.CreateParameter(); 529 idParameter.ParameterName = "@Id"; 530 idParameter.Value = id; 531 c.Parameters.Add(idParameter); 532 using(DbDataReader r = c.ExecuteReader()) { 533 if(r.HasRows) { 534 r.Read(); 535 return (byte[])r.GetValue(0); 536 } 537 } 538 } 539 } 540 } finally { 541 rwLock.ExitReadLock(); 542 } 543 return null; // result with the given id not found 499 544 } 500 545 -
trunk/sources/HeuristicLab.CEDMA.Server/RunScheduler.cs
r497 r503 74 74 scope.AddVariable(new Variable("AgentId", new IntData((int)entry.Id))); 75 75 scope.AddVariable(new Variable("CedmaServerUri", new StringData(serverUri))); 76 IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(entry.RawData); 76 77 byte[] rawData = database.GetAgentRawData(entry.Id); 78 IOperatorGraph opGraph = (IOperatorGraph)PersistenceManager.RestoreFromGZip(rawData); 77 79 78 80 PatchLinks(opGraph, new Dictionary<long, IOperator>());
Note: See TracChangeset
for help on using the changeset viewer.