Example #1
0
        /// <summary>
        /// Gets the printable CacheIndexInternalList.
        /// </summary>
        /// <param name="internalIndexList">The internal index list.</param>
        /// <returns></returns>
        internal static string GetPrintableCacheIndexInternalList(List <CacheIndexInternal> internalIndexList,
                                                                  TagHashCollection tagHashCollection, short typeId)
        {
            StringBuilder logStr = new StringBuilder();

            logStr.Append("CacheIndexInternalList Info").Append(Environment.NewLine);

            int itemCount;

            foreach (CacheIndexInternal cii in internalIndexList)
            {
                if (cii.InDeserializationContext != null && cii.InDeserializationContext.IndexId != null)
                {
                    //CacheIndexInternal Name
                    logStr.Append("IndexName : ").Append(cii.InDeserializationContext.IndexName);
                    logStr.Append(", IndexId : ").Append(IndexCacheUtils.GetReadableByteArray(cii.InDeserializationContext.IndexId)).Append(Environment.NewLine);
                }

                if (cii.InternalItemList != null)
                {
                    logStr.Append("CacheIndexInternal.InternalItemList.Count : ").Append(cii.InternalItemList.Count.ToString()).Append(Environment.NewLine);
                    itemCount = 0;
                    foreach (InternalItem internalItem in cii.InternalItemList)
                    {
                        LogItem(logStr, internalItem, itemCount++, tagHashCollection, typeId);
                    }
                }
                else
                {
                    logStr.Append("CacheIndexInternal.ItemIdList = null").Append(Environment.NewLine);
                }
            }
            return(logStr.ToString());
        }
Example #2
0
        /// <summary>
        /// Gets printable CacheIndex.
        /// </summary>
        /// <param name="clientIndex">client index.</param>
        /// <param name="tagHashCollection">tag Hash Collection.</param>
        /// <param name="typeId">type id.</param>
        /// <returns></returns>
        internal static string GetPrintableCacheIndex(CacheIndex clientIndex, TagHashCollection tagHashCollection, short typeId)
        {
            StringBuilder logStr = new StringBuilder();

            logStr.Append(Environment.NewLine).Append("Client Index Info").Append(Environment.NewLine);
            int itemCount;

            logStr.Append("IndexId : ").Append(IndexCacheUtils.GetReadableByteArray(clientIndex.IndexId)).Append(Environment.NewLine);
            logStr.Append("Metadata : ").Append(clientIndex.Metadata == null ? "Null" : IndexCacheUtils.GetReadableByteArray(clientIndex.Metadata)).Append(Environment.NewLine);
            logStr.Append("TargetIndexName : ").Append(clientIndex.TargetIndexName).Append(Environment.NewLine);
            logStr.Append("IndexTagmapping : ").Append(clientIndex.IndexTagMapping == null ? "Null" : clientIndex.IndexTagMapping.Count.ToString()).Append(Environment.NewLine);
            if (clientIndex.IndexTagMapping != null && clientIndex.IndexTagMapping.Count > 0)
            {
                logStr.Append("IndexTagmapping Items : ");
                foreach (var indexTag in clientIndex.IndexTagMapping)
                {
                    logStr.Append("IndexName : ").Append(indexTag.Key).Append(" Tags : ");
                    foreach (var tag in indexTag.Value)
                    {
                        logStr.Append(tag).Append(" , ");
                    }
                }
                logStr.Append(Environment.NewLine);
            }

            //AddList))
            if (clientIndex.AddList != null)
            {
                logStr.Append("ClientIndex.AddList.Count : ").Append(clientIndex.AddList.Count).Append(Environment.NewLine);

                itemCount = 0;
                foreach (IndexDataItem indexDataItem in clientIndex.AddList)
                {
                    LogItem(logStr, indexDataItem, itemCount, tagHashCollection, typeId);
                }
            }
            else
            {
                logStr.Append("ClientIndex.AddList = null").Append(Environment.NewLine);
            }

            //DeleteList
            if (clientIndex.DeleteList != null)
            {
                logStr.Append("ClientIndex.DeleteList.Count : ").Append(clientIndex.DeleteList.Count).Append(Environment.NewLine);

                itemCount = 0;
                foreach (IndexItem indexItem in clientIndex.DeleteList)
                {
                    LogItem(logStr, indexItem, itemCount, tagHashCollection, typeId);
                }
            }
            else
            {
                logStr.Append("ClientIndex.DeleteList = null").Append(Environment.NewLine);
            }
            return(logStr.ToString());
        }
Example #3
0
        /// <summary>
        /// Updates the existing index item.
        /// </summary>
        /// <param name="clientIndex">Index from the client.</param>
        /// <param name="cacheIndexInternal">The cache index internal.</param>
        /// <param name="indexInfo">The index info.</param>
        /// <param name="addItem">The add item.</param>
        /// <param name="searchIndex">Index to search.</param>
        /// <param name="storeContext">The store context.</param>
        /// <param name="comparer">The comparer.</param>
        private static void UpdateExistingIndexItem(CacheIndex clientIndex, CacheIndexInternal cacheIndexInternal, Index indexInfo, IndexDataItem addItem, int searchIndex, IndexStoreContext storeContext, InternalItemComparer comparer)
        {
            InternalItem internalItem = cacheIndexInternal.InternalItemList[searchIndex];

            if (clientIndex.TargetIndexName != null) //Save to single index
            {
                if (addItem.Tags != null && addItem.Tags.Count > 0)
                {
                    bool reposition = IsRepositioningOfIndexItemRequired(indexInfo, addItem, internalItem);

                    // Update all tags on the internal item
                    foreach (KeyValuePair <string, byte[]> kvp in addItem.Tags)
                    {
                        storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, kvp.Key);
                        internalItem.UpdateTag(TagHashCollection.GetTagHashCode(kvp.Key), kvp.Value);
                    }

                    // Reposition index item if required
                    if (reposition)
                    {
                        RepositionIndexItem(cacheIndexInternal, indexInfo, addItem, searchIndex, internalItem, comparer);
                    }
                }
            }
            else //Save to multiple indexes
            {
                if (addItem.Tags != null && addItem.Tags.Count > 0)
                {
                    List <string> tagNameList;
                    byte[]        tagValue;
                    clientIndex.IndexTagMapping.TryGetValue(cacheIndexInternal.InDeserializationContext.IndexName, out tagNameList);

                    bool reposition = IsRepositioningOfIndexItemRequired(indexInfo, addItem, internalItem);

                    // Update all tags on the internal item
                    foreach (string tagName in tagNameList)
                    {
                        //Add to tagHashCollection
                        storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, tagName);
                        addItem.TryGetTagValue(tagName, out tagValue);
                        internalItem.UpdateTag(TagHashCollection.GetTagHashCode(tagName), tagValue);
                    }

                    // Reposition index item if required
                    if (reposition)
                    {
                        RepositionIndexItem(cacheIndexInternal, indexInfo, addItem, searchIndex, internalItem, comparer);
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Processes the filter.
        /// </summary>
        /// <param name="internalItem">The internal item.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="inclusiveFilter">if set to <c>true</c> includes the items that pass the filter; otherwise , <c>false</c>.</param>
        /// <param name="tagHashCollection">The TagHashCollection.</param>
        /// <param name="metadataPropertyCollection">The MetadataPropertyCollection.</param>
        /// <returns><c>true</c> if item passes the filter; otherwise, <c>false</c></returns>
        internal static bool ProcessFilter(InternalItem internalItem,
                                           Filter filter,
                                           bool inclusiveFilter,
                                           TagHashCollection tagHashCollection,
                                           MetadataPropertyCollection metadataPropertyCollection)
        {
            bool retVal = DoProcessFilter(internalItem, filter, tagHashCollection, metadataPropertyCollection);

            if (inclusiveFilter)
            {
                return(retVal);
            }
            return(!retVal);
        }
Example #5
0
 internal static void Process(InternalItem internalItem,
                              TagHashCollection tagHashCollection,
                              short typeId,
                              DomainSpecificProcessingType domainSpecificProcessingType,
                              DomainSpecificConfig domainSpecificConfig)
 {
     switch (domainSpecificProcessingType)
     {
     case DomainSpecificProcessingType.StreamRecency:
         tagHashCollection.AddTag(typeId, RecencyTagName);
         internalItem.TagList.Add(new System.Collections.Generic.KeyValuePair <int, byte[]>(TagHashCollection.GetTagHashCode(RecencyTagName),
                                                                                            GetRecency(internalItem, domainSpecificConfig.StreamRecencyConfig)));
         break;
     }
 }
        /// <summary>
        /// Converts to tag list.
        /// </summary>
        /// <param name="tagsDictionary">The tags dictionary.</param>
        /// <returns></returns>
        internal static List <KeyValuePair <int /*TagHashCode*/, byte[] /*TagName*/> > ConvertToTagList(
            Dictionary <string /*TagName*/, byte[] /* TagValue*/> tagsDictionary)
        {
            List <KeyValuePair <int, byte[]> > tagsList = null;

            if (tagsDictionary != null && tagsDictionary.Count > 0)
            {
                tagsList = new List <KeyValuePair <int, byte[]> >(tagsDictionary.Count);
                foreach (KeyValuePair <string, byte[]> kvp in tagsDictionary)
                {
                    tagsList.Add(new KeyValuePair <int, byte[]>(TagHashCollection.GetTagHashCode(kvp.Key), kvp.Value));
                }
            }
            return(tagsList);
        }
Example #7
0
 /// <summary>
 /// Tries the get tag value.
 /// </summary>
 /// <param name="tagName">Name of the tag.</param>
 /// <param name="tagValue">The tag value.</param>
 /// <returns></returns>
 public bool TryGetTagValue(string tagName, out byte[] tagValue)
 {
     tagValue = null;
     if (TagList != null && TagList.Count > 0 && tagName != null)
     {
         int tagHashCode = TagHashCollection.GetTagHashCode(tagName);
         for (int i = 0; i < TagList.Count; i++)
         {
             if (TagList[i].Key == tagHashCode)
             {
                 tagValue = TagList[i].Value;
                 return(true);
             }
         }
     }
     return(false);
 }
Example #8
0
        /// <summary>
        /// Gets printable CacheIndex.
        /// </summary>
        /// <param name="clientIndex">client index.</param>
        /// <param name="tagHashCollection">tag Hash Collection.</param>
        /// <returns></returns>
        internal static string GetPrintableCacheIndex(CacheIndex clientIndex, TagHashCollection tagHashCollection, short typeId)
        {
            StringBuilder logStr = new StringBuilder();

            logStr.Append(Environment.NewLine).Append("Client Index Info").Append(Environment.NewLine);
            int itemCount;

            logStr.Append("IndexId : ").Append(IndexCacheUtils.GetReadableByteArray(clientIndex.IndexId)).
            Append(Environment.NewLine);

            //AddList
            if (clientIndex.AddList != null)
            {
                logStr.Append("ClientIndex.AddList.Count : ").Append(clientIndex.AddList.Count).Append(Environment.NewLine);

                itemCount = 0;
                foreach (IndexDataItem indexDataItem in clientIndex.AddList)
                {
                    LogItem(logStr, indexDataItem, itemCount, tagHashCollection, typeId);
                }
            }
            else
            {
                logStr.Append("ClientIndex.AddList = null").Append(Environment.NewLine);
            }

            //DeleteList
            if (clientIndex.DeleteList != null)
            {
                logStr.Append("ClientIndex.DeleteList.Count : ").Append(clientIndex.DeleteList.Count).Append(Environment.NewLine);

                itemCount = 0;
                foreach (IndexItem indexItem in clientIndex.DeleteList)
                {
                    LogItem(logStr, indexItem, itemCount, tagHashCollection, typeId);
                }
            }
            else
            {
                logStr.Append("ClientIndex.DeleteList = null").Append(Environment.NewLine);
            }
            return(logStr.ToString());
        }
Example #9
0
        /// <summary>
        /// Adds the new item.
        /// </summary>
        /// <param name="clientIndex">Index from the client.</param>
        /// <param name="cacheIndexInternal">The cache index internal.</param>
        /// <param name="indexInfo">The index info.</param>
        /// <param name="addItem">The add item.</param>
        /// <param name="storeContext">The store context.</param>
        /// <param name="comparer">The comparer.</param>
        private static void AddNewItem(CacheIndex clientIndex,
                                       CacheIndexInternal cacheIndexInternal,
                                       Index indexInfo, IndexDataItem addItem,
                                       IndexStoreContext storeContext,
                                       InternalItemComparer comparer)
        {
            int searchIndex;
            List <KeyValuePair <int, byte[]> > kvpList;

            searchIndex = cacheIndexInternal.GetInsertPosition(addItem, indexInfo.PrimarySortInfo.SortOrderList[0].SortBy, comparer);

            //Add item to CacheIndexInternal
            kvpList = null;
            if (addItem.Tags != null && addItem.Tags.Count > 0)
            {
                kvpList = new List <KeyValuePair <int, byte[]> >();

                if (clientIndex.TargetIndexName != null) //Save to single index
                {
                    foreach (KeyValuePair <string, byte[]> kvp in addItem.Tags)
                    {
                        //Add to tagHashCollection
                        storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, kvp.Key);
                        kvpList.Add(new KeyValuePair <int, byte[]>(TagHashCollection.GetTagHashCode(kvp.Key), kvp.Value));
                    }
                }
                else //Save to multiple indexes
                {
                    List <string> tagNameList;
                    clientIndex.IndexTagMapping.TryGetValue(cacheIndexInternal.InDeserializationContext.IndexName, out tagNameList);
                    foreach (string tagName in tagNameList)
                    {
                        //Add to tagHashCollection
                        storeContext.TagHashCollection.AddTag(cacheIndexInternal.InDeserializationContext.TypeId, tagName);
                        kvpList.Add(new KeyValuePair <int, byte[]>(TagHashCollection.GetTagHashCode(tagName), addItem.Tags[tagName]));
                    }
                }
            }
            cacheIndexInternal.InsertItem(new InternalItem {
                ItemId = addItem.ItemId, TagList = kvpList
            }, searchIndex, true);
        }
Example #10
0
        /// <summary>
        /// Processes the aggregate filter.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="internalItem">The internal item.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="tagHashCollection">The TagHashCollection.</param>
        /// <param name="metadataPropertyCollection">The MetadataPropertyCollection.</param>
        /// <returns><c>true</c> if item passes the filter; otherwise, <c>false</c></returns>
        private static bool ProcessAggregateFilter <T>(InternalItem internalItem,
                                                       T filter,
                                                       TagHashCollection tagHashCollection,
                                                       MetadataPropertyCollection metadataPropertyCollection)
            where T : AggregateFilter
        {
            bool          retVal = !filter.ShortCircuitHint;
            List <Filter> later  = new List <Filter>();

            // evaluate root level items first
            for (ushort i = 0; i < filter.Count; i++)
            {
                if (filter[i] is Condition)
                {
                    // evaluate now
                    retVal = DoProcessFilter(internalItem, filter[i], tagHashCollection, metadataPropertyCollection);
                    if (retVal == filter.ShortCircuitHint)
                    {
                        break;
                    }
                }
                else
                {
                    // evaluate later
                    later.Add(filter[i]);
                }
            }

            // No need to evaluate aggreate filters if result already obtained.
            if (retVal != filter.ShortCircuitHint)
            {
                foreach (Filter f in later)
                {
                    retVal = DoProcessFilter(internalItem, f, tagHashCollection, metadataPropertyCollection);
                    if (retVal == filter.ShortCircuitHint)
                    {
                        break;
                    }
                }
            }
            return(retVal);
        }
Example #11
0
        /// <summary>
        /// Does the process filter.
        /// </summary>
        /// <param name="internalItem">The internal item.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="tagHashCollection">The TagHashCollection.</param>
        /// <param name="metadataPropertyCollection">The MetadataPropertyCollection.</param>
        /// <returns><c>true</c> if item passes the filter; otherwise, <c>false</c></returns>
        private static bool DoProcessFilter(InternalItem internalItem,
                                            Filter filter,
                                            TagHashCollection tagHashCollection,
                                            MetadataPropertyCollection metadataPropertyCollection)
        {
            bool retVal = false;

            switch (filter.FilterType)
            {
            case FilterType.Condition:
                retVal = ProcessCondition(internalItem, filter as Condition, metadataPropertyCollection);
                break;

            case FilterType.And:
                retVal = ProcessAggregateFilter(internalItem, filter as AndFilter, tagHashCollection, metadataPropertyCollection);
                break;

            case FilterType.Or:
                retVal = ProcessAggregateFilter(internalItem, filter as OrFilter, tagHashCollection, metadataPropertyCollection);
                break;
            }

            return(retVal);
        }
        private static void LogItem(StringBuilder logStr, IItem iItem, int itemCount, TagHashCollection tagHashCollection, short typeId)
        {           
            if (iItem.ItemId == null)
            {
                logStr.Append("ItemList[").Append(itemCount.ToString()).Append("].ItemId = null").Append(Environment.NewLine);
            }
            else if (iItem.ItemId.Length == 0)
            {
                logStr.Append("ItemList[").Append(itemCount.ToString()).Append("].ItemId.Length = 0").Append(Environment.NewLine);
            }
            else
            {
                logStr.Append("ItemList[").Append(itemCount.ToString()).Append("].ItemId = ").Append(IndexCacheUtils.GetReadableByteArray(iItem.ItemId)).Append(Environment.NewLine);
            }

            logStr.Append("Tags.Count : ");
            if (iItem is IndexItem)
            {
                var indexItem = (IndexItem)iItem;
                if (indexItem.Tags != null && indexItem.Tags.Count > 0)
                {
                    logStr.Append(indexItem.Tags.Count).Append(" - ");
                    foreach (var tag in indexItem.Tags)
                    {
                        logStr.Append(tag.Key).Append("=").Append(IndexCacheUtils.GetReadableByteArray(tag.Value)).
                            Append(", ");
                    }
                }
                else
                {
                    logStr.Append("0");
                }
            }
            else if (iItem is InternalItem)
            {
                var internalItem = (InternalItem)iItem;
                if (internalItem.TagList != null && internalItem.TagList.Count > 0)
                {
                    logStr.Append(internalItem.TagList.Count).Append(" - ");
                    foreach (var tag in internalItem.TagList)
                    {
                        logStr.Append(tagHashCollection.GetTagName(typeId, tag.Key)).
                            Append("=").Append(IndexCacheUtils.GetReadableByteArray(tag.Value)).
                            Append(", ");
                    }
                }
                else
                {
                    logStr.Append("0");
                }
            }
            logStr.Append(Environment.NewLine);
        }
        /// <summary>
        /// Gets printable CacheIndex.
        /// </summary>
        /// <param name="clientIndex">client index.</param>
        /// <param name="tagHashCollection">tag Hash Collection.</param>
        /// <returns></returns>
        internal static string GetPrintableCacheIndex(CacheIndex clientIndex, TagHashCollection tagHashCollection, short typeId)
        {
            StringBuilder logStr = new StringBuilder();
            logStr.Append(Environment.NewLine).Append("Client Index Info").Append(Environment.NewLine);
            int itemCount;

            logStr.Append("IndexId : ").Append(IndexCacheUtils.GetReadableByteArray(clientIndex.IndexId)).
                Append(Environment.NewLine);

            //AddList
            if (clientIndex.AddList != null)
            {
                logStr.Append("ClientIndex.AddList.Count : ").Append(clientIndex.AddList.Count).Append(Environment.NewLine);

                itemCount = 0;
                foreach (IndexDataItem indexDataItem in clientIndex.AddList)
                {
                    LogItem(logStr, indexDataItem, itemCount, tagHashCollection, typeId);
                }
            }
            else
            {
                logStr.Append("ClientIndex.AddList = null").Append(Environment.NewLine);
            }

            //DeleteList
            if (clientIndex.DeleteList != null)
            {
                logStr.Append("ClientIndex.DeleteList.Count : ").Append(clientIndex.DeleteList.Count).Append(Environment.NewLine);

                itemCount = 0;
                foreach (IndexItem indexItem in clientIndex.DeleteList)
                {
                    LogItem(logStr, indexItem, itemCount, tagHashCollection, typeId);
                }
            }
            else
            {
                logStr.Append("ClientIndex.DeleteList = null").Append(Environment.NewLine);
            }
            return logStr.ToString();
        }
        /// <summary>
        /// Gets the printable CacheIndexInternalList.
        /// </summary>
        /// <param name="internalIndexList">The internal index list.</param>
        /// <returns></returns>
        internal static string GetPrintableCacheIndexInternalList(List<CacheIndexInternal> internalIndexList, 
            TagHashCollection tagHashCollection, short typeId)
        {
            StringBuilder logStr = new StringBuilder();
            logStr.Append("CacheIndexInternalList Info").Append(Environment.NewLine);

            int itemCount;
            foreach (CacheIndexInternal cii in internalIndexList)
            {
                if (cii.InDeserializationContext != null && cii.InDeserializationContext.IndexId != null)
                {
                    //CacheIndexInternal Name
                    logStr.Append("IndexName : ").Append(cii.InDeserializationContext.IndexName);
                    logStr.Append(", IndexId : ").Append(IndexCacheUtils.GetReadableByteArray(cii.InDeserializationContext.IndexId)).Append(Environment.NewLine);
                }

                if (cii.InternalItemList != null)
                {
                    logStr.Append("CacheIndexInternal.InternalItemList.Count : ").Append(cii.InternalItemList.Count.ToString()).Append(Environment.NewLine);
                    itemCount = 0;
                    foreach (InternalItem internalItem in cii.InternalItemList)
                    {
                        LogItem(logStr, internalItem, itemCount++, tagHashCollection, typeId);                        
                    }
                }
                else
                {
                    logStr.Append("CacheIndexInternal.ItemIdList = null").Append(Environment.NewLine);
                }
            }
            return logStr.ToString();
        }
Example #15
0
        private static void LogItem(StringBuilder logStr, IItem iItem, int itemCount, TagHashCollection tagHashCollection, short typeId)
        {
            if (iItem.ItemId == null)
            {
                logStr.Append("ItemList[").Append(itemCount.ToString()).Append("].ItemId = null").Append(Environment.NewLine);
            }
            else if (iItem.ItemId.Length == 0)
            {
                logStr.Append("ItemList[").Append(itemCount.ToString()).Append("].ItemId.Length = 0").Append(Environment.NewLine);
            }
            else
            {
                logStr.Append("ItemList[").Append(itemCount.ToString()).Append("].ItemId = ").Append(IndexCacheUtils.GetReadableByteArray(iItem.ItemId)).Append(Environment.NewLine);
            }

            logStr.Append("Tags.Count : ");
            if (iItem is IndexItem)
            {
                var indexItem = (IndexItem)iItem;
                if (indexItem.Tags != null && indexItem.Tags.Count > 0)
                {
                    logStr.Append(indexItem.Tags.Count).Append(" - ");
                    foreach (var tag in indexItem.Tags)
                    {
                        logStr.Append(tag.Key).Append("=").Append(IndexCacheUtils.GetReadableByteArray(tag.Value)).
                        Append(", ");
                    }
                }
                else
                {
                    logStr.Append("0");
                }
            }
            else if (iItem is InternalItem)
            {
                var internalItem = (InternalItem)iItem;
                if (internalItem.TagList != null && internalItem.TagList.Count > 0)
                {
                    logStr.Append(internalItem.TagList.Count).Append(" - ");
                    foreach (var tag in internalItem.TagList)
                    {
                        logStr.Append(tagHashCollection.GetTagName(typeId, tag.Key)).
                        Append("=").Append(IndexCacheUtils.GetReadableByteArray(tag.Value)).
                        Append(", ");
                    }
                }
                else
                {
                    logStr.Append("0");
                }
            }
            logStr.Append(Environment.NewLine);
        }