public void BatchRenameTablesFixupTest() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddTable("T1"); var t2 = model.AddTable("T2"); var m3 = t1.AddMeasure("M3", "COUNTROWS(T1)+COUNTROWS(T2)"); handler.BeginUpdate("Batch rename"); t1.Name = "T1X"; t2.Name = "T2X"; handler.EndUpdate(); Assert.AreEqual("COUNTROWS('T1X')+COUNTROWS('T2X')", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("COUNTROWS(T1)+COUNTROWS(T2)", m3.Expression); handler.BeginUpdate("Batch rename"); t2.Name = "T2X"; t1.Name = "T1X"; handler.EndUpdate(); Assert.AreEqual("COUNTROWS('T1X')+COUNTROWS('T2X')", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("COUNTROWS(T1)+COUNTROWS(T2)", m3.Expression); }
public void BatchRenameMeasuresFixupTest() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddTable(); var m1 = t1.AddMeasure("M1", "1"); var m2 = t1.AddMeasure("M2", "2"); var m3 = t1.AddMeasure("M3", "[M1]+[M2]"); handler.BeginUpdate("Batch rename"); m1.Name = "M1X"; m2.Name = "M2X"; handler.EndUpdate(); Assert.AreEqual("[M1X]+[M2X]", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("[M1]+[M2]", m3.Expression); handler.BeginUpdate("Batch rename"); m2.Name = "M2X"; m1.Name = "M1X"; handler.EndUpdate(); Assert.AreEqual("[M1X]+[M2X]", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("[M1]+[M2]", m3.Expression); }
public void BatchRenameColumnsFixupTest() { var handler = new TabularModelHandler(); var model = handler.Model; var t1 = model.AddTable("T1"); var c1 = t1.AddDataColumn("C1"); var c2 = t1.AddDataColumn("C2"); var m3 = t1.AddMeasure("M3", "SUM('T1'[C1])+SUM('T1'[C2])"); handler.BeginUpdate("Batch rename"); c1.Name = "C1X"; c2.Name = "C2X"; handler.EndUpdate(); Assert.AreEqual("SUM('T1'[C1X])+SUM('T1'[C2X])", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("SUM('T1'[C1])+SUM('T1'[C2])", m3.Expression); handler.BeginUpdate("Batch rename"); c2.Name = "C2X"; c1.Name = "C1X"; handler.EndUpdate(); Assert.AreEqual("SUM('T1'[C1X])+SUM('T1'[C2X])", m3.Expression); handler.UndoManager.Undo(); Assert.AreEqual("SUM('T1'[C1])+SUM('T1'[C2])", m3.Expression); }
public void UIRemoveFolders() { Handler.BeginUpdate("remove folders"); foreach (var f in Selected.FolderObjects) { f.SetFolderName(""); } Handler.EndUpdate(); }
public void BatchActionTest() { var handler = new TabularModelHandler("localhost", "AdventureWorks"); handler.Tree = new MockTree(handler.Model); Assert.AreEqual(0, handler.UndoManager.BatchDepth); Assert.AreEqual(0, handler.UndoManager.UndoSize); handler.BeginUpdate("Batch 1"); handler.BeginUpdate("Batch 1.1"); handler.BeginUpdate("Batch 1.1.1"); Assert.AreEqual(3, handler.UndoManager.UndoSize); Assert.AreEqual(3, handler.UndoManager.BatchDepth); handler.Model.Tables["Reseller Sales"].AddMeasure("Test 1"); // 3 actions (BeginBatch - AddMeasure - EndBatch) handler.Model.Tables["Reseller Sales"].AddMeasure("Test 2"); // 3 actions (BeginBatch - AddMeasure - EndBatch) Assert.AreEqual(5, handler.UndoManager.UndoSize); Assert.AreEqual(3, handler.UndoManager.BatchDepth); handler.EndUpdate(); // Batch 1.1.1 Assert.AreEqual(6, handler.UndoManager.UndoSize); Assert.AreEqual(2, handler.UndoManager.BatchDepth); handler.EndUpdate(); // Batch 1.1 Assert.AreEqual(7, handler.UndoManager.UndoSize); Assert.AreEqual(1, handler.UndoManager.BatchDepth); handler.BeginUpdate("Batch 1.2"); Assert.AreEqual(8, handler.UndoManager.UndoSize); Assert.AreEqual(2, handler.UndoManager.BatchDepth); handler.Model.Tables["Reseller Sales"].AddMeasure("Test 3"); // 4 actions (BeginBatch - AddMeasure - EndBatch) handler.Model.Tables["Reseller Sales"].AddMeasure("Test 4"); // 4 actions (BeginBatch - AddMeasure - EndBatch) Assert.AreEqual(10, handler.UndoManager.UndoSize); Assert.AreEqual(2, handler.UndoManager.BatchDepth); handler.EndUpdate(true, true); // Rollback Batch 1.2 Assert.AreEqual(7, handler.UndoManager.UndoSize); Assert.AreEqual(1, handler.UndoManager.BatchDepth); handler.EndUpdate(true, true); // Rollback Batch 1 Assert.AreEqual(0, handler.UndoManager.BatchDepth); Assert.AreEqual(0, handler.UndoManager.UndoSize); }
public void BatchActionTest() { var handler = new TabularModelHandler(Constants.ServerName, "TomWrapperTest"); Assert.AreEqual(0, handler.UndoManager.BatchDepth); Assert.AreEqual(0, handler.UndoManager.UndoSize); handler.BeginUpdate("Batch 1"); handler.BeginUpdate("Batch 1.1"); handler.BeginUpdate("Batch 1.1.1"); Assert.AreEqual(3, handler.UndoManager.UndoSize); Assert.AreEqual(3, handler.UndoManager.BatchDepth); handler.Model.Tables["Reseller Sales"].AddMeasure("Test 1"); // 3 actions (BeginBatch - AddMeasure - EndBatch) handler.Model.Tables["Reseller Sales"].AddMeasure("Test 2"); // 3 actions (BeginBatch - AddMeasure - EndBatch) Assert.AreEqual(5, handler.UndoManager.UndoSize); Assert.AreEqual(3, handler.UndoManager.BatchDepth); handler.EndUpdate(); // Batch 1.1.1 Assert.AreEqual(6, handler.UndoManager.UndoSize); Assert.AreEqual(2, handler.UndoManager.BatchDepth); handler.EndUpdate(); // Batch 1.1 Assert.AreEqual(7, handler.UndoManager.UndoSize); Assert.AreEqual(1, handler.UndoManager.BatchDepth); handler.BeginUpdate("Batch 1.2"); Assert.AreEqual(8, handler.UndoManager.UndoSize); Assert.AreEqual(2, handler.UndoManager.BatchDepth); handler.Model.Tables["Reseller Sales"].AddMeasure("Test 3"); // 4 actions (BeginBatch - AddMeasure - EndBatch) handler.Model.Tables["Reseller Sales"].AddMeasure("Test 4"); // 4 actions (BeginBatch - AddMeasure - EndBatch) Assert.AreEqual(10, handler.UndoManager.UndoSize); Assert.AreEqual(2, handler.UndoManager.BatchDepth); handler.EndUpdate(true, true); // Rollback Batch 1.2 Assert.AreEqual(7, handler.UndoManager.UndoSize); Assert.AreEqual(1, handler.UndoManager.BatchDepth); handler.EndUpdate(true, true); // Rollback Batch 1 Assert.AreEqual(0, handler.UndoManager.BatchDepth); Assert.AreEqual(0, handler.UndoManager.UndoSize); }
internal void XDo(bool redo, bool inversable) { if (!Enabled) { throw new InvalidOperationException("UndoManager is not enabled."); } //if (undoDepth == -1 && batchDepth != 0) throw new InvalidOperationException("Cannot undo/redo while a batch is in progress."); _handler.BeginUpdate(null); var stack = redo ? _RedoStack : _UndoStack; var inverseStack = redo ? _UndoStack : _RedoStack; if (stack.Count > 0) { inProgress = true; IsRedoing = redo; IsUndoing = !IsRedoing; var item = stack.Pop(); if (redo) { item.Redo(); } else { item.Undo(); } if (inversable) { inverseStack.Push(item); } if (item is UndoBatchAction) { var batchDepth = (item as UndoBatchAction).Depth; do { item = stack.Pop(); if (redo) { item.Redo(); } else { item.Undo(); } if (inversable) { inverseStack.Push(item); } }while (!(item is UndoBatchAction) || (item as UndoBatchAction).Depth > batchDepth); } IsRedoing = false; IsUndoing = false; inProgress = false; } UndoStateChanged?.Invoke(this, new EventArgs()); _handler.EndUpdate(false); }
protected override void CancelChanges() { canceled = true; base.CancelChanges(); handler?.EndUpdate(rollback: true); }