Provides a way to edit an ArchiveList since all edits must be atomic. WARNING: Instancing this class on an ArchiveList will lock the class until Dispose is called. Therefore, keep locks to a minimum and always use a Using block.
Inheritance: IDisposable
Ejemplo n.º 1
0
        private void DeleteFiles(List <Guid> files)
        {
            using ArchiveListEditor <TKey, TValue> editor = m_archiveList.AcquireEditLock();

            foreach (Guid file in files)
            {
                editor.TryRemoveAndDelete(file);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the specified files into the archive list.
        /// </summary>
        /// <param name="archiveFiles"></param>
        public override void LoadFiles(IEnumerable <string> archiveFiles)
        {
            if (m_disposed)
            {
                throw new Exception("Object is disposing");
            }

            List <SortedTreeTable <TKey, TValue> > loadedFiles = new List <SortedTreeTable <TKey, TValue> >();

            foreach (string file in archiveFiles)
            {
                try
                {
                    SortedTreeFile sortedTreeFile        = SortedTreeFile.OpenFile(file, isReadOnly: true);
                    SortedTreeTable <TKey, TValue> table = sortedTreeFile.OpenTable <TKey, TValue>();

                    if (table is null)
                    {
                        sortedTreeFile.Dispose();
                        //archiveFile.Delete(); // TODO: Consider the consequences of deleting a file.
                    }
                    else
                    {
                        if (m_listLog.ShouldBeDeleted(table.ArchiveId))
                        {
                            Log.Publish(MessageLevel.Warning, "File being deleted", "The supplied file is being deleted because it was part of a previous rollover that completed but the server crashed before it was properly deleted." + file);
                            table.BaseFile.Delete();
                        }
                        else
                        {
                            loadedFiles.Add(table);
                        }
                    }

                    Log.Publish(MessageLevel.Info, "Loading Files", "Successfully opened: " + file);
                }
                catch (Exception ex)
                {
                    Log.Publish(MessageLevel.Warning, "Loading Files", "Skipping Failed File: " + file, null, ex);
                }
            }

            using ArchiveListEditor <TKey, TValue> edit = AcquireEditLock();

            if (m_disposed)
            {
                loadedFiles.ForEach(table => table.Dispose());
                throw new Exception("Object is disposing");
            }

            foreach (SortedTreeTable <TKey, TValue> file in loadedFiles)
            {
                try
                {
                    edit.Add(file);
                }
                catch (Exception ex)
                {
                    Log.Publish(MessageLevel.Warning, "Attaching File", "File already attached: " + file.ArchiveId, file.BaseFile.FilePath, ex);
                    file.BaseFile.Dispose();
                }
            }
        }