Exemplo n.º 1
0
            private void RemoveSubscription(string id, ref int subscriptions)
            {
                object o;

                if (Subscribers.TryRemove(id, out o))
                {
                    if (!Subscribers.Any())
                    {
                        var variable = new List <string> {
                            Name
                        };
                        var parent = Parent;
                        while (parent != null)
                        {
                            variable.Insert(0, parent.Name);
                            parent = parent.Parent;
                        }

                        using (var guard = new ReaderGuard(_papperLock))
                        {
                            _papper.SetActiveState(false, variable.FirstOrDefault(), variable.Skip(1).Aggregate((a, b) => $"{a}.{b}"));
                            _papper.UnsubscribeDataChanges(Name, OnDataChanged);
                        }
                    }
                    Interlocked.Decrement(ref subscriptions);
                }
                foreach (var child in Childs)
                {
                    child.Value.RemoveSubscription(id, ref subscriptions);
                }
            }
Exemplo n.º 2
0
        public static Packet AtomicValueFrom(IDataRowReader reader)
        {
            using (ReaderGuard rg = new ReaderGuard(reader))
            {
                if (reader.HasNext())
                {
                    return(new Packet(reader.ReadNext().FetchField(0), PacketType.Atomic));
                }
            }

            return(new Packet(null, PacketType.Atomic));
        }
Exemplo n.º 3
0
        public static PacketArray AtomicArrayFrom(IDataRowReader reader)
        {
            PacketArray array = new PacketArray();

            using (ReaderGuard rg = new ReaderGuard(reader))
            {
                while (reader.HasNext())
                {
                    array.Add(new Packet(reader.ReadNext().FetchField(0), PacketType.Atomic));
                }
            }

            return(array);
        }
Exemplo n.º 4
0
        public static PacketArray DatasetArrayFrom(IDataRowReader reader)
        {
            PacketArray array = new PacketArray();

            using (ReaderGuard rg = new ReaderGuard(reader))
            {
                while (reader.HasNext())
                {
                    array.Add(new Packet(DatasetFromRow(reader.Headers, reader.ReadNext()), PacketType.Dataset));
                }
            }

            return(array);
        }
Exemplo n.º 5
0
 public static PacketDataset DatasetFrom(IDataRowReader reader)
 {
     using (ReaderGuard rg = new ReaderGuard(reader))
     {
         if (reader.HasNext())
         {
             return(DatasetFromRow(reader.Headers, reader.ReadNext()));
         }
         else
         {
             return(new PacketDataset());
         }
     }
 }
Exemplo n.º 6
0
            public int AddSubscribtion(string id, IEnumerable <IEnumerable <string> > vars)
            {
                var updated  = 0;
                var varNames = new List <string>();

                foreach (var variablePath in vars)
                {
                    if (UpdateSubscribtion(id, variablePath, false, ref _subscriptions))
                    {
                        varNames.Add(variablePath.Aggregate((a, b) => $"{a}.{b}"));
                        updated++;
                    }
                }
                if (_subscriptions > 0 && _dataChanged != null)
                {
                    using (var guard = new ReaderGuard(_papperLock))
                    {
                        _papper.SetActiveState(true, Name, varNames.ToArray());
                        _papper.SubscribeDataChanges(Name, OnDataChanged);
                    }
                }
                return(updated);
            }
Exemplo n.º 7
0
            public int RemoveRawSubscription(string id, IEnumerable <string> adresses)
            {
                var updated = 0;

                foreach (var address in adresses)
                {
                    if (UpdateSubscribtion(id, new List <string> {
                        address
                    }, true, ref _subscriptions))
                    {
                        updated++;
                    }
                }

                if (_subscriptions <= 0 && _dataChanged != null)
                {
                    using (var guard = new ReaderGuard(_papperLock))
                    {
                        _papper.SetRawActiveState(false, Name, adresses.ToArray());
                        _papper.UnsubscribeRawDataChanges(Name, OnDataChanged);
                    }
                }
                return(updated);
            }