diff --git a/Src/Common/Filters/FiltersTests/TestPersistence.cs b/Src/Common/Filters/FiltersTests/TestPersistence.cs index c2c519428e..be35fd76bd 100644 --- a/Src/Common/Filters/FiltersTests/TestPersistence.cs +++ b/Src/Common/Filters/FiltersTests/TestPersistence.cs @@ -4,7 +4,6 @@ using System; using System.Collections; -using System.IO; using System.Xml; using NUnit.Framework; using SIL.LCModel.Core.Text; @@ -407,118 +406,4 @@ public void PersistReverseComparer() Assert.That(rcOut.SubComp is IntStringComparer, Is.True); } } - - /// - /// Tests persisting a list of ManyOnePathSortItems - /// - [TestFixture] - public class ManyOnePathSortItemsPersistenceTests : MemoryOnlyBackendProviderTestBase - { - private ISilDataAccess m_sda; - private ArrayList m_list; - private ILexEntry m_le1; - private ILexEntry m_le2; - - public override void FixtureSetup() - { - base.FixtureSetup(); - - m_sda = Cache.DomainDataByFlid; - } - - public override void FixtureTeardown() - { - m_sda = null; - - base.FixtureTeardown(); - } - - public override void TestSetup() - { - base.TestSetup(); - - - IManyOnePathSortItem mopsi = new ManyOnePathSortItem(Cache.LangProject); - m_list = new ArrayList(); - m_list.Add(mopsi); - var leFactory = Cache.ServiceLocator.GetInstance(); - UndoableUnitOfWorkHelper.Do("undoit", "redoit", Cache.ActionHandlerAccessor, () => - { - m_le1 = leFactory.Create(); - m_le2 = leFactory.Create(); - }); - mopsi = new ManyOnePathSortItem(Cache.LangProject.LexDbOA.Hvo, new int[] { m_le1.Hvo, m_le2.Hvo }, new int[] { 2, 3 }); - m_list.Add(mopsi); - } - - /// - /// Test persisting a list of ManyOnePathSortItems. - /// - [Test] - public void PersistMopsiList() - { - var mopsi = (IManyOnePathSortItem)m_list[m_list.Count - 1]; - using (var stream = new MemoryStream()) - { - var objRepo = Cache.ServiceLocator.ObjectRepository; - var originalPersistData = mopsi.PersistData(objRepo); - using (var writer = new StreamWriter(stream)) - { - ManyOnePathSortItem.WriteItems(m_list, writer, objRepo); - stream.Seek(0, SeekOrigin.Begin); - using (var reader = new StreamReader(stream)) - { - var items = ManyOnePathSortItem.ReadItems(reader, objRepo); - Assert.That(items.Count, Is.EqualTo(m_list.Count)); - mopsi = (IManyOnePathSortItem)items[0]; - Assert.That(mopsi.KeyObject, Is.EqualTo(Cache.LangProject.Hvo)); - Assert.That(mopsi.PathLength, Is.EqualTo(0)); - // Root object is key object, if no path. - Assert.That(mopsi.RootObjectHvo, Is.EqualTo(Cache.LangProject.Hvo)); - Assert.That(mopsi.RootObjectUsing(Cache), Is.EqualTo(Cache.LangProject)); - // PathObject(0) is also the key, if no path. - Assert.That(mopsi.PathObject(0), Is.EqualTo(Cache.LangProject.Hvo)); - mopsi = (IManyOnePathSortItem)items[1]; - Assert.That(mopsi.KeyObject, Is.EqualTo(Cache.LangProject.LexDbOA.Hvo)); - Assert.That(mopsi.PathLength, Is.EqualTo(2)); - Assert.That(mopsi.PathFlid(0), Is.EqualTo(2)); - Assert.That(mopsi.PathFlid(1), Is.EqualTo(3)); - Assert.That(mopsi.PathObject(0), Is.EqualTo(m_le1.Hvo)); - Assert.That(mopsi.PathObject(1), Is.EqualTo(m_le2.Hvo)); - Assert.That(mopsi.PathObject(2), Is.EqualTo(Cache.LangProject.LexDbOA.Hvo), "Index one too large yields key object."); - Assert.That(mopsi.RootObjectHvo, Is.EqualTo(m_le1.Hvo)); - Assert.That(mopsi.RootObjectUsing(Cache), Is.EqualTo(m_le1)); - Assert.That(mopsi.KeyObjectUsing(Cache), Is.EqualTo(Cache.LangProject.LexDbOA)); - Assert.That(mopsi.PersistData(objRepo), Is.EqualTo(originalPersistData)); - } - } - } - } - - /// - /// Test persisting a list of ManyOnePathSortItems. - /// - [Test] - public void PersistMopsiList_BadGUID() - { - // Now make one containing a bad GUID. - using (var stream = new MemoryStream()) - { - var objRepo = Cache.ServiceLocator.ObjectRepository; - using (var writer = new StreamWriter(stream)) - { - ManyOnePathSortItem.WriteItems(m_list, writer, objRepo); - writer.WriteLine(Convert.ToBase64String(Guid.NewGuid().ToByteArray())); - // fake item, bad guid - writer.Flush(); - stream.Seek(0, SeekOrigin.Begin); - using (var reader = new StreamReader(stream)) - { - var items = ManyOnePathSortItem.ReadItems(reader, objRepo); - Assert.That(items, Is.Null); - } - } - } - } - } } diff --git a/Src/Common/Filters/IManyOnePathSortItem.cs b/Src/Common/Filters/IManyOnePathSortItem.cs index d852842645..f01b3b09d3 100644 --- a/Src/Common/Filters/IManyOnePathSortItem.cs +++ b/Src/Common/Filters/IManyOnePathSortItem.cs @@ -23,7 +23,5 @@ public interface IManyOnePathSortItem int PathLength { get; } int PathObject(int index); int PathFlid(int index); - // This is in the interface only for internal use. - string PersistData(ICmObjectRepository repo); } } diff --git a/Src/Common/Filters/ManyOnePathSortItem.cs b/Src/Common/Filters/ManyOnePathSortItem.cs index 963c09637e..412631e00f 100644 --- a/Src/Common/Filters/ManyOnePathSortItem.cs +++ b/Src/Common/Filters/ManyOnePathSortItem.cs @@ -4,8 +4,6 @@ using System; using System.Collections; -using System.IO; -using System.Text; using SIL.LCModel; namespace SIL.FieldWorks.Filters @@ -223,241 +221,5 @@ public int PathLength return m_pathObjects.Length; } } - - string PersistGuid(Guid guid) - { - return Convert.ToBase64String(guid.ToByteArray()); - } - - /// - /// A representation that can be used to create an equivalent LazyManyOnePathSortItem. - /// Keep consistent with the LazyManyOnePathSortItem constructor and PersisData. - /// - public string PersistData(ICmObjectRepository repo) - { - StringBuilder builder = new StringBuilder(); - builder.Append(PersistGuid(repo.GetObject(m_hvoItem).Guid)); - if (PathLength > 0) - { - for (int i = 0; i < m_pathObjects.Length; i++) - { - builder.Append(";"); - builder.Append(m_pathFlids[i]); - builder.Append(";"); - builder.Append(PersistGuid(repo.GetObject(m_pathObjects[i]).Guid)); - } - } - return builder.ToString(); - } - - /// - /// Write a collection of IManyOneSortItems in a form that can be reconstituted by ReadItems. - /// - public static void WriteItems(ArrayList items, StreamWriter output, ICmObjectRepository repo) - { - foreach (IManyOnePathSortItem item in items) - output.WriteLine(item.PersistData(repo)); - output.Flush(); - } - - /// - /// Build a collection of IManyOneSortItems from data written by WriteItems. - /// - public static ArrayList ReadItems(StreamReader input, ICmObjectRepository repo) - { - try - { - var result = new ArrayList(); - while (!input.EndOfStream) - result.Add(new LazyManyOnePathSortItem(input.ReadLine(), repo)); - return result; - - } - // If we find a guid we don't recognize as a valid object, the actual data is somehow - // not consistent with what we saved, so discard the saved information. - catch (InvalidObjectGuidException) - { - return null; - } - // Likewise, if anything goes wrong with reading the file, we'll just rebuild the index. - catch (IOException) - { - return null; - } - // Also if the file has been corrupted somehow with invalid Base64 data, we'll rebuild - // the index. See FWR-1110. - catch (FormatException) - { - return null; - } - // This occurs if an input line has an even number of chunks (semi-colon-separated). LT-11240. - // This again indicates the file is corrupt and we will just rebuild the index. - catch (IndexOutOfRangeException) - { - return null; - } - // If the string representing a GUID that we read from the file doesn't produce - // a byte array exactly 8 bytes long, we get this (FWR-2890). Similar to FormatException, - // if the file is corrupt we'll just rebuild the index. - // Review JohnT: is this a case where we should just catch all exceptions? But then - // if someone introduces a defect the program may just slow down without our ever - // realizing why. - catch (ArgumentException) - { - return null; - } - } - } - - /// - /// Private marker class so we can catch the specific problem of seeking an HVO for an unknown - /// (probably deleted object) guid. - /// - class InvalidObjectGuidException : ApplicationException - { - - } - - /// - /// This alternative implementation is used when restoring a saved list of mopsis. - /// The main point of it is to be able to restore a list of Imopsis, but NOT actually create the - /// objects until they are needed for something. Accordingly, it mainly stores ICmObjectIds - /// rather than CmObjects or HVOs, though the variables are ICmObjectOrIds so we can - /// retrieve the objects efficiently once they are real. - /// - class LazyManyOnePathSortItem : IManyOnePathSortItem - { - /// - /// The actual item that we are sorting, filtering, etc. by. - /// - ICmObjectOrId m_item; - - /// - /// The repository that can interpret ICmObjectOrIds and give ICmObjects. - /// - private ICmObjectRepository m_repo; - - /// - /// Array of objects in the path. m_pathObjects[0] is one of the original list items. - /// m_pathObjects[n+1] is an object in property m_pathFlids[n] of m_pathObjects[n]. - /// m_item is an object in property m_pathFlids[last] of m_pathObjects[last]. - /// - ICmObjectOrId[] m_pathObjects; - int[] m_pathFlids; - - public LazyManyOnePathSortItem(string persistInfo, ICmObjectRepository repo) - { - m_repo = repo; - var chunks = persistInfo.Split(';'); - m_item = ParseGuidRep(repo, chunks[0]); - if (chunks.Length > 1) - { - var pathLen = chunks.Length/2; - m_pathObjects = new ICmObjectOrId[pathLen]; - m_pathFlids = new int[pathLen]; - for (int i = 0; i < pathLen; i++) - { - m_pathFlids[i] = int.Parse(chunks[i*2 + 1]); - m_pathObjects[i] = ParseGuidRep(repo, chunks[i * 2 + 2]); - } - } - } - - /// A representation that can be used to create an equivalent LazyManyOnePathSortItem later. - /// Keep consistent with the ManyOnePathSortItem PersistData (and our constructor). - /// - public string PersistData(ICmObjectRepository repo) - { - StringBuilder builder = new StringBuilder(); - builder.Append(PersistGuid(m_item)); - if (PathLength > 0) - { - for (int i = 0; i < m_pathObjects.Length; i++) - { - builder.Append(";"); - builder.Append(m_pathFlids[i]); - builder.Append(";"); - builder.Append(PersistGuid(m_pathObjects[i])); - } - } - return builder.ToString(); - } - - private string PersistGuid(ICmObjectOrId item) - { - return Convert.ToBase64String(item.Id.Guid.ToByteArray()); - } - - private ICmObjectOrId ParseGuidRep(ICmObjectRepository repo, string chunk) - { - var result = repo.GetObjectOrIdWithHvoFromGuid(new Guid(Convert.FromBase64String(chunk))); - if (result == null) - throw new InvalidObjectGuidException(); - return result; - } - - public ICmObject RootObjectUsing(LcmCache cache) - { - if (m_pathObjects == null) - return RealKeyObject(); - var result = m_pathObjects[0].GetObject(m_repo); - // makes future updates more efficient, if it was an ID. - // I believe locking is not necessary, since even if two threads update this, - // both will update it to the same thing. - m_pathObjects[0] = result; - return result; - } - - public int RootObjectHvo - { - get { - var objOrId = m_pathObjects == null ? m_item : m_pathObjects[0]; - return m_repo.GetHvoFromObjectOrId(objOrId); - } - } - - public int KeyObject - { - get - { - return m_repo.GetHvoFromObjectOrId(m_item); - } - } - - public ICmObject KeyObjectUsing(LcmCache cache) - { - return RealKeyObject(); - } - - private ICmObject RealKeyObject() - { - var temp = m_item.GetObject(m_repo); - m_item = temp; // locking not needed, all threads will update to same thing - return temp; - } - - public int PathLength - { - get - { - if (m_pathObjects == null) - return 0; - return m_pathObjects.Length; - } - } - - public int PathObject(int index) - { - if (m_pathObjects == null && index == 0) - return KeyObject; - if (index == m_pathObjects.Length) - return KeyObject; - return m_repo.GetHvoFromObjectOrId(m_pathObjects[index]); - } - - public int PathFlid(int index) - { - return m_pathFlids[index]; - } } } diff --git a/Src/LexText/Lexicon/FLExBridgeListener.cs b/Src/LexText/Lexicon/FLExBridgeListener.cs index 40d42022b0..5ea4b0f227 100644 --- a/Src/LexText/Lexicon/FLExBridgeListener.cs +++ b/Src/LexText/Lexicon/FLExBridgeListener.cs @@ -1437,8 +1437,6 @@ private static FwXWindow RefreshCacheWindowAndAll(LexTextApp app, string fullPro (FwXWindow)manager.ReopenProject(manager.Cache.ProjectId.Name, appArgs).ActiveMainWindow; if (IsVernacularSpellingEnabled(newAppWindow.PropTable)) WfiWordformServices.ConformSpellingDictToWordforms(newAppWindow.Cache); - //clear out any sort cache files (or whatever else might mess us up) and then refresh - newAppWindow.ClearInvalidatedStoredData(); newAppWindow.RefreshDisplay(); return newAppWindow; } diff --git a/Src/LexText/Lexicon/ReversalListener.cs b/Src/LexText/Lexicon/ReversalListener.cs index 313a494204..07432cfde1 100644 --- a/Src/LexText/Lexicon/ReversalListener.cs +++ b/Src/LexText/Lexicon/ReversalListener.cs @@ -575,11 +575,6 @@ public override void OnPropertyChanged(string name) { CheckDisposed(); - var window = m_propertyTable.GetValue("window"); - if (window != null) - { - window.ClearInvalidatedStoredData(); - } switch (name) { default: diff --git a/Src/XCore/xWindow.cs b/Src/XCore/xWindow.cs index 6f26338579..f54780bae9 100644 --- a/Src/XCore/xWindow.cs +++ b/Src/XCore/xWindow.cs @@ -1128,10 +1128,6 @@ protected void RestoreWindowSettings(bool wasCrashDuringPreviousStartup) RestoreProperties(); // nb some subclasses will also reload database-specific properties later. } - else - { - DiscardProperties(); - } if (m_propertyTable.PropertyExists("windowState")) { @@ -1173,15 +1169,6 @@ protected virtual void RestoreProperties() m_propertyTable.RestoreFromFile(m_propertyTable.GlobalSettingsId); } - /// - /// If we don't RestoreProperties we may need to discard some information. - /// For example if we are discarding a saved filter we need to discard the saved object sequences. - /// - protected virtual void DiscardProperties() - { - // Default is to do nothing (it's not necessary to actually delete the saved settings file). - } - /// /// sets up either the menubar, toolbar collection, or sidebar /// diff --git a/Src/xWorks/FwXWindow.cs b/Src/xWorks/FwXWindow.cs index 380a67e401..a076bcabc1 100644 --- a/Src/xWorks/FwXWindow.cs +++ b/Src/xWorks/FwXWindow.cs @@ -17,7 +17,6 @@ using SIL.FieldWorks.LexText.Controls; using SIL.FieldWorks.Resources; using SIL.FieldWorks.XWorks.Archiving; -using SIL.IO; using SIL.LCModel; using SIL.LCModel.Application; using SIL.LCModel.Core.KernelInterfaces; @@ -383,21 +382,6 @@ protected override void RestoreProperties() GlobalSettingServices.RestoreSettings(Cache.ServiceLocator, m_propertyTable); } - /// - /// If we are discarding saved settings, we must not keep any saved sort sequences, - /// as they may represent a filter we are not restoring (LT-11647) - /// - protected override void DiscardProperties() - { - var tempDirectory = Path.Combine(Cache.ProjectId.ProjectFolder, LcmFileHelper.ksSortSequenceTempDir); - RobustIO.DeleteDirectoryAndContents(tempDirectory); - } - - public void ClearInvalidatedStoredData() - { - DiscardProperties(); - } - /// ----------------------------------------------------------------------------------- /// /// Construct a new form diff --git a/Src/xWorks/InterestingTextList.cs b/Src/xWorks/InterestingTextList.cs index ccfdb63393..88aa472b07 100644 --- a/Src/xWorks/InterestingTextList.cs +++ b/Src/xWorks/InterestingTextList.cs @@ -10,7 +10,6 @@ using SIL.FieldWorks.Common.ViewsInterfaces; using SIL.LCModel; using SIL.LCModel.DomainImpl; -using SIL.LCModel.Utils; using XCore; namespace SIL.FieldWorks.XWorks @@ -37,15 +36,10 @@ public class InterestingTextList : IVwNotifyChange /// tested efficiently. /// private HashSet m_interestingTests; - /// - /// These two RecordClerks both need to respond to InterestingTextList changes EVEN when not loaded. - /// (LT-13217) - /// So if one changes this list of texts, the other's sort sequence file will be deleted. - /// - private static string[] RelatedClerkIds = { "interlinearTexts", "concordanceWords", "OccurrencesOfSelectedUnit", "complexConcOccurrencesOfSelectedUnit"}; /// - /// Used by InvalidateRelatedSortSequences() + /// Read from the property table; PropChanged uses it to recognize the + /// LangProjTexts virtual property. /// public LcmCache Cache { get; set; } @@ -283,43 +277,10 @@ private void RaiseInterestingTextsChanged(int insertAt, int inserted, int delete { if (inserted == 0 && deleted == 0) return; - InvalidateRelatedSortSequences(); if (InterestingTextsChanged != null) InterestingTextsChanged(this, new InterestingTextsChangedArgs(insertAt, inserted, deleted)); } - private void InvalidateRelatedSortSequences() - { - if (Cache == null) - return; - - // We won't keep track of the clerk between calls since it could change from time to time. - var clerk = m_propertyTable.GetValue("ActiveClerk", null); - if (clerk == null) - return; - - if (!RelatedClerkIds.Contains(clerk.Id)) - { - Debug.Fail("We may need to add a new RelatedClerkId."); - return; // somehow we got in here with the wrong clerk?! - } - var otherRelatedClerkIds = GetRelatedClerkIds(clerk.Id); - foreach (var clerkId in otherRelatedClerkIds) - { - RemoveSortSequenceFile(RecordView.GetSortFilePersistPathname(Cache, clerkId)); - } - } - - private void RemoveSortSequenceFile(string filename) - { - FileUtils.Delete(filename); - } - - private static IEnumerable GetRelatedClerkIds(string id) - { - return RelatedClerkIds.Where(clerkId => clerkId != id); - } - //Remove invalid objects from the list. Return true if any were removed. private bool ClearInvalidObjects(List listToSearch, int offset, bool raiseChangeNotification) { diff --git a/Src/xWorks/RecordBrowseView.cs b/Src/xWorks/RecordBrowseView.cs index 7ea5271d10..46613ace05 100644 --- a/Src/xWorks/RecordBrowseView.cs +++ b/Src/xWorks/RecordBrowseView.cs @@ -72,7 +72,6 @@ protected override void Dispose(bool disposing) if (ExistingClerk != null) // ExistingClerk, *not* Clerk (see doc on ExistingClerk) { - PersistSortSequence(); ExistingClerk.FilterChangedByClerk -= Clerk_FilterChangedByClerk; ExistingClerk.SorterChangedByClerk -= Clerk_SorterChangedByClerk; } @@ -360,18 +359,6 @@ public bool OnLinkFollowed(object args) return m_browseViewer.FollowLink(args); } - - /// - /// This is the best way I can find to catch when the control is going away. - /// - /// - protected override void OnParentChanged(EventArgs e) - { - if (Parent == null) - PersistSortSequence(); - base.OnParentChanged(e); - } - protected virtual BrowseViewer CreateBrowseViewer(XmlNode nodeSpec, int hvoRoot, int fakeFlid, LcmCache cache, Mediator mediator, PropertyTable propertyTable, ISortItemProvider sortItemProvider,ISilDataAccessManaged sda) diff --git a/Src/xWorks/RecordClerk.cs b/Src/xWorks/RecordClerk.cs index c6fdb99546..649cbaf69c 100644 --- a/Src/xWorks/RecordClerk.cs +++ b/Src/xWorks/RecordClerk.cs @@ -408,27 +408,6 @@ public virtual void Init(Mediator mediator, PropertyTable propertyTable, XmlNode SetupDataContext(false); } - /// - /// Persist this list for retrieval by RestoreListFrom, if we are a primary Clerk. - /// - internal void PersistListOn(string pathname) - { - if (IsPrimaryClerk) - m_list.PersistOn(pathname); - } - - /// - /// Returns true if successful, false if some problem reading the file, including - /// detecting that part of a key is a deleted object. Return false if this is not - /// the primary clerk. - /// - internal bool RestoreListFrom(string pathname) - { - if (!IsPrimaryClerk) - return false; - return m_list.RestoreFrom(pathname); - } - private string GetSortNamePropertyTableId(DictionaryConfigurationModel dictConfig = null) { CheckDisposed(); @@ -3331,15 +3310,6 @@ public bool TriggerPendingReloadOnDispose set { m_fTriggerPendingReloadOnDispose = value; } } - /// - /// The list was successfully restored (from a persisted sort sequence). - /// We should NOT sort it when disposed, nor restore an original flag indicating it needed sorting. - /// - internal void ListWasRestored() - { - m_fTriggerPendingReloadOnDispose = false; - m_fOriginalLoadRequestedWhileSuppressed = false; - } #region DisposableBase Members protected override void DisposeManagedResources() diff --git a/Src/xWorks/RecordList.cs b/Src/xWorks/RecordList.cs index a302b76687..b2f790cfa1 100644 --- a/Src/xWorks/RecordList.cs +++ b/Src/xWorks/RecordList.cs @@ -6,7 +6,6 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; using System.Reflection; using System.Windows.Forms; @@ -673,15 +672,6 @@ public override void ReloadList() base.ReloadList(); } - internal override bool RestoreFrom(string pathname) - { - // If we are restoring, presumably the 'previous flid' (which should be the flid from the last complete - // ReloadList) should match the flid that is current, which in turn should correspond to the saved list - // of sorted objects. - m_prevFlid = m_flid; - return base.RestoreFrom(pathname); - } - /// /// Stores the target flid (that is, typically the field we want to bulk edit) most recently passed to ReloadList. /// @@ -3825,83 +3815,6 @@ public virtual void DeleteCurrentObject(ProgressState state, ICmObject thingToDe } } - internal void PersistOn(string pathname) - { - // Ensure that all the items in the sorted list are valid ICmObject references before - // actually persisting anything. Some lists store dummy objects. - if (m_sortedObjects == null || m_sortedObjects.Count == 0) - return; - var repo = Cache.ServiceLocator.ObjectRepository; - foreach (var obj in m_sortedObjects) - { - ManyOnePathSortItem item = obj as ManyOnePathSortItem; - if (item == null) - return; - if (item.KeyObject <= 0 || item.RootObjectHvo <= 0 || - // The object might have been deleted. See LT-11169. - !repo.IsValidObjectId(item.KeyObject) || !repo.IsValidObjectId(item.RootObjectHvo)) - { - return; - } - } - try - { - using (var stream = new StreamWriter(pathname)) - { - ManyOnePathSortItem.WriteItems(m_sortedObjects, stream, repo); - stream.Close(); - } - } - // LT-11395 and others: somehow the current list contains a deleted object. - // Writing out this file is just an optimization, so if we can't do it, just skip it. - catch (KeyNotFoundException) - { - TryToDelete(pathname); - } - catch (IOException) - { - TryToDelete(pathname); - } - } - - private void TryToDelete(string pathname) - { - if (File.Exists(pathname)) - { - try - { - File.Delete(pathname); - } - catch (IOException) - { - } - } - } - - /// - /// Returns true if it successfully set m_sortedObjects to a restored list. - /// - internal virtual bool RestoreFrom(string pathname) - { - // If something has created instances of the class we display, the persisted list may be - // missing things. For example, if the program starts up in interlinear text view, and the user - // creates entries as a side effect of glossing texts, we shouldn't use the saved list of - // lex entries when we switch to the lexicon view. - if (Cache.ServiceLocator.ObjectRepository.InstancesCreatedThisSession(ListItemsClass)) - return false; - ArrayList items; - using (var stream = new StreamReader(pathname)) - { - items = ManyOnePathSortItem.ReadItems(stream, Cache.ServiceLocator.ObjectRepository); - stream.Close(); - } - // This particular cache cannot reliably be used again, since items may be created or deleted - // while the program is running. In case a crash occurs, we don't want to reload an obsolete - // list the next time we start up. - FileUtils.Delete(pathname); - return false; // could not restore, bad file or deleted objects or... - } - /// /// LT-12780: On reloading FLEX there were situtaions where it reloaded on the first element of a list instead of /// the last item the user was working on before closing Flex. The CurrentIndex was being set to zero. This method diff --git a/Src/xWorks/RecordView.cs b/Src/xWorks/RecordView.cs index fff7afb81e..c2ba2f96ea 100644 --- a/Src/xWorks/RecordView.cs +++ b/Src/xWorks/RecordView.cs @@ -10,10 +10,8 @@ // // ------------------- ------------------------------------------------------------------------- using System; -using System.IO; using System.Diagnostics; using System.Xml; -using SIL.FieldWorks.Common.Framework; using SIL.FieldWorks.Common.FwUtils; using static SIL.FieldWorks.Common.FwUtils.FwUtils; using XCore; @@ -204,7 +202,6 @@ protected void InitBase(Mediator mediator, PropertyTable propertyTable, XmlNode RecordClerk clerk = ExistingClerk; bool fClerkAlreadySuppressed = false; - bool fClerkWasCreated = false; if (clerk == null) { // We do NOT want to load the list as part of creating the clerk. @@ -218,7 +215,6 @@ protected void InitBase(Mediator mediator, PropertyTable propertyTable, XmlNode // we want to pass FALSE to the ListUpdateHelper constructor, however, to pretend that the // list was NOT suppressed when the helper was created, so it will duly be sorted when // the helper is disposed. - fClerkWasCreated = true; clerk = CreateClerk(false); Debug.Assert(clerk != null); } @@ -227,7 +223,6 @@ protected void InitBase(Mediator mediator, PropertyTable propertyTable, XmlNode // suspend any loading of the Clerk's list items until after a // subclass (possibly) initializes sorters/filters // in SetupDataContext() - bool didRestoreFromPersistence = false; using (var luh = new RecordClerk.ListUpdateHelper(clerk, fClerkAlreadySuppressed)) { luh.ClearBrowseListUntilReload = true; @@ -239,68 +234,14 @@ protected void InitBase(Mediator mediator, PropertyTable propertyTable, XmlNode // view. This is handled by Priority now, RecordView is by default just after RecordClerk in the processing. mediator.AddColleague(this); SetupDataContext(); - // Only if it was just now created should we try to restore from what we persisted. - // Otherwise (e.g., FWR-1128) we may miss changes made to the list in other tools. - if (fClerkWasCreated) - didRestoreFromPersistence = RestoreSortSequence(); - if (didRestoreFromPersistence) - luh.ListWasRestored(); } // In case it hasn't yet been loaded, load it! See LT-10185. - if (!didRestoreFromPersistence && !Clerk.ListLoadingSuppressed && Clerk.RequestedLoadWhileSuppressed) + if (!Clerk.ListLoadingSuppressed && Clerk.RequestedLoadWhileSuppressed) Clerk.UpdateList(true, true); // sluggishness culprit for LT-12844 was in here Clerk.SetCurrentFromRelatedClerk(); // See if some other clerk wants to influence our current object. ShowRecord(); } - private string GetClerkPersistPathname() - { - return GetSortFilePersistPathname(Cache, Clerk.Id); - } - - internal static string GetSortFilePersistPathname(LcmCache cache, string clerkId) - { - var filename = clerkId + "_SortSeq"; - //(This extension is also known to ProjectRestoreService.RestoreFrom7_0AndNewerBackup.) - // Also to FwXWindow.DiscardProperties(). - var filenameWithExt = Path.ChangeExtension(filename, "fwss"); - var tempDirectory = Path.Combine(cache.ProjectId.ProjectFolder, LcmFileHelper.ksSortSequenceTempDir); - if (!Directory.Exists(tempDirectory)) - Directory.CreateDirectory(tempDirectory); - return Path.Combine(tempDirectory, filenameWithExt); - } - - protected virtual void PersistSortSequence() - { - if (Clerk == null || Clerk.IsDisposed) - return; // temporary clerk, such as a concordance in find example dialog. - // If we're being disposed because the application is crashing, we do NOT want to save the sort - // sequence. It might contain bad objects, or represent a filtered state that is NOT going to - // be persisted because of the crash. LT-11446. - if (FwApp.InCrashedState || Cache == null || Cache.IsDisposed) - return; - var pathname = GetClerkPersistPathname(); - var watch = new Stopwatch(); - watch.Start(); - Clerk.PersistListOn(pathname); - watch.Stop(); - Debug.WriteLine("Saving clerk " + pathname + " took " + watch.ElapsedMilliseconds + " ms."); - } - - // Enhance JohnT: need to verify that sort sequence is current. - private bool RestoreSortSequence() - { - var pathname = GetClerkPersistPathname(); - if (!File.Exists(pathname)) - return false; - var watch = new Stopwatch(); - watch.Start(); - var result = Clerk.RestoreListFrom(pathname); - watch.Stop(); - Debug.WriteLine("Restoring clerk " + pathname + " took " + watch.ElapsedMilliseconds + " ms."); - return result; - } - private void SetTreebarAvailability() { string a = XmlUtils.GetOptionalAttributeValue(m_configurationParameters, "treeBarAvailability", ""); diff --git a/Src/xWorks/xWorksTests/BulkEditBarTests.cs b/Src/xWorks/xWorksTests/BulkEditBarTests.cs index 78e68e413f..075be1de22 100644 --- a/Src/xWorks/xWorksTests/BulkEditBarTests.cs +++ b/Src/xWorks/xWorksTests/BulkEditBarTests.cs @@ -604,12 +604,6 @@ protected override BrowseViewer CreateBrowseViewer(XmlNode nodeSpec, int hvoRoot mediator, propertyTable, sortItemProvider, sda); } - - protected override void PersistSortSequence() - { - // Do no persisting. - } - } }