public override void AddToDatabase(FdoCache cache) { if (m_fInDatabase) return; // It's already in the database, so nothing more can be done. using (var undoHelper = new UndoableUnitOfWorkHelper( cache.ServiceLocator.GetInstance<IActionHandler>(), MGAStrings.ksUndoCreateInflectionFeature, MGAStrings.ksRedoCreateInflectionFeature)) { m_featDefn = cache.LanguageProject.MsFeatureSystemOA.AddFeatureFromXml(m_node); // Attempt to add feature to category as an inflectable feature var sPosId = XmlUtils.GetOptionalAttributeValue(m_node, "posid"); var node = m_node; while (node.ParentNode != null && sPosId == null) { node = node.ParentNode; sPosId = XmlUtils.GetOptionalAttributeValue(node, "posid"); } foreach (IPartOfSpeech pos in cache.LanguageProject.PartsOfSpeechOA.ReallyReallyAllPossibilities) { if (pos.CatalogSourceId == sPosId) { pos.InflectableFeatsRC.Add(m_featDefn); break; } } undoHelper.RollBack = false; } }
protected override void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { using (var undoHelper = new UndoableUnitOfWorkHelper( m_cache.ServiceLocator.GetInstance<IActionHandler>(), LexTextControls.ksUndoInsertInflectionFeature, LexTextControls.ksRedoInsertInflectionFeature)) { IFsFeatDefn fd; if (m_sClassName == "FsComplexFeature") fd = m_cache.ServiceLocator.GetInstance<IFsComplexFeatureFactory>().Create(); else fd = m_cache.ServiceLocator.GetInstance<IFsClosedFeatureFactory>().Create(); m_cache.LanguageProject.MsFeatureSystemOA.FeaturesOC.Add(fd); IFsFeatStrucType type = m_cache.LanguageProject.MsFeatureSystemOA.GetFeatureType("Infl"); if (type == null) { type = m_cache.ServiceLocator.GetInstance<IFsFeatStrucTypeFactory>().Create(); m_cache.LanguageProject.MsFeatureSystemOA.TypesOC.Add(type); type.CatalogSourceId = "Infl"; foreach (IWritingSystem ws in m_cache.ServiceLocator.WritingSystems.AnalysisWritingSystems) { var tss = m_cache.TsStrFactory.MakeString("Infl", ws.Handle); type.Abbreviation.set_String(ws.Handle, tss); type.Name.set_String(ws.Handle, tss); } } type.FeaturesRS.Add(fd); m_selFeatDefn = fd; undoHelper.RollBack = false; } DialogResult = DialogResult.Yes; Close(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Perform the specified task, making it an undoable task in the specified action handler, with /// the specified labels. The task will automatically be begun and ended if all goes well, and rolled /// back if an exception is thrown; the exception will then be rethrown. /// </summary> /// ------------------------------------------------------------------------------------ public static void Do(string undoText, string redoText, IActionHandler actionHandler, Action task) { using (var undoHelper = new UndoableUnitOfWorkHelper(actionHandler, undoText, redoText)) { task(); undoHelper.RollBack = false; // task ran successfully, don't roll back. } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Perform the specified task, making it an undoable task in the specified action handler, with /// the specified labels. The task will automatically be begun and ended if all goes well, and rolled /// back if an exception is thrown; the exception will then be rethrown. /// </summary> /// ------------------------------------------------------------------------------------ public static void Do(string undoText, string redoText, IActionHandler actionHandler, Action task) { using (var undoHelper = new UndoableUnitOfWorkHelper(actionHandler, undoText, redoText)) { task(); undoHelper.RollBack = false; // task ran successfully, don't roll back. } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Save results when closed. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> that contains the event data.</param> /// ------------------------------------------------------------------------------------ protected override void OnClosed(EventArgs e) { if (DialogResult == DialogResult.OK) { using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper( m_draft.Cache.ServiceLocator.GetInstance<IActionHandler>(), TeResourceHelper.GetResourceString("ksUndoDraftProperties"), TeResourceHelper.GetResourceString("ksRedoDraftProperties"))) { m_draft.Protected = m_cbProtected.Checked; m_draft.Description = m_tbDescription.Text; undoHelper.RollBack = false; } } base.OnClosed(e); }
public override void AddItem(ICmObject obj) { CheckDisposed(); ILexSense selectedSense = obj as ILexSense; IFdoReferenceCollection<IReversalIndexEntry> col = selectedSense.ReversalEntriesRC; if (!col.Contains(m_obj as IReversalIndexEntry)) { int h1 = m_vectorRefView.RootBox.Height; using (UndoableUnitOfWorkHelper helper = new UndoableUnitOfWorkHelper( m_cache.ActionHandlerAccessor, LexEdStrings.ksUndoAddRevToSense, LexEdStrings.ksRedoAddRevToSense)) { col.Add(m_obj as IReversalIndexEntry); helper.RollBack = false; } int h2 = m_vectorRefView.RootBox.Height; CheckViewSizeChanged(h1, h2); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the mouse up event. /// </summary> /// <param name="e"></param> /// ------------------------------------------------------------------------------------ protected override void OnMouseUp(MouseEventArgs e) { if (e.Button != MouseButtons.Right) { // If the selection is on the status box of a back translation... Rectangle rcSrcRoot; Rectangle rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); IVwSelection sel = m_rootb.MakeSelAt(e.X, e.Y, rcSrcRoot, rcDstRoot, false); if (sel != null && sel.SelType == VwSelType.kstPicture) { SelectionHelper selHelper = SelectionHelper.Create(sel, this); SelLevInfo[] info = selHelper.LevelInfo; // (check the tag and confirm that the same translation status box is selected on // mouse down and mouse up) if (info[0].tag == StTxtParaTags.kflidTranslations && info[0].hvo == m_selectedTransHvo) { // ...toggle the back translation status to the next status. string undo; string redo; TeResourceHelper.MakeUndoRedoLabels("kstidUndoRedoChangeBackTransStatus", out undo, out redo); using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper( Cache.ServiceLocator.GetInstance<IActionHandler>(), undo, redo)) { ICmTranslation trans = m_fdoCache.ServiceLocator.GetInstance<ICmTranslationRepository>().GetObject(m_selectedTransHvo); BackTranslationStatus btStatus = GetBackTranslationStatus(trans); switch (btStatus) { case BackTranslationStatus.Unfinished: default: SetBackTranslationStatus(trans, BackTranslationStatus.Finished); break; case BackTranslationStatus.Finished: SetBackTranslationStatus(trans, BackTranslationStatus.Checked); break; case BackTranslationStatus.Checked: SetBackTranslationStatus(trans, BackTranslationStatus.Unfinished); break; } undoHelper.RollBack = false; } } } base.OnMouseUp(e); return; } ShowContextMenu(new Point(e.X, e.Y)); }
public void CollapseToMarkTest_ItemAddedThenDeleted() { Assert.AreEqual(0, m_actionHandler.TopMarkHandle); IWfiWordform wordForm; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Object")) { wordForm = m_wordFormFactory.Create(); undoHelper.RollBack = false; } int hMark = m_actionHandler.Mark(); IWfiAnalysis wfiA; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Monkeys")) { wfiA = Cache.ServiceLocator.GetInstance<IWfiAnalysisFactory>().Create(); wordForm.AnalysesOC.Add(wfiA); undoHelper.RollBack = false; } using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Pigs")) { wordForm.AnalysesOC.Remove(wfiA); undoHelper.RollBack = false; } Assert.AreEqual(5, m_actionHandler.UndoableActionCount); Assert.AreEqual(3, m_actionHandler.UndoableSequenceCount); Assert.AreEqual(0, m_actionHandler.RedoableSequenceCount); m_actionHandler.CollapseToMark(hMark, "Undo....", "Redo...."); Assert.AreEqual(2, m_actionHandler.UndoableSequenceCount); Assert.AreEqual(0, m_actionHandler.RedoableSequenceCount); Assert.AreEqual(0, m_actionHandler.TopMarkHandle); Assert.AreEqual(5, m_actionHandler.UndoableActionCount, "Should still have 5 undoable actions"); Stack<FdoUnitOfWork> undoBundle = (Stack<FdoUnitOfWork>)ReflectionHelper.GetField(m_actionHandler, "m_undoBundles"); List<FdoUnitOfWork> uowList = undoBundle.ToList(); Assert.AreEqual(2, uowList.Count); List<IUndoAction> actionList = (List<IUndoAction>)ReflectionHelper.GetField(uowList[0], "m_changes"); Assert.AreEqual(4, actionList.Count); // Make sure the collapsed sequences can be undone Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(1, m_actionHandler.UndoableSequenceCount); Assert.AreEqual(1, m_actionHandler.RedoableSequenceCount); }
public void MarkTest_InvalidMark() { using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Object")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } int hMark = m_actionHandler.Mark(); Assert.IsTrue(hMark > 0); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Swine")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } while (m_actionHandler.CanUndo()) Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(0, m_actionHandler.TopMarkHandle); m_actionHandler.DiscardToMark(hMark); }
public void kcptStringTests() { Assert.AreEqual("(Nothing to Undo.)", m_actionHandler.GetUndoText(), "Wrong undo text."); // JohnT: can't be sure of this now, may depend on previous test. //Assert.AreEqual("(Nothing to Redo.)", m_actionHandler.GetRedoText(), "Wrong redo text."); ILexEntry le; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Add entry")) { le = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(); undoHelper.RollBack = false; } Assert.AreEqual("Undo Add entry", m_actionHandler.GetUndoText(), "Wrong undo text."); m_actionHandler.Commit(); var startValue = le.ImportResidue; var secondValue = Cache.TsStrFactory.MakeString("import residue", Cache.WritingSystemFactory.UserWs); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Add import residue")) { le.ImportResidue = secondValue; undoHelper.RollBack = false; } Assert.AreEqual("Undo Add import residue", m_actionHandler.GetUndoText(), "Wrong undo text."); Assert.AreEqual("(Nothing to Redo.)", m_actionHandler.GetRedoText(), "Wrong redo text."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual("Redo Add import residue", m_actionHandler.GetRedoText(), "Wrong redo text."); Assert.AreEqual("(Nothing to Undo.)", m_actionHandler.GetUndoText(), "Wrong undo text."); Assert.AreSame(startValue, le.ImportResidue, "Wrong undo value."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreSame(secondValue, le.ImportResidue, "Wrong redo value."); Assert.AreEqual("Undo Add import residue", m_actionHandler.GetUndoText(), "Wrong undo text."); Assert.AreEqual("(Nothing to Redo.)", m_actionHandler.GetRedoText(), "Wrong redo text."); // Set to new value. var thirdValue = Cache.TsStrFactory.MakeString("new import residue", Cache.WritingSystemFactory.UserWs); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Change import residue")) { le.ImportResidue = thirdValue; undoHelper.RollBack = false; } Assert.AreEqual("Undo Change import residue", m_actionHandler.GetUndoText(), "Wrong undo text."); Assert.AreEqual("(Nothing to Redo.)", m_actionHandler.GetRedoText(), "Wrong redo text."); Assert.AreSame(thirdValue, le.ImportResidue, "Wrong value."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual("Undo Add import residue", m_actionHandler.GetUndoText(), "Wrong undo text."); //Assert.AreEqual("Redo Add import residue", m_actionHandler.GetRedoText(), "Wrong redo text."); Assert.AreEqual("Redo Change import residue", m_actionHandler.GetRedoText(), "Wrong redo text."); Assert.AreSame(secondValue, le.ImportResidue, "Wrong undo value."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual("(Nothing to Undo.)", m_actionHandler.GetUndoText(), "Wrong undo text."); Assert.AreEqual("Redo Add import residue", m_actionHandler.GetRedoText(), "Wrong redo text."); Assert.AreSame(startValue, le.ImportResidue, "Wrong undo value."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); // Cleanup: get rid of lex entry we committed earlier. NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () => { le.Delete(); }); }
public void kcptIntegerTests() { var startValue = Cache.LanguageProject.PeopleOA.Depth; var newValue = startValue + 1; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "set Depth property")) { Cache.LanguageProject.PeopleOA.Depth = newValue; undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(startValue, Cache.LanguageProject.PeopleOA.Depth, "Wrong undone Depth."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(newValue, Cache.LanguageProject.PeopleOA.Depth, "Wrong redone Depth."); }
public void kcptGenDateTests() { var firstPerson = (ICmPerson)Cache.LanguageProject.PeopleOA.PossibilitiesOS[0]; var startValue = firstPerson.DateOfBirth; var newValue = new GenDate(GenDate.PrecisionType.Before, 1, 1, 3000, true); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "set DOB")) { firstPerson.DateOfBirth = newValue; undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(startValue, firstPerson.DateOfBirth, "Wrong starting DOB"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(newValue, firstPerson.DateOfBirth, "Wrong undone DOB"); }
public void UnknownTests() { var userWs = Cache.WritingSystemFactory.UserWs; var bldr = TsPropsBldrClass.Create(); bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Arial"); bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); var tppOriginal = bldr.GetTextProps(); bldr = TsPropsBldrClass.Create(); bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Times new Roman"); bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs); var tppNew = bldr.GetTextProps(); IStStyle style; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add style")) { style = Cache.ServiceLocator.GetInstance<IStStyleFactory>().Create(); Cache.LanguageProject.StylesOC.Add(style); undoHelper.RollBack = false; } using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Rule")) { style.Rules = tppOriginal; undoHelper.RollBack = false; } using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add new Rule")) { style.Rules = tppNew; undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreSame(tppOriginal, style.Rules, "Not the right text props after Undo."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreSame(tppNew, style.Rules, "Not the right text props after Redo."); }
public void GetUndoTextNTest() { using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Object")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Monkeys")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } Assert.AreEqual("Undo add Object", m_actionHandler.GetUndoTextN(0)); Assert.AreEqual("Undo add Monkeys", m_actionHandler.GetUndoTextN(1)); }
public void CreateMarkIfNeededTest() { // Test that one is not created Assert.AreEqual(0, m_actionHandler.TopMarkHandle); m_actionHandler.CreateMarkIfNeeded(false); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Object")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } Assert.AreEqual(0, m_actionHandler.TopMarkHandle); // Test that one is created m_actionHandler.CreateMarkIfNeeded(true); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Monkeys")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } Assert.IsTrue(m_actionHandler.TopMarkHandle > 0); }
public void kcptBinaryTests() { IUserConfigAcctFactory acctFactory = Cache.ServiceLocator.GetInstance<IUserConfigAcctFactory>(); IUserConfigAcct acct; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add UserAccount")) { acct = acctFactory.Create(); Cache.LanguageProject.UserAccountsOC.Add(acct); undoHelper.RollBack = false; } m_actionHandler.Commit(); var startValue = acct.Sid; var firstChangedValue = new byte[] { 4, 5 }; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Details")) { acct.Sid = firstChangedValue; undoHelper.RollBack = false; } var secondChangedValue = new byte[] { 1, 2, 3 }; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Details")) { acct.Sid = secondChangedValue; undoHelper.RollBack = false; } // Should be two undos. Assert.AreEqual(2, m_uowService.UnsavedUnitsOfWork.Count, "Wrong unsaved UOW count."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(firstChangedValue, acct.Sid, "Wrong first details after undo."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(startValue, acct.Sid, "Wrong original details after undo."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(firstChangedValue, acct.Sid, "Wrong second details after redo."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(secondChangedValue, acct.Sid, "Wrong second details after redo."); }
public void UndoRedoObjectCreationDeletionSameUowTest() { IFdoServiceLocator servLoc = Cache.ServiceLocator; ICmPossibilityListFactory listFactory = servLoc.GetInstance<ICmPossibilityListFactory>(); ICmPossibilityListRepository listRepo = servLoc.GetInstance<ICmPossibilityListRepository>(); int origCount = listRepo.AllInstances().Count(); ILangProject lp = Cache.LanguageProject; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add original anthro list")) { lp.AnthroListOA = listFactory.Create(); lp.AnthroListOA = listFactory.Create(); undoHelper.RollBack = false; } ICmPossibilityList newAnthroList = lp.AnthroListOA; Assert.AreSame(newAnthroList, lp.AnthroListOA, "Wrong anthro list."); Assert.IsTrue(listRepo.AllInstances().Contains(newAnthroList)); // This checks both Undo of the creation of 'newAnthroList' and the deletion of 'originalAnthroList'. Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(origCount, listRepo.AllInstances().Count()); // This checks both Redo of the creation of 'newAnthroList' and the deletion of 'originalAnthroList'. Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreSame(newAnthroList, lp.AnthroListOA, "Wrong redone anthro list."); Assert.IsTrue(listRepo.AllInstances().Contains(newAnthroList)); }
public void kcptBooleanTests() { var startVal = Cache.LanguageProject.PeopleOA.IsVernacular; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "set IsVernacular")) { Cache.LanguageProject.PeopleOA.IsVernacular = !startVal; undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(startVal, Cache.LanguageProject.PeopleOA.IsVernacular, "Wrong undone boolean property"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(!startVal, Cache.LanguageProject.PeopleOA.IsVernacular, "Wrong redone boolean property"); }
public void CustomPropertyTests() { var servLoc = Cache.ServiceLocator; var mdc = servLoc.GetInstance<IFwMetaDataCacheManaged>(); var customCertifiedFlid = mdc.AddCustomField("WfiWordform", "Certified", CellarPropertyType.Boolean, 0); var customITsStringFlid = mdc.AddCustomField("WfiWordform", "NewTsStringProp", CellarPropertyType.String, 0); var customMultiUnicodeFlid = mdc.AddCustomField("WfiWordform", "MultiUnicodeProp", CellarPropertyType.MultiUnicode, 0); var customAtomicReferenceFlid = mdc.AddCustomField("WfiWordform", "NewAtomicRef", CellarPropertyType.ReferenceAtomic, CmPersonTags.kClassId); IWfiWordform wf; ICmPerson person; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add wordform")) { var lp = Cache.LanguageProject; wf = servLoc.GetInstance<IWfiWordformFactory>().Create(); lp.PeopleOA = servLoc.GetInstance<ICmPossibilityListFactory>().Create(); var personFactory = servLoc.GetInstance<ICmPersonFactory>(); person = personFactory.Create(); lp.PeopleOA.PossibilitiesOS.Add(person); undoHelper.RollBack = false; } m_actionHandler.Commit(); var sda = Cache.DomainDataByFlid; var startingValue = sda.get_BooleanProp(wf.Hvo, customCertifiedFlid); var newValue = !startingValue; var tsf = Cache.TsStrFactory; var userWs = Cache.WritingSystemFactory.UserWs; var emptyStr = tsf.EmptyString(userWs); var newStringValue = tsf.MakeString("New ITsString", userWs); var newUnicodeTsStringValue = tsf.MakeString("New unicode ITsString", userWs); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "set Certified")) { sda.SetBoolean(wf.Hvo, customCertifiedFlid, newValue); sda.SetString(wf.Hvo, customITsStringFlid, newStringValue); sda.SetMultiStringAlt(wf.Hvo, customMultiUnicodeFlid, userWs, newUnicodeTsStringValue); sda.SetObjProp(wf.Hvo, customAtomicReferenceFlid, person.Hvo); undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(startingValue, sda.get_BooleanProp(wf.Hvo, customCertifiedFlid), "Wrong undone boolean."); Assert.AreSame(emptyStr, sda.get_StringProp(wf.Hvo, customITsStringFlid), "TsString custom property is not undone to tsf.EmptyString."); Assert.AreSame(emptyStr, sda.get_MultiStringAlt(wf.Hvo, customMultiUnicodeFlid, userWs), "MultiUnicode custom property is not undone to tsf.EmptyString."); Assert.AreEqual(0, sda.get_ObjectProp(wf.Hvo, customAtomicReferenceFlid), "Add atomic ref not undone in custom property."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(newValue, sda.get_BooleanProp(wf.Hvo, customCertifiedFlid), "Wrong redone boolean."); Assert.AreSame(newStringValue, sda.get_StringProp(wf.Hvo, customITsStringFlid), "Wrong redone TsString value in custom property."); Assert.AreSame(newUnicodeTsStringValue, sda.get_MultiStringAlt(wf.Hvo, customMultiUnicodeFlid, userWs), "Wrong redone MultiUnicode value in custom property."); Assert.AreEqual(person.Hvo, sda.get_ObjectProp(wf.Hvo, customAtomicReferenceFlid), "Add atomic ref not redone in custom property."); }
public void kcptGuidTests() { ICmPossibilityListFactory possFactory = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>(); ICmPossibilityList possList; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add TimeOfDay")) { possList = possFactory.Create(); Cache.LanguageProject.TimeOfDayOA = possList; undoHelper.RollBack = false; } m_actionHandler.Commit(); var startingValue = possList.ListVersion; var newValue = Guid.NewGuid(); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "set new App guid")) { possList.ListVersion = newValue; undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(startingValue, possList.ListVersion, "Wrong undone App guid."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(newValue, possList.ListVersion, "Wrong redone App guid."); }
public void HandleDeletingOfObjHierarcy() { IScripture scr; IScrBook book; IScrSection section; IStText content; IScrTxtPara para; Guid bookGuid; Guid sectionGuid; Guid textGuid; Guid paraGuid; IFdoServiceLocator servloc = Cache.ServiceLocator; // Create the data used for testing using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add para")) { scr = Cache.LangProject.TranslatedScriptureOA; book = servloc.GetInstance<IScrBookFactory>().Create(1); bookGuid = book.Guid; section = servloc.GetInstance<IScrSectionFactory>().Create(); book.SectionsOS.Add(section); sectionGuid = section.Guid; content = servloc.GetInstance<IStTextFactory>().Create(); section.ContentOA = content; textGuid = content.Guid; para = servloc.GetInstance<IScrTxtParaFactory>().CreateWithStyle(content, "Monkey"); paraGuid = para.Guid; undoHelper.RollBack = false; } // Remove a book from scripture using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Delete book")) { scr.ScriptureBooksOS.Remove(book); undoHelper.RollBack = false; } // Try undo and make sure it put everything back together Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); book = scr.ScriptureBooksOS[0]; Assert.AreEqual(bookGuid, book.Guid); section = book.SectionsOS[0]; Assert.AreEqual(sectionGuid, section.Guid); content = section.ContentOA; Assert.AreEqual(textGuid, content.Guid); para = (IScrTxtPara)content[0]; Assert.AreEqual(paraGuid, para.Guid); // Undo again to make sure that scripture gets removed Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(scr.ScriptureBooksOS.Count, 0); // Redo to make sure that scripture, book, section, etc. are re-created Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); book = scr.ScriptureBooksOS[0]; Assert.AreEqual(bookGuid, book.Guid); section = book.SectionsOS[0]; Assert.AreEqual(sectionGuid, section.Guid); content = section.ContentOA; Assert.AreEqual(textGuid, content.Guid); para = (IScrTxtPara)content[0]; Assert.AreEqual(paraGuid, para.Guid); // Redo again to make sure the book is deleted Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(0, scr.ScriptureBooksOS.Count); }
public void kcptTimeTests() { var startValue = Cache.LanguageProject.DateCreated; var newValue = DateTime.Now; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "set DateCreated property.")) { Cache.LanguageProject.DateCreated = newValue; undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(startValue, Cache.LanguageProject.DateCreated, "Wrong undone DateCreated"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(newValue, Cache.LanguageProject.DateCreated, "Wrong redone DateCreated"); }
public void UndoOrRedoEventsTests() { // Before we can do undo or redo we need to have actually done something // so here is some test data so we can do undos and redos. var english = Cache.LanguageProject.CurrentAnalysisWritingSystems.First(); var firstNewValue = Cache.TsStrFactory.MakeString("Some Value", english.Handle); var actionHandlerExtensions = (IActionHandlerExtensions)m_actionHandler; int didUndoOrRedoCounter = 0; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Some Test Value")) { Cache.LanguageProject.MainCountry.set_String(english.Handle, firstNewValue); actionHandlerExtensions.DoAtEndOfPropChangedAlways(() => didUndoOrRedoCounter++); undoHelper.RollBack = false; } Assert.AreEqual(1, didUndoOrRedoCounter, "DoAtEndOfPropChangedAlways action should have fired at end of original UOW"); int doingUndoOrRedoCounter = 0; // Create some Delegate instances that are going to help us test the IActionHandlerExtension events DoingUndoOrRedoDelegate doingCountingDelegate = (cancelArg) => { doingUndoOrRedoCounter++; }; DoingUndoOrRedoDelegate cancelDelegate = (cancelArg) => { cancelArg.Cancel = true; }; Assert.IsTrue(actionHandlerExtensions != null); actionHandlerExtensions.DoingUndoOrRedo += doingCountingDelegate; Assert.AreEqual(0, doingUndoOrRedoCounter); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(1, doingUndoOrRedoCounter); Assert.AreEqual(2, didUndoOrRedoCounter, "Undo should have executed DoAtEndOfPropChangedAlways action"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(2, doingUndoOrRedoCounter); Assert.AreEqual(3, didUndoOrRedoCounter, "Redo should have executed DoAtEndOfPropChangedAlways action"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(3, doingUndoOrRedoCounter); Assert.AreEqual(4, didUndoOrRedoCounter, "Undo (again)should have executed DoAtEndOfPropChangedAlways action"); // Do another Redo so we can Undo Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(4, doingUndoOrRedoCounter); Assert.AreEqual(5, didUndoOrRedoCounter, "Redo (again) should have executed DoAtEndOfPropChangedAlways action"); actionHandlerExtensions.DoingUndoOrRedo -= doingCountingDelegate; // Now try a cancelled undo actionHandlerExtensions.DoingUndoOrRedo += cancelDelegate; Assert.AreEqual(UndoResult.kuresError, m_actionHandler.Undo()); actionHandlerExtensions.DoingUndoOrRedo -= cancelDelegate; Assert.AreEqual(5, didUndoOrRedoCounter); // Go back to inital state. Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(6, didUndoOrRedoCounter); // Now try a cancelled redo actionHandlerExtensions.DoingUndoOrRedo += cancelDelegate; Assert.AreEqual(UndoResult.kuresError, m_actionHandler.Redo()); actionHandlerExtensions.DoingUndoOrRedo -= cancelDelegate; Assert.AreEqual(6, didUndoOrRedoCounter); }
public void GetRedoTextNTest() { using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add WordForm")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Monkeys")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual("Redo add WordForm", m_actionHandler.GetRedoTextN(0)); Assert.AreEqual("Redo add Monkeys", m_actionHandler.GetRedoTextN(1)); }
public void DoAtEndOfPropChanged_TasksAreDone() { var english = Cache.LanguageProject.CurrentAnalysisWritingSystems.First(); var firstNewValue = Cache.TsStrFactory.MakeString("Some Value", english.Handle); var actionHandlerExtensions = (IActionHandlerExtensions)m_actionHandler; int doAtEndOfPropChangedAlwaysCount = 0; var doAtEndOfPropChangedCount1 = 0; var doAtEndOfPropChangedCount2 = 0; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Some Test Value")) { Cache.LanguageProject.MainCountry.set_String(english.Handle, firstNewValue); actionHandlerExtensions.DoAtEndOfPropChangedAlways(() => doAtEndOfPropChangedAlwaysCount++); actionHandlerExtensions.DoAtEndOfPropChanged(() => { Assert.That(actionHandlerExtensions.CanStartUow, Is.True, "DoAtEndOfPropChanged should be fired when UOW can be started"); if (doAtEndOfPropChangedCount1 == 0) { // These out-of-order checks should only be done when this action was supposed to be done itself. // We have other checks with more appropriate messages if it was done when it should not be at all. Assert.That(doAtEndOfPropChangedAlwaysCount, Is.EqualTo(0), "DoAtEndOfPropChanged task should be done before DoAtEndOfPropChangedAlways"); Assert.That(doAtEndOfPropChangedCount2, Is.EqualTo(0), "First DoAtEndOfPropChanged task should be done before second"); } doAtEndOfPropChangedCount1++; }); actionHandlerExtensions.DoAtEndOfPropChanged(() => { if (doAtEndOfPropChangedCount2 == 0) { // These out-of-order checks should only be done when this action was supposed to be done itself. // We have other checks with more appropriate messages if it was done when it should not be at all. Assert.That(doAtEndOfPropChangedAlwaysCount, Is.EqualTo(0), "DoAtEndOfPropChanged task should be done before DoAtEndOfPropChangedAlways"); Assert.That(doAtEndOfPropChangedCount1, Is.EqualTo(1), "First DoAtEndOfPropChanged task should be done before second"); } doAtEndOfPropChangedCount2++; }); undoHelper.RollBack = false; } Assert.AreEqual(1, doAtEndOfPropChangedAlwaysCount, "DoAtEndOfPropChangedAlways action should have fired at end of original UOW"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "DoAtEndOfPropChanged action should have executed at end of UOW"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "DoAtEndOfPropChanged action should have executed at end of UOW"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(2, doAtEndOfPropChangedAlwaysCount, "Undo should have executed DoAtEndOfPropChangedAlways action"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "Undo should not have executed DoAtEndOfPropChanged action"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "Undo should not have executed DoAtEndOfPropChanged action"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(3, doAtEndOfPropChangedAlwaysCount, "Redo should have executed DoAtEndOfPropChangedAlways action"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "Redo should not have executed DoAtEndOfPropChanged action"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "Redo should not have executed DoAtEndOfPropChanged action"); UndoableUnitOfWorkHelper.Do("undo", "redo", m_actionHandler, () => Cache.LanguageProject.MainCountry.set_String(english.Handle, "some other string")); Assert.AreEqual(3, doAtEndOfPropChangedAlwaysCount, "DoAtEndOfPropChangedAlways action should not fire for a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "DoAtEndOfPropChanged action should not fire for a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "DoAtEndOfPropChanged action should not fire for a different task"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(3, doAtEndOfPropChangedAlwaysCount, "DoAtEndOfPropChangedAlways action should not fire undoing a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "DoAtEndOfPropChanged action should not fire undoing a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "DoAtEndOfPropChanged action should not fire undoing a different task"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(3, doAtEndOfPropChangedAlwaysCount, "DoAtEndOfPropChangedAlways action should not fire redoing a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "DoAtEndOfPropChanged action should not fire redoing a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "DoAtEndOfPropChanged action should not fire redoing a different task"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(3, doAtEndOfPropChangedAlwaysCount, "DoAtEndOfPropChangedAlways action should not fire undoing a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "DoAtEndOfPropChanged action should not fire undoing a different task"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "DoAtEndOfPropChanged action should not fire undoing a different task"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(4, doAtEndOfPropChangedAlwaysCount, "DoAtEndOfPropChangedAlways action should fire undoing this task after undoing a different one"); Assert.AreEqual(1, doAtEndOfPropChangedCount1, "DoAtEndOfPropChanged action should not fire on Undo"); Assert.AreEqual(1, doAtEndOfPropChangedCount2, "DoAtEndOfPropChanged action should not fire on Undo"); }
public void MarkTest_CloseClears() { int hMark = m_actionHandler.Mark(); Assert.IsTrue(hMark > 0); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Object")) { m_wordFormFactory.Create(); undoHelper.RollBack = false; } Assert.AreEqual(hMark, m_actionHandler.TopMarkHandle); m_actionHandler.Close(); Assert.AreEqual(0, m_actionHandler.TopMarkHandle); }
public void DoAtEndOfPropChanged_RollbackAbortsTasks() { var english = Cache.LanguageProject.CurrentAnalysisWritingSystems.First(); var firstNewValue = Cache.TsStrFactory.MakeString("Some Value", english.Handle); var actionHandlerExtensions = (IActionHandlerExtensions)m_actionHandler; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Some Test Value")) { Cache.LanguageProject.MainCountry.set_String(english.Handle, firstNewValue); actionHandlerExtensions.DoAtEndOfPropChangedAlways(() => Assert.Fail("Should not do after-prop-changed always task")); actionHandlerExtensions.DoAtEndOfPropChanged(() => Assert.Fail("Should not do after-prop-changed task")); // undoHelper.RollBack = false; //without this disposing the helper will roll back. } using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "Some Test Value")) { Cache.LanguageProject.MainCountry.set_String(english.Handle, firstNewValue); undoHelper.RollBack = false; // This time the change succeeds, but the actions were for the failed one, so they should not happen. } }
public void DiscardToMarkTest() { Assert.AreEqual(0, m_actionHandler.TopMarkHandle); int hMark = m_actionHandler.Mark(); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Object")) { IUndoAction action = MockRepository.GenerateMock<IUndoAction>(); m_actionHandler.AddAction(action); undoHelper.RollBack = false; } using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add Monkeys")) { IUndoAction action = MockRepository.GenerateMock<IUndoAction>(); m_actionHandler.AddAction(action); undoHelper.RollBack = false; } m_actionHandler.DiscardToMark(hMark); Assert.AreEqual(0, m_actionHandler.UndoableSequenceCount); Assert.AreEqual(0, m_actionHandler.RedoableSequenceCount); Assert.AreEqual(0, m_actionHandler.TopMarkHandle); }
public void MultiStringTest() { // Start with expected information. var english = Cache.LanguageProject.CurrentAnalysisWritingSystems.First(); Assert.AreEqual(0, Cache.LanguageProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LanguageProject.MainCountryAccessor"); // Create a good string. var firstNewValue = Cache.TsStrFactory.MakeString("Mexico", english.Handle); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add MainCountry alt")) { Cache.LanguageProject.MainCountry.set_String(english.Handle, firstNewValue); undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(0, Cache.LanguageProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LanguageProject.MainCountryAccessor"); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(1, Cache.LanguageProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LanguageProject.MainCountryAccessor"); Assert.AreSame(firstNewValue, Cache.LanguageProject.MainCountry.get_String(english.Handle)); var secondNewValue = Cache.TsStrFactory.MakeString("USA", english.Handle); using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "add MainCountry alt")) { Cache.LanguageProject.MainCountry.set_String(english.Handle, secondNewValue); undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreEqual(1, Cache.LanguageProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LanguageProject.MainCountryAccessor"); Assert.AreSame(firstNewValue, Cache.LanguageProject.MainCountry.get_String(english.Handle)); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreEqual(1, Cache.LanguageProject.MainCountry.StringCount, "Wrong number of alternatives for Cache.LanguageProject.MainCountryAccessor"); Assert.AreSame(secondNewValue, Cache.LanguageProject.MainCountry.get_String(english.Handle)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle a click on the Back Translation Checked menu option /// </summary> /// ------------------------------------------------------------------------------------ protected bool OnBackTranslationChecked(object args) { string undo; string redo; TeResourceHelper.MakeUndoRedoLabels("kstidUndoRedoChangeBackTransStatus", out undo, out redo); using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper( Cache.ServiceLocator.GetInstance<IActionHandler>(), undo, redo)) { ICmTranslation trans = m_fdoCache.ServiceLocator.GetInstance<ICmTranslationRepository>().GetObject( TeEditingHelper.CurrentSelection.LevelInfo[0].hvo); SetBackTranslationStatus(trans, BackTranslationStatus.Checked); undoHelper.RollBack = false; } return true; }
public void kcptUnicodeTests() { var startValue = Cache.LanguageProject.EthnologueCode; const string newValue = "NEWCode"; using (var undoHelper = new UndoableUnitOfWorkHelper(m_actionHandler, "set EthnologueCode")) { Cache.LanguageProject.EthnologueCode = newValue; undoHelper.RollBack = false; } Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Undo()); Assert.AreSame(startValue, Cache.LanguageProject.EthnologueCode, "Wrong undone EthnologueCode."); Assert.AreEqual(UndoResult.kuresSuccess, m_actionHandler.Redo()); Assert.AreSame(newValue, Cache.LanguageProject.EthnologueCode, "Wrong redone EthnologueCode."); }