Changeset 13550 for trunk/sources
- Timestamp:
- 01/19/16 08:38:56 (9 years ago)
- Location:
- trunk/sources
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.Designer.cs
r13540 r13550 216 216 this.calculatorListView.UseCompatibleStateImageBehavior = false; 217 217 this.calculatorListView.View = System.Windows.Forms.View.Details; 218 this.calculatorListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.calculatorListView_ItemChecked); 218 219 // 219 220 // characteristicColumnHeader -
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
r13540 r13550 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Globalization;25 24 using System.Linq; 26 25 using System.Windows.Forms; … … 92 91 uploadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly 93 92 && characteristicsMatrixView.Content != null && characteristicsMatrixView.Content.Rows > 0; 93 calculateButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly && calculatorListView.CheckedItems.Count > 0; 94 94 } 95 95 … … 114 114 var item = calculatorListView.Items.Add(c, c); 115 115 item.Group = group; 116 item.Checked = true; 116 117 } 117 118 } … … 186 187 try { 187 188 RunCreationClient.SetCharacteristicValues(Content.ProblemId, values); 188 } catch (Exception ex) { PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex); }189 } catch (Exception ex) { ErrorHandling.ShowErrorDialog(ex); } 189 190 } 190 191 private void calculateButton_Click(object sender, EventArgs e) { 192 var characteristics = calculatorListView.CheckedItems.OfType<ListViewItem>().GroupBy(x => x.Group).ToList(); 193 if (characteristics.Count == 0) return; 191 194 var problem = Content.CloneProblem(); 192 var characteristics = calculatorListView.CheckedItems.OfType<ListViewItem>().GroupBy(x => x.Group); 193 var results = new Dictionary<string, double>(); 195 var results = new Dictionary<string, Value>(); 194 196 foreach (var c in characteristics) { 195 197 var calc = (ICharacteristicCalculator)c.Key.Tag; 196 198 foreach (var result in calc.Calculate(problem, c.Select(x => x.Text).ToArray())) 197 results[result.Key] = result.Value; 198 } 199 var matrix = characteristicsMatrixView.Content as StringMatrix; 200 if (matrix == null) matrix = new StringMatrix(results.Count, 3); 199 results[result.Key] = RunCreationClient.Instance.ConvertToValue(result.Value, result.Key); 200 } 201 var matrix = (characteristicsMatrixView.Content as StringMatrix) ?? (new StringMatrix(results.Count, 3)); 201 202 for (var i = 0; i < matrix.Rows; i++) { 202 double r;203 Value r; 203 204 if (results.TryGetValue(matrix[i, 0], out r)) { 204 matrix[i, 1] = r. ToString(CultureInfo.CurrentCulture.NumberFormat);205 matrix[i, 2] = "DoubleValue";205 matrix[i, 1] = r.GetValue(); 206 matrix[i, 2] = r.GetType().Name; 206 207 results.Remove(matrix[i, 0]); 207 208 } … … 213 214 if (string.IsNullOrEmpty(matrix[i, 0])) { 214 215 matrix[i, 0] = resultsList[counter].Key; 215 matrix[i, 1] = resultsList[counter].Value. ToString(CultureInfo.CurrentCulture.NumberFormat);216 matrix[i, 2] = "DoubleValue";216 matrix[i, 1] = resultsList[counter].Value.GetValue(); 217 matrix[i, 2] = resultsList[counter].Value.GetType().Name; 217 218 resultsList.RemoveAt(counter); 218 219 counter--; … … 224 225 for (var i = matrix.Rows - 1; counter >= 0; i--) { 225 226 matrix[i, 0] = resultsList[0].Key; 226 matrix[i, 1] = resultsList[0].Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 227 matrix[i, 2] = "DoubleValue"; 227 matrix[i, 1] = resultsList[0].Value.GetValue(); 228 matrix[i, 2] = resultsList[0].Value.GetType().Name; 229 resultsList.RemoveAt(0); 228 230 counter--; 229 231 } 230 232 } 233 SetEnabledStateOfControls(); 234 } 235 private void calculatorListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 236 SetEnabledStateOfControls(); 231 237 } 232 238 #endregion … … 239 245 } 240 246 #endregion 247 241 248 } 242 249 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/RunCreationClient.cs
r13534 r13550 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.Data; 30 using HeuristicLab.Persistence.Default.Xml; 28 31 29 32 namespace HeuristicLab.Clients.OKB.RunCreation { … … 114 117 #endregion 115 118 119 #region OKB-Item Conversion 120 public IItem ConvertToItem(Value value) { 121 if (value is BinaryValue) { 122 IItem item = null; 123 var binaryValue = (BinaryValue)value; 124 if (binaryValue.Value != null) { 125 using (var stream = new MemoryStream(binaryValue.Value)) { 126 try { 127 item = XmlParser.Deserialize<IItem>(stream); 128 } catch (Exception) { } 129 stream.Close(); 130 } 131 } 132 return item ?? new Data.StringValue(value.DataType.Name); 133 } else if (value is BoolValue) { 134 return new Data.BoolValue(((BoolValue)value).Value); 135 } else if (value is FloatValue) { 136 return new Data.DoubleValue(((FloatValue)value).Value); 137 } else if (value is PercentValue) { 138 return new Data.PercentValue(((PercentValue)value).Value); 139 } else if (value is DoubleValue) { 140 return new Data.DoubleValue(((DoubleValue)value).Value); 141 } else if (value is IntValue) { 142 return new Data.IntValue((int)((IntValue)value).Value); 143 } else if (value is LongValue) { 144 return new Data.IntValue((int)((LongValue)value).Value); 145 } else if (value is StringValue) { 146 return new Data.StringValue(((StringValue)value).Value); 147 } else if (value is TimeSpanValue) { 148 return new Data.TimeSpanValue(TimeSpan.FromSeconds((long)((TimeSpanValue)value).Value)); 149 } 150 return null; 151 } 152 153 public Value ConvertToValue(IItem item, string name) { 154 Value result = null; 155 if (item is ValueTypeValue<bool>) { 156 var boolValue = (ValueTypeValue<bool>)item; 157 result = new BoolValue() { Value = boolValue.Value }; 158 } else if (item is ValueTypeValue<int>) { 159 var intValue = (ValueTypeValue<int>)item; 160 result = new IntValue() { Value = intValue.Value }; 161 } else if (item is ValueTypeValue<long>) { 162 var longValue = (ValueTypeValue<long>)item; 163 result = new LongValue() { Value = longValue.Value }; 164 } else if (item is ValueTypeValue<float>) { 165 var floatValue = (ValueTypeValue<float>)item; 166 result = new FloatValue() { Value = floatValue.Value }; 167 } else if (item is ValueTypeValue<double>) { 168 var doubleValue = (ValueTypeValue<double>)item; 169 if (item is Data.PercentValue) result = new PercentValue() { Value = doubleValue.Value }; 170 else result = new DoubleValue() { Value = doubleValue.Value }; 171 } else if (item is ValueTypeValue<TimeSpan>) { 172 var timeSpanValue = (ValueTypeValue<TimeSpan>)item; 173 result = new TimeSpanValue() { Value = (long)timeSpanValue.Value.TotalSeconds }; 174 } else if (item is Data.StringValue) { 175 var stringValue = (Data.StringValue)item; 176 result = new StringValue() { Value = stringValue.Value }; 177 } 178 if (result == null) { 179 var binaryValue = new BinaryValue { 180 DataType = new DataType() { 181 Name = item.GetType().Name, 182 TypeName = item.GetType().AssemblyQualifiedName 183 } 184 }; 185 using (var memStream = new MemoryStream()) { 186 XmlGenerator.Serialize(item, memStream); 187 binaryValue.Value = memStream.ToArray(); 188 } 189 result = binaryValue; 190 } 191 result.Name = name; 192 return result; 193 } 194 #endregion 195 116 196 #region Events 117 197 public event EventHandler Refreshing; -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/BoolValue.cs
r13534 r13550 24 24 namespace HeuristicLab.Clients.OKB.RunCreation { 25 25 public partial class BoolValue { 26 26 27 public BoolValue() { 27 28 DataType = new DataType() { … … 31 32 } 32 33 33 public override string ToString() {34 public override string GetValue() { 34 35 return Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 35 36 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/DoubleValue.cs
r13534 r13550 31 31 } 32 32 33 public override string ToString() {33 public override string GetValue() { 34 34 return Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 35 35 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/FloatValue.cs
r13534 r13550 31 31 } 32 32 33 public override string ToString() {33 public override string GetValue() { 34 34 return Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 35 35 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/IntValue.cs
r13534 r13550 31 31 } 32 32 33 public override string ToString() {33 public override string GetValue() { 34 34 return Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 35 35 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/LongValue.cs
r13534 r13550 31 31 } 32 32 33 public override string ToString() {33 public override string GetValue() { 34 34 return Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 35 35 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/PercentValue.cs
r13534 r13550 31 31 } 32 32 33 public override string ToString() {34 return (100 * Value).ToString(CultureInfo.CurrentCulture.NumberFormat) + "%";33 public override string GetValue() { 34 return Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 35 35 } 36 36 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/StringValue.cs
r13534 r13550 30 30 } 31 31 32 public override string ToString() {32 public override string GetValue() { 33 33 return Value; 34 34 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/TimeSpanValue.cs
r13534 r13550 31 31 } 32 32 33 public override string ToString() {34 return Value.ToString(CultureInfo.CurrentCulture. DateTimeFormat);33 public override string GetValue() { 34 return Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 35 35 } 36 36 } -
trunk/sources/HeuristicLab.Clients.OKB/3.3/RunCreation/ServiceClient/Value.cs
r13534 r13550 26 26 namespace HeuristicLab.Clients.OKB.RunCreation { 27 27 public partial class Value { 28 public virtual string GetValue() { 29 return string.Empty; 30 } 31 28 32 public static Value Create(string name, string strValue, string type) { 29 33 switch (type) {
Note: See TracChangeset
for help on using the changeset viewer.