Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10580


Ignore:
Timestamp:
03/12/14 15:30:38 (11 years ago)
Author:
tsteinre
Message:
  • Added transaction support for DataPreprocessing (Undo Feature)
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  
    2929    DeleteRow,
    3030    AddRow,
    31     ChangeItem
     31    ChangeItem,
     32    Any
    3233  }
    3334
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ManipulationLogic.cs

    r10539 r10580  
    126126      Random random = new Random();
    127127
     128      preprocessingData.BeginTransaction();
    128129      // process all given ranges - e.g. TrainingPartition, Trainingpartition
    129130      foreach (IntRange range in ranges) {
     
    138139        ReOrderToIndices(shuffledIndices);
    139140      }
     141      preprocessingData.EndTransaction();
    140142    }
    141143
     
    151153
    152154    public void ReOrderToIndices(IList<System.Tuple<int, int>> indices) {
     155      preprocessingData.BeginTransaction();
    153156      for (int i = 0; i < preprocessingData.Columns; ++i) {
    154157        if (preprocessingData.IsType<double>(i)) {
     
    160163        }
    161164      }
     165      preprocessingData.EndTransaction();
    162166    }
    163167
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingData.cs

    r10554 r10580  
    5757
    5858    private IList<PDSnapshot> undoHistory;
     59
     60    //TODO: refactor extract Transaction logic in a own class
     61    private int transactionDepth = 0;
    5962
    6063    private PreprocessingData(PreprocessingData original, Cloner cloner)
     
    109112
    110113    private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) {
     114      if (transactionDepth > 0) return;
     115
    111116      PDSnapshot currentSnapshot = new PDSnapshot();
    112117      currentSnapshot.VariableValues = CopyVariableValues(variableValues);
     
    141146      SaveSnapshot(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
    142147      variableValues[columnIndex][rowIndex] = value;
    143       OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
     148      if (transactionDepth <= 0)
     149        OnChanged(DataPreprocessingChangedEventType.ChangeItem, columnIndex, rowIndex);
    144150    }
    145151
     
    166172        throw new ArgumentException("The datatype of column " + columnIndex + " must be of type " + variableValues[columnIndex].GetType().Name + " but was " + typeof(T).Name);
    167173      }
    168       OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
     174      if (transactionDepth <= 0)
     175        OnChanged(DataPreprocessingChangedEventType.ChangeColumn, columnIndex, -1);
    169176    }
    170177
     
    175182        column.Insert(rowIndex, type.IsValueType ? Activator.CreateInstance(type) : null);
    176183      }
    177       OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
     184      if (transactionDepth <= 0)
     185        OnChanged(DataPreprocessingChangedEventType.AddRow, -1, rowIndex);
    178186    }
    179187
     
    183191        column.RemoveAt(rowIndex);
    184192      }
    185       OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
     193      if (transactionDepth <= 0)
     194        OnChanged(DataPreprocessingChangedEventType.DeleteRow, -1, rowIndex);
    186195    }
    187196
     
    190199      variableValues.Add(columnIndex, new List<T>(Rows));
    191200      variableNames.Insert(columnIndex, variableName);
    192       OnChanged(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1);
     201      if (transactionDepth <= 0)
     202        OnChanged(DataPreprocessingChangedEventType.AddColumn, columnIndex, -1);
    193203    }
    194204
     
    197207      variableValues.Remove(columnIndex);
    198208      variableNames.RemoveAt(columnIndex);
    199       OnChanged(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);
    200     }
    201 
     209      if (transactionDepth <= 0)
     210        OnChanged(DataPreprocessingChangedEventType.DeleteColumn, columnIndex, -1);
     211    }
    202212
    203213    public IntRange TrainingPartition {
     
    267277    }
    268278
     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
    269292    #endregion
    270293  }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IPreprocessingData.cs

    r10547 r10580  
    6666    bool IsUndoAvailable { get; }
    6767    void Undo();
     68    void BeginTransaction();
     69    void EndTransaction();
    6870  }
    6971}
Note: See TracChangeset for help on using the changeset viewer.