Exemple #1
0
 /// <summary>
 /// Adds an active publisher.
 /// </summary>
 /// <param name="instance">The instance.</param>
 internal void AddActivePublisher(Publisher instance)
 {
     _activePublishersLock.EnterWriteLock();
     if (!ActivePublishers.ContainsKey(instance))
     {
         ActivePublishers.Add(instance, Interlocked.Increment(ref _nextModuleID));
     }
     _activePublishersLock.ExitWriteLock();
 }
Exemple #2
0
 /// <summary>
 /// Gets the publisher id.
 /// </summary>
 /// <param name="p">The p.</param>
 /// <returns></returns>
 internal int GetPublisherId(object p)
 {
     _activePublishersLock.EnterReadLock();
     try
     {
         return(ActivePublishers.Where(k => k.Key.Instance == p).Select(k => k.Value).DefaultIfEmpty(-1).FirstOrDefault());
     }
     finally
     {
         _activePublishersLock.ExitReadLock();
     }
 }
Exemple #3
0
 /// <summary>
 /// Determines whether <paramref name="publisher"/> is an active publisher.
 /// </summary>
 /// <param name="publisher">The publisher.</param>
 /// <returns>
 ///   <c>true</c> if [is active publisher] [the specified publisher]; otherwise, <c>false</c>.
 /// </returns>
 internal bool IsActivePublisher(object publisher)
 {
     _activePublishersLock.EnterReadLock();
     try
     {
         return(ActivePublishers.Any(k => k.Key.Instance == publisher));
     }
     finally
     {
         _activePublishersLock.ExitReadLock();
     }
 }
Exemple #4
0
        /// <summary>
        /// Removes the active publisher.
        /// </summary>
        /// <param name="instance">The instance.</param>
        internal void RemoveActivePublisher(Publisher instance)
        {
            if (instance == null)
            {
                return;
            }
            _activePublishersLock.EnterWriteLock();

            if (ActivePublishers.ContainsKey(instance))
            {
                ActivePublishers.Remove(instance);
            }
            _activePublishersLock.ExitWriteLock();
        }
Exemple #5
0
 internal Publisher GetPublisher(object instance)
 {
     try
     {
         if (IsActivePublisher(instance))
         {
             _activePublishersLock.EnterReadLock();
             return(ActivePublishers.Where(p => p.Key.Instance == instance).Select(p => p.Key).FirstOrDefault());
         }
         return(null);
     }
     finally
     {
         _activePublishersLock.ExitReadLock();
     }
 }
Exemple #6
0
 /// <summary>
 /// Gets the publisher to a certain ID.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <returns>The publisher object associated with the specified <paramref name="id"/>, or <c>null</c> if no such id has been issued</returns>
 internal Publisher GetPublisher(int id)
 {
     _activePublishersLock.EnterReadLock();
     try
     {
         if (ActivePublishers.Values.Contains(id))
         {
             return(ActivePublishers.Where(p => p.Value == id).Select(p => p.Key).FirstOrDefault());
         }
         return(null);
     }
     finally
     {
         _activePublishersLock.ExitReadLock();
     }
 }