Beispiel #1
0
        public HashSet <string> GetAllFilePaths()
        {
            try
            {
                HashSet <string> filePlaceholderPaths = new HashSet <string>(StringComparer.Ordinal);

                string error;
                if (!this.TryLoadFromDisk <string, string>(
                        this.TryParseAddLine,
                        this.TryParseRemoveLine,
                        (key, value) =>
                {
                    if (!PlaceholderData.IsShaAFolder(value))
                    {
                        filePlaceholderPaths.Add(key);
                    }
                },
                        out error))
                {
                    throw new InvalidDataException(error);
                }

                return(filePlaceholderPaths);
            }
            catch (Exception e)
            {
                throw new FileBasedCollectionException(e);
            }
        }
        public Dictionary <string, PlaceholderListDatabase.PlaceholderData> GetAllFileEntries()
        {
            try
            {
                Dictionary <string, PlaceholderListDatabase.PlaceholderData> filePlaceholdersFromDiskByPath =
                    new Dictionary <string, PlaceholderListDatabase.PlaceholderData>(Math.Max(1, this.EstimatedCount), StringComparer.Ordinal);

                string error;
                if (!this.TryLoadFromDisk <string, string>(
                        this.TryParseAddLine,
                        this.TryParseRemoveLine,
                        (key, value) =>
                {
                    if (!PlaceholderData.IsShaAFolder(value))
                    {
                        filePlaceholdersFromDiskByPath[key] = new PlaceholderData(path: key, fileShaOrFolderValue: value);
                    }
                },
                        out error))
                {
                    throw new InvalidDataException(error);
                }

                return(filePlaceholdersFromDiskByPath);
            }
            catch (Exception e)
            {
                throw new FileBasedCollectionException(e);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets all entries and prepares the PlaceholderListDatabase for a call to WriteAllEntriesAndFlush.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// GetAllEntries was called (a second time) without first calling WriteAllEntriesAndFlush.
        /// </exception>
        /// <remarks>
        /// Usage notes:
        ///     - All calls to GetAllEntries must be paired with a subsequent call to WriteAllEntriesAndFlush
        ///     - If WriteAllEntriesAndFlush is *not* called entries that were added to the PlaceholderListDatabase after
        ///       calling GetAllEntries will be lost
        /// </remarks>
        public void GetAllEntries(out List <IPlaceholderData> filePlaceholders, out List <IPlaceholderData> folderPlaceholders)
        {
            try
            {
                List <IPlaceholderData> filePlaceholdersFromDisk   = new List <IPlaceholderData>(Math.Max(1, this.count));
                List <IPlaceholderData> folderPlaceholdersFromDisk = new List <IPlaceholderData>(Math.Max(1, (int)(this.count * .3)));

                string error;
                if (!this.TryLoadFromDisk <string, string>(
                        this.TryParseAddLine,
                        this.TryParseRemoveLine,
                        (key, value) =>
                {
                    if (PlaceholderData.IsShaAFolder(value))
                    {
                        folderPlaceholdersFromDisk.Add(new PlaceholderData(path: key, fileShaOrFolderValue: value));
                    }
                    else
                    {
                        filePlaceholdersFromDisk.Add(new PlaceholderData(path: key, fileShaOrFolderValue: value));
                    }
                },
                        out error,
                        () =>
                {
                    if (this.placeholderChangesWhileRebuildingList != null)
                    {
                        throw new InvalidOperationException($"PlaceholderListDatabase should always flush queue placeholders using WriteAllEntriesAndFlush before calling {(nameof(this.GetAllEntries))} again.");
                    }

                    this.placeholderChangesWhileRebuildingList = new List <PlaceholderDataEntry>();
                }))
                {
                    throw new InvalidDataException(error);
                }

                filePlaceholders   = filePlaceholdersFromDisk;
                folderPlaceholders = folderPlaceholdersFromDisk;
            }
            catch (Exception e)
            {
                throw new FileBasedCollectionException(e);
            }
        }