Beispiel #1
0
 private bool UpdateSubscribtion(string id, IEnumerable <string> variablePath, bool remove, ref int subscriptions)
 {
     if (variablePath.Any())
     {
         var key = variablePath.First();
         SubscriptionTree entry;
         if (!Childs.TryGetValue(key, out entry) && !remove)
         {
             entry = new SubscriptionTree
             {
                 Name   = key,
                 Parent = this
             };
             if (!Childs.TryAdd(key, entry))
             {
                 entry = Childs[key];
             }
         }
         return(entry != null?entry.UpdateSubscribtion(id, variablePath.Skip(1), remove, ref subscriptions) : false);
     }
     else
     {
         if (remove)
         {
             object o;
             if (Subscribers.TryRemove(id, out o))
             {
                 Interlocked.Decrement(ref subscriptions);
                 return(true);
             }
             return(false);
         }
         else
         {
             if (Subscribers.TryAdd(id, null))
             {
                 Interlocked.Increment(ref subscriptions);
                 return(true);
             }
             return(false);
         }
     }
 }