Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15055


Ignore:
Timestamp:
06/25/17 15:22:47 (7 years ago)
Author:
gkronber
Message:

#2547 merged r13474 from trunk to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Clients.OKB.Views/3.3/Query/Views/QueryView.cs

    r14186 r15055  
    2323using System.Collections;
    2424using System.Collections.Generic;
    25 using System.IO;
    2625using System.Linq;
    2726using System.Threading;
    2827using System.Threading.Tasks;
    2928using System.Windows.Forms;
    30 using HeuristicLab.Core;
    3129using HeuristicLab.MainForm;
    3230using HeuristicLab.MainForm.WindowsForms;
    3331using HeuristicLab.Optimization;
    34 using HeuristicLab.Persistence.Default.Xml;
    3532using HeuristicLab.PluginInfrastructure;
    3633
     
    103100          cancellationToken.ThrowIfCancellationRequested();
    104101          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)));
    106103          } 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)));
    108105          }
    109106          ids = ids.Skip(batchSize);
     
    124121          try {
    125122            t.Wait();
    126           }
    127           catch (AggregateException ex) {
     123          } catch (AggregateException ex) {
    128124            try {
    129125              ex.Flatten().Handle(x => x is OperationCanceledException);
    130             }
    131             catch (AggregateException remaining) {
     126            } catch (AggregateException remaining) {
    132127              if (remaining.InnerExceptions.Count == 1) ErrorHandling.ShowErrorDialog(this, "Refresh results failed.", remaining.InnerExceptions[0]);
    133128              else ErrorHandling.ShowErrorDialog(this, "Refresh results failed.", remaining);
     
    195190    }
    196191
    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 
    240192    private void SetCheckedState(bool val) {
    241193      for (int i = 0; i < constraintsCheckedListBox.Items.Count; i++) {
  • stable/HeuristicLab.Clients.OKB/3.3/Query/QueryClient.cs

    r14186 r15055  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using System.Linq;
    2526using HeuristicLab.Clients.Common;
    2627using HeuristicLab.Common;
    2728using HeuristicLab.Core;
     29using HeuristicLab.Persistence.Default.Xml;
    2830
    2931namespace HeuristicLab.Clients.OKB.Query {
     
    6163        filters.AddRange(CallQueryService<List<Filter>>(s => s.GetFilters()));
    6264        valueNames.AddRange(CallQueryService<List<ValueName>>(s => s.GetValueNames()));
    63       }
    64       finally {
     65      } finally {
    6566        OnRefreshed();
    6667      }
     
    7071        try {
    7172          Refresh();
    72         }
    73         catch (Exception ex) {
     73        } catch (Exception ex) {
    7474          return ex;
    7575        }
     
    9898    #endregion
    9999
     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
    100144    #region Events
    101145    public event EventHandler Refreshing;
     
    116160      try {
    117161        return call(client);
    118       }
    119       finally {
     162      } finally {
    120163        try {
    121164          client.Close();
    122         }
    123         catch (Exception) {
     165        } catch (Exception) {
    124166          client.Abort();
    125167        }
Note: See TracChangeset for help on using the changeset viewer.