[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 |
|
---|
[1939] | 57 | if (result.ClientId != Guid.Empty) {
|
---|
[1017] | 58 | ClientInfo client =
|
---|
[1939] | 59 | ClientAdapter.GetById(result.ClientId);
|
---|
[1017] | 60 |
|
---|
| 61 | if (client != null)
|
---|
| 62 | row.ResourceId = client.Id;
|
---|
| 63 | else
|
---|
| 64 | row.SetResourceIdNull();
|
---|
| 65 | }
|
---|
[1005] | 66 | else
|
---|
| 67 | row.SetResourceIdNull();
|
---|
| 68 |
|
---|
[1103] | 69 | if (result.Exception != null)
|
---|
| 70 | row.Message = result.Exception.ToString();
|
---|
[1092] | 71 | else
|
---|
| 72 | row.SetMessageNull();
|
---|
| 73 |
|
---|
[1169] | 74 | row.Percentage = result.Percentage;
|
---|
| 75 |
|
---|
| 76 | if (result.DateFinished != DateTime.MinValue)
|
---|
| 77 | row.DateFinished = result.DateFinished;
|
---|
| 78 | else
|
---|
| 79 | row.SetDateFinishedNull();
|
---|
| 80 |
|
---|
[1005] | 81 | return row;
|
---|
| 82 | } else
|
---|
| 83 | return null;
|
---|
[1000] | 84 | }
|
---|
| 85 |
|
---|
[1131] | 86 | protected override JobResult ConvertRow(dsHiveServer.JobResultRow row,
|
---|
[1005] | 87 | JobResult result) {
|
---|
| 88 | if (row != null && result != null) {
|
---|
| 89 | result.Id = row.JobResultId;
|
---|
| 90 |
|
---|
| 91 | if (!row.IsJobIdNull())
|
---|
[1939] | 92 | result.JobId = row.JobId;
|
---|
[1005] | 93 | else
|
---|
[1939] | 94 | result.JobId = Guid.Empty;
|
---|
[1005] | 95 |
|
---|
| 96 | if (!row.IsResourceIdNull())
|
---|
[1939] | 97 | result.ClientId = row.ResourceId;
|
---|
[1005] | 98 | else
|
---|
[1939] | 99 | result.ClientId = Guid.Empty;
|
---|
[1005] | 100 |
|
---|
[1092] | 101 | if (!row.IsMessageNull())
|
---|
[1103] | 102 | result.Exception = new Exception(row.Message);
|
---|
[1092] | 103 | else
|
---|
[1103] | 104 | result.Exception = null;
|
---|
[1092] | 105 |
|
---|
[1169] | 106 | result.Percentage = row.Percentage;
|
---|
| 107 |
|
---|
| 108 | if (!row.IsDateFinishedNull())
|
---|
| 109 | result.DateFinished = row.DateFinished;
|
---|
| 110 | else
|
---|
| 111 | result.DateFinished = DateTime.MinValue;
|
---|
| 112 |
|
---|
[1005] | 113 | return result;
|
---|
| 114 | } else
|
---|
| 115 | return null;
|
---|
| 116 | }
|
---|
[1000] | 117 | #endregion
|
---|
| 118 |
|
---|
| 119 | #region IJobResultsAdapter Members
|
---|
[2099] | 120 | public ICollection<JobResult> GetResultsOf(Guid jobId) {
|
---|
[1005] | 121 | return
|
---|
| 122 | base.FindMultiple(
|
---|
| 123 | delegate() {
|
---|
[2099] | 124 | return Adapter.GetDataByJob(jobId);
|
---|
[1005] | 125 | });
|
---|
[1000] | 126 | }
|
---|
[2086] | 127 |
|
---|
[2099] | 128 | public JobResult GetLastResultOf(Guid jobId) {
|
---|
[2086] | 129 | return
|
---|
| 130 | base.FindSingle(
|
---|
| 131 | delegate() {
|
---|
[2099] | 132 | return Adapter.GetDataByLastResult(jobId);
|
---|
[2086] | 133 | });
|
---|
[2099] | 134 | }
|
---|
[2086] | 135 |
|
---|
[2099] | 136 | public SerializedJobResult GetSerializedJobResult(Guid jobResultId) {
|
---|
| 137 | return (SerializedJobResult)base.doInTransaction(
|
---|
| 138 | delegate() {
|
---|
| 139 | SerializedJobResult jobResult =
|
---|
| 140 | new SerializedJobResult();
|
---|
| 141 |
|
---|
| 142 | jobResult.JobResult = GetById(jobResultId);
|
---|
| 143 | if (jobResult.JobResult != null) {
|
---|
| 144 | jobResult.SerializedJobResultData =
|
---|
| 145 | base.Adapter.GetSerializedJobResultById(jobResultId);
|
---|
| 146 |
|
---|
| 147 | return jobResult;
|
---|
| 148 | } else {
|
---|
| 149 | return null;
|
---|
| 150 | }
|
---|
| 151 | });
|
---|
[2086] | 152 | }
|
---|
[2099] | 153 |
|
---|
| 154 | public void UpdateSerializedJobResult(SerializedJobResult jobResult) {
|
---|
| 155 | if (jobResult != null &&
|
---|
| 156 | jobResult.JobResult != null) {
|
---|
| 157 | base.doInTransaction(
|
---|
| 158 | delegate() {
|
---|
| 159 | Update(jobResult.JobResult);
|
---|
| 160 | return base.Adapter.UpdateSerializedJobResultById(
|
---|
| 161 | jobResult.SerializedJobResultData,
|
---|
| 162 | jobResult.JobResult.Id);
|
---|
| 163 | });
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
[1000] | 166 | #endregion
|
---|
| 167 | }
|
---|
| 168 | }
|
---|