/// <summary> /// Creates an ArchiveList /// </summary> /// <param name="settings">The settings for the archive list. Null will revert to a default setting.</param> public ArchiveList(ArchiveListSettings settings = null) { if (settings == null) { settings = new ArchiveListSettings(); } m_settings = settings.CloneReadonly(); m_settings.Validate(); m_syncRoot = new object(); m_fileSummaries = new SortedList <Guid, ArchiveTableSummary <TKey, TValue> >(); m_allSnapshots = new WeakList <ArchiveListSnapshot <TKey, TValue> >(); m_listLog = new ArchiveListLog(m_settings.LogSettings); m_filesToDelete = new List <SortedTreeTable <TKey, TValue> >(); m_filesToDispose = new List <SortedTreeTable <TKey, TValue> >(); m_processRemovals = new ScheduledTask(ThreadingMode.DedicatedBackground); m_processRemovals.Running += ProcessRemovals_Running; m_processRemovals.Disposing += ProcessRemovals_Disposing; m_processRemovals.UnhandledException += ProcessRemovals_UnhandledException; AttachFileOrPath(m_settings.ImportPaths); HashSet <Guid> files = new HashSet <Guid>(m_filesToDelete.Select(x => x.ArchiveId)); m_listLog.ClearCompletedLogs(files); }
private void ProcessRemovals_Running(object sender, EventArgs <ScheduledTaskRunningReason> eventArgs) { bool wasAFileDeleted = false; lock (m_syncRoot) { for (int x = m_filesToDelete.Count - 1; x >= 0; x--) { SortedTreeTable <TKey, TValue> file = m_filesToDelete[x]; if (!InternalIsFileBeingUsed(file)) { wasAFileDeleted = true; file.BaseFile.Delete(); m_filesToDelete.RemoveAt(x); } } for (int x = m_filesToDispose.Count - 1; x >= 0; x--) { SortedTreeTable <TKey, TValue> file = m_filesToDispose[x]; if (!InternalIsFileBeingUsed(file)) { file.BaseFile.Dispose(); m_filesToDispose.RemoveAt(x); } } if (wasAFileDeleted) { HashSet <Guid> files = new HashSet <Guid>(m_filesToDelete.Select(x => x.ArchiveId)); m_listLog.ClearCompletedLogs(files); } if (m_filesToDelete.Count > 0 || m_filesToDispose.Count > 0) { m_processRemovals.Start(1000); } } }