Changeset 10580
- Timestamp:
- 03/12/14 15:30:38 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataPreprocessingChangedEvent.cs
r10551 r10580 29 29 DeleteRow, 30 30 AddRow, 31 ChangeItem 31 ChangeItem, 32 Any 32 33 } 33 34 -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ManipulationLogic.cs
r10539 r10580 126 126 Random random = new Random(); 127 127 128 preprocessingData.BeginTransaction(); 128 129 // process all given ranges - e.g. TrainingPartition, Trainingpartition 129 130 foreach (IntRange range in ranges) { … … 138 139 ReOrderToIndices(shuffledIndices); 139 140 } 141 preprocessingData.EndTransaction(); 140 142 } 141 143 … … 151 153 152 154 public void ReOrderToIndices(IList<System.Tuple<int, int>> indices) { 155 preprocessingData.BeginTransaction(); 153 156 for (int i = 0; i < preprocessingData.Columns; ++i) { 154 157 if (preprocessingData.IsType<double>(i)) { … … 160 163 } 161 164 } 165 preprocessingData.EndTransaction(); 162 166 } 163 167 -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingData.cs
r10554 r10580 57 57 58 58 private IList<PDSnapshot> undoHistory; 59 60 //TODO: refactor extract Transaction logic in a own class 61 private int transactionDepth = 0; 59 62 60 63 private PreprocessingData(PreprocessingData original, Cloner cloner) … … 109 112 110 113 private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) { 114 if (transactionDepth > 0) return; 115 111 116 PDSnapshot currentSnapshot = new PDSnapshot(); 112 117 currentSnapshot.VariableValues = CopyVariableValues(variableValues); … … 141 146 SaveSnapshot(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex); 142 147 variableValues[columnIndex][rowIndex] = value; 143 OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex); 148 if (transactionDepth <= 0) 149 OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex); 144 150 } 145 151 … … 166 172 throw new ArgumentException("The datatype of column " + columnIndex + " must be of type " + variableValues[columnIndex].GetType().Name + " but was " + typeof(T).Name); 167 173 } 168 OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1); 174 if (transactionDepth <= 0) 175 OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1); 169 176 } 170 177 … … 175 182 column.Insert(rowIndex, type.IsValueType ? Activator.CreateInstance(type) : null); 176 183 } 177 OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex); 184 if (transactionDepth <= 0) 185 OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex); 178 186 } 179 187 … … 183 191 column.RemoveAt(rowIndex); 184 192 } 185 OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex); 193 if (transactionDepth <= 0) 194 OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex); 186 195 } 187 196 … … 190 199 variableValues.Add(columnIndex, new List<T>(Rows)); 191 200 variableNames.Insert(columnIndex, variableName); 192 OnChanged(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1); 201 if (transactionDepth <= 0) 202 OnChanged(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1); 193 203 } 194 204 … … 197 207 variableValues.Remove(columnIndex); 198 208 variableNames.RemoveAt(columnIndex); 199 OnChanged(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);200 }201 209 if (transactionDepth <= 0) 210 OnChanged(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1); 211 } 202 212 203 213 public IntRange TrainingPartition { … … 267 277 } 268 278 279 public void BeginTransaction() { 280 SaveSnapshot(DataPreprocessingChangedEventType.Any, 0, 0); //TODO: fix event handling, so that the ints can be -1, -1 281 transactionDepth++; 282 } 283 284 public void EndTransaction() { 285 transactionDepth--; 286 if (transactionDepth < 0) 287 throw new InvalidOperationException("There is no open transaction that can be ended."); 288 if (transactionDepth == 0) 289 OnChanged(DataPreprocessingChangedEventType.Any, 0, 0); //TODO: fix event handling, so that the ints can be -1, -1 290 } 291 269 292 #endregion 270 293 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IPreprocessingData.cs
r10547 r10580 66 66 bool IsUndoAvailable { get; } 67 67 void Undo(); 68 void BeginTransaction(); 69 void EndTransaction(); 68 70 } 69 71 }
Note: See TracChangeset
for help on using the changeset viewer.