Example #1
0
        /// <summary>
        /// Handles the callback after sending a request.
        /// </summary>
        /// <param name="sender">The sender of the notification.</param>
        /// <param name="args">The event args.</param>
        private void SendRequestCallback(object sender, SendPostEventArgs args)
        {
            if (args.ErrorText != null)
            {
                string errorText = "Error in talking to HealthVault: " + args.ErrorText;
                InvokeApplicationResponseCallback(args.HealthVaultRequest, null, null, errorText);
                return;
            }

            HealthVaultResponse response = null;

            try
            {
                response = new HealthVaultResponse(args.ResponseData);
            }
            catch (InvalidOperationException)
            {
                string errorText = "Response was not a valid HealthVault response: " + args.ResponseData;
                InvokeApplicationResponseCallback(args.HealthVaultRequest, null, null, errorText);
                return;
            }

            // The token that is returned from GetAuthenticatedSessionToken has a limited lifetime. When it expires,
            // we will get an error here. We detect that situation, get a new token, and then re-issue the call.
            if (response.StatusCode == AuthenticatedSessionTokenExpired)
            {
                RefreshSessionToken(args);
                return;
            }

            InvokeApplicationResponseCallback(args.HealthVaultRequest, args.ResponseData, response, response.ErrorMessage);
        }
Example #2
0
        /// <summary>
        /// Invoke the calling application's callback.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="resultText">The raw response.</param>
        /// <param name="response">The response object.</param>
        /// <param name="errorText">The error text, or null if successful. </param>
        private void InvokeApplicationResponseCallback(
            HealthVaultRequest request,
            string resultText,
            HealthVaultResponse response,
            string errorText)
        {
            HealthVaultResponseEventArgs eventArgs = new HealthVaultResponseEventArgs(request, resultText, response);

            eventArgs.ErrorText = errorText;

            if (request.ResponseCallback != null)
            {
                request.ResponseCallback(this, eventArgs);
            }
        }
        /// <summary>
        /// Initializes a new instance of the HealthVaultResponseEventArgs class.
        /// </summary>
        /// <param name="request">The request that is being processed.</param>
        /// <param name="responseXml">The raw response xml from the request.</param>
        /// <param name="response">A deserialized version of the request.</param>
        public HealthVaultResponseEventArgs(
            HealthVaultRequest request,
            string responseXml,
            HealthVaultResponse response)
        {
            Request = request;
            ResponseXml = responseXml;
            Response = response;

            if (responseXml != null)
            {
                XElement element = XElement.Parse(responseXml);

                XElement status = element.Element("status");

                ErrorCode = Int32.Parse(status.Element("code").Value);
            }
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the HealthVaultResponseEventArgs class.
        /// </summary>
        /// <param name="request">The request that is being processed.</param>
        /// <param name="responseXml">The raw response xml from the request.</param>
        /// <param name="response">A deserialized version of the request.</param>
        public HealthVaultResponseEventArgs(
            HealthVaultRequest request,
            string responseXml,
            HealthVaultResponse response)
        {
            Request     = request;
            ResponseXml = responseXml;
            Response    = response;

            if (responseXml != null)
            {
                XElement element = XElement.Parse(responseXml);

                XElement status = element.Element("status");

                ErrorCode = Int32.Parse(status.Element("code").Value);
            }
        }