Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/JobResultsAdapter.cs @ 6319

Last change on this file since 6319 was 1716, checked in by msteinbi, 16 years ago

Several refactorings (#466)

File size: 4.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Hive.Server.DataAccess;
6using HeuristicLab.Hive.Contracts.BusinessObjects;
7using HeuristicLab.DataAccess.ADOHelper;
8using HeuristicLab.Hive.Server.ADODataAccess.dsHiveServerTableAdapters;
9using System.Data.Common;
10using System.Data.SqlClient;
11using HeuristicLab.Hive.Server.ADODataAccess.TableAdapterWrapper;
12
13namespace 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        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
111        if (!row.IsMessageNull())
112          result.Exception = new Exception(row.Message);
113        else
114          result.Exception = null;
115
116        result.Percentage = row.Percentage;
117
118        if (!row.IsDateFinishedNull())
119          result.DateFinished = row.DateFinished;
120        else
121          result.DateFinished = DateTime.MinValue;
122
123        return result;
124      } else
125        return null;
126    }
127    #endregion
128
129    #region IJobResultsAdapter Members
130    protected override void doUpdate(JobResult result) {
131      if (result != null) {
132        ClientAdapter.Update(result.Client);
133        JobAdapter.Update(result.Job);
134
135        base.doUpdate(result);
136      }
137    }
138
139    public ICollection<JobResult> GetResultsOf(Job job) {
140      if (job != null) {
141        return
142          base.FindMultiple(
143            delegate() {
144              return Adapter.GetDataByJob(job.Id);
145            });
146      }
147
148      return null;
149    }
150    #endregion
151  }
152}
Note: See TracBrowser for help on using the repository browser.