Пример #1
0
        /// <summary>
        /// Procedure to run when payload is received from stream. Data is cast to the appropriate data type, and the OnPayloadReceived_Callback is invoked on all subscriptions that involves the given attribute
        /// </summary>
        /// <param name="payload">The data being received from the data stream</param>
        /// <param name="attribute">The attribute being received</param>
        /// <param name="data_type">The data type that the received data is represented as</param>
        public void ReceivePayload(object payload, string attribute, string data_type, string stream_label)
        {
            if (subscriptions.Count > 0 && HasSubscription(attribute) && OnPayloadReceived_Callback != null)
            {
                DataSubscription subscription = subscriptions[attribute];
                payload = Utils.Cast.ToType(payload, data_type);

                OnPayloadReceived_Callback.Invoke(payload, attribute, stream_label);

                if (observe_values)
                {
                    if (!observedValues.ContainsLabel(attribute))
                    {
                        if (observedValues.AddWithType(attribute, data_type) != null)
                        {
                            observedValues[attribute].OnUpdate(onObservableValueChanged_cb);
                        }
                    }

                    if (observedValues.ContainsLabel(attribute))
                    {
                        IObservableNumericValue observedAttribute = observedValues[attribute];
                        observedAttribute       = observedValues[attribute];
                        observedAttribute.Value = payload;
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Subscribe to data on a stream with a given attribute and data type
        /// </summary>
        /// <param name="stream">The data stream to receive data trough</param>
        /// <param name="attribute">The attribute to receive data from in the data stream</param>
        /// <param name="data_type">The datatype the data is represented as</param>
        public void Subscribe(DataStream stream, string attribute, string data_type)
        {
            DataSubscription sub = new DataSubscription(this, attribute, data_type);

            stream.AddReceiver(this);

            if (!HasSubscription(attribute))
            {
                stream.Output(Request.Subscription("subscribe", attribute));
                subscriptions.Add(attribute, sub);
            }
        }