Changeset 5482 for branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/Administration/AdministrationService.cs
- Timestamp:
- 02/16/11 04:59:43 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/Administration/AdministrationService.cs
r5479 r5482 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Data.Linq;25 24 using System.Linq; 26 using System.Security.Cryptography;27 25 using System.ServiceModel; 28 26 using HeuristicLab.Services.OKB.DataAccess; … … 35 33 public class AdministrationService : IAdministrationService { 36 34 #region Platform Methods 37 public DataTransfer.Platform GetPlatform(long id) {38 using (OKBDataContext okb = new OKBDataContext()) {39 return Convert.ToDto(okb.Platforms.FirstOrDefault(x => x.Id == id));40 }41 }42 35 public IEnumerable<DataTransfer.Platform> GetPlatforms() { 43 36 using (OKBDataContext okb = new OKBDataContext()) { … … 69 62 #endregion 70 63 71 #region DataType Methods72 public DataTransfer.DataType GetDataType(long id) {73 using (OKBDataContext okb = new OKBDataContext()) {74 return Convert.ToDto(okb.DataTypes.FirstOrDefault(x => x.Id == id));75 }76 }77 public long AddDataType(DataTransfer.DataType dto) {78 using (OKBDataContext okb = new OKBDataContext()) {79 var entity = okb.DataTypes.Where(x => (x.PlatformId == dto.PlatformId) && (x.Name == dto.Name) && (x.TypeName == dto.TypeName)).FirstOrDefault();80 if (entity == null) {81 entity = Convert.ToEntity(dto); entity.Id = 0;82 okb.DataTypes.InsertOnSubmit(entity);83 okb.SubmitChanges();84 }85 return entity.Id;86 }87 }88 #endregion89 90 #region BinaryData Methods91 public long GetBinaryDataId(byte[] hash) {92 using (OKBDataContext okb = new OKBDataContext()) {93 var id = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).Select(x => x.Id).FirstOrDefault();94 if (id == 0) return -1;95 else return id;96 }97 }98 public long AddBinaryData(DataTransfer.BinaryData dto) {99 byte[] hash;100 using (SHA1 sha1 = SHA1.Create()) {101 hash = sha1.ComputeHash(dto.Data);102 }103 104 using (OKBDataContext okb = new OKBDataContext()) {105 var id = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).Select(x => x.Id).FirstOrDefault();106 if (id != 0) {107 return id;108 } else {109 DataAccess.BinaryData entity = Convert.ToEntity(dto); entity.Id = 0;110 okb.BinaryDatas.InsertOnSubmit(entity);111 okb.SubmitChanges();112 return entity.Id;113 }114 }115 }116 #endregion117 118 64 #region AlgorithmClass Methods 119 public DataTransfer.AlgorithmClass GetAlgorithmClass(long id) {120 using (OKBDataContext okb = new OKBDataContext()) {121 return Convert.ToDto(okb.AlgorithmClasses.FirstOrDefault(x => x.Id == id));122 }123 }124 65 public IEnumerable<DataTransfer.AlgorithmClass> GetAlgorithmClasses() { 125 66 using (OKBDataContext okb = new OKBDataContext()) { … … 152 93 153 94 #region Algorithm Methods 154 public DataTransfer.Algorithm GetAlgorithm(long id) {155 using (OKBDataContext okb = new OKBDataContext()) {156 return Convert.ToDto(okb.Algorithms.FirstOrDefault(x => x.Id == id));157 }158 }159 95 public IEnumerable<DataTransfer.Algorithm> GetAlgorithms() { 160 96 using (OKBDataContext okb = new OKBDataContext()) { … … 164 100 public long AddAlgorithm(DataTransfer.Algorithm dto) { 165 101 using (OKBDataContext okb = new OKBDataContext()) { 166 DataAccess.Algorithm entity = Convert.ToEntity(dto ); entity.Id = 0;102 DataAccess.Algorithm entity = Convert.ToEntity(dto, okb); entity.Id = 0; 167 103 okb.Algorithms.InsertOnSubmit(entity); 168 104 okb.SubmitChanges(); … … 173 109 using (OKBDataContext okb = new OKBDataContext()) { 174 110 DataAccess.Algorithm entity = okb.Algorithms.FirstOrDefault(x => x.Id == dto.Id); 175 Convert.ToEntity(dto, entity );111 Convert.ToEntity(dto, entity, okb); 176 112 okb.SubmitChanges(); 177 113 } … … 196 132 } 197 133 } 198 public DataTransfer.BinaryData GetAlgorithmData(long algorithmId) { 199 using (OKBDataContext okb = new OKBDataContext()) { 200 DataLoadOptions dlo = new DataLoadOptions(); 201 dlo.LoadWith<Algorithm>(x => x.BinaryData); 202 okb.LoadOptions = dlo; 203 return Convert.ToDto(okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData).FirstOrDefault()); 134 public byte[] GetAlgorithmData(long algorithmId) { 135 using (OKBDataContext okb = new OKBDataContext()) { 136 return okb.Algorithms.Where(x => x.Id == algorithmId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault(); 137 } 138 } 139 public void UpdateAlgorithmData(long algorithmId, byte[] data) { 140 using (OKBDataContext okb = new OKBDataContext()) { 141 var entity = okb.Algorithms.Where(x => x.Id == algorithmId).FirstOrDefault(); 142 if (entity != null) 143 entity.BinaryData = Convert.ToEntity(data, okb); 144 okb.SubmitChanges(); 204 145 } 205 146 } … … 207 148 208 149 #region ProblemClass Methods 209 public DataTransfer.ProblemClass GetProblemClass(long id) {210 using (OKBDataContext okb = new OKBDataContext()) {211 return Convert.ToDto(okb.ProblemClasses.FirstOrDefault(x => x.Id == id));212 }213 }214 150 public IEnumerable<DataTransfer.ProblemClass> GetProblemClasses() { 215 151 using (OKBDataContext okb = new OKBDataContext()) { … … 242 178 243 179 #region Problem Methods 244 public DataTransfer.Problem GetProblem(long id) {245 using (OKBDataContext okb = new OKBDataContext()) {246 return Convert.ToDto(okb.Problems.FirstOrDefault(x => x.Id == id));247 }248 }249 180 public IEnumerable<DataTransfer.Problem> GetProblems() { 250 181 using (OKBDataContext okb = new OKBDataContext()) { … … 254 185 public long AddProblem(DataTransfer.Problem dto) { 255 186 using (OKBDataContext okb = new OKBDataContext()) { 256 DataAccess.Problem entity = Convert.ToEntity(dto ); entity.Id = 0;187 DataAccess.Problem entity = Convert.ToEntity(dto, okb); entity.Id = 0; 257 188 okb.Problems.InsertOnSubmit(entity); 258 189 okb.SubmitChanges(); … … 263 194 using (OKBDataContext okb = new OKBDataContext()) { 264 195 DataAccess.Problem entity = okb.Problems.FirstOrDefault(x => x.Id == dto.Id); 265 Convert.ToEntity(dto, entity );196 Convert.ToEntity(dto, entity, okb); 266 197 okb.SubmitChanges(); 267 198 } … … 286 217 } 287 218 } 288 public DataTransfer.BinaryData GetProblemData(long problemId) { 289 using (OKBDataContext okb = new OKBDataContext()) { 290 DataLoadOptions dlo = new DataLoadOptions(); 291 dlo.LoadWith<Problem>(x => x.BinaryData); 292 okb.LoadOptions = dlo; 293 return Convert.ToDto(okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData).FirstOrDefault()); 294 } 295 } 296 #endregion 297 298 #region Run Methods 299 public DataTransfer.Run GetRun(long id) { 300 using (OKBDataContext okb = new OKBDataContext()) { 301 DataLoadOptions dlo = new DataLoadOptions(); 302 dlo.LoadWith<Run>(x => x.Values); 303 dlo.LoadWith<Value>(x => x.ValueName); 304 okb.LoadOptions = dlo; 305 return Convert.ToDto(okb.Runs.FirstOrDefault(x => x.Id == id)); 306 } 307 } 308 public IEnumerable<DataTransfer.Run> GetRuns(long algorithmId, long problemId) { 309 using (OKBDataContext okb = new OKBDataContext()) { 310 DataLoadOptions dlo = new DataLoadOptions(); 311 dlo.LoadWith<Run>(x => x.Values); 312 dlo.LoadWith<Value>(x => x.ValueName); 313 okb.LoadOptions = dlo; 314 if ((algorithmId != 0) && (problemId != 0)) 315 return okb.Runs.Where(x => (x.AlgorithmId == algorithmId) && (x.ProblemId == problemId)).Select(x => Convert.ToDto(x)).ToArray(); 316 else if (algorithmId != 0) 317 return okb.Runs.Where(x => x.AlgorithmId == algorithmId).Select(x => Convert.ToDto(x)).ToArray(); 318 else if (problemId != 0) 319 return okb.Runs.Where(x => x.ProblemId == problemId).Select(x => Convert.ToDto(x)).ToArray(); 320 else 321 return okb.Runs.Select(x => Convert.ToDto(x)).ToArray(); 322 } 323 } 324 public long AddRun(DataTransfer.Run dto) { 325 using (OKBDataContext okb = new OKBDataContext()) { 326 DataAccess.Run entity = Convert.ToEntity(dto); entity.Id = 0; 327 okb.Runs.InsertOnSubmit(entity); 328 okb.SubmitChanges(); 329 return entity.Id; 330 } 331 } 332 public void DeleteRun(long id) { 333 using (OKBDataContext okb = new OKBDataContext()) { 334 IEnumerable<DataAccess.ResultBlobValue> resultBlobValues = okb.ResultBlobValues.Where(x => x.RunId == id); 335 okb.ResultBlobValues.DeleteAllOnSubmit(resultBlobValues); 336 IEnumerable<DataAccess.ResultBoolValue> resultBoolValues = okb.ResultBoolValues.Where(x => x.RunId == id); 337 okb.ResultBoolValues.DeleteAllOnSubmit(resultBoolValues); 338 IEnumerable<DataAccess.ResultFloatValue> resultFloatValues = okb.ResultFloatValues.Where(x => x.RunId == id); 339 okb.ResultFloatValues.DeleteAllOnSubmit(resultFloatValues); 340 IEnumerable<DataAccess.ResultIntValue> resultIntValues = okb.ResultIntValues.Where(x => x.RunId == id); 341 okb.ResultIntValues.DeleteAllOnSubmit(resultIntValues); 342 IEnumerable<DataAccess.ResultStringValue> resultStringValues = okb.ResultStringValues.Where(x => x.RunId == id); 343 okb.ResultStringValues.DeleteAllOnSubmit(resultStringValues); 344 345 DataAccess.Run entity = okb.Runs.FirstOrDefault(x => x.Id == id); 346 if (entity != null) okb.Runs.DeleteOnSubmit(entity); 219 public byte[] GetProblemData(long problemId) { 220 using (OKBDataContext okb = new OKBDataContext()) { 221 return okb.Problems.Where(x => x.Id == problemId).Select(x => x.BinaryData.Data.ToArray()).FirstOrDefault(); 222 } 223 } 224 public void UpdateProblemData(long problemId, byte[] data) { 225 using (OKBDataContext okb = new OKBDataContext()) { 226 var entity = okb.Problems.Where(x => x.Id == problemId).FirstOrDefault(); 227 if (entity != null) 228 entity.BinaryData = Convert.ToEntity(data, okb); 347 229 okb.SubmitChanges(); 348 230 }
Note: See TracChangeset
for help on using the changeset viewer.