private void ProcessDirectory(DirectoryInfo directory, int retry = 0) { DateTime processStart = DateTime.Now; try { if (Globals.VerboseLogging) { Logger.Info($"Loading details for directory '{directory.FullName}'."); } var album = new Repository.Album(Logger, directory, SpecialtyAlbums, AlbumSubDirectories); var existsInDb = album.Exists(); if (album.Changed > LastScan || !existsInDb) { album.LoadData(); album.AddOrUpdate(); DirectoriesProcessed++; } else { DirectoriesSkipped++; } if ((DirectoriesProcessed + DirectoriesSkipped) % int.Parse(ConfigurationManager.AppSettings["ProcessUpdateCounter"] ?? "100") == 0) { Logger.Info($"Processed {(DirectoriesProcessed + DirectoriesSkipped)} directories..."); } } catch (Exception ex) { if (retry < 3) { retry++; Logger.Info($"Error processing directory: {directory.FullName}. Retrying {retry} of 3..."); ProcessDirectory(directory, retry); } else { Logger.Error($"Error processing directory: {directory.FullName}", ex); if (!ex.Message.Contains("An error occurred while starting a transaction on the provider connection")) { Errors.Add(new FileError(ex, directory.FullName, $"Error processing directory. Error: {ex.Message}")); } else { ScanActionsRetry.Add(() => ProcessDirectory(directory)); } } } DateTime processEnd = DateTime.Now; if (Globals.VerboseLogging) { Logger.Info($"Directory '{directory.FullName}' processed in {(processEnd - processStart).TotalMilliseconds} milliseconds."); } }
private void ProcessDirectory(DirectoryInfo directory) { try { var album = new Repository.Album(Logger, directory); album.AddOrUpdate(); DirectoriesProcessed++; } catch (Exception ex) { Logger.Error($"Error processing directory: {directory.FullName}", ex); Errors.Add(new FileError(ex, directory.FullName, "Error processing directory.")); } }