Changeset 13474
- Timestamp:
- 12/16/15 17:00:31 (9 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/QueryView.cs
r12012 r13474 23 23 using System.Collections; 24 24 using System.Collections.Generic; 25 using System.IO;26 25 using System.Linq; 27 26 using System.Threading; 28 27 using System.Threading.Tasks; 29 28 using System.Windows.Forms; 30 using HeuristicLab.Core;31 29 using HeuristicLab.MainForm; 32 30 using HeuristicLab.MainForm.WindowsForms; 33 31 using HeuristicLab.Optimization; 34 using HeuristicLab.Persistence.Default.Xml;35 32 using HeuristicLab.PluginInfrastructure; 36 33 … … 103 100 cancellationToken.ThrowIfCancellationRequested(); 104 101 if (AllValueNamesChecked()) { 105 runs.AddRange(QueryClient.Instance.GetRuns(ids.Take(batchSize), includeBinaryValues).Select(x => ConvertToOptimizationRun(x)));102 runs.AddRange(QueryClient.Instance.GetRuns(ids.Take(batchSize), includeBinaryValues).Select(x => QueryClient.Instance.ConvertToOptimizationRun(x))); 106 103 } else { 107 runs.AddRange(QueryClient.Instance.GetRunsWithValues(ids.Take(batchSize), includeBinaryValues, valueNames).Select(x => ConvertToOptimizationRun(x)));104 runs.AddRange(QueryClient.Instance.GetRunsWithValues(ids.Take(batchSize), includeBinaryValues, valueNames).Select(x => QueryClient.Instance.ConvertToOptimizationRun(x))); 108 105 } 109 106 ids = ids.Skip(batchSize); … … 124 121 try { 125 122 t.Wait(); 126 } 127 catch (AggregateException ex) { 123 } catch (AggregateException ex) { 128 124 try { 129 125 ex.Flatten().Handle(x => x is OperationCanceledException); 130 } 131 catch (AggregateException remaining) { 126 } catch (AggregateException remaining) { 132 127 if (remaining.InnerExceptions.Count == 1) ErrorHandling.ShowErrorDialog(this, "Refresh results failed.", remaining.InnerExceptions[0]); 133 128 else ErrorHandling.ShowErrorDialog(this, "Refresh results failed.", remaining); … … 195 190 } 196 191 197 private Optimization.IRun ConvertToOptimizationRun(Run run) {198 Optimization.Run optRun = new Optimization.Run();199 foreach (Value value in run.ParameterValues)200 optRun.Parameters.Add(value.Name, ConvertToItem(value));201 foreach (Value value in run.ResultValues)202 optRun.Results.Add(value.Name, ConvertToItem(value));203 return optRun;204 }205 206 private IItem ConvertToItem(Value value) {207 if (value is BinaryValue) {208 IItem item = null;209 BinaryValue binaryValue = (BinaryValue)value;210 if (binaryValue.Value != null) {211 using (MemoryStream stream = new MemoryStream(binaryValue.Value)) {212 try {213 item = XmlParser.Deserialize<IItem>(stream);214 }215 catch (Exception) { }216 stream.Close();217 }218 }219 return item != null ? item : new Data.StringValue(value.DataType.Name);220 } else if (value is BoolValue) {221 return new Data.BoolValue(((BoolValue)value).Value);222 } else if (value is FloatValue) {223 return new Data.DoubleValue(((FloatValue)value).Value);224 } else if (value is PercentValue) {225 return new Data.PercentValue(((PercentValue)value).Value);226 } else if (value is DoubleValue) {227 return new Data.DoubleValue(((DoubleValue)value).Value);228 } else if (value is IntValue) {229 return new Data.IntValue((int)((IntValue)value).Value);230 } else if (value is LongValue) {231 return new Data.IntValue((int)((LongValue)value).Value);232 } else if (value is StringValue) {233 return new Data.StringValue(((StringValue)value).Value);234 } else if (value is TimeSpanValue) {235 return new Data.TimeSpanValue(TimeSpan.FromSeconds((long)((TimeSpanValue)value).Value));236 }237 return null;238 }239 240 192 private void SetCheckedState(bool val) { 241 193 for (int i = 0; i < constraintsCheckedListBox.Items.Count; i++) { -
trunk/sources/HeuristicLab.Clients.OKB/3.3/Query/QueryClient.cs
r12012 r13474 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.IO; 24 25 using System.Linq; 25 26 using HeuristicLab.Clients.Common; 26 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Core; 29 using HeuristicLab.Persistence.Default.Xml; 28 30 29 31 namespace HeuristicLab.Clients.OKB.Query { … … 61 63 filters.AddRange(CallQueryService<List<Filter>>(s => s.GetFilters())); 62 64 valueNames.AddRange(CallQueryService<List<ValueName>>(s => s.GetValueNames())); 63 } 64 finally { 65 } finally { 65 66 OnRefreshed(); 66 67 } … … 70 71 try { 71 72 Refresh(); 72 } 73 catch (Exception ex) { 73 } catch (Exception ex) { 74 74 return ex; 75 75 } … … 98 98 #endregion 99 99 100 #region OKB-Item Conversion 101 public Optimization.IRun ConvertToOptimizationRun(Run run) { 102 Optimization.Run optRun = new Optimization.Run(); 103 foreach (Value value in run.ParameterValues) 104 optRun.Parameters.Add(value.Name, ConvertToItem(value)); 105 foreach (Value value in run.ResultValues) 106 optRun.Results.Add(value.Name, ConvertToItem(value)); 107 return optRun; 108 } 109 110 public IItem ConvertToItem(Value value) { 111 if (value is BinaryValue) { 112 IItem item = null; 113 var binaryValue = (BinaryValue)value; 114 if (binaryValue.Value != null) { 115 using (var stream = new MemoryStream(binaryValue.Value)) { 116 try { 117 item = XmlParser.Deserialize<IItem>(stream); 118 } catch (Exception) { } 119 stream.Close(); 120 } 121 } 122 return item ?? new Data.StringValue(value.DataType.Name); 123 } else if (value is BoolValue) { 124 return new Data.BoolValue(((BoolValue)value).Value); 125 } else if (value is FloatValue) { 126 return new Data.DoubleValue(((FloatValue)value).Value); 127 } else if (value is PercentValue) { 128 return new Data.PercentValue(((PercentValue)value).Value); 129 } else if (value is DoubleValue) { 130 return new Data.DoubleValue(((DoubleValue)value).Value); 131 } else if (value is IntValue) { 132 return new Data.IntValue((int)((IntValue)value).Value); 133 } else if (value is LongValue) { 134 return new Data.IntValue((int)((LongValue)value).Value); 135 } else if (value is StringValue) { 136 return new Data.StringValue(((StringValue)value).Value); 137 } else if (value is TimeSpanValue) { 138 return new Data.TimeSpanValue(TimeSpan.FromSeconds((long)((TimeSpanValue)value).Value)); 139 } 140 return null; 141 } 142 #endregion 143 100 144 #region Events 101 145 public event EventHandler Refreshing; … … 116 160 try { 117 161 return call(client); 118 } 119 finally { 162 } finally { 120 163 try { 121 164 client.Close(); 122 } 123 catch (Exception) { 165 } catch (Exception) { 124 166 client.Abort(); 125 167 }
Note: See TracChangeset
for help on using the changeset viewer.