Ejemplo n.º 1
0
        private static Dictionary <string, HealthServiceInstance> GetServiceInstances(
            XPathNavigator nav,
            out string currentInstanceId)
        {
            Dictionary <string, HealthServiceInstance> instances =
                new Dictionary <string, HealthServiceInstance>(StringComparer.OrdinalIgnoreCase);

            XPathNavigator instancesNav = nav.SelectSingleNode("instances");

            if (instancesNav != null)
            {
                currentInstanceId = instancesNav.GetAttribute("current-instance-id", string.Empty);

                XPathNodeIterator instanceNavs = instancesNav.Select("instance");

                foreach (XPathNavigator instanceNav in instanceNavs)
                {
                    HealthServiceInstance instance = HealthServiceInstance.CreateInstance(instanceNav);
                    instances.Add(instance.Id, instance);
                }

                return(instances);
            }

            currentInstanceId = null;
            return(null);
        }
Ejemplo n.º 2
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);
        }
        internal static HealthServiceInstance CreateInstance(
            XPathNavigator nav)
        {
            HealthServiceInstance instance =
                new HealthServiceInstance();

            instance.ParseXml(nav);
            return(instance);
        }