Exemplo n.º 1
0
        /// <summary>
        /// Gets the instance where a HealthVault account should be created
        /// for the specified account location.
        /// </summary>
        ///
        /// <param name="connection">
        /// The connection to use to perform the operation.
        /// </param>
        ///
        /// <param name="preferredLocation">
        /// A user's preferred geographical location, used to select the best instance
        /// in which to create a new HealthVault account. If there is a location associated
        /// with the credential that will be used to log into the account, that location
        /// should be used.
        /// </param>
        ///
        /// <remarks>
        /// If no suitable instance can be found, a null value is returned. This can happen,
        /// for example, if the account location is not supported by HealthVault.
        ///
        /// Currently the returned instance IDs all parse to integers, but that is not
        /// guaranteed and should not be relied upon.
        /// </remarks>
        ///
        /// <returns>
        /// A <see cref="HealthServiceInstance"/> object represents the selected instance,
        /// or null if no suitable instance exists.
        /// </returns>
        ///
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error.
        /// </exception>
        ///
        /// <exception cref="ArgumentException">
        /// If <paramref name="preferredLocation"/> is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="connection"/> parameter is <b>null</b>.
        /// </exception>
        public virtual async Task <HealthServiceInstance> SelectInstanceAsync(
            IHealthVaultConnection connection,
            Location preferredLocation)
        {
            Validator.ThrowIfArgumentNull(connection, nameof(connection), Resources.TypeManagerConnectionNull);
            Validator.ThrowIfArgumentNull(preferredLocation, nameof(preferredLocation), Resources.SelectInstanceLocationRequired);

            StringBuilder     requestParameters = new StringBuilder();
            XmlWriterSettings settings          = SDKHelper.XmlUnicodeWriterSettings;

            using (XmlWriter writer = XmlWriter.Create(requestParameters, settings))
            {
                preferredLocation.WriteXml(writer, "preferred-location");
                writer.Flush();
            }

            HealthServiceResponseData responseData = await connection.ExecuteAsync(
                HealthVaultMethods.SelectInstance,
                1,
                requestParameters.ToString()).ConfigureAwait(false);

            XPathExpression infoPath = SDKHelper.GetInfoXPathExpressionForMethod(
                responseData.InfoNavigator,
                "SelectInstance");
            XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode(infoPath);

            XPathNavigator instanceNav = infoNav.SelectSingleNode("selected-instance");

            if (instanceNav != null)
            {
                return(HealthServiceInstance.CreateInstance(instanceNav));
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generates a new signup code that should be passed to HealthVault Shell in order
        /// to create a new user account.
        /// </summary>
        ///
        /// <param name="connection">The connection to use to perform the operation. This connection
        /// must be application level. </param>
        ///
        /// <returns>
        /// A signup code that can be used to create an account.
        /// </returns>
        ///
        public virtual async Task <string> NewSignupCodeAsync(IHealthVaultConnection connection)
        {
            HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.NewSignupCode, 1).ConfigureAwait(false);

            XPathExpression infoPath = SDKHelper.GetInfoXPathExpressionForMethod(responseData.InfoNavigator, "NewSignupCode");

            XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode(infoPath);

            return(infoNav.SelectSingleNode("signup-code").Value);
        }
        /// <summary>
        /// Gets valid group memberships for a record.
        /// </summary>
        ///
        /// <remarks>
        /// Group membership thing types allow an application to signify that the
        /// record belongs to an application defined group.  A record in the group may be
        /// eligible for special programs offered by other applications, for example.
        /// Applications then need a away to query for valid group memberships.
        /// <br/>
        /// Valid group memberships are those memberships which are not expired, and whose
        /// last updating application is authorized by the last updating person to
        /// read and delete the membership.
        /// </remarks>
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// <param name="applicationIds">
        /// A collection of unique application identifiers for which to
        /// search for group memberships.  For a null or empty application identifier
        /// list, return all valid group memberships for the record.  Otherwise,
        /// return only those group memberships last updated by one of the
        /// supplied application identifiers.
        /// </param>
        /// <returns>
        /// A List of things representing the valid group memberships.
        /// </returns>
        /// <exception cref="HealthServiceException">
        /// If an error occurs while contacting the HealthVault service.
        /// </exception>
        public virtual async Task <Collection <ThingBase> > GetValidGroupMembershipAsync(
            IHealthVaultConnection connection,
            HealthRecordAccessor accessor,
            IList <Guid> applicationIds)
        {
            StringBuilder parameters = new StringBuilder(128);

            if (applicationIds != null)
            {
                XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;
                using (XmlWriter writer = XmlWriter.Create(parameters, settings))
                {
                    foreach (Guid guid in applicationIds)
                    {
                        writer.WriteElementString(
                            "application-id",
                            guid.ToString());
                    }
                }
            }

            var thingDeserializer = Ioc.Container.Locate <IThingDeserializer>(
                new
            {
                connection         = connection,
                thingTypeRegistrar = Ioc.Get <IThingTypeRegistrar>()
            });

            HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.GetValidGroupMembership, 1, parameters.ToString()).ConfigureAwait(false);

            XPathExpression infoPath =
                SDKHelper.GetInfoXPathExpressionForMethod(
                    responseData.InfoNavigator,
                    "GetValidGroupMembership");

            XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode(infoPath);

            Collection <ThingBase> memberships = new Collection <ThingBase>();

            XPathNodeIterator membershipIterator = infoNav.Select("thing");

            if (membershipIterator != null)
            {
                foreach (XPathNavigator membershipNav in membershipIterator)
                {
                    memberships.Add(thingDeserializer.Deserialize(membershipNav.OuterXml));
                }
            }

            return(memberships);
        }
Exemplo n.º 4
0
        private static async Task <ServiceInfo> GetServiceDefinitionAsync(IHealthVaultConnection connection, string parameters)
        {
            HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.GetServiceDefinition, 2, parameters).ConfigureAwait(false);

            if (responseData.InfoNavigator.HasChildren)
            {
                XPathExpression infoPath = SDKHelper.GetInfoXPathExpressionForMethod(
                    responseData.InfoNavigator,
                    "GetServiceDefinition2");

                XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode(infoPath);

                return(ServiceInfo.CreateServiceInfo(infoNav));
            }

            return(null);
        }
        /// <summary>
        /// Calls the BeginPutBlob HealthVault method.
        /// </summary>
        ///
        /// <returns>
        /// The result of the BeginPutBlob method call as a BlobPutParameters instance.
        /// </returns>
        ///
        /// <exception cref="HealthServiceException">
        /// If the call to HealthVault fails in some way.
        /// </exception>
        ///
        private async Task <BlobPutParameters> BeginPutBlobAsync()
        {
            HealthServiceResponseData responseData = await _record.Connection.ExecuteAsync(HealthVaultMethods.BeginPutBlob, 1).ConfigureAwait(false);

            XPathExpression infoPath =
                SDKHelper.GetInfoXPathExpressionForMethod(
                    responseData.InfoNavigator,
                    "BeginPutBlob");

            XPathNavigator infoNav =
                responseData.InfoNavigator.SelectSingleNode(infoPath);

            Uri               blobReferenceUrl  = new Uri(infoNav.SelectSingleNode("blob-ref-url").Value);
            int               chunkSize         = infoNav.SelectSingleNode("blob-chunk-size").ValueAsInt;
            long              maxBlobSize       = infoNav.SelectSingleNode("max-blob-size").ValueAsLong;
            string            blobHashAlgString = infoNav.SelectSingleNode("blob-hash-algorithm").Value;
            BlobHashAlgorithm blobHashAlg;

            try
            {
                blobHashAlg =
                    (BlobHashAlgorithm)Enum.Parse(
                        typeof(BlobHashAlgorithm), blobHashAlgString);
            }
            catch (ArgumentException)
            {
                blobHashAlg = BlobHashAlgorithm.Unknown;
            }

            int            blocksize = 0;
            XPathNavigator blockNav  = infoNav.SelectSingleNode("blob-hash-parameters/block-size");

            if (blockNav != null)
            {
                blocksize = blockNav.ValueAsInt;
            }

            return(new BlobPutParameters(
                       blobReferenceUrl,
                       chunkSize,
                       maxBlobSize,
                       blobHashAlg,
                       blocksize));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the application configuration information for the calling application.
        /// </summary>
        ///
        /// <param name="connection">The connection to use to perform the operation. This connection
        /// must be application level. </param>
        ///
        /// <param name="allLanguages">
        /// A boolean value indicating whether the localized values all languages should be
        /// returned, just one language. This affects all properties which can have multiple
        /// localized values, including <see cref="ApplicationInfo.CultureSpecificNames"/>,
        /// <see cref="ApplicationInfo.CultureSpecificDescriptions"/>,
        /// <see cref="ApplicationInfo.CultureSpecificAuthorizationReasons"/>,
        /// <see cref="ApplicationInfo.LargeLogo"/>,
        /// <see cref="ApplicationInfo.SmallLogo"/>,
        /// <see cref="ApplicationInfo.PrivacyStatement"/>,
        /// <see cref="ApplicationInfo.TermsOfUse"/>,
        /// and <see cref="ApplicationInfo.DtcSuccessMessage"/>
        /// </param>
        ///
        /// <returns>
        /// An ApplicationInfo object for the calling application.
        /// </returns>
        ///
        /// <remarks>
        /// This method always calls the HealthVault service to get the latest
        /// information. It returns installation configuration about the calling
        /// application.
        /// </remarks>
        ///
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error.
        /// </exception>
        ///
        public virtual async Task <ApplicationInfo> GetApplicationInfoAsync(
            IHealthVaultConnection connection,
            bool allLanguages)
        {
            string parameters = allLanguages ? "<all-languages>true</all-languages>" : null;

            HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.GetApplicationInfo, 2, parameters).ConfigureAwait(false);

            XPathExpression xPathExpression = SDKHelper.GetInfoXPathExpressionForMethod(
                responseData.InfoNavigator, "GetApplicationInfo");

            XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode(xPathExpression);

            XPathNavigator appInfoNav = infoNav.SelectSingleNode("application");

            ApplicationInfo appInfo = null;

            if (appInfoNav != null)
            {
                appInfo = ApplicationInfo.CreateFromInfoXml(appInfoNav);
            }

            return(appInfo);
        }
Exemplo n.º 7
0
        internal static async Task <GetAuthorizedPeopleResult> GetAuthorizedPeopleAsync(
            IHealthVaultConnection connection,
            Guid personIdCursor,
            Instant?authCreatedSinceDate,
            int numResults)
        {
            if (numResults < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(numResults), Resources.GetAuthorizedPeopleNumResultsNegative);
            }

            StringBuilder     parameters = new StringBuilder(256);
            XmlWriterSettings settings   = SDKHelper.XmlUnicodeWriterSettings;

            settings.OmitXmlDeclaration = true;
            settings.ConformanceLevel   = ConformanceLevel.Fragment;

            using (XmlWriter writer = XmlWriter.Create(parameters, settings))
            {
                writer.WriteStartElement("parameters");

                if (personIdCursor != Guid.Empty)
                {
                    writer.WriteElementString("person-id-cursor", personIdCursor.ToString());
                }

                if (authCreatedSinceDate != null)
                {
                    writer.WriteElementString(
                        "authorizations-created-since",
                        SDKHelper.XmlFromInstant(authCreatedSinceDate.Value));
                }

                if (numResults != 0)
                {
                    writer.WriteElementString("num-results", numResults.ToString(CultureInfo.InvariantCulture));
                }

                writer.WriteEndElement(); // parameters
                writer.Flush();
            }

            HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.GetAuthorizedPeople, 1, parameters.ToString()).ConfigureAwait(false);

            Collection <PersonInfo> personInfos = new Collection <PersonInfo>();

            XPathExpression navExp =
                SDKHelper.GetInfoXPathExpressionForMethod(
                    responseData.InfoNavigator, "GetAuthorizedPeople");
            XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode(navExp);
            XPathNavigator nav     = infoNav.SelectSingleNode("response-results/person-info");

            if (nav != null)
            {
                do
                {
                    PersonInfo personInfo = PersonInfo.CreateFromXml(nav);
                    personInfos.Add(personInfo);
                }while (nav.MoveToNext("person-info", string.Empty));

                nav.MoveToNext();
            }
            else
            {
                nav = infoNav.SelectSingleNode("response-results/more-results");
            }

            return(new GetAuthorizedPeopleResult(personInfos, nav.ValueAsBoolean));
        }