Changeset 7741
- Timestamp:
- 04/18/12 20:01:42 (13 years ago)
- Location:
- branches/OKB (trunk integration)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OKB (trunk integration)/HeuristicLab.Clients.OKB/3.3/RunCreation/OKBRun.cs
r7634 r7741 190 190 List<Value> ConvertToValues(IDictionary<string, IItem> items) { 191 191 List<Value> values = new List<Value>(); 192 bool add = true; 192 193 foreach (var item in items) { 193 194 Value value; … … 208 209 v.Value = ((Data.PercentValue)item.Value).Value; 209 210 value = v; 211 if (double.IsNaN(v.Value)) { 212 add = false; 213 } 210 214 } else if (item.Value is Data.DoubleValue) { 211 215 DoubleValue v = new DoubleValue(); 212 216 v.Value = ((Data.DoubleValue)item.Value).Value; 213 217 value = v; 218 if (double.IsNaN(v.Value)) { 219 add = false; 220 } 214 221 } else if (item.Value is Data.StringValue) { 215 222 StringValue v = new StringValue(); … … 225 232 value = v; 226 233 } 227 value.Name = item.Key; 228 value.DataType = new DataType(); 229 value.DataType.Name = item.Value.GetType().Name; 230 value.DataType.TypeName = item.Value.GetType().AssemblyQualifiedName; 231 values.Add(value); 234 if (add) { 235 value.Name = item.Key; 236 value.DataType = new DataType(); 237 value.DataType.Name = item.Value.GetType().Name; 238 value.DataType.TypeName = item.Value.GetType().AssemblyQualifiedName; 239 values.Add(value); 240 } else { 241 add = true; 242 } 232 243 } 233 244 return values; -
branches/OKB (trunk integration)/HeuristicLab.Services.OKB/3.3/RunCreation/Convert.cs
r7574 r7741 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Security.Cryptography; … … 58 59 public static DA.Run ToEntity(DT.Run source, DA.OKBDataContext okb) { 59 60 if (source == null) return null; 61 62 List<DA.BinaryData> binCache = new List<DA.BinaryData>(); 63 60 64 DA.Run entity = new DA.Run { Id = 0, AlgorithmId = source.AlgorithmId, ProblemId = source.ProblemId, CreatedDate = source.CreatedDate, UserId = source.UserId, ClientId = source.ClientId }; 61 65 foreach (var value in source.ParameterValues) 62 entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Parameter, okb ));66 entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Parameter, okb, binCache)); 63 67 foreach (var value in source.ResultValues) 64 entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb ));68 entity.Values.Add(Convert.ToEntity(value, entity, DA.ValueNameCategory.Result, okb, binCache)); 65 69 return entity; 66 70 } 67 71 68 private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb ) {72 private static DA.Value ToEntity(DT.Value source, DA.Run run, DA.ValueNameCategory category, DA.OKBDataContext okb, List<DA.BinaryData> binCache) { 69 73 if (source == null) return null; 70 74 var entity = new DA.Value(); … … 97 101 } else if (source is DT.BinaryValue) { 98 102 entity.ValueName = Convert.ToEntity(source.Name, category, DA.ValueNameType.Binary, okb); 99 entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb );103 entity.BinaryData = Convert.ToEntity(((DT.BinaryValue)source).Value, okb, binCache); 100 104 } else { 101 105 throw new ArgumentException("Unknown value type.", "source"); … … 120 124 } 121 125 122 private static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb ) {126 private static DA.BinaryData ToEntity(byte[] data, DA.OKBDataContext okb, List<DA.BinaryData> binCache) { 123 127 if (data == null) return null; 124 128 byte[] hash; … … 126 130 hash = sha1.ComputeHash(data); 127 131 } 132 133 var cachedBinaryData = binCache.Where(x => x.Hash.SequenceEqual(hash)).FirstOrDefault(); 134 if (cachedBinaryData != null) 135 return cachedBinaryData; 136 128 137 var entity = okb.BinaryDatas.Where(x => x.Hash.Equals(hash)).FirstOrDefault(); 129 if (entity == null) 138 if (entity == null) { 130 139 entity = new DA.BinaryData() { Id = 0, Data = data, Hash = hash }; 140 binCache.Add(entity); 141 } 142 131 143 return entity; 132 144 }
Note: See TracChangeset
for help on using the changeset viewer.