/// <summary>
 /// Remove a dependencia.
 /// </summary>
 /// <param name="key">Chave.</param>
 /// <param name="dependency">Instancia da dependencia.</param>
 public void RemoveDependency(object key, CacheSyncDependency dependency)
 {
     if (_context.IsDbSyncCoordinator)
     {
         if (dependency != null)
         {
             try
             {
                 SyncItem item = new SyncItem(key, dependency.Key, dependency.CacheId);
                 lock (_dependenciesStatus.SyncRoot)
                 {
                     if (_dependenciesKeyMap.Contains(item))
                     {
                         ArrayList list = _dependenciesKeyMap[item] as ArrayList;
                         if (list != null)
                         {
                             list.Remove(key);
                             if (list.Count > 0)
                             {
                                 return;
                             }
                         }
                         _dependenciesKeyMap.Remove(item);
                     }
                     if (_dependenciesStatus.Contains(item))
                     {
                         _dependenciesStatus.Remove(item);
                     }
                     else
                     {
                         return;
                     }
                 }
                 ISyncCache cache = _synCaches[item.CacheId] as ISyncCache;
                 ISyncCacheEventsListener eventListener = _listeners[item.CacheId] as ISyncCacheEventsListener;
                 if ((cache != null) && (eventListener != null))
                 {
                     cache.UnRegisterSyncKeyNotifications((string)item.Key, eventListener);
                 }
             }
             catch (Exception exception)
             {
                 this.Logger.Error(("CacheSyncManager:" + exception.ToString()).GetFormatter());
             }
         }
     }
     else
     {
         _inactiveDependencies.Remove(key);
     }
 }
 /// <summary>
 /// Ativa as dependencias.
 /// </summary>
 public void ActivateDependencies()
 {
     try
     {
         lock (_inactiveDependencies.SyncRoot)
         {
             IDictionaryEnumerator enumerator = _inactiveDependencies.GetEnumerator();
             while (enumerator.MoveNext())
             {
                 SyncItem            key        = (SyncItem)enumerator.Key;
                 CacheSyncDependency dependency = (CacheSyncDependency)enumerator.Value;
                 this.AddDependency(key.ThisKey, dependency);
             }
             _inactiveDependencies.Clear();
         }
     }
     catch (Exception exception)
     {
         this.Logger.Error("CacheSyncManager.ActivateDependencies()".GetFormatter(), exception.GetFormatter());
     }
 }
        /// <summary>
        /// Adiciona uma dependencia para o gerenciador.
        /// </summary>
        /// <param name="key">Chave da entrada.</param>
        /// <param name="dependency">Instancia da dependencia.</param>
        public void AddDependency(object key, CacheSyncDependency dependency)
        {
            if (_context.IsDbSyncCoordinator)
            {
                ISyncCache        syncCache = dependency.SyncCache;
                SyncEventListener listener  = null;
                if ((dependency == null) || (dependency.CacheId == null))
                {
                    return;
                }
                lock (_dependenciesStatus.SyncRoot)
                {
                    SyncItem  item = new SyncItem(key, dependency.Key, dependency.CacheId);
                    ArrayList list = null;
                    if (!_dependenciesKeyMap.Contains(item))
                    {
                        list = new ArrayList();
                        list.Add(item.ThisKey);
                        _dependenciesKeyMap.Add(item, list);
                    }
                    else
                    {
                        list = _dependenciesKeyMap[item] as ArrayList;
                        if (!list.Contains(item.ThisKey))
                        {
                            list.Add(item.ThisKey);
                        }
                    }
                    if (!_dependenciesStatus.Contains(item))
                    {
                        _dependenciesStatus.Add(item, DependencyStatus.Unchanged);
                    }
                    if (_synCaches.Contains(dependency.CacheId))
                    {
                        listener  = _listeners[dependency.CacheId] as SyncEventListener;
                        syncCache = _synCaches[dependency.CacheId] as ISyncCache;
                    }
                    else
                    {
                        syncCache.Initialize();
                        _synCaches.Add(dependency.CacheId, syncCache);
                        if (_listeners.Contains(dependency.CacheId))
                        {
                            listener = _listeners[dependency.CacheId] as SyncEventListener;
                        }
                        else
                        {
                            listener = new SyncEventListener(dependency.CacheId, this);
                            _listeners.Add(dependency.CacheId, listener);
                        }
                    }
                    if ((list != null) && (list.Count < 2))
                    {
                        syncCache.RegisterSyncKeyNotifications((string)item.Key, listener);
                    }
                    return;
                }
            }
            SyncItem item2 = new SyncItem(key, dependency.Key, dependency.CacheId);

            if (!_inactiveDependencies.Contains(item2))
            {
                _inactiveDependencies.Add(item2, dependency);
            }
        }