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