コード例 #1
0
        public VltCollection AddCollection(Vault addToVault, string className, string collectionName, VltCollection parentCollection)
        {
            if (FindCollectionByName(className, collectionName) != null)
            {
                throw new DuplicateNameException(
                          $"A collection in the class '{className}' with the name '{collectionName}' already exists.");
            }

            var collection = new VltCollection(addToVault, Database.FindClass(className), collectionName);

            if (parentCollection != null)
            {
                // Make the new collection a child of the parent
                parentCollection.AddChild(collection);
            }
            else
            {
                // Just add the collection
                Database.RowManager.Rows.Add(collection);
            }

            Collections[collection.ShortPath] = collection;

            return(collection);
        }
コード例 #2
0
        public VltCollection AddCollection(VltCollection collection, VltCollection parentCollection = null)
        {
            if (parentCollection != null)
            {
                parentCollection.AddChild(collection);
            }
            else
            {
                Database.RowManager.Rows.Add(collection);
            }

            Collections[collection.ShortPath] = collection;

            return(collection);
        }
コード例 #3
0
        /// <summary>
        ///     Called after all vaults have been loaded in order to generate a proper hierarchy.
        /// </summary>
        public void CompleteLoad()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            Dictionary <VltClass, ulong> hashDictionary = Classes.ToDictionary(c => c, c => VLT64Hasher.Hash(c.Name));
            Dictionary <ulong, Dictionary <string, VltCollection> > collectionDictionary =
                RowManager.Rows.GroupBy(r => hashDictionary[r.Class])
                .ToDictionary(g => g.Key, g => g.ToDictionary(c => c.Name, c => c));

            for (int i = RowManager.Rows.Count - 1; i >= 0; i--)
            {
                VltCollection row = RowManager.Rows[i];

                if (_parentKeyDictionary.TryGetValue(row, out string parentKey))
                {
                    VltCollection parentCollection = collectionDictionary[hashDictionary[row.Class]][parentKey];
                    parentCollection.AddChild(row);
                    RowManager.Rows.RemoveAt(i);
                }
            }

            stopwatch.Stop();
            _parentKeyDictionary.Clear();
        }
コード例 #4
0
ファイル: RowManager.cs プロジェクト: funk-yourself/VaultLib
        /// <summary>
        ///     Adds a collection with the given name to the given class, optionally making it
        ///     the child of the given parent collection.
        /// </summary>
        /// <param name="vault">The vault to add the collection to.</param>
        /// <param name="className">The name of the class to add the collection to.</param>
        /// <param name="newName">The name of the collection.</param>
        /// <param name="parentCollection">The parent collection, if one is necessary.</param>
        /// <returns>The new collection</returns>
        public VltCollection AddCollection(Vault vault, string className, string newName,
                                           VltCollection parentCollection = null)
        {
            if (FindCollectionByName(className, newName) != null)
            {
                throw new DuplicateNameException(
                          $"A collection in the class '{className}' with the name '{newName}' already exists.");
            }

            var collection = new VltCollection(vault, _database.FindClass(className), newName);

            if (parentCollection != null)
            {
                // Make the new collection a child of the parent
                parentCollection.AddChild(collection);
            }
            else
            {
                // Just add the collection
                Rows.Add(collection);
            }

            return(collection);
        }