[1000] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
[1377] | 5 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
[1000] | 6 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[1377] | 7 | using HeuristicLab.DataAccess.ADOHelper;
|
---|
[1468] | 8 | using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
|
---|
| 9 | using System.Data.Common;
|
---|
| 10 | using System.Data.SqlClient;
|
---|
[1580] | 11 | using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
|
---|
[1000] | 12 |
|
---|
| 13 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
| 14 | class JobResultsAdapter:
|
---|
| 15 | DataAdapterBase<dsHiveServerTableAdapters.JobResultTableAdapter,
|
---|
| 16 | JobResult,
|
---|
| 17 | dsHiveServer.JobResultRow>,
|
---|
| 18 | IJobResultsAdapter {
|
---|
[1005] | 19 | #region Fields
|
---|
| 20 | private IClientAdapter clientAdapter = null;
|
---|
| 21 |
|
---|
| 22 | private IClientAdapter ClientAdapter {
|
---|
| 23 | get {
|
---|
| 24 | if (clientAdapter == null)
|
---|
[1468] | 25 | clientAdapter =
|
---|
| 26 | this.Session.GetDataAdapter<ClientInfo, IClientAdapter>();
|
---|
[1005] | 27 |
|
---|
| 28 | return clientAdapter;
|
---|
| 29 | }
|
---|
[1000] | 30 | }
|
---|
| 31 |
|
---|
[1005] | 32 | private IJobAdapter jobAdapter = null;
|
---|
| 33 |
|
---|
| 34 | private IJobAdapter JobAdapter {
|
---|
| 35 | get {
|
---|
| 36 | if (jobAdapter == null)
|
---|
[1468] | 37 | jobAdapter =
|
---|
| 38 | this.Session.GetDataAdapter<Job, IJobAdapter>();
|
---|
[1005] | 39 |
|
---|
| 40 | return jobAdapter;
|
---|
| 41 | }
|
---|
[1000] | 42 | }
|
---|
[1005] | 43 | #endregion
|
---|
[1000] | 44 |
|
---|
[1468] | 45 | public JobResultsAdapter(): base(new JobResultsAdapterWrapper()) {
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[1005] | 48 | #region Overrides
|
---|
[1131] | 49 | protected override dsHiveServer.JobResultRow ConvertObj(JobResult result,
|
---|
[1005] | 50 | dsHiveServer.JobResultRow row) {
|
---|
| 51 | if (row != null && result != null) {
|
---|
[1939] | 52 | if (result.JobId != Guid.Empty)
|
---|
| 53 | row.JobId = result.JobId;
|
---|
[1005] | 54 | else
|
---|
| 55 | row.SetJobIdNull();
|
---|
| 56 |
|
---|
| 57 | if (result.Result != null)
|
---|
| 58 | row.JobResult = result.Result;
|
---|
| 59 | else
|
---|
| 60 | row.SetJobResultNull();
|
---|
| 61 |
|
---|
[1939] | 62 | if (result.ClientId != Guid.Empty) {
|
---|
[1017] | 63 | ClientInfo client =
|
---|
[1939] | 64 | ClientAdapter.GetById(result.ClientId);
|
---|
[1017] | 65 |
|
---|
| 66 | if (client != null)
|
---|
| 67 | row.ResourceId = client.Id;
|
---|
| 68 | else
|
---|
| 69 | row.SetResourceIdNull();
|
---|
| 70 | }
|
---|
[1005] | 71 | else
|
---|
| 72 | row.SetResourceIdNull();
|
---|
| 73 |
|
---|
[1103] | 74 | if (result.Exception != null)
|
---|
| 75 | row.Message = result.Exception.ToString();
|
---|
[1092] | 76 | else
|
---|
| 77 | row.SetMessageNull();
|
---|
| 78 |
|
---|
[1169] | 79 | row.Percentage = result.Percentage;
|
---|
| 80 |
|
---|
| 81 | if (result.DateFinished != DateTime.MinValue)
|
---|
| 82 | row.DateFinished = result.DateFinished;
|
---|
| 83 | else
|
---|
| 84 | row.SetDateFinishedNull();
|
---|
| 85 |
|
---|
[1005] | 86 | return row;
|
---|
| 87 | } else
|
---|
| 88 | return null;
|
---|
[1000] | 89 | }
|
---|
| 90 |
|
---|
[1131] | 91 | protected override JobResult ConvertRow(dsHiveServer.JobResultRow row,
|
---|
[1005] | 92 | JobResult result) {
|
---|
| 93 | if (row != null && result != null) {
|
---|
| 94 | result.Id = row.JobResultId;
|
---|
| 95 |
|
---|
| 96 | if (!row.IsJobIdNull())
|
---|
[1939] | 97 | result.JobId = row.JobId;
|
---|
[1005] | 98 | else
|
---|
[1939] | 99 | result.JobId = Guid.Empty;
|
---|
[1005] | 100 |
|
---|
| 101 | if (!row.IsJobResultNull())
|
---|
| 102 | result.Result = row.JobResult;
|
---|
| 103 | else
|
---|
| 104 | result.Result = null;
|
---|
| 105 |
|
---|
| 106 | if (!row.IsResourceIdNull())
|
---|
[1939] | 107 | result.ClientId = row.ResourceId;
|
---|
[1005] | 108 | else
|
---|
[1939] | 109 | result.ClientId = Guid.Empty;
|
---|
[1005] | 110 |
|
---|
[1092] | 111 | if (!row.IsMessageNull())
|
---|
[1103] | 112 | result.Exception = new Exception(row.Message);
|
---|
[1092] | 113 | else
|
---|
[1103] | 114 | result.Exception = null;
|
---|
[1092] | 115 |
|
---|
[1169] | 116 | result.Percentage = row.Percentage;
|
---|
| 117 |
|
---|
| 118 | if (!row.IsDateFinishedNull())
|
---|
| 119 | result.DateFinished = row.DateFinished;
|
---|
| 120 | else
|
---|
| 121 | result.DateFinished = DateTime.MinValue;
|
---|
| 122 |
|
---|
[1005] | 123 | return result;
|
---|
| 124 | } else
|
---|
| 125 | return null;
|
---|
| 126 | }
|
---|
[1000] | 127 | #endregion
|
---|
| 128 |
|
---|
| 129 | #region IJobResultsAdapter Members
|
---|
[1005] | 130 | public ICollection<JobResult> GetResultsOf(Job job) {
|
---|
| 131 | if (job != null) {
|
---|
| 132 | return
|
---|
| 133 | base.FindMultiple(
|
---|
| 134 | delegate() {
|
---|
[1131] | 135 | return Adapter.GetDataByJob(job.Id);
|
---|
[1005] | 136 | });
|
---|
| 137 | }
|
---|
[1000] | 138 |
|
---|
[1005] | 139 | return null;
|
---|
[1000] | 140 | }
|
---|
[2086] | 141 |
|
---|
| 142 | public JobResult GetLastResultOf(Job job) {
|
---|
| 143 | if (job != null) {
|
---|
| 144 | return
|
---|
| 145 | base.FindSingle(
|
---|
| 146 | delegate() {
|
---|
| 147 | return Adapter.GetDataByLastResult(job.Id);
|
---|
| 148 | });
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | return null;
|
---|
| 152 | }
|
---|
[1000] | 153 | #endregion
|
---|
| 154 | }
|
---|
| 155 | }
|
---|