protected void RenewEventSubscription(EventSubscription subscription)
        {
            if (!subscription.Service.IsConnected)
            {
                throw new IllegalCallException("Service '{0}' is not connected to a UPnP network service", subscription.Service.FullQualifiedName);
            }

            using (_cpData.Lock.EnterWrite())
            {
                HttpWebRequest request             = CreateRenewEventSubscribeRequest(subscription);
                ChangeEventSubscriptionState state = new ChangeEventSubscriptionState(subscription.ServiceDescriptor, subscription.Service, request);
                _pendingCalls.Add(state);
                IAsyncResult result = state.Request.BeginGetResponse(OnSubscribeOrRenewSubscriptionResponseReceived, state);
                NetworkHelper.AddTimeout(request, result, EVENT_SUBSCRIPTION_CALL_TIMEOUT * 1000);
            }
        }
Exemple #2
0
        private void ContinueGetServiceDescription(DescriptionRequestState state)
        {
            RootDescriptor rootDescriptor = state.RootDescriptor;

            IEnumerator <ServiceDescriptor> enumer = state.PendingServiceDescriptions.GetEnumerator();

            if (!enumer.MoveNext())
            {
                lock (_cpData.SyncObj)
                {
                    if (rootDescriptor.State != RootDescriptorState.AwaitingServiceDescriptions)
                    {
                        return;
                    }
                    _pendingRequests.Remove(state);
                    rootDescriptor.State = RootDescriptorState.Ready;
                }
                // This event is needed for two cases: 1) "Normal" first device advertisement, 2) configuration change event (see comment in method HandleDeviceConfigurationChanged)
                InvokeRootDeviceAdded(rootDescriptor);
            }
            else
            {
                lock (_cpData.SyncObj)
                    if (rootDescriptor.State != RootDescriptorState.AwaitingServiceDescriptions)
                    {
                        return;
                    }
                state.CurrentServiceDescriptor = enumer.Current;
                string url = state.CurrentServiceDescriptor.DescriptionURL;
                state.PendingServiceDescriptions.Remove(state.CurrentServiceDescriptor);
                state.CurrentServiceDescriptor.State = ServiceDescriptorState.AwaitingDescription;
                try
                {
                    LinkData       preferredLink = rootDescriptor.SSDPRootEntry.PreferredLink;
                    HttpWebRequest request       = CreateHttpGetRequest(new Uri(new Uri(preferredLink.DescriptionLocation), url),
                                                                        preferredLink.Endpoint.EndPointIPAddress);
                    state.Request = request;
                    IAsyncResult result = request.BeginGetResponse(OnServiceDescriptionReceived, state);
                    NetworkHelper.AddTimeout(request, result, PENDING_REQUEST_TIMEOUT * 1000);
                }
                catch (Exception) // Don't log exceptions at this low protocol level
                {
                    lock (_cpData.SyncObj)
                        state.CurrentServiceDescriptor.State = ServiceDescriptorState.Erroneous;
                }
            }
        }
Exemple #3
0
            /// <summary>
            /// Initializes the HTTP range request asynchronously.
            /// </summary>
            protected void Load_Async()
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url);

                NetworkUtils.SetLocalEndpoint(request, _localIpAddress);
                request.Method            = "GET";
                request.KeepAlive         = true;
                request.AllowAutoRedirect = true;
                request.UserAgent         = _userAgent;
                request.AddRange(_startIndex, _endIndex - 1);

                IAsyncResult result = request.BeginGetResponse(OnResponseReceived, request);

                NetworkHelper.AddTimeout(request, result, HTTP_RANGE_REQUEST_TIMEOUT);
                _pendingRequest = request;
                _numTries++;
            }
Exemple #4
0
        private void OnEventGetRequestStream(IAsyncResult ar)
        {
            AsyncRequestState state = (AsyncRequestState)ar.AsyncState;

            try
            {
                Stream requestStream = state.Request.EndGetRequestStream(ar);
                // ... then write to it...
                requestStream.Write(state.MessageData, 0, state.MessageData.Length);
                requestStream.Close();
                // ... and get the response
                IAsyncResult result = state.Request.BeginGetResponse(OnEventResponseReceived, state);
                NetworkHelper.AddTimeout(state.Request, result, PENDING_EVENT_NOTIFICATION_TIMEOUT * 1000);
            }
            catch (IOException) { }
            catch (WebException) { }
            ContinueEventNotification(state);
        }
Exemple #5
0
        internal void OnActionCalled(CpAction action, IList <object> inParams, object clientState)
        {
            if (!action.IsConnected)
            {
                throw new UPnPDisconnectedException("Action '{0}' is not connected to a UPnP network action", action.FullQualifiedName);
            }
            CpService         service = action.ParentService;
            ServiceDescriptor sd      = GetServiceDescriptor(service);
            string            message = SOAPHandler.EncodeCall(action, inParams, _rootDescriptor.SSDPRootEntry.UPnPVersion);

            HttpWebRequest  request = CreateActionCallRequest(sd, action);
            ActionCallState state   = new ActionCallState(action, clientState, request);

            state.SetRequestMessage(message);
            lock (_cpData.SyncObj)
                _pendingCalls.Add(state);
            IAsyncResult result = state.Request.BeginGetResponse(OnCallResponseReceived, state);

            NetworkHelper.AddTimeout(request, result, PENDING_ACTION_CALL_TIMEOUT * 1000);
        }