diff --git a/SayMore.sln.DotSettings b/SayMore.sln.DotSettings index 33231761..6e4107c3 100644 --- a/SayMore.sln.DotSettings +++ b/SayMore.sln.DotSettings @@ -6,6 +6,7 @@ True True True + True True True True diff --git a/src/SayMore/Model/ElementRepository.cs b/src/SayMore/Model/ElementRepository.cs index f737d28a..650fb553 100644 --- a/src/SayMore/Model/ElementRepository.cs +++ b/src/SayMore/Model/ElementRepository.cs @@ -5,17 +5,19 @@ using System.Xml; using SIL.Code; using SIL.Windows.Forms.FileSystem; -using SayMore.Model.Files; -using SayMore.UI.ProjectWindow; +using SIL.Reporting; +using L10NSharp; +using FileType = SayMore.Model.Files.FileType; +using System.Threading; namespace SayMore.Model { /// ---------------------------------------------------------------------------------------- public class ElementIdChangedArgs : EventArgs { - public ProjectElement Element { get; private set; } - public string OldId { get; private set; } - public string NewId { get; private set; } + public ProjectElement Element { get; } + public string OldId { get; } + public string NewId { get; } /// ------------------------------------------------------------------------------------ public ElementIdChangedArgs(ProjectElement element, string oldId, string newId) @@ -28,7 +30,7 @@ public ElementIdChangedArgs(ProjectElement element, string oldId, string newId) /// ---------------------------------------------------------------------------------------- /// - /// This is reposible for finding, creating, and removing items of the given type T + /// This is responsible for finding, creating, and removing items of the given type T /// (i.e. Sessions or People) /// /// ---------------------------------------------------------------------------------------- @@ -67,14 +69,14 @@ public ElementRepository(string projectDirectory, string elementGroupName, [Obsolete("For Mocking Only")] public ElementRepository(){} - public List FileLoadErrors { get; private set; } + public List FileLoadErrors { get; } /// ------------------------------------------------------------------------------------ /// /// Updates the list of items by looking in the file system for all the subfolders /// in the project's folder corresponding to this repository. /// - /// Any file load errors ocurring during this call will be noted in + /// Any file load errors occurring during this call will be noted in /// FileLoadErrors. Caller is responsible for checking this and handling them as /// appropriate. /// ------------------------------------------------------------------------------------ @@ -82,11 +84,56 @@ public void RefreshItemList() { FileLoadErrors.Clear(); - var folders = new HashSet(Directory.GetDirectories(_rootFolder)); + // SP-2273... + string[] sessionDirectories = null; + var retry = false; + do + { + try + { + sessionDirectories = Directory.GetDirectories(_rootFolder); + } + catch (Exception e) + { + if (retry) + throw; + + if (e is DirectoryNotFoundException) + { + Thread.Sleep(200); // Give it a fighting chance in case it was something transient. + if (Directory.Exists(_rootFolder)) + { + retry = true; + continue; + } + } + if (e is IOException || e is UnauthorizedAccessException) + { + ErrorReport.ReportNonFatalExceptionWithMessage(e, + string.Format(LocalizationManager.GetString( + "MainWindow.ElementFolderMissingOrUnavailable", + "It looks like the {0} folder is no longer accessible. If you " + + "are able to fix this, {1} will retry. Otherwise, please report " + + "this ({2}).", + "Param 0: element type (\"Session\" or \"Person\"); "+ + "Param 1: \"SayMore\" (program name); "+ + "Param 2: Jira issue number (for developers)"), + ElementFileType.Name, Program.ProductName, "SP-2273")); + if (!Directory.Exists(_rootFolder)) + throw; + retry = true; + } + else + throw; + } + } while (retry); + // ...SP-2273 + + var folders = new HashSet(sessionDirectories); // Go through the existing sessions we have and remove // any that no longer have a sessions folder. - for (int i = _items.Count() - 1; i >= 0; i--) + for (int i = _items.Count - 1; i >= 0; i--) { if (!folders.Contains(_items[i].FolderPath)) _items.RemoveAt(i); @@ -116,19 +163,13 @@ public void RefreshItemList() } /// ------------------------------------------------------------------------------------ - public virtual IEnumerable AllItems - { - get { return _items; } - } + public virtual IEnumerable AllItems => _items; /// ------------------------------------------------------------------------------------ - public virtual string PathToFolder - { - get { return _rootFolder; } - } + public virtual string PathToFolder => _rootFolder; /// ------------------------------------------------------------------------------------ - public FileType ElementFileType { get; private set; } + public FileType ElementFileType { get; } /// ------------------------------------------------------------------------------------ public T CreateNew(string id)