- Timestamp:
- 01/15/16 12:13:51 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.OKB/3.3/RunCreation/RunCreationService.cs
r13501 r13511 137 137 } 138 138 139 140 public void SetCharacteristicValue(long problemId, string characteristicName, DataTransfer.Value value) { 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) { 141 148 roleVerifier.AuthenticateForAnyRole(OKBRoles.OKBAdministrator, OKBRoles.OKBUser); 142 149 … … 144 151 var problem = okb.Problems.SingleOrDefault(x => x.Id == problemId); 145 152 if (problem == null) throw new FaultException<MissingProblem>(new MissingProblem("Problem with id {0} cannot be found", problemId)); 146 CharacteristicType characteristicType; 147 try { 148 characteristicType = GetCharacteristicType(value); 149 } catch (ArgumentException ex) { 150 throw new FaultException<UnknownCharacteristicType>(new UnknownCharacteristicType(ex.Message)); 151 } 152 153 var entity = okb.CharacteristicValues.SingleOrDefault(x => x.Characteristic.Name == characteristicName && x.Characteristic.Type == characteristicType); 154 if (entity != null) { 155 // Update 156 switch (characteristicType) { 157 case CharacteristicType.Bool: entity.BoolValue = ((DataTransfer.BoolValue)value).Value; break; 158 case CharacteristicType.Int: entity.IntValue = ((DataTransfer.IntValue)value).Value; break; 159 case CharacteristicType.Long: entity.LongValue = ((DataTransfer.LongValue)value).Value; break; 160 case CharacteristicType.Float: entity.FloatValue = ((DataTransfer.FloatValue)value).Value; break; 161 case CharacteristicType.Double: entity.DoubleValue = ((DataTransfer.DoubleValue)value).Value; break; 162 case CharacteristicType.Percent: entity.DoubleValue = ((DataTransfer.PercentValue)value).Value; break; 163 case CharacteristicType.String: entity.StringValue = ((DataTransfer.StringValue)value).Value; break; 164 case CharacteristicType.TimeSpan: entity.LongValue = ((DataTransfer.TimeSpanValue)value).Value; break; 165 } 166 } else { 167 // Insert 168 entity = Convert.ToEntity(value, okb, problem, characteristicName, characteristicType); 169 okb.CharacteristicValues.InsertOnSubmit(entity); 170 } 153 154 DoSetCharacteristicValue(okb, problem, value); 171 155 okb.SubmitChanges(); 172 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 = okb.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 173 200 } 174 201
Note: See TracChangeset
for help on using the changeset viewer.