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 |
|
---|
9 | namespace HeuristicLab.Hive.Server.ADODataAccess {
|
---|
10 | class JobResultsAdapter:
|
---|
11 | DataAdapterBase<dsHiveServerTableAdapters.JobResultTableAdapter,
|
---|
12 | JobResult,
|
---|
13 | dsHiveServer.JobResultRow>,
|
---|
14 | IJobResultsAdapter {
|
---|
15 | #region Fields
|
---|
16 | private IClientAdapter clientAdapter = null;
|
---|
17 |
|
---|
18 | private IClientAdapter ClientAdapter {
|
---|
19 | get {
|
---|
20 | if (clientAdapter == null)
|
---|
21 | clientAdapter = ServiceLocator.GetClientAdapter();
|
---|
22 |
|
---|
23 | return clientAdapter;
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | private IJobAdapter jobAdapter = null;
|
---|
28 |
|
---|
29 | private IJobAdapter JobAdapter {
|
---|
30 | get {
|
---|
31 | if (jobAdapter == null)
|
---|
32 | jobAdapter = ServiceLocator.GetJobAdapter();
|
---|
33 |
|
---|
34 | return jobAdapter;
|
---|
35 | }
|
---|
36 | }
|
---|
37 | #endregion
|
---|
38 |
|
---|
39 | #region Overrides
|
---|
40 | protected override dsHiveServer.JobResultRow ConvertObj(JobResult result,
|
---|
41 | dsHiveServer.JobResultRow row) {
|
---|
42 | if (row != null && result != null) {
|
---|
43 | if (result.Job != null)
|
---|
44 | row.JobId = result.Job.Id;
|
---|
45 | else
|
---|
46 | row.SetJobIdNull();
|
---|
47 |
|
---|
48 | if (result.Result != null)
|
---|
49 | row.JobResult = result.Result;
|
---|
50 | else
|
---|
51 | row.SetJobResultNull();
|
---|
52 |
|
---|
53 | if (result.Client != null) {
|
---|
54 | ClientInfo client =
|
---|
55 | ClientAdapter.GetById(result.Client.ClientId);
|
---|
56 |
|
---|
57 | if (client != null)
|
---|
58 | row.ResourceId = client.Id;
|
---|
59 | else
|
---|
60 | row.SetResourceIdNull();
|
---|
61 | }
|
---|
62 | else
|
---|
63 | row.SetResourceIdNull();
|
---|
64 |
|
---|
65 | if (result.Exception != null)
|
---|
66 | row.Message = result.Exception.ToString();
|
---|
67 | else
|
---|
68 | row.SetMessageNull();
|
---|
69 |
|
---|
70 | row.Percentage = result.Percentage;
|
---|
71 |
|
---|
72 | if (result.DateFinished != DateTime.MinValue)
|
---|
73 | row.DateFinished = result.DateFinished;
|
---|
74 | else
|
---|
75 | row.SetDateFinishedNull();
|
---|
76 |
|
---|
77 | return row;
|
---|
78 | } else
|
---|
79 | return null;
|
---|
80 | }
|
---|
81 |
|
---|
82 | protected override JobResult ConvertRow(dsHiveServer.JobResultRow row,
|
---|
83 | JobResult result) {
|
---|
84 | if (row != null && result != null) {
|
---|
85 | result.Id = row.JobResultId;
|
---|
86 |
|
---|
87 | if (!row.IsJobIdNull())
|
---|
88 | result.Job = JobAdapter.GetById(row.JobId);
|
---|
89 | else
|
---|
90 | result.Job = null;
|
---|
91 |
|
---|
92 | if (!row.IsJobResultNull())
|
---|
93 | result.Result = row.JobResult;
|
---|
94 | else
|
---|
95 | result.Result = null;
|
---|
96 |
|
---|
97 | if (!row.IsResourceIdNull())
|
---|
98 | result.Client = ClientAdapter.GetById(row.ResourceId);
|
---|
99 | else
|
---|
100 | result.Client = null;
|
---|
101 |
|
---|
102 | if (!row.IsMessageNull())
|
---|
103 | result.Exception = new Exception(row.Message);
|
---|
104 | else
|
---|
105 | result.Exception = null;
|
---|
106 |
|
---|
107 | result.Percentage = row.Percentage;
|
---|
108 |
|
---|
109 | if (!row.IsDateFinishedNull())
|
---|
110 | result.DateFinished = row.DateFinished;
|
---|
111 | else
|
---|
112 | result.DateFinished = DateTime.MinValue;
|
---|
113 |
|
---|
114 | return result;
|
---|
115 | } else
|
---|
116 | return null;
|
---|
117 | }
|
---|
118 |
|
---|
119 | protected override void UpdateRow(dsHiveServer.JobResultRow row) {
|
---|
120 | Adapter.Update(row);
|
---|
121 | }
|
---|
122 |
|
---|
123 | protected override dsHiveServer.JobResultRow InsertNewRow(JobResult obj) {
|
---|
124 | dsHiveServer.JobResultDataTable data =
|
---|
125 | new dsHiveServer.JobResultDataTable();
|
---|
126 |
|
---|
127 | dsHiveServer.JobResultRow row = data.NewJobResultRow();
|
---|
128 | data.AddJobResultRow(row);
|
---|
129 |
|
---|
130 | return row;
|
---|
131 | }
|
---|
132 |
|
---|
133 | protected override IEnumerable<dsHiveServer.JobResultRow> FindById(long id) {
|
---|
134 | return Adapter.GetDataById(id);
|
---|
135 | }
|
---|
136 |
|
---|
137 | protected override IEnumerable<dsHiveServer.JobResultRow> FindAll() {
|
---|
138 | return Adapter.GetData();
|
---|
139 | }
|
---|
140 | #endregion
|
---|
141 |
|
---|
142 | #region IJobResultsAdapter Members
|
---|
143 | public override void Update(JobResult result) {
|
---|
144 | if (result != null) {
|
---|
145 | ClientAdapter.Update(result.Client);
|
---|
146 | JobAdapter.Update(result.Job);
|
---|
147 |
|
---|
148 | base.Update(result);
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | public ICollection<JobResult> GetResultsOf(Job job) {
|
---|
153 | if (job != null) {
|
---|
154 | return
|
---|
155 | base.FindMultiple(
|
---|
156 | delegate() {
|
---|
157 | return Adapter.GetDataByJob(job.Id);
|
---|
158 | });
|
---|
159 | }
|
---|
160 |
|
---|
161 | return null;
|
---|
162 | }
|
---|
163 | #endregion
|
---|
164 | }
|
---|
165 | }
|
---|