- Timestamp:
- 09/13/10 01:21:32 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.OKB/3.3/AdminService.cs
r4279 r4381 24 24 using System.ServiceModel; 25 25 using HeuristicLab.Services.OKB.DataAccess; 26 using log4net;27 26 28 27 namespace HeuristicLab.Services.OKB { 29 30 28 /// <summary> 31 29 /// Implementation of <see cref="IAdminService"/> 32 30 /// </summary> 33 [ServiceBehavior( 34 InstanceContextMode = InstanceContextMode.PerSession, 35 IncludeExceptionDetailInFaults = true)] 31 [ServiceBehavior(IncludeExceptionDetailInFaults = true)] 36 32 public class AdminService : IAdminService { 37 38 private static ILog logger = LogManager.GetLogger(typeof(AdminService));39 40 private OKBDataContext GetDataContext() {41 return new OKBDataContext();42 }43 44 33 /// <summary> 45 34 /// Gets all available platforms. 46 35 /// </summary> 47 36 /// <returns>A list of <see cref="Platform"/>s.</returns> 48 public Platform[] GetPlatformNames() { 49 OKBDataContext okb = GetDataContext(); 50 return okb.Platforms.ToArray(); 37 public Platform[] GetPlatforms() { 38 using (OKBDataContext okb = new OKBDataContext()) { 39 return okb.Platforms.ToArray(); 40 } 51 41 } 52 42 … … 54 44 /// Gets the complete algorithm object graph up to the following entities: 55 45 /// <list type="bullet"> 56 /// 57 /// 58 /// 59 /// 46 /// <item>Parameter</item> 47 /// <item>Algorithm_Paramters.Parameter.DataType</item> 48 /// <item>Algorithm_Results.Result.DataType</item> 49 /// </list> 60 50 /// </summary> 61 51 /// <param name="id">The algorithm id.</param> 62 52 /// <returns>An <see cref="Algorithm"/></returns> 63 53 public Algorithm GetCompleteAlgorithm(int id) { 64 OKBDataContext okb = GetDataContext(); 65 var dlo = new DataLoadOptions(); 66 dlo.LoadWith<Algorithm>(a => a.Platform); 67 dlo.LoadWith<Algorithm>(a => a.Algorithm_Parameters); 68 dlo.LoadWith<Algorithm>(a => a.Algorithm_Results); 69 dlo.LoadWith<Algorithm_Parameter>(ap => ap.Parameter); 70 dlo.LoadWith<Algorithm_Result>(ar => ar.Result); 71 dlo.LoadWith<Parameter>(p => p.DataType); 72 dlo.LoadWith<Result>(r => r.DataType); 73 okb.LoadOptions = dlo; 74 return okb.Algorithms.Single(a => a.Id == id); 54 using (OKBDataContext okb = new OKBDataContext()) { 55 var dlo = new DataLoadOptions(); 56 dlo.LoadWith<Algorithm>(a => a.AlgorithmClass); 57 dlo.LoadWith<Algorithm>(a => a.Platform); 58 dlo.LoadWith<Algorithm>(a => a.AlgorithmUsers); 59 dlo.LoadWith<AlgorithmUser>(u => u.User); 60 okb.LoadOptions = dlo; 61 return okb.Algorithms.Single(a => a.Id == id); 62 } 75 63 } 76 64 … … 78 66 /// Gets the complete problem object graph up to the following entities: 79 67 /// <list type="bullet"> 80 /// 81 /// 82 /// 83 /// 84 /// 85 /// 86 /// 68 /// <item>Platform</item> 69 /// <item>SolutionRepresentation</item> 70 /// <item>Problem_Parameters.Parameter</item> 71 /// <item>IntProblemCharacteristicValues.ProblemCharacteristic.DataType</item> 72 /// <item>FloatProblemCharacteristicValues.ProblemCharacteristic.DataType</item> 73 /// <item>CharProblemCharacteristicValues.ProblemCharacteristic.DataType</item> 74 /// </list> 87 75 /// </summary> 88 76 /// <param name="id">The problem id.</param> 89 77 /// <returns>A <see cref="Problem"/></returns> 90 78 public Problem GetCompleteProblem(int id) { 91 OKBDataContext okb = GetDataContext(); 92 var dlo = new DataLoadOptions(); 93 dlo.LoadWith<Problem>(p => p.Platform); 94 dlo.LoadWith<Problem>(p => p.SolutionRepresentation); 95 dlo.LoadWith<Problem>(p => p.Problem_Parameters); 96 dlo.LoadWith<Problem>(p => p.IntProblemCharacteristicValues); 97 dlo.LoadWith<Problem>(p => p.FloatProblemCharacteristicValues); 98 dlo.LoadWith<Problem>(p => p.CharProblemCharacteristicValues); 99 dlo.LoadWith<Problem_Parameter>(ap => ap.Parameter); 100 dlo.LoadWith<IntProblemCharacteristicValue>(ipcv => ipcv.ProblemCharacteristic); 101 dlo.LoadWith<FloatProblemCharacteristicValue>(fpcv => fpcv.ProblemCharacteristic); 102 dlo.LoadWith<CharProblemCharacteristicValue>(cpcv => cpcv.ProblemCharacteristic); 103 dlo.LoadWith<Parameter>(p => p.DataType); 104 dlo.LoadWith<ProblemCharacteristic>(pc => pc.DataType); 105 okb.LoadOptions = dlo; 106 return okb.Problems.Single(p => p.Id == id); 79 using (OKBDataContext okb = new OKBDataContext()) { 80 var dlo = new DataLoadOptions(); 81 dlo.LoadWith<Problem>(p => p.ProblemClass); 82 dlo.LoadWith<Problem>(p => p.SolutionRepresentation); 83 dlo.LoadWith<Problem>(p => p.Platform); 84 dlo.LoadWith<Problem>(p => p.ProblemUsers); 85 dlo.LoadWith<ProblemUser>(u => u.User); 86 dlo.LoadWith<Problem>(p => p.ProblemCharacteristicIntValues); 87 dlo.LoadWith<Problem>(p => p.ProblemCharacteristicFloatValues); 88 dlo.LoadWith<Problem>(p => p.ProblemCharacteristicStringValues); 89 dlo.LoadWith<ProblemCharacteristicIntValue>(ipcv => ipcv.ProblemCharacteristic); 90 dlo.LoadWith<ProblemCharacteristicFloatValue>(fpcv => fpcv.ProblemCharacteristic); 91 dlo.LoadWith<ProblemCharacteristicStringValue>(cpcv => cpcv.ProblemCharacteristic); 92 dlo.LoadWith<ProblemCharacteristic>(pc => pc.DataType); 93 okb.LoadOptions = dlo; 94 return okb.Problems.Single(p => p.Id == id); 95 } 107 96 } 108 97 … … 110 99 /// Updates the algorithm object graph including the following properties and linked entitites: 111 100 /// <list type="bullet"> 112 /// 113 /// 114 /// 115 /// 116 /// 117 /// 118 /// 119 /// 101 /// <item>Name</item> 102 /// <item>Description</item> 103 /// <item>AlgorithmClassId</item> 104 /// <item>PlatformId</item> 105 /// <item>Algorithm_Parameters</item> 106 /// <item>Algorithm_Results</item> 107 /// </list> 108 /// <remarks> 120 109 /// New <see cref="Parameter"/>s or <see cref="Result"/>s will not be 121 110 /// created but have to be pre-existing. … … 124 113 /// <param name="algorithm">The algorithm.</param> 125 114 public void UpdateCompleteAlgorithm(Algorithm algorithm) { 126 OKBDataContext okb = GetDataContext(); 127 Algorithm original = okb.Algorithms.Single(a => a.Id == algorithm.Id); 115 using (OKBDataContext okb = new OKBDataContext()) { 116 Algorithm original = okb.Algorithms.Single(a => a.Id == algorithm.Id); 117 UpdateAlgorithmData(algorithm, original, okb); 118 okb.SubmitChanges(); 119 } 120 } 121 122 /// <summary> 123 /// Updates the problem object graph including the following properties and linked entities: 124 /// <list type="bullet"> 125 /// <item>Name</item> 126 /// <item>Description</item> 127 /// <item>ProblemClassId</item> 128 /// <item>PlatformId</item> 129 /// <item>SolutionRepresentationId</item> 130 /// <item>IntProblemCharacteristicValues.Value</item> 131 /// <item>FloatProblemCharacteristicValues.Value</item> 132 /// <item>CharProblemCharacteristicValues.Value</item> 133 /// <item>Problem_Parameters</item> 134 /// </list> 135 /// <remarks> 136 /// New <see cref="ProblemCharacteristic"/>s or <see cref="Parameter"/>s will 137 /// not be created but have to be pre-existing. 138 /// </remarks> 139 /// </summary> 140 /// <param name="problem">The problem.</param> 141 public void UpdateCompleteProblem(Problem problem) { 142 using (OKBDataContext okb = new OKBDataContext()) { 143 Problem originalProblem = okb.Problems.Single(p => p.Id == problem.Id); 144 UpdateProblemData(problem, originalProblem, okb); 145 UpdateProblemCharacteristics(problem, originalProblem, okb); 146 okb.SubmitChanges(); 147 } 148 } 149 150 private static void UpdateAlgorithmData(Algorithm algorithm, Algorithm original, OKBDataContext okb) { 128 151 original.Name = algorithm.Name; 129 152 original.Description = algorithm.Description; 130 153 original.AlgorithmClassId = algorithm.AlgorithmClassId; 131 154 original.PlatformId = algorithm.PlatformId; 132 okb.Algorithm_Parameters.DeleteAllOnSubmit(original.Algorithm_Parameters); 133 foreach (var a_p in algorithm.Algorithm_Parameters) 134 original.Algorithm_Parameters.Add(new Algorithm_Parameter() { 155 okb.AlgorithmUsers.DeleteAllOnSubmit(original.AlgorithmUsers); 156 original.AlgorithmUsers.Clear(); 157 foreach (var u in algorithm.AlgorithmUsers) { 158 original.AlgorithmUsers.Add(new AlgorithmUser() { 135 159 AlgorithmId = original.Id, 136 ParameterId = a_p.ParameterId, 137 }); 138 okb.Algorithm_Results.DeleteAllOnSubmit(original.Algorithm_Results); 139 foreach (var a_r in algorithm.Algorithm_Results) 140 original.Algorithm_Results.Add(new Algorithm_Result() { 141 AlgorithmId = original.Id, 142 ResultId = a_r.ResultId, 143 }); 144 logger.Info("Updating algorithm implementation for " + original.Name); 145 okb.SubmitChanges(); 146 } 147 148 /// <summary> 149 /// Updates the problem object graph including the following properties and linked entities: 150 /// <list type="bullet"> 151 /// <item>Name</item> 152 /// <item>Description</item> 153 /// <item>ProblemClassId</item> 154 /// <item>PlatformId</item> 155 /// <item>SolutionRepresentationId</item> 156 /// <item>IntProblemCharacteristicValues.Value</item> 157 /// <item>FloatProblemCharacteristicValues.Value</item> 158 /// <item>CharProblemCharacteristicValues.Value</item> 159 /// <item>Problem_Parameters</item> 160 /// </list> 161 /// <remarks> 162 /// New <see cref="ProblemCharacteristic"/>s or <see cref="Parameter"/>s will 163 /// not be created but have to be pre-existing. 164 /// </remarks> 165 /// </summary> 166 /// <param name="problem">The problem.</param> 167 public void UpdateCompleteProblem(Problem problem) { 168 OKBDataContext okb = GetDataContext(); 169 Problem originalProblem = okb.Problems.Single(p => p.Id == problem.Id); 170 UpdateProblemMasterInfo(problem, originalProblem); 171 UpdateProblemCharacteristics(problem, okb, originalProblem); 172 UpdateProblemParameters(problem, okb, originalProblem); 173 logger.Info("Updating problem " + originalProblem.Name); 174 okb.SubmitChanges(); 175 } 176 177 private static void UpdateProblemParameters(Problem problem, OKBDataContext okb, Problem originalProblem) { 178 okb.Problem_Parameters.DeleteAllOnSubmit(originalProblem.Problem_Parameters); 179 originalProblem.Problem_Parameters.Clear(); 180 foreach (var p_p in problem.Problem_Parameters) { 181 originalProblem.Problem_Parameters.Add(new Problem_Parameter() { 182 ProblemId = originalProblem.Id, 183 ParameterId = p_p.ParameterId, 184 }); 185 } 186 } 187 188 private static void UpdateProblemCharacteristics(Problem problem, OKBDataContext okb, Problem originalProblem) { 189 okb.IntProblemCharacteristicValues.DeleteAllOnSubmit(originalProblem.IntProblemCharacteristicValues); 190 okb.FloatProblemCharacteristicValues.DeleteAllOnSubmit(originalProblem.FloatProblemCharacteristicValues); 191 okb.CharProblemCharacteristicValues.DeleteAllOnSubmit(originalProblem.CharProblemCharacteristicValues); 192 originalProblem.IntProblemCharacteristicValues.Clear(); 193 originalProblem.FloatProblemCharacteristicValues.Clear(); 194 originalProblem.CharProblemCharacteristicValues.Clear(); 195 foreach (var ipc in problem.IntProblemCharacteristicValues) { 196 originalProblem.IntProblemCharacteristicValues.Add(new IntProblemCharacteristicValue() { 197 ProblemId = originalProblem.Id, 160 UserId = u.UserId 161 }); 162 } 163 } 164 165 private static void UpdateProblemData(Problem problem, Problem original, OKBDataContext okb) { 166 original.Name = problem.Name; 167 original.Description = problem.Description; 168 original.ProblemClassId = problem.ProblemClassId; 169 original.SolutionRepresentationId = problem.SolutionRepresentationId; 170 original.PlatformId = problem.PlatformId; 171 okb.ProblemUsers.DeleteAllOnSubmit(original.ProblemUsers); 172 original.ProblemUsers.Clear(); 173 foreach (var u in problem.ProblemUsers) { 174 original.ProblemUsers.Add(new ProblemUser() { 175 ProblemId = original.Id, 176 UserId = u.UserId 177 }); 178 } 179 } 180 private static void UpdateProblemCharacteristics(Problem problem, Problem original, OKBDataContext okb) { 181 okb.ProblemCharacteristicIntValues.DeleteAllOnSubmit(original.ProblemCharacteristicIntValues); 182 okb.ProblemCharacteristicFloatValues.DeleteAllOnSubmit(original.ProblemCharacteristicFloatValues); 183 okb.ProblemCharacteristicStringValues.DeleteAllOnSubmit(original.ProblemCharacteristicStringValues); 184 original.ProblemCharacteristicIntValues.Clear(); 185 original.ProblemCharacteristicFloatValues.Clear(); 186 original.ProblemCharacteristicStringValues.Clear(); 187 foreach (var ipc in problem.ProblemCharacteristicIntValues) { 188 original.ProblemCharacteristicIntValues.Add(new ProblemCharacteristicIntValue() { 189 ProblemId = original.Id, 198 190 ProblemCharacteristicId = ipc.ProblemCharacteristicId, 199 191 Value = ipc.Value, 200 192 }); 201 193 } 202 foreach (var fpc in problem. FloatProblemCharacteristicValues) {203 original Problem.FloatProblemCharacteristicValues.Add(new FloatProblemCharacteristicValue() {204 ProblemId = original Problem.Id,194 foreach (var fpc in problem.ProblemCharacteristicFloatValues) { 195 original.ProblemCharacteristicFloatValues.Add(new ProblemCharacteristicFloatValue() { 196 ProblemId = original.Id, 205 197 ProblemCharacteristicId = fpc.ProblemCharacteristicId, 206 198 Value = fpc.Value, 207 199 }); 208 200 } 209 foreach (var cpc in problem. CharProblemCharacteristicValues) {210 original Problem.CharProblemCharacteristicValues.Add(new CharProblemCharacteristicValue() {211 ProblemId = original Problem.Id,201 foreach (var cpc in problem.ProblemCharacteristicStringValues) { 202 original.ProblemCharacteristicStringValues.Add(new ProblemCharacteristicStringValue() { 203 ProblemId = original.Id, 212 204 ProblemCharacteristicId = cpc.ProblemCharacteristicId, 213 205 Value = cpc.Value, … … 215 207 } 216 208 } 217 218 private static void UpdateProblemMasterInfo(Problem problem, Problem originalProblem) {219 originalProblem.Name = problem.Name;220 originalProblem.Description = problem.Description;221 originalProblem.ProblemClassId = problem.ProblemClassId;222 originalProblem.PlatformId = problem.PlatformId;223 originalProblem.SolutionRepresentationId = problem.SolutionRepresentationId;224 }225 209 } 226 210 }
Note: See TracChangeset
for help on using the changeset viewer.