/// <summary>
        /// Generates the XML for the parameters for the "GetThings" request.
        /// </summary>
        ///
        /// <returns>
        /// An XML string defining the parameters for the "GetThings" call.
        /// </returns>
        ///
        /// <exception cref="HealthServiceException">
        /// No filters have been specified.
        /// </exception>
        ///
        internal string GetParametersXml()
        {
            if (Filters.Count == 0)
            {
                HealthServiceResponseError error = new HealthServiceResponseError();
                error.Message = Resources.HealthRecordSearcherNoFilters;

                HealthServiceException e =
                    HealthServiceExceptionHelper.GetHealthServiceException(
                        HealthServiceStatusCode.InvalidFilter, error);
                throw e;
            }

            StringBuilder parameters = new StringBuilder(128);

            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;

            using (XmlWriter writer = XmlWriter.Create(parameters, settings))
            {
                foreach (ThingQuery filter in Filters)
                {
                    // Add all filters
                    filter.AddFilterXml(writer);
                }

                writer.Flush();
            }

            return(parameters.ToString());
        }
Example #2
0
        /// <summary>
        /// Checks whether at least one property is set.
        /// </summary>
        ///
        /// <exception cref="HealthServiceException">
        /// One of the following is true:
        /// (1) The filter has no properties set;
        /// (2) Both ItemIds and ItemKeys are specified; or
        /// (3) There are more than the allowable number of order by clauses.
        /// </exception>
        ///
        internal void ThrowIfNotValid()
        {
            bool isValid = AreFiltersPresent();

            // if no filters are present,
            // at least one of ItemKeys or ItemIds should be non-empty
            isValid |=
                ItemKeys.Count != 0 ||
                ItemIds.Count != 0 ||
                ClientItemIds.Count != 0;

            if (!isValid)
            {
                HealthServiceResponseError error = new HealthServiceResponseError
                {
                    Message = Resources.HealthRecordSearcherInvalidFilter
                };

                HealthServiceException e =
                    HealthServiceExceptionHelper.GetHealthServiceException(
                        HealthServiceStatusCode.InvalidFilter,
                        error);
                throw e;
            }

            int idTypesSpecified =
                ItemKeys.Count > 0 ? 1 : 0 +
                ItemIds.Count > 0 ? 1 : 0 +
                ClientItemIds.Count > 0 ? 1 : 0;

            // only one of ItemKeys or ItemIds can be non-empty
            // throw a specific error in this particular case
            if (idTypesSpecified > 1)
            {
                HealthServiceResponseError error = new HealthServiceResponseError
                {
                    Message = Resources.HealthRecordSearcherInvalidFilterIdsAndKeysSpecified
                };

                HealthServiceException e = HealthServiceExceptionHelper.GetHealthServiceException(
                    HealthServiceStatusCode.InvalidFilter,
                    error);
                throw e;
            }

            if (OrderByClauses.Count > 1)
            {
                HealthServiceResponseError error = new HealthServiceResponseError
                {
                    Message = Resources.HealthRecordSearcherInvalidOrderSpecified
                };

                HealthServiceException e =
                    HealthServiceExceptionHelper.GetHealthServiceException(
                        HealthServiceStatusCode.InvalidFilter,
                        error);
                throw e;
            }
        }
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceException"/>
 /// class with the specified error identifier and error information.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type.
 /// </remarks>
 ///
 /// <param name="errorCodeId">
 /// An integer representing the identifier of the status code
 /// of the error.
 /// </param>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceException(
     int errorCodeId,
     HealthServiceResponseError error)
     : base(GetMessage(errorCodeId, error))
 {
     Error       = error;
     ErrorCodeId = errorCodeId;
 }
        /// <summary>
        /// Helper method that allows the SDK to throw the appropriate
        /// HealthServiceException based on the status code indicating the error
        /// type.
        /// </summary>
        ///
        /// <param name="errorCode">
        /// The status code representing the error which occurred.
        /// </param>
        ///
        /// <param name="error">
        /// Information about an error that occurred while processing
        /// the request.
        /// </param>
        ///
        internal static HealthServiceException GetHealthServiceException(
            HealthServiceStatusCode errorCode,
            HealthServiceResponseError error)
        {
            HealthServiceException e;

            switch (errorCode)
            {
            case HealthServiceStatusCode.CredentialTokenExpired:
                e = new HealthServiceCredentialTokenExpiredException(error);
                break;

            case HealthServiceStatusCode.AuthenticatedSessionTokenExpired:
                e = new HealthServiceAuthenticatedSessionTokenExpiredException(error);
                break;

            case HealthServiceStatusCode.InvalidPerson:
                e = new HealthServiceInvalidPersonException(error);
                break;

            case HealthServiceStatusCode.InvalidRecord:
                e = new HealthServiceInvalidRecordException(error);
                break;

            case HealthServiceStatusCode.AccessDenied:
                e = new HealthServiceAccessDeniedException(error);
                break;

            case HealthServiceStatusCode.InvalidApplicationAuthorization:
                e = new HealthServiceInvalidApplicationAuthorizationException(error);
                break;

            case HealthServiceStatusCode.DuplicateCredentialFound:
                e = new HealthServiceApplicationDuplicateCredentialException(error);
                break;

            case HealthServiceStatusCode.MailAddressMalformed:
                e = new HealthServiceMailAddressMalformedException(error);
                break;

            case HealthServiceStatusCode.PasswordNotStrong:
                e = new HealthServicePasswordNotStrongException(error);
                break;

            case HealthServiceStatusCode.RecordQuotaExceeded:
                e = new HealthServiceRecordQuotaExceededException(error);
                break;

            default:
                e = new HealthServiceException(errorCode, error);
                break;
            }

            return(e);
        }
Example #5
0
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceAuthenticatedSessionTokenExpiredException"/>
 /// class with the specified error information representing a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.AuthenticatedSessionTokenExpired"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type. This error indicates that the
 /// authorization token supplied to HealthVault is malformed or
 /// otherwise faulty.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceAuthenticatedSessionTokenExpiredException(HealthServiceResponseError error)
     : base(HealthServiceStatusCode.AuthenticatedSessionTokenExpired, error)
 {
 }
Example #6
0
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceInvalidPersonException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.InvalidPerson"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type. The error indicates that
 /// the person specified in the request is either nonexistent or inactive.
 /// </remarks>
 ///
 /// <param name="error">
 /// information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceInvalidPersonException(HealthServiceResponseError error)
     : base(HealthServiceStatusCode.InvalidPerson, error)
 {
 }
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceApplicationDuplicateCredentialException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.DuplicateCredentialFound"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceApplicationDuplicateCredentialException(
     HealthServiceResponseError error)
     : base(HealthServiceStatusCode.DuplicateCredentialFound, error)
 {
 }
Example #8
0
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceEmailNotValidatedException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.EmailNotValidated"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceEmailNotValidatedException(
     HealthServiceResponseError error)
     : base(HealthServiceStatusCode.EmailNotValidated, error)
 {
 }
Example #9
0
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceRecordQuotaExceededException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.RecordQuotaExceeded"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceRecordQuotaExceededException(
     HealthServiceResponseError error)
     : base(HealthServiceStatusCode.RecordQuotaExceeded, error)
 {
 }
 private static string GetMessage(
     int errorCodeId,
     HealthServiceResponseError error)
 {
     return(error != null ? error.Message : Resources.HealthServiceExceptionNoResponseError.FormatResource(errorCodeId));
 }
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceException"/>
 /// class with the specified error (status) code and error information.
 /// </summary>
 /// <param name="errorCode">The status code representing the error.</param>
 /// <param name="error">Information about an error that occurred while processing
 /// the request.</param>
 internal HealthServiceException(
     HealthServiceStatusCode errorCode,
     HealthServiceResponseError error)
     : this((int)errorCode, error)
 {
 }
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceInvalidApplicationAuthorizationException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref="HealthServiceStatusCode.InvalidApplicationAuthorization"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type. The error indicates that the
 /// application does not have an entry in the authorized application
 /// information and as such is not authorized to perform the task.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceInvalidApplicationAuthorizationException(HealthServiceResponseError error)
     : base(HealthServiceStatusCode.InvalidApplicationAuthorization, error)
 {
 }
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceAuthenticatedSessionTokenExpiredException"/>
 /// class with the specified error information representing a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.CredentialTokenExpired"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type. This error indicates that the
 /// authorization token supplied to HealthVault is malformed or
 /// otherwise faulty.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceCredentialTokenExpiredException(HealthServiceResponseError error)
     : base(HealthServiceStatusCode.CredentialTokenExpired, error)
 {
 }
        /// <summary>
        /// Checks whether at least one filter was specified
        /// and that all specified filters are valid.
        /// </summary>
        /// 
        /// <exception cref="HealthServiceResponseError">
        /// If no filter was specified or if any specified filter was invalid.
        /// </exception>
        /// 
        internal static void ValidateFilters(HealthRecordSearcher searcher)
        {
            if (searcher.Filters.Count == 0)
            {
                HealthServiceResponseError error = new HealthServiceResponseError();

                error.Message =
                    ResourceRetriever.GetResourceString(
                        "HealthRecordSearcherInvalidFilter");

                HealthServiceException e =
                    HealthServiceExceptionHelper.GetHealthServiceException(
                        HealthServiceStatusCode.InvalidFilter,
                        error);
                throw e;
            }

            for (int i = 0; i < searcher.Filters.Count; ++i)
            {
                searcher.Filters[i].ThrowIfNotValid();
            }
        }
        /// <summary>
        /// Generates the XML for the parameters for the "GetThings" request.
        /// </summary>
        /// 
        /// <returns>
        /// An XML string defining the parameters for the "GetThings" call.
        /// </returns>
        /// 
        /// <exception cref="HealthServiceException">
        /// No filters have been specified.
        /// </exception>
        ///         
        internal static string GetParametersXml(HealthRecordSearcher searcher)
        {
            if (searcher.Filters.Count == 0)
            {
                HealthServiceResponseError error = new HealthServiceResponseError();
                error.Message =
                    ResourceRetriever.GetResourceString(
                        "HealthRecordSearcherNoFilters");

                HealthServiceException e =
                    HealthServiceExceptionHelper.GetHealthServiceException(
                        HealthServiceStatusCode.InvalidFilter, error);
                throw e;

            }

            StringBuilder parameters = new StringBuilder(128);

            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;

            using (XmlWriter writer = XmlWriter.Create(parameters, settings))
            {
                foreach (HealthRecordFilter filter in searcher.Filters)
                {
                    // Add all filters
                    filter.AddFilterXml(writer);
                }
                writer.Flush();
            }
            return parameters.ToString();
        }
 private static void ThrowIfConfigValueMissing(string key)
 {
     HealthServiceResponseError error = new HealthServiceResponseError();
     error.Message = ResourceRetriever.FormatResourceString(
         "ConfigValueAbsentOrMalformed",
         key);
     HealthServiceException e =
         HealthServiceExceptionHelper.GetHealthServiceException(
             HealthServiceStatusCode.ConfigValueMissingOrMalformed,
             error);
     throw e;
 }
Example #17
0
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceInvalidRecordException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.InvalidRecord"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type. The error indicates that the
 /// specified record is nonexistent.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceInvalidRecordException(HealthServiceResponseError error)
     : base(HealthServiceStatusCode.InvalidRecord, error)
 {
 }
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceMailAddressMalformedException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.MailAddressMalformed"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceMailAddressMalformedException(
     HealthServiceResponseError error)
     : base(HealthServiceStatusCode.MailAddressMalformed, error)
 {
 }
 /// <summary>
 /// Creates an instance of the <see cref="HealthServiceAccessDeniedException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.AccessDenied"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServiceAccessDeniedException(HealthServiceResponseError error)
     : base(HealthServiceStatusCode.AccessDenied, error)
 {
 }
Example #20
0
 /// <summary>
 /// Creates an instance of the <see cref="HealthServicePasswordNotStrongException"/>
 /// class with the specified error information to represent a
 /// HealthVault error code of
 /// <see cref = "HealthServiceStatusCode.PasswordNotStrong"/>.
 /// </summary>
 ///
 /// <remarks>
 /// This constructor is internal to the SDK. Application developers
 /// using the SDK should catch instances of this exception instead of
 /// throwing new exceptions of this type.
 /// </remarks>
 ///
 /// <param name="error">
 /// Information about an error that occurred while processing
 /// the request.
 /// </param>
 ///
 internal HealthServicePasswordNotStrongException(
     HealthServiceResponseError error)
     : base(HealthServiceStatusCode.PasswordNotStrong, error)
 {
 }