Changeset 4381 for trunk/sources/HeuristicLab.Services.OKB
- Timestamp:
- 09/13/10 01:21:32 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Services.OKB/3.3
- Files:
-
- 12 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 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/DataService.cs
r4298 r4381 26 26 using System.ServiceModel; 27 27 using HeuristicLab.Services.OKB.DataAccess; 28 using log4net;29 28 30 29 namespace HeuristicLab.Services.OKB { 31 32 30 /// <summary> 33 31 /// Implementation of the <see cref="IDataService"/>. 34 32 /// </summary> 35 [ServiceBehavior( 36 InstanceContextMode = InstanceContextMode.PerSession, 37 IncludeExceptionDetailInFaults = true, 38 ConcurrencyMode = ConcurrencyMode.Multiple)] 33 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, IncludeExceptionDetailInFaults = true)] 39 34 class DataService : IDisposable, IDataService { 40 41 35 private enum Mode { Request, Submit, None }; 42 36 43 37 private Mode mode = Mode.None; 44 45 38 private EntityType type; 46 39 private int id = -1; 47 40 private MemoryStream dataStream; 48 41 49 private Guid sessionID;50 private static ILog logger = LogManager.GetLogger(typeof(DataService));51 52 private void Log(string message, params object[] args) {53 using (log4net.ThreadContext.Stacks["NDC"].Push(sessionID.ToString())) {54 logger.Info(String.Format(message, args));55 }56 }57 58 /// <summary>59 /// Initializes a new instance of the <see cref="DataService"/> class.60 /// </summary>61 public DataService() {62 sessionID = Guid.NewGuid();63 Log("Instantiating new service");64 }65 66 42 private void EnsureInit() { 67 43 if (mode != Mode.None) 68 throw new FaultException(String.Format( 69 "Cannot service new request while processing another {0}-Operation", mode)); 44 throw new FaultException(String.Format("Cannot service new request while processing another {0}-Operation.", mode)); 70 45 } 71 46 72 47 private byte[] GetData(EntityType type, int id) { 73 Log("loading data", type, id);74 48 using (OKBDataContext okb = new OKBDataContext()) { 75 49 switch (type) { … … 84 58 } 85 59 return algorithm.AlgorithmData.Data.ToArray(); 86 break;87 60 case EntityType.Problem: 88 61 Problem problem = okb.Problems.Single(p => p.Id == id); … … 95 68 } 96 69 return problem.ProblemData.Data.ToArray(); 97 break;98 70 default: 99 throw new FaultException("Unsupported EntityType ");71 throw new FaultException("Unsupported EntityType."); 100 72 } 101 73 } … … 103 75 104 76 private void SetData(EntityType type, int id, byte[] data) { 105 Log("saving data", type, id, data.Length);106 OKBDataContext okb = new OKBDataContext();107 switch (type) {108 case EntityType.Algorithm:109 Algorithm algorithm = okb.Algorithms.Single(a => a.Id == id);110 if (algorithm.AlgorithmData == null)111 algorithm.AlgorithmData = new AlgorithmData() {112 AlgorithmId = algorithm.Id,113 Data = new Binary(new byte[0])114 };115 algorithm.AlgorithmData.Data = new Binary(data);116 okb.SubmitChanges();117 break;118 case EntityType.Problem:119 Problem problem = okb.Problems.Single(p => p.Id == id);120 if (problem.ProblemData == null)121 problem.ProblemData = new ProblemData() {122 ProblemId = problem.Id,123 Data = new Binary(new byte[0])124 };125 problem.ProblemData.Data = new Binary(data);126 okb.SubmitChanges();127 break;128 default:129 throw new FaultException("Unsupported EntityType");77 using (OKBDataContext okb = new OKBDataContext()) { 78 switch (type) { 79 case EntityType.Algorithm: 80 Algorithm algorithm = okb.Algorithms.Single(a => a.Id == id); 81 if (algorithm.AlgorithmData == null) 82 algorithm.AlgorithmData = new AlgorithmData() { 83 AlgorithmId = algorithm.Id, 84 Data = new Binary(new byte[0]) 85 }; 86 algorithm.AlgorithmData.Data = new Binary(data); 87 okb.SubmitChanges(); 88 break; 89 case EntityType.Problem: 90 Problem problem = okb.Problems.Single(p => p.Id == id); 91 if (problem.ProblemData == null) 92 problem.ProblemData = new ProblemData() { 93 ProblemId = problem.Id, 94 Data = new Binary(new byte[0]) 95 }; 96 problem.ProblemData.Data = new Binary(data); 97 okb.SubmitChanges(); 98 break; 99 default: 100 throw new FaultException("Unsupported EntityType."); 101 } 130 102 } 131 okb.Dispose();132 103 } 133 104 134 105 #region IDataService Members 135 136 106 /// <summary> 137 107 /// Request the specified <see cref="Algorithm"/> or <see cref="Problem"/>. … … 141 111 /// <returns>The size of the data blob.</returns> 142 112 public int Request(EntityType type, int id) { 143 Log("requesting data", type, id);144 113 EnsureInit(); 145 114 dataStream = new MemoryStream(GetData(type, id)); … … 155 124 public byte[] GetNextChunk(int size) { 156 125 if (dataStream == null || mode != Mode.Request) 157 throw new FaultException("No data has been prepared, call Request first ");126 throw new FaultException("No data has been prepared, call Request first."); 158 127 byte[] chunk = new byte[Math.Min(size, dataStream.Length - dataStream.Position)]; 159 128 dataStream.Read(chunk, 0, chunk.Length); … … 167 136 /// <param name="id">The entity id.</param> 168 137 public void Submit(EntityType type, int id) { 169 Log("Submitting", type, id);170 138 EnsureInit(); 171 139 GetData(type, id); … … 189 157 /// </summary> 190 158 public void TransferDone() { 191 Log("commiting transfer");192 159 if (mode == Mode.Submit) 193 160 SetData(type, id, dataStream.ToArray()); … … 201 168 Dispose(); 202 169 } 203 204 170 #endregion 205 171 206 172 #region IDisposable Members 207 208 173 /// <summary> 209 174 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. 210 175 /// </summary> 211 176 public void Dispose() { 212 Log("disposing");213 177 mode = Mode.None; 214 178 if (dataStream != null) 215 179 dataStream.Dispose(); 216 180 } 217 218 181 #endregion 219 182 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/HeuristicLab.Services.OKB-3.3.csproj
r4321 r4381 128 128 <Compile Include="Interfaces\IDataService.cs" /> 129 129 <Compile Include="Interfaces\IQueryService.cs" /> 130 <Compile Include="Interfaces\IRunnerService.cs" /> 130 <Compile Include="Interfaces\IRunnerService.cs"> 131 <SubType>Code</SubType> 132 </Compile> 131 133 <Compile Include="Interfaces\ITableService.cs" /> 132 134 <Compile Include="Properties\AssemblyInfo.cs" /> 133 135 <Compile Include="QueryService.cs" /> 134 <Compile Include="RunnerService.cs" /> 136 <Compile Include="RunnerService.cs"> 137 <SubType>Code</SubType> 138 </Compile> 135 139 <Compile Include="StarterKit.cs" /> 136 140 <Compile Include="TableService.cs" /> -
trunk/sources/HeuristicLab.Services.OKB/3.3/Interfaces/IAdminService.cs
r4279 r4381 25 25 26 26 namespace HeuristicLab.Services.OKB { 27 28 27 /// <summary> 29 28 /// Allows updating the implementation of algorithms and problems. All … … 38 37 /// <returns>A list of <see cref="Platform"/>s.</returns> 39 38 [OperationContract] 40 Platform[] GetPlatform Names();39 Platform[] GetPlatforms(); 41 40 42 41 /// <summary> … … 109 108 [OperationContract] 110 109 void UpdateCompleteProblem(Problem problem); 111 112 110 } 113 111 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/Interfaces/IDataService.cs
r4279 r4381 24 24 25 25 namespace HeuristicLab.Services.OKB { 26 27 26 /// <summary> 28 27 /// Choose between <see cref="Algorithm"/> or <see cref="Problem"/>. … … 30 29 public enum EntityType { 31 30 /// <summary> 32 /// Selects<see cref="Algorithm"/> as entity type.31 /// Use <see cref="Algorithm"/> as entity type. 33 32 /// </summary> 34 33 Algorithm, … … 93 92 void AbortTransfer(); 94 93 } 95 96 94 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/Interfaces/IQueryService.cs
r4279 r4381 25 25 26 26 namespace HeuristicLab.Services.OKB { 27 28 27 /// <summary> 29 28 /// Service interface for downloading selected information about <see cref="Experiment"/> <see cref="Run"/>s. … … 31 30 [ServiceContract(SessionMode = SessionMode.Required, ProtectionLevel = ProtectionLevel.EncryptAndSign)] 32 31 public interface IQueryService { 33 34 32 /// <summary> 35 33 /// Gets a list of all possible attribute selectors. -
trunk/sources/HeuristicLab.Services.OKB/3.3/Interfaces/IRunnerService.cs
r4313 r4381 31 31 [ServiceContract(SessionMode = SessionMode.Required, ProtectionLevel = ProtectionLevel.EncryptAndSign)] 32 32 public interface IRunnerService { 33 34 33 /// <summary> 35 34 /// Logs the current user in. In case the user or client … … 86 85 /// <param name="project">The project.</param> 87 86 [OperationContract(IsInitiating = false)] 88 void AddRun(Algorithm algorithm, Problem problem , Project project);87 void AddRun(Algorithm algorithm, Problem problem); 89 88 90 89 /// <summary> … … 103 102 void Logout(); 104 103 } 105 106 104 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/Interfaces/ITableService.cs
r4279 r4381 25 25 26 26 namespace HeuristicLab.Services.OKB { 27 28 27 /// <summary> 29 28 /// Service interface for downloading and uploading data tables. … … 75 74 void DeleteTableRows(int[] ids, string tableName); 76 75 } 77 78 76 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/QueryService.cs
r4279 r4381 27 27 using HeuristicLab.Services.OKB.AttributeSelection; 28 28 using HeuristicLab.Services.OKB.DataAccess; 29 using log4net;30 29 31 30 namespace HeuristicLab.Services.OKB { 32 33 31 /// <summary> 34 32 /// Implementation of the <see cref="IQueryService"/>. … … 36 34 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, IncludeExceptionDetailInFaults = true)] 37 35 public class QueryService : IQueryService, IDisposable { 38 39 private Guid sessionID;40 private static ILog logger = LogManager.GetLogger(typeof(QueryService));41 42 private void Log(string message, params object[] args) {43 using (log4net.ThreadContext.Stacks["NDC"].Push(sessionID.ToString())) {44 logger.Info(String.Format(message, args));45 }46 }47 48 /// <summary>49 /// Initializes a new instance of the <see cref="QueryService"/> class.50 /// </summary>51 public QueryService() {52 sessionID = Guid.NewGuid();53 Log("Instantiating new service");54 }55 56 private OKBDataContext GetDataContext() {57 return new OKBDataContext();58 }59 60 36 /// <summary> 61 37 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. … … 76 52 /// </returns> 77 53 public AttributeSelector[] GetAllAttributeSelectors() { 78 Log("retrieving all attribute specifiers"); 79 try { 80 OKBDataContext okb = GetDataContext(); 54 using (OKBDataContext okb = new OKBDataContext()) { 81 55 return RunAttributeSelector.GetAllAttributeSelectors(okb).Select(s => new AttributeSelector(s)).ToArray(); 82 }83 catch (Exception x) {84 Log("exception caught: " + x.ToString());85 throw;86 56 } 87 57 } … … 95 65 /// </returns> 96 66 public DataTable PrepareQuery(AttributeSelector[] selectors) { 97 okb = GetDataContext(); 98 Log("validating new query"); 99 if (selectors.Length == 0) 100 throw new FaultException("No columns selected"); 101 IEnumerable<RunAttributeSelector> checkedSelectors = 102 selectors.Select(s => new RunAttributeSelector(new OKBDataContext(okb.Connection.ConnectionString), s)).ToList(); 103 Log("preparing query:\n {0}", string.Join("\n ", checkedSelectors.Select(s => s.ToString()).ToArray())); 104 dataSetBuilder = new DataSetBuilder(okb, checkedSelectors); 105 dataEnumerator = dataSetBuilder.GetEnumerator(); 106 return dataSetBuilder.Runs; 67 using (OKBDataContext okb = new OKBDataContext()) { 68 if (selectors.Length == 0) 69 throw new FaultException("No columns selected"); 70 IEnumerable<RunAttributeSelector> checkedSelectors = 71 selectors.Select(s => new RunAttributeSelector(new OKBDataContext(okb.Connection.ConnectionString), s)).ToList(); 72 dataSetBuilder = new DataSetBuilder(okb, checkedSelectors); 73 dataEnumerator = dataSetBuilder.GetEnumerator(); 74 return dataSetBuilder.Runs; 75 } 107 76 } 108 77 … … 137 106 /// </summary> 138 107 public void Terminate() { 139 Log("Terminating session");140 108 dataSetBuilder = null; 141 109 if (dataEnumerator != null) { 142 Log("disposing data enumerate");143 110 dataEnumerator.Dispose(); 144 111 dataEnumerator = null; 145 112 } 146 113 if (okb != null) { 147 Log("disposing data context");148 114 okb.Dispose(); 149 115 okb = null; 150 116 } 151 117 } 152 153 118 } 154 119 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/RunnerService.cs
r4321 r4381 27 27 using System.Web.Security; 28 28 using HeuristicLab.Services.OKB.DataAccess; 29 using log4net;30 29 31 30 namespace HeuristicLab.Services.OKB { 32 33 31 /// <summary> 34 32 /// Implementation of the <see cref="IRunnerService"/>. 35 33 /// </summary> 36 [ServiceBehavior( 37 InstanceContextMode = InstanceContextMode.PerSession)] 34 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 38 35 public class RunnerService : IRunnerService, IDisposable { 39 40 private Guid sessionID;41 private static ILog logger = LogManager.GetLogger(typeof(RunnerService));42 43 private void Log(string message, params object[] args) {44 using (log4net.ThreadContext.Stacks["NDC"].Push(sessionID.ToString())) {45 logger.Info(String.Format(message, args));46 }47 }48 49 /// <summary>50 /// Initializes a new instance of the <see cref="RunnerService"/> class.51 /// </summary>52 public RunnerService() {53 sessionID = Guid.NewGuid();54 Log("Instantiating new service");55 }56 57 36 /// <summary> 58 37 /// Obtain a "starter kit" of information, containing: … … 64 43 /// </summary> 65 44 public StarterKit GetStarterKit(string platformName) { 66 Log("distributing starter kit");67 45 Platform platform; 68 46 using (OKBDataContext okb = new OKBDataContext()) { … … 86 64 var StarterKit = new StarterKit() { 87 65 AlgorithmClasses = okb.AlgorithmClasses.ToList(), 88 ProblemClasses = okb.ProblemClasses.ToList(), 89 Projects = okb.Projects.ToList() 66 ProblemClasses = okb.ProblemClasses.ToList() 90 67 }; 91 68 return StarterKit; … … 100 77 /// </summary> 101 78 public ExperimentKit PrepareExperiment(Algorithm algorithm, Problem problem) { 102 Log("preparing experiment: {0}@{1}", algorithm.Name, problem.Name);103 79 OKBDataContext okb = new OKBDataContext(); 104 80 try { 105 81 DataLoadOptions dlo = new DataLoadOptions(); 106 82 dlo.LoadWith<Problem>(p => p.SolutionRepresentation); 107 dlo.LoadWith<Parameter>(p => p.DataType); 83 dlo.LoadWith<AlgorithmParameter>(p => p.DataType); 84 dlo.LoadWith<ProblemParameter>(p => p.DataType); 108 85 dlo.LoadWith<Result>(r => r.DataType); 109 dlo.LoadWith<Algorithm_Parameter>(ap => ap.Parameter);110 dlo.LoadWith<Problem_Parameter>(pp => pp.Parameter);111 dlo.LoadWith<Algorithm_Result>(ar => ar.Result);112 86 okb.LoadOptions = dlo; 113 87 algorithm = okb.Algorithms.Single(a => a.Id == algorithm.Id); 114 88 problem = okb.Problems.Single(p => p.Id == problem.Id); 115 algorithm.Algorithm _Parameters.Load();116 algorithm. Algorithm_Results.Load();117 problem. IntProblemCharacteristicValues.Load();118 problem. FloatProblemCharacteristicValues.Load();119 problem. CharProblemCharacteristicValues.Load();120 problem.Problem _Parameters.Load();89 algorithm.AlgorithmParameters.Load(); 90 algorithm.Results.Load(); 91 problem.ProblemCharacteristicIntValues.Load(); 92 problem.ProblemCharacteristicFloatValues.Load(); 93 problem.ProblemCharacteristicStringValues.Load(); 94 problem.ProblemParameters.Load(); 121 95 return new ExperimentKit() { 122 96 Algorithm = algorithm, … … 125 99 } 126 100 catch (Exception x) { 127 Log("exception caught: " + x.ToString());128 101 throw new FaultException("Excaption caught: " + x.ToString()); 129 102 } … … 141 114 /// <param name="problem">The problem.</param> 142 115 /// <param name="project">The project.</param> 143 public void AddRun(Algorithm algorithm, Problem problem, Project project) { 144 Log("adding run for {0}@{1}({2})[{3}, {4}]", 145 algorithm.Name, problem.Name, project.Name, currentUser.Name, currentClient.Name); 116 public void AddRun(Algorithm algorithm, Problem problem) { 146 117 try { 147 118 using (OKBDataContext okb = new OKBDataContext()) { 148 Experiment experiment = GetOrCreateExperiment(algorithm, problem, project,currentUser, okb);119 Experiment experiment = GetOrCreateExperiment(algorithm, problem, currentUser, okb); 149 120 Run run = new Run() { 150 121 Experiment = experiment, … … 159 130 } 160 131 catch (Exception x) { 161 Log(x.ToString());162 132 throw new FaultException("Could not add run: " + x.ToString()); 163 133 } 164 134 } 165 135 166 private Experiment GetOrCreateExperiment(Algorithm algorithm, Problem problem, 167 Project project, User user, OKBDataContext okb) { 136 private Experiment GetOrCreateExperiment(Algorithm algorithm, Problem problem, User user, OKBDataContext okb) { 168 137 MatchResults(algorithm.Results, okb); 169 138 EnsureParametersExist(algorithm.Parameters, okb); 170 var experimentQuery = CreateExperimentQuery(algorithm, problem, project,okb);139 var experimentQuery = CreateExperimentQuery(algorithm, problem, okb); 171 140 if (experimentQuery.Count() > 0) { 172 if (experimentQuery.Count() > 1)173 Log("Warning: duplicate experiment found");174 Log("reusing existing experiment");175 141 Experiment experiment = experimentQuery.First(); 176 142 return experiment; 177 143 } else { 178 Log("creating new experiment");179 144 Experiment experiment = new Experiment() { 180 145 AlgorithmId = algorithm.Id, 181 146 ProblemId = problem.Id, 182 ProjectId = project.Id,183 147 ParameterValues = algorithm.ParameterValues 184 148 }; … … 191 155 foreach (var result in results.Where(r => r.Name != null)) { 192 156 result.Id = okb.Results.Single(r => r.Name == result.Name).Id; 193 Log("mapping named result {0} -> Id {1}", result.Name, result.Id);194 157 var value = result.ResultValue; 195 158 if (value != null) { … … 205 168 DataType dataType = GetOrCreateDataType(okb, param.DataType.ClrName); 206 169 param.DataType = new DataType() { Id = dataType.Id }; 207 Log("mapping datatype {0} to id {1}", dataType.ClrName, dataType.Id);208 170 } 209 171 okb.SubmitChanges(); … … 211 173 var newParams = namedParams.Except(okb.Parameters, new NameComprarer()); 212 174 foreach (var p in newParams) { 213 Log("creating new parameter {0} ({2}:{1})", p.Name, p.DataType.ClrName, p.DataType.Id);214 175 okb.Parameters.InsertOnSubmit(new Parameter() { 215 176 Name = p.Name, … … 220 181 foreach (var np in namedParams) { 221 182 np.Id = okb.Parameters.Single(p => p.Name == np.Name).Id; 222 Log("mapping named parameter {0} -> Id {1}", np.Name, np.Id);223 183 var value = np.ParameterValue; 224 184 if (value != null) { … … 231 191 DataType dataType = GetOrCreateDataType(okb, opVal.DataType.ClrName); 232 192 newVal.DataType = new DataType() { Id = dataType.Id }; 233 Log("mapping operator parameter datatype {0} to id {1}", dataType.ClrName, dataType.Id);234 193 } 235 194 } … … 240 199 DataType dataType = okb.DataTypes.SingleOrDefault(dt => dt.ClrName == clrName); 241 200 if (dataType == null) { 242 Log("creating new datatype for ", clrName);243 201 dataType = new DataType() { 244 202 ClrName = clrName, … … 251 209 } 252 210 253 private IQueryable<Experiment> CreateExperimentQuery(Algorithm algorithm, Problem problem, Project project, 254 OKBDataContext okb) { 211 private IQueryable<Experiment> CreateExperimentQuery(Algorithm algorithm, Problem problem, OKBDataContext okb) { 255 212 var experimentQuery = 256 213 from x in okb.Experiments 257 214 where x.Algorithm == algorithm 258 215 where x.Problem == problem 259 where x.ProjectId == project.Id260 216 select x; 261 217 foreach (IntParameterValue ipv in algorithm.IntParameterValues) { … … 279 235 p.ParameterId == opv.ParameterId && p.DataTypeId == opv.DataTypeId)); 280 236 } 281 Log("experiment query: ", experimentQuery.Expression.ToString());282 237 return experimentQuery; 283 238 } … … 310 265 MembershipUser user = Membership.GetUser(); 311 266 312 Log("Authenticating {0}@{1}", user.UserName, clientname);313 267 if (user == null || 314 268 string.IsNullOrEmpty(clientname) || 315 269 ServiceSecurityContext.Current.IsAnonymous) { 316 Log("rejecting anonymous login");317 270 return false; 318 271 } … … 330 283 okb.SubmitChanges(); 331 284 } 332 Log(" user = {0}, client = {1}", currentUser, currentClient);333 285 return true; 334 286 } … … 339 291 /// </summary> 340 292 public void Logout() { 341 Log("Logging out");342 293 currentUser = null; 343 294 currentClient = null; … … 348 299 /// </summary> 349 300 public void Dispose() { 350 Log("Closing session...");351 301 Logout(); 352 302 } … … 383 333 return obj.Name.GetHashCode(); 384 334 } 385 386 335 } 387 336 } -
trunk/sources/HeuristicLab.Services.OKB/3.3/StarterKit.cs
r4279 r4381 50 50 [DataMember] 51 51 public IEnumerable<ProblemClass> ProblemClasses { get; set; } 52 53 /// <summary>54 /// Gets a list of all available projects.55 /// </summary>56 /// <value>The projects.</value>57 [DataMember]58 public IEnumerable<Project> Projects { get; set; }59 52 } 60 53 -
trunk/sources/HeuristicLab.Services.OKB/3.3/TableService.cs
r4313 r4381 31 31 using HeuristicLab.Services.OKB.AttributeSelection; 32 32 using HeuristicLab.Services.OKB.DataAccess; 33 using log4net;34 33 35 34 namespace HeuristicLab.Services.OKB { … … 38 37 /// Implementation of the <see cref="ITableService"/>. 39 38 /// </summary> 40 [ServiceBehavior( 41 InstanceContextMode = InstanceContextMode.PerSession, 42 IncludeExceptionDetailInFaults = true)] 39 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, IncludeExceptionDetailInFaults = true)] 43 40 public class TableService : ITableService, IDisposable { 44 45 private static ILog logger = LogManager.GetLogger(typeof(TableService));46 47 private OKBDataContext GetDataContext() {48 return new OKBDataContext();49 }50 51 41 private static List<Type> SupportedTypes = new List<Type>() { 52 42 typeof(int), 43 typeof(long), 53 44 typeof(double), 54 45 typeof(string), … … 57 48 }; 58 49 50 private DataTable tableTemplate; 51 private IEnumerable<PropertyInfo> properties; 52 private IEnumerator rowEnumerator; 53 59 54 #region ITableService Members 60 61 55 /// <summary> 62 56 /// Updates the data table. … … 65 59 /// <param name="tableName">Name of the table.</param> 66 60 public void UpdateDataTable(DataTable updatedRows, string tableName) { 67 logger.Info("updating table: " + tableName);68 61 Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.Services.OKB.DataAccess." + tableName, true); 69 62 var properties = from p in tableType.GetProperties() 70 63 where SupportedTypes.Contains(p.PropertyType) 71 64 select p; 72 OKBDataContext okb = GetDataContext(); 73 ITable table = okb.GetTable(tableType); 74 foreach (DataRow row in updatedRows.Rows) { 75 if (row["Id"] == DBNull.Value) 76 table.InsertOnSubmit(CreateEntity(tableType, properties, row)); 77 } 78 var updated = updatedRows.Rows.Cast<DataRow>().Where(row => row["Id"] != DBNull.Value).OrderBy(row => row["Id"]); 79 var entities = DataSetBuilder.GetEntities(okb, tableType, updated.Select(u => (int)u["Id"])); 80 var updateEnum = updated.GetEnumerator(); 81 var entityEnum = entities.GetEnumerator(); 82 while (updateEnum.MoveNext() && entityEnum.MoveNext()) { 83 bool idChecked = false; 84 foreach (var property in properties) { 85 Console.WriteLine("{0}.{1} = '{2}' -> '{3}'", 86 tableName, property.Name, 87 property.GetGetMethod().Invoke(entityEnum.Current, new object[0]), 88 updateEnum.Current[property.Name]); 89 if (property.Name == "Id") { 90 int entityId = (int)property.GetGetMethod().Invoke(entityEnum.Current, new object[0]); 91 int updateId = (int)updateEnum.Current["Id"]; 92 Debug.Assert(entityId == updateId); 93 idChecked = true; 65 using (OKBDataContext okb = new OKBDataContext()) { 66 ITable table = okb.GetTable(tableType); 67 foreach (DataRow row in updatedRows.Rows) { 68 if (row["Id"] == DBNull.Value) 69 table.InsertOnSubmit(CreateEntity(tableType, properties, row)); 70 } 71 var updated = updatedRows.Rows.Cast<DataRow>().Where(row => row["Id"] != DBNull.Value).OrderBy(row => row["Id"]); 72 var entities = DataSetBuilder.GetEntities(okb, tableType, updated.Select(u => (int)u["Id"])); 73 var updateEnum = updated.GetEnumerator(); 74 var entityEnum = entities.GetEnumerator(); 75 while (updateEnum.MoveNext() && entityEnum.MoveNext()) { 76 bool idChecked = false; 77 foreach (var property in properties) { 78 Console.WriteLine("{0}.{1} = '{2}' -> '{3}'", 79 tableName, property.Name, 80 property.GetGetMethod().Invoke(entityEnum.Current, new object[0]), 81 updateEnum.Current[property.Name]); 82 if (property.Name == "Id") { 83 int entityId = (int)property.GetGetMethod().Invoke(entityEnum.Current, new object[0]); 84 int updateId = (int)updateEnum.Current["Id"]; 85 Debug.Assert(entityId == updateId); 86 idChecked = true; 87 } 88 object newValue = updateEnum.Current[property.Name]; 89 if (newValue != DBNull.Value) 90 property.GetSetMethod().Invoke(entityEnum.Current, new object[] { newValue }); 94 91 } 95 object newValue = updateEnum.Current[property.Name]; 96 if (newValue != DBNull.Value) 97 property.GetSetMethod().Invoke(entityEnum.Current, new object[] { newValue }); 98 } 99 Debug.Assert(idChecked); 100 } 101 okb.SubmitChanges(); 92 Debug.Assert(idChecked); 93 } 94 okb.SubmitChanges(); 95 } 102 96 } 103 97 104 98 private object CreateEntity(Type tableType, IEnumerable<PropertyInfo> properties, DataRow row) { 105 99 object instance = Activator.CreateInstance(tableType); 106 logger.Info("Creating new instance of " + tableType.Name);107 100 bool empty = true; 108 101 foreach (var property in properties) { … … 125 118 /// <param name="tableName">Name of the table.</param> 126 119 public void DeleteTableRows(int[] ids, string tableName) { 127 logger.Info("delete rows from table: " + tableName);128 120 Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.Services.OKB.DataAccess" + tableName, true); 129 OKBDataContext okb = GetDataContext(); 130 ITable table = okb.GetTable(tableType); 131 table.DeleteAllOnSubmit(DataSetBuilder.GetEntities(okb, tableType, ids)); 132 okb.SubmitChanges(); 133 } 134 135 private DataTable tableTemplate; 136 private IEnumerable<PropertyInfo> properties; 137 private IEnumerator rowEnumerator; 121 using (OKBDataContext okb = new OKBDataContext()) { 122 ITable table = okb.GetTable(tableType); 123 table.DeleteAllOnSubmit(DataSetBuilder.GetEntities(okb, tableType, ids)); 124 okb.SubmitChanges(); 125 } 126 } 138 127 139 128 /// <summary> … … 147 136 /// </returns> 148 137 public DataTable PrepareDataTable(string tableName, out int count) { 149 logger.Info("preparing data table: " + tableName);150 138 Type tableType = Assembly.GetAssembly(typeof(Run)).GetType("HeuristicLab.Services.OKB.DataAccess." + tableName, true); 151 139 properties = from p in tableType.GetProperties() … … 163 151 tableTemplate.Columns.Add(column); 164 152 } 165 OKBDataContext okb = GetDataContext(); 166 ITable table = okb.GetTable(tableType); 167 rowEnumerator = table.GetEnumerator(); 168 count = DataSetBuilder.CountEntities(GetDataContext(), tableType); 169 return tableTemplate; 153 using (OKBDataContext okb = new OKBDataContext()) { 154 ITable table = okb.GetTable(tableType); 155 rowEnumerator = table.GetEnumerator(); 156 count = DataSetBuilder.CountEntities(new OKBDataContext(), tableType); 157 return tableTemplate; 158 } 170 159 } 171 160 … … 198 187 Dispose(); 199 188 } 200 201 189 #endregion 202 190 203 191 #region IDisposable Members 204 205 192 /// <summary> 206 193 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. … … 210 197 properties = null; 211 198 } 212 213 199 #endregion 214 200 }
Note: See TracChangeset
for help on using the changeset viewer.