[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) {
|
---|
| 52 | if (result.Job != null)
|
---|
| 53 | row.JobId = result.Job.Id;
|
---|
| 54 | else
|
---|
| 55 | row.SetJobIdNull();
|
---|
| 56 |
|
---|
| 57 | if (result.Result != null)
|
---|
| 58 | row.JobResult = result.Result;
|
---|
| 59 | else
|
---|
| 60 | row.SetJobResultNull();
|
---|
| 61 |
|
---|
[1017] | 62 | if (result.Client != null) {
|
---|
| 63 | ClientInfo client =
|
---|
[1449] | 64 | ClientAdapter.GetById(result.Client.Id);
|
---|
[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())
|
---|
| 97 | result.Job = JobAdapter.GetById(row.JobId);
|
---|
| 98 | else
|
---|
| 99 | result.Job = null;
|
---|
| 100 |
|
---|
| 101 | if (!row.IsJobResultNull())
|
---|
| 102 | result.Result = row.JobResult;
|
---|
| 103 | else
|
---|
| 104 | result.Result = null;
|
---|
| 105 |
|
---|
| 106 | if (!row.IsResourceIdNull())
|
---|
| 107 | result.Client = ClientAdapter.GetById(row.ResourceId);
|
---|
| 108 | else
|
---|
| 109 | result.Client = null;
|
---|
| 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
|
---|
[1468] | 130 | protected override void doUpdate(JobResult result) {
|
---|
[1005] | 131 | if (result != null) {
|
---|
| 132 | ClientAdapter.Update(result.Client);
|
---|
| 133 | JobAdapter.Update(result.Job);
|
---|
[1000] | 134 |
|
---|
[1468] | 135 | base.doUpdate(result);
|
---|
[1005] | 136 | }
|
---|
[1000] | 137 | }
|
---|
| 138 |
|
---|
[1005] | 139 | public ICollection<JobResult> GetResultsOf(Job job) {
|
---|
| 140 | if (job != null) {
|
---|
| 141 | return
|
---|
| 142 | base.FindMultiple(
|
---|
| 143 | delegate() {
|
---|
[1131] | 144 | return Adapter.GetDataByJob(job.Id);
|
---|
[1005] | 145 | });
|
---|
| 146 | }
|
---|
[1000] | 147 |
|
---|
[1005] | 148 | return null;
|
---|
[1000] | 149 | }
|
---|
| 150 | #endregion
|
---|
| 151 | }
|
---|
| 152 | }
|
---|