/// <summary>
        /// Occurs when any of the following network conditions occur:
        /// 1. Unable to connect to target host for any reason
        /// 2. Write request fails
        /// 3. Read request fails
        /// </summary>
        /// <param name="response">The <see cref="Response"/> that contains information about the failure</param>
        /// <param name="state">An optional state object that will be passed into the response events associated with this request</param>
        protected override void OnCommunicationFailure(Response response, object state)
        {
            SubscriptionResponse sr = SubscriptionResponse.FromResponse(response, null);

            ResetTimerBasedOnResponse(sr);
            this.OnErrorResponse(sr);
        }
 /// <summary>
 /// Called when an 'ERROR' response occurs.
 /// </summary>
 /// <param name="response">The <see cref="Response"/></param>
 protected void OnErrorResponse(SubscriptionResponse response)
 {
     if (this.ErrorResponse != null)
     {
         this.ErrorResponse(response);
     }
 }
Ejemplo n.º 3
0
        /// <summary>

        /// Parses the response and raises the appropriate event

        /// </summary>

        /// <param name="responseText">The raw GNTP response</param>

        /// <param name="state">An optional state object that will be passed into the response events associated with this request</param>

        protected override void OnResponseReceived(string responseText, object state)

        {
            CallbackData cd;

            HeaderCollection headers;

            MessageParser mp = new MessageParser();

            Response response = mp.Parse(responseText, out cd, out headers);



            SubscriptionResponse sr = SubscriptionResponse.FromResponse(response, headers);



            ResetTimerBasedOnResponse(sr);



            if (sr.IsOK)

            {
                this.OnOKResponse(sr);
            }

            else

            {
                this.OnErrorResponse(sr);
            }
        }
Ejemplo n.º 4
0
        /// <summary>

        /// Creates a new <see cref="SubscriptionResponse"/> from a base <see cref="Response"/> and a list of headers

        /// </summary>

        /// <param name="response">The base <see cref="Response"/></param>

        /// <param name="headers">The <see cref="HeaderCollection"/> used to populate the response</param>

        /// <returns><see cref="SubscriptionResponse"/></returns>

        internal static SubscriptionResponse FromResponse(Response response, HeaderCollection headers)

        {
            SubscriptionResponse sr = null;

            if (response.IsOK)

            {
                int ttl = headers.GetHeaderIntValue(Header.SUBSCRIPTION_TTL, true);



                sr = new SubscriptionResponse(ttl);
            }

            else

            {
                sr = new SubscriptionResponse(response.ErrorCode, response.ErrorDescription);

                sr.ttl = 0;
            }



            SetInhertiedAttributesFromHeaders(sr, headers);

            return(sr);
        }
 private void ResetTimerBasedOnResponse(SubscriptionResponse sr)
 {
     // try to renew 30 seconds before the server disconnects us, or at the retry interval if this failed
     this.ttl = (sr.IsOK ? Math.Max((sr.TTL - 30), 0) : RETRY_INTERVAL);
     if (this.ttl > 0)
     {
         StartRenewalTimer();
     }
     else
     {
         StopRenewalTimer();
     }
 }
        /// <summary>
        /// Creates a new <see cref="SubscriptionResponse"/> from a base <see cref="Response"/> and a list of headers
        /// </summary>
        /// <param name="response">The base <see cref="Response"/></param>
        /// <param name="headers">The <see cref="HeaderCollection"/> used to populate the response</param>
        /// <returns><see cref="SubscriptionResponse"/></returns>
        internal static SubscriptionResponse FromResponse(Response response, HeaderCollection headers)
        {
            SubscriptionResponse sr = null;
            if (response.IsOK)
            {
                int ttl = headers.GetHeaderIntValue(Header.SUBSCRIPTION_TTL, true);

                sr = new SubscriptionResponse(ttl);
            }
            else
            {
                sr = new SubscriptionResponse(response.ErrorCode, response.ErrorDescription);
                sr.ttl = 0;
            }

            SetInhertiedAttributesFromHeaders(sr, headers);
            return sr;
        }
 /// <summary>
 /// Called when an 'ERROR' response occurs.
 /// </summary>
 /// <param name="response">The <see cref="Response"/></param>
 protected void OnErrorResponse(SubscriptionResponse response)
 {
     if (this.ErrorResponse != null)
     {
         this.ErrorResponse(response);
     }
 }
 private void ResetTimerBasedOnResponse(SubscriptionResponse sr)
 {
     // try to renew 30 seconds before the server disconnects us, or at the retry interval if this failed
     this.ttl = (sr.IsOK ? Math.Max((sr.TTL - 30), 0) : RETRY_INTERVAL);
     if (this.ttl > 0)
         StartRenewalTimer();
     else
         StopRenewalTimer();
 }