Exemplo n.º 1
0
        /// <summary>
        /// Removes the first or all of an item from the queue collection
        /// </summary>
        /// <param name="name">The name of the item</param>
        /// <param name="removeAll">True if to remove all instances of an item, and false if only the first</param>
        public async Task <bool> RemoveItemFromCacheQueue(string name, bool removeAll)
        {
            foreach (string cache in mCollection)
            {
                string cacheName = "";

                cacheName = await QueueCollectionHelpers.GetCacheItemNameAsync(cache);

                if (name == cacheName)
                {
                    // If dev wants to remove all instances of name
                    if (removeAll)
                    {
                        mCollection.RemoveAll(c => c == cache);
                    }
                    else
                    {
                        // Otherwise remove first instance of name
                        mCollection.Remove(cache);
                    }

                    return(true);
                }
            }

            // If no instance of name in collection return false
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a named item to the current queue collection
        /// </summary>
        /// <param name="value">The item to add</param>
        /// <param name="name">The name of the item</param>
        public void AddItemToCacheQueue <TItemType>(TItemType value, string name)
        {
            // Check if the item is valid
            QueueCollectionHelpers.CheckItem(value, mCycle, Length, mQueueCapacity);

            // Add item and it's name to queue collection
            mCollection.Add($"/{ name }:{ value }@{ value.GetType().Name }");
        }
Exemplo n.º 3
0
        public void AddCollectionToCacheQueue <TQueueCollectionType>(IEnumerable <TQueueCollectionType> collection, string name)
        {
            // Check if collection is valid
            QueueCollectionHelpers.CheckItem(collection, mCycle, Length, mQueueCapacity);

            // Start cache string
            string cacheCollection = $"/${ name }";

            Parallel.ForEach(collection, (data) =>
            {
                // Add all items in collection to cached collection
                cacheCollection += $"{ data },";
            });

            // Write collection item type
            cacheCollection += $"@{ typeof(TQueueCollectionType).Name }";

            // Add collection to queue collection
            mCollection.Add(cacheCollection);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a named object to the current queue collection
        /// </summary>
        /// <param name="obj">The object to add</param>
        /// <param name="name">The name of the object</param>
        public void AddObjectToCacheQueue <TObjType>(TObjType obj, string name)
            where TObjType : class
        {
            // Check if object is valid
            QueueCollectionHelpers.CheckItem(obj, mCycle, Length, mQueueCapacity);

            // Start cache string
            string cacheObject = $"/*{ name }:";

            Parallel.ForEach(typeof(TObjType).GetProperties(), (property) =>
            {
                // Add all property names and it's values to cached object
                cacheObject += $"{ property.Name }={ property.GetValue(obj) },";
            });

            // Write object class type
            cacheObject += $"@{ obj.GetType().Name }";

            // Add object to queue collection
            mCollection.Add(cacheObject);
        }