/// <summary> /// Limpa os indices gerenciados. /// </summary> public void Clear() { if (IndexMapInternal != null) { lock (IndexMapInternal) { IDictionaryEnumerator enumerator = IndexMapInternal.GetEnumerator(); while (enumerator.MoveNext()) { (enumerator.Value as IQueryIndex).Clear(); } } } }
/// <summary> /// Libera a instancia. /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (_typeMap != null) { _typeMap.HandleAdded -= new Action <int>(TypeMap_HandleAdded); } if (_asyncProcessor != null) { _asyncProcessor.Stop(); _asyncProcessor = null; } if (IndexMapInternal != null) { IndexMapInternal.Clear(); IndexMapInternal = null; } _cache = null; }
/// <summary> /// Remove a chave e o valor do indice. /// </summary> /// <param name="key">Chave que será removida.</param> /// <param name="queryInfo">Informações da consulta que serão removidas.</param> public virtual void RemoveFromIndex(object key, Hashtable queryInfo) { if (queryInfo != null) { lock (IndexMapInternal) { IDictionaryEnumerator enumerator = ((Hashtable)queryInfo).GetEnumerator(); while (enumerator.MoveNext()) { int handle = (int)enumerator.Key; string typeName = _typeMap.GetTypeName(handle); if (IndexMapInternal.ContainsKey(typeName)) { Hashtable indexValues = new Hashtable(); var list = (ArrayList)enumerator.Value; var attribList = _typeMap.GetAttribList(handle); if (list.Count != attribList.Count) { throw new InvalidOperationException("Attributes count not equals value list count"); } for (int i = 0; i < attribList.Count; i++) { var attributes = _typeMap.GetAttributes(handle); var attributeName = attribList[i]; string attributeType = attributes[attributeName] as string; Type conversionType = Type.GetType(attributeType, true, true); object value = list[i]; if (value != null) { try { if (conversionType == typeof(DateTime) && !(value is DateTime)) { if (value is DateTimeOffset) { value = ((DateTimeOffset)value).DateTime; } else { value = new DateTime(Convert.ToInt64(value)); } } else if (conversionType == typeof(Guid) && (value is string)) { value = Guid.Parse((string)value); } else { value = Convert.ChangeType(value, conversionType); } } catch (Exception) { throw new FormatException(string.Format("Cannot convert ({0})'{1}' to {2}", (list[i] ?? new object()).GetType().FullName, list[i], conversionType.ToString())); } } if ((value != null) && (value is string)) { indexValues.Add(attributeName, ((string)value).ToLower()); } else { indexValues.Add(attributeName, value); } } ((IQueryIndex)IndexMapInternal[typeName]).RemoveFromIndex(key, indexValues); } } } } }