Example #1
0
        private static void CheckDuplicateIndexName(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
        {
            if (namedTags == null || value == null || typeMap == null)
            {
                return;
            }

            string typeName = value.GetType().FullName;

            typeName = typeName.Replace("+", ".");

            int handleId = typeMap.GetHandleId(typeName);

            if (handleId != -1)
            {
                ArrayList attributes = typeMap.GetAttribList(handleId);
                foreach (string name in attributes)
                {
                    if (namedTags.Contains(name)) //@UH whether this should be case insensitive
                    {
                        throw new Exception("Key in named tags conflicts with the indexed attribute name of the specified object.");
                    }
                }
            }
        }
Example #2
0
        private static void CheckJavaDuplicateIndexName(string fullName, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
        {
            if (namedTags == null || typeMap == null)
            {
                return;
            }

            string typeName = fullName;

            typeName = typeName.Replace("+", ".");

            int handleId = typeMap.GetHandleId(typeName);

            if (handleId != -1)
            {
                ArrayList attributes = typeMap.GetAttribList(handleId);
                foreach (string name in attributes)
                {
                    if (namedTags.Contains(name))
                    {
                        throw new Exception("Key in named tags conflicts with the indexed attribute name of the specified object.");
                    }
                }
            }
        }
Example #3
0
 /// <summary>
 /// Verifica se existem itens com o nome publicados.
 /// </summary>
 /// <param name="value">Instancia.</param>
 /// <param name="namedTags">Dicionário com as tags nomeadas.</param>
 /// <param name="typeMap"></param>
 private static void CheckDuplicateIndexName(object value, NamedTagsDictionary namedTags, TypeInfoMap typeMap)
 {
     if (namedTags != null && value != null && typeMap != null)
     {
         int handleId = 0;
         if (value is CacheItemRecord)
         {
             handleId = typeMap.GetHandleId(((CacheItemRecord)value).TypeName);
         }
         else
         {
             handleId = typeMap.GetHandleId(value.GetType());
         }
         if (handleId != -1)
         {
             foreach (string str2 in typeMap.GetAttribList(handleId))
             {
                 if (namedTags.Contains(str2))
                 {
                     throw new Exception(ResourceMessageFormatter.Create(() => Properties.Resources.Exception_DuplicateIndexName).Format());
                 }
             }
         }
     }
 }
        public virtual void AddToIndex(object key, object value, OperationContext operationContext)
        {
            CacheEntry entry = (CacheEntry)value;

            if (entry == null)
            {
                return;
            }
            Hashtable queryInfo = entry.QueryInfo["query-info"] as Hashtable;

            if (queryInfo == null)
            {
                return;
            }


            lock (_indexMap.SyncRoot)
            {
                IDictionaryEnumerator queryInfoEnumerator = queryInfo.GetEnumerator();

                while (queryInfoEnumerator.MoveNext())
                {
                    int    handleId = (int)queryInfoEnumerator.Key;
                    string type     = _typeMap.GetTypeName(handleId);
                    if (_indexMap.Contains(type))
                    {
                        Hashtable indexAttribs    = new Hashtable();
                        Hashtable metaInfoAttribs = new Hashtable();

                        ArrayList values = (ArrayList)queryInfoEnumerator.Value;

                        ArrayList attribList = _typeMap.GetAttribList(handleId);
                        for (int i = 0; i < attribList.Count; i++)
                        {
                            string attribute = attribList[i].ToString();
                            string val       = _typeMap.GetAttributes(handleId)[attribList[i]] as string;

                            Type t1 = Type.GetType(val, true, true);

                            object obj = null;

                            if (values[i] != null)
                            {
                                try
                                {
                                    if (t1 == typeof(System.DateTime))
                                    {
                                        obj = new DateTime(Convert.ToInt64(values[i]));
                                    }
                                    else
                                    {
                                        obj = Convert.ChangeType(values[i], t1);
                                    }
                                }
                                catch (Exception)
                                {
                                    throw new System.FormatException("Cannot convert '" + values[i] + "' to " + t1.ToString());
                                }

                                indexAttribs.Add(attribute, obj);
                            }
                            else
                            {
                                indexAttribs.Add(attribute, null);
                            }


                            metaInfoAttribs.Add(attribute, obj);
                        }



                        entry.ObjectType = _typeMap.GetTypeName(handleId);
                        IQueryIndex index = (IQueryIndex)_indexMap[type];

                        long prevSize = index.IndexInMemorySize;
                        index.AddToIndex(key, new QueryItemContainer(entry, indexAttribs));
                        this._queryIndexMemorySize += index.IndexInMemorySize - prevSize;
                    }
                }
            }
        }
Example #5
0
        internal static Hashtable GetQueryInfo(Object value, TypeInfoMap typeMap)
        {
            Hashtable queryInfo = null;

            if (typeMap == null)
            {
                return(null);
            }

            try
            {
                int handleId = typeMap.GetHandleId(value.GetType().FullName);
                if (handleId != -1)
                {
                    queryInfo = new Hashtable();
                    ArrayList attribValues = new ArrayList();
                    ArrayList attributes   = typeMap.GetAttribList(handleId);
                    for (int i = 0; i < attributes.Count; i++)
                    {
                        PropertyInfo propertyAttrib = value.GetType().GetProperty((string)attributes[i]);
                        if (propertyAttrib != null)
                        {
                            Object attribValue = propertyAttrib.GetValue(value, null);

                            if (attribValue is String)                //add all strings as lower case in index tree
                            {
                                attribValue = attribValue.ToString(); //.ToLower();
                            }

                            if (attribValue is DateTime) //add all DateTime as ticks
                            {
                                attribValue = ((DateTime)(attribValue)).Ticks.ToString(CultureInfo.InvariantCulture);
                            }

                            attribValues.Add(attribValue);
                        }
                        else
                        {
                            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance;

                            FieldInfo fieldAttrib = value.GetType().GetField((string)attributes[i], flags);
                            if (fieldAttrib != null)
                            {
                                Object attribValue = fieldAttrib.GetValue(value);

                                if (attribValue is String) //add all strings as lower case in index tree
                                {
                                    attribValue = attribValue.ToString();
                                }

                                if (attribValue is DateTime) //add all DateTime as ticks
                                {
                                    attribValue = ((DateTime)(attribValue)).Ticks.ToString(CultureInfo.InvariantCulture);
                                }

                                attribValues.Add(attribValue);
                            }
                            else
                            {
                                throw new Exception("Unable extracting query information from user object.");
                            }
                        }
                    }
                    queryInfo.Add(handleId, attribValues);
                }
            }
            catch (Exception) { }
            return(queryInfo);
        }
Example #6
0
        /// <summary>
        /// Recupera as informações de consulta.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="typeMap"></param>
        /// <returns></returns>
        internal static Hashtable GetQueryInfo(object value, TypeInfoMap typeMap)
        {
            Hashtable hashtable = null;
            ArrayList list      = null;

            if (typeMap == null)
            {
                return(null);
            }
            try
            {
                int handleId = -1;
                if (value is ICacheItemRecord)
                {
                    var record = (ICacheItemRecord)value;
                    handleId = typeMap.GetHandleId(record.TypeName);
                    if (handleId == -1)
                    {
                        return(hashtable);
                    }
                    hashtable = new Hashtable();
                    list      = new ArrayList();
                    var attribList = typeMap.GetAttribList(handleId);
                    for (int i = 0; i < attribList.Count; i++)
                    {
                        var fieldIndex = -1;
                        for (int j = 0; j < record.Descriptor.Count; j++)
                        {
                            if (record.Descriptor[j].Name == attribList[i])
                            {
                                fieldIndex = j;
                                break;
                            }
                        }
                        if (fieldIndex >= 0)
                        {
                            object obj2 = record.GetValue(fieldIndex);
                            if (obj2 is string)
                            {
                                obj2 = obj2.ToString().ToLower();
                            }
                            else if (obj2 is DateTime)
                            {
                                DateTime time = (DateTime)obj2;
                                obj2 = time.Ticks.ToString();
                            }
                            list.Add(obj2);
                        }
                        else
                        {
                            list.Add(null);
                        }
                    }
                }
                else
                {
                    handleId = typeMap.GetHandleId(value.GetType());
                    if (handleId == -1)
                    {
                        return(hashtable);
                    }
                    hashtable = new Hashtable();
                    list      = new ArrayList();
                    var attribList = typeMap.GetAttribList(handleId);
                    for (int i = 0; i < attribList.Count; i++)
                    {
                        var property = value.GetType().GetProperty(attribList[i]);
                        if (property != null)
                        {
                            object obj2 = property.GetValue(value, null);
                            if (obj2 is string)
                            {
                                obj2 = obj2.ToString().ToLower();
                            }
                            if (obj2 is DateTime)
                            {
                                DateTime time = (DateTime)obj2;
                                obj2 = time.Ticks.ToString();
                            }
                            list.Add(obj2);
                        }
                        else
                        {
                            var field = value.GetType().GetField((string)attribList[i]);
                            if (field == null)
                            {
                                throw new Exception("Unable extracting query information from user object.");
                            }
                            object obj3 = field.GetValue(value);
                            if (obj3 is string)
                            {
                                obj3 = obj3.ToString().ToLower();
                            }
                            if (obj3 is DateTime)
                            {
                                DateTime time2 = (DateTime)obj3;
                                obj3 = time2.Ticks.ToString();
                            }
                            list.Add(obj3);
                        }
                    }
                }
                hashtable.Add(handleId, list);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Fail("An error ocurred when get query info", Colosoft.Diagnostics.ExceptionFormatter.FormatException(ex, true));
                throw;
            }
            return(hashtable);
        }