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