示例#1
0
        /// <summary>
        /// Creates a log that monitors pending deletions.
        /// </summary>
        /// <param name="settings">Optional settings for the log. If none are specified, the default will not load the settings.</param>
        public ArchiveListLog(ArchiveListLogSettings settings = null)
            : base(MessageClass.Framework)
        {
            if (settings == null)
            {
                settings = new ArchiveListLogSettings();
            }

            m_settings = settings.CloneReadonly();
            m_settings.Validate();

            m_syncRoot    = new object();
            m_pendingFile = new ArchiveListLogFile();

            if (m_settings.IsFileBacked)
            {
                foreach (var file in Directory.GetFiles(m_settings.LogPath, m_settings.SearchPattern))
                {
                    var logFile = new ArchiveListLogFile();
                    logFile.Load(file);
                    if (logFile.IsValid)
                    {
                        m_files.Add(logFile);
                    }
                }
            }

            m_allFilesToDelete = new HashSet <Guid>(GetAllFilesToDelete());
        }
示例#2
0
        /// <summary>
        /// If the log is file backed
        /// </summary>
        public void SaveLogToDisk()
        {
            if (!m_settings.IsFileBacked)
            {
                return;
            }

            lock (m_syncRoot)
            {
                if (m_disposed)
                {
                    throw new ObjectDisposedException(GetType().FullName);
                }

                if (m_pendingFile.FilesToDelete.Count > 0)
                {
                    string file = m_settings.GenerateNewFileName();
                    m_pendingFile.Save(file);
                    m_files.Add(m_pendingFile);
                    m_pendingFile = new ArchiveListLogFile();
                }
            }
        }