Example #1
0
        public void Notify(GenaPropertySet props)
        {
            GenaSubscription[] temp;
            lock (_subscriptions)
            {
                temp = _subscriptions.Values.ToArray();
            }

            Parallel.ForEach(temp, subscription => subscription.Notify(props));
        }
Example #2
0
        public void Notify(GenaPropertySet props)
        {
            GenaSubscription[] temp;
            lock (_subscriptions)
            {
                temp = _subscriptions.Values.ToArray();
            }

            Parallel.ForEach(temp, subscription => subscription.Notify(props));
        }
Example #3
0
        public void Notify(GenaPropertySet props)
        {
            //TODO: need to probably wait for a small amount of time to reduce the number of network updates
            uint key;

            lock (_eventKeyLock)
            {
                key = this._eventKey;
                this._eventKey++;
            }

            var callbacks = Callbacks;

            Task.Factory.StartNew(() =>
            {
                //TODO: we probably should support UDP also
                foreach (var uri in callbacks.Where(uri => uri.Scheme == "http"))
                {
                    try
                    {
                        var request = (HttpWebRequest)WebRequest.Create(uri);

                        request.ServicePoint.Expect100Continue = false;
                        request.Method      = "NOTIFY";
                        request.ContentType = "text/xml; charset=\"utf-8\"";

                        request.Headers.Add("NT", "upnp:event");
                        request.Headers.Add("NTS", "upnp:propchange");
                        request.Headers.Add("SID", this.SubscriptionId);
                        request.Headers.Add("SEQ", key.ToString());

                        using (var stream = request.GetRequestStream())
                        {
                            var writer = new XmlTextWriter(stream, Encoding.ASCII);
                            props.WriteXml(writer);
                            writer.Close();
                        }

                        //send it
                        var response = (HttpWebResponse)request.GetResponse();

                        return;
                    }
                    catch (WebException exception)
                    {
                        Trace.WriteLine(exception);
                    }
                }
            });
        }
Example #4
0
        public void Notify(GenaPropertySet props)
        {
            //TODO: need to probably wait for a small amount of time to reduce the number of network updates
            uint key;
            lock (_eventKeyLock)
            {
                key = this._eventKey;
                this._eventKey++;
            }

            var callbacks = Callbacks;
            Task.Factory.StartNew(() =>
            {
                //TODO: we probably should support UDP also
                foreach (var uri in callbacks.Where(uri => uri.Scheme == "http"))
                {
                    try
                    {

                        var request = (HttpWebRequest) WebRequest.Create(uri);

                        request.ServicePoint.Expect100Continue = false;
                        request.Method = "NOTIFY";
                        request.ContentType = "text/xml; charset=\"utf-8\"";

                        request.Headers.Add("NT", "upnp:event");
                        request.Headers.Add("NTS", "upnp:propchange");
                        request.Headers.Add("SID", this.SubscriptionId);
                        request.Headers.Add("SEQ", key.ToString());

                        using (var stream = request.GetRequestStream())
                        {
                            var writer = new XmlTextWriter(stream, Encoding.ASCII);
                            props.WriteXml(writer);
                            writer.Close();
                        }

                        //send it
                        var response = (HttpWebResponse)request.GetResponse();

                        return;
                    }
                    catch (WebException exception)
                    {
                        Trace.WriteLine(exception);
                    }
                }
            });
        }