Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.ADODataAccess/3.2/JobResultsAdapter.cs @ 1939

Last change on this file since 1939 was 1939, checked in by svonolfe, 15 years ago

Large amounts of data are now transferred streamed (fixed ticket #660)

File size: 3.8 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.JobId != Guid.Empty)
53          row.JobId = result.JobId;
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.ClientId != Guid.Empty)  {
63          ClientInfo client =
64                 ClientAdapter.GetById(result.ClientId);
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.JobId = row.JobId;
98        else
99          result.JobId = Guid.Empty;
100
101        if (!row.IsJobResultNull())
102          result.Result = row.JobResult;
103        else
104          result.Result = null;
105
106        if (!row.IsResourceIdNull())
107          result.ClientId = row.ResourceId;
108        else
109          result.ClientId = Guid.Empty;
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    public ICollection<JobResult> GetResultsOf(Job job) {
131      if (job != null) {
132        return
133          base.FindMultiple(
134            delegate() {
135              return Adapter.GetDataByJob(job.Id);
136            });
137      }
138
139      return null;
140    }
141    #endregion
142  }
143}
Note: See TracBrowser for help on using the repository browser.