- Timestamp:
- 06/28/17 22:10:45 (7 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13501,13503,13511,13513,13534-13535,13540,13550,13552,13593,13666
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs
r14186 r15081 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Data.Linq; … … 135 136 } 136 137 } 138 139 public IEnumerable<DataTransfer.Value> GetCharacteristicValues(long problemId) { 140 using (OKBDataContext okb = new OKBDataContext()) { 141 var prob = okb.Problems.SingleOrDefault(x => x.Id == problemId); 142 if (prob == null) return Enumerable.Empty<DataTransfer.Value>(); 143 return prob.CharacteristicValues.Select(Convert.ToDto).ToArray(); 144 } 145 } 146 147 public void SetCharacteristicValue(long problemId, DataTransfer.Value value) { 148 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 149 150 using (OKBDataContext okb = new OKBDataContext()) { 151 var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId); 152 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId)); 153 154 DoSetCharacteristicValue(okb, problem, value); 155 okb.SubmitChanges(); 156 } 157 } 158 159 public void SetCharacteristicValues(long problemId, DataTransfer.Value[] values) { 160 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 161 162 using (OKBDataContext okb = new OKBDataContext()) { 163 var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId); 164 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId)); 165 166 foreach (var v in values) { 167 DoSetCharacteristicValue(okb, problem, v); 168 } 169 okb.SubmitChanges(); 170 } 171 } 172 173 private void DoSetCharacteristicValue(OKBDataContext okb, Problem problem, DataTransfer.Value value) { 174 CharacteristicType characteristicType; 175 try { 176 characteristicType = GetCharacteristicType(value); 177 } catch (ArgumentException ex) { 178 throw new FaultException<UnknownCharacteristicType>(new UnknownCharacteristicType(ex.Message)); 179 } 180 181 var entity = problem.CharacteristicValues.SingleOrDefault(x => x.Characteristic.Name == value.Name && x.Characteristic.Type == characteristicType); 182 if (entity != null) { 183 // Update 184 switch (characteristicType) { 185 case CharacteristicType.Bool: entity.BoolValue = ((DataTransfer.BoolValue)value).Value; break; 186 case CharacteristicType.Int: entity.IntValue = ((DataTransfer.IntValue)value).Value; break; 187 case CharacteristicType.Long: entity.LongValue = ((DataTransfer.LongValue)value).Value; break; 188 case CharacteristicType.Float: entity.FloatValue = ((DataTransfer.FloatValue)value).Value; break; 189 case CharacteristicType.Double: entity.DoubleValue = ((DataTransfer.DoubleValue)value).Value; break; 190 case CharacteristicType.Percent: entity.DoubleValue = ((DataTransfer.PercentValue)value).Value; break; 191 case CharacteristicType.String: entity.StringValue = ((DataTransfer.StringValue)value).Value; break; 192 case CharacteristicType.TimeSpan: entity.LongValue = ((DataTransfer.TimeSpanValue)value).Value; break; 193 } 194 } else { 195 // Insert 196 entity = Convert.ToEntity(value, okb, problem, characteristicType); 197 okb.CharacteristicValues.InsertOnSubmit(entity); 198 } 199 200 } 201 202 private CharacteristicType GetCharacteristicType(DataTransfer.Value source) { 203 if (source is DataTransfer.BoolValue) { 204 return CharacteristicType.Bool; 205 } else if (source is DataTransfer.IntValue) { 206 return CharacteristicType.Int; 207 } else if (source is DataTransfer.TimeSpanValue) { 208 return CharacteristicType.TimeSpan; 209 } else if (source is DataTransfer.LongValue) { 210 return CharacteristicType.Long; 211 } else if (source is DataTransfer.FloatValue) { 212 return CharacteristicType.Float; 213 } else if (source is DataTransfer.DoubleValue) { 214 return CharacteristicType.Double; 215 } else if (source is DataTransfer.PercentValue) { 216 return CharacteristicType.Percent; 217 } else if (source is DataTransfer.StringValue) { 218 return CharacteristicType.String; 219 } else { 220 throw new ArgumentException("Unknown characteristic type.", "source"); 221 } 222 } 137 223 } 138 224 }
Note: See TracChangeset
for help on using the changeset viewer.