Example #1
0
        /// <summary>
        /// Gets the definitions for one or more thing type definitions
        /// supported by HealthVault.
        /// </summary>
        ///
        /// <param name="typeIds">
        /// A collection of health item type IDs whose details are being requested. Null
        /// indicates that all health item types should be returned.
        /// </param>
        ///
        /// <param name="sections">
        /// A collection of ThingTypeSections enumeration values that indicate the type
        /// of details to be returned for the specified health item records(s).
        /// </param>
        ///
        /// <param name="imageTypes">
        /// A collection of strings that identify which health item record images should be
        /// retrieved.
        ///
        /// This requests an image of the specified mime type should be returned. For example,
        /// to request a GIF image, "image/gif" should be specified. For icons, "image/vnd.microsoft.icon"
        /// should be specified. Note, not all health item records will have all image types and
        /// some may not have any images at all.
        ///
        /// If '*' is specified, all image types will be returned.
        /// </param>
        ///
        /// <param name="lastClientRefreshDate">
        /// A <see cref="DateTime"/> instance that specifies the time of the last refresh
        /// made by the client.
        /// </param>
        ///
        /// <param name="connection">
        /// A connection to the HealthVault service.
        /// </param>
        ///
        /// <returns>
        /// The type definitions for the specified types, or empty if the
        /// <paramref name="typeIds"/> parameter does not represent a known unique
        /// type identifier.
        /// </returns>
        ///
        /// <remarks>
        /// This method calls the HealthVault service if the types are not
        /// already in the client-side cache.
        /// </remarks>
        ///
        /// <exception cref="ArgumentException">
        /// If <paramref name="typeIds"/> is <b>null</b> and empty, or
        /// <paramref name="typeIds"/> is <b>null</b> and member in <paramref name="typeIds"/> is
        /// <see cref="System.Guid.Empty"/>.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="connection"/> parameter is <b>null</b>.
        /// </exception>
        ///
        public virtual async Task <IDictionary <Guid, ThingTypeDefinition> > GetHealthRecordItemTypeDefinitionAsync(
            IList <Guid> typeIds,
            ThingTypeSections sections,
            IList <string> imageTypes,
            Instant?lastClientRefreshDate,
            IHealthVaultConnection connection)
        {
            Validator.ThrowIfArgumentNull(connection, nameof(connection), Resources.TypeManagerConnectionNull);

            if ((typeIds != null && typeIds.Contains(Guid.Empty)) ||
                (typeIds != null && typeIds.Count == 0))
            {
                throw new ArgumentException(Resources.TypeIdEmpty, nameof(typeIds));
            }

            if (lastClientRefreshDate != null)
            {
                return(await GetHealthRecordItemTypeDefinitionByDateAsync(
                           typeIds,
                           sections,
                           imageTypes,
                           lastClientRefreshDate.Value,
                           connection).ConfigureAwait(false));
            }

            return(await GetHealthRecordItemTypeDefinitionNoDateAsync(
                       typeIds,
                       sections,
                       imageTypes,
                       connection).ConfigureAwait(false));
        }
 public Task <IDictionary <Guid, ThingTypeDefinition> > GetHealthRecordItemTypeDefinitionAsync(
     IList <Guid> typeIds,
     ThingTypeSections sections,
     IList <string> imageTypes,
     Instant?lastClientRefreshDate)
 {
     return(HealthVaultPlatformInformation.Current.GetHealthRecordItemTypeDefinitionAsync(typeIds, sections, imageTypes, lastClientRefreshDate, _connection));
 }
Example #3
0
 /// <summary>
 /// Gets the requested definitions for the specified thing type definitions
 /// supported by HealthVault.
 /// </summary>
 ///
 /// <param name="typeIds">
 /// A collection of health item record type Ids whose details are being requested. Null
 /// indicates that all health item record types should be returned.
 /// </param>
 ///
 /// <param name="sections">
 /// A collection of ThingTypeSections enumeration values that indicate the type of
 /// details to be returned for the specified health item record(s).
 /// </param>
 ///
 /// <param name="connection">
 /// A connection to the HealthVault service.
 /// </param>
 ///
 /// <returns>
 /// The type definitions for the specified types, or empty if the
 /// <paramref name="typeIds"/> parameter does not represent a known unique
 /// type identifier.
 /// </returns>
 ///
 /// <remarks>
 /// This method calls the HealthVault service if the types are not
 /// already in the client-side cache.
 /// </remarks>
 ///
 /// <exception cref="ArgumentException">
 /// If <paramref name="typeIds"/> is <b>null</b> and empty, or
 /// <paramref name="typeIds"/> is <b>null</b> and member in <paramref name="typeIds"/> is
 /// <see cref="System.Guid.Empty"/>.
 /// </exception>
 ///
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="connection"/> parameter is <b>null</b>.
 /// </exception>
 ///
 public static async Task <IDictionary <Guid, ThingTypeDefinition> > GetHealthRecordItemTypeDefinitionAsync(
     IList <Guid> typeIds,
     ThingTypeSections sections,
     IConnectionInternal connection)
 {
     return(await GetHealthRecordItemTypeDefinitionAsync(
                typeIds,
                sections,
                null,
                null,
                connection).ConfigureAwait(false));
 }
Example #4
0
        private static void WriteSectionSpecs(
            XmlWriter writer,
            ThingTypeSections sectionSpecs)
        {
            if ((sectionSpecs & ThingTypeSections.Core) != ThingTypeSections.None)
            {
                writer.WriteStartElement("section");
                writer.WriteString(ThingTypeSections.Core.ToString().ToLowerInvariant());
                writer.WriteEndElement();
            }

            if ((sectionSpecs & ThingTypeSections.Xsd) != ThingTypeSections.None)
            {
                writer.WriteStartElement("section");
                writer.WriteString(ThingTypeSections.Xsd.ToString().ToLowerInvariant());
                writer.WriteEndElement();
            }

            if ((sectionSpecs & ThingTypeSections.Columns) != ThingTypeSections.None)
            {
                writer.WriteStartElement("section");
                writer.WriteString(ThingTypeSections.Columns.ToString().ToLowerInvariant());
                writer.WriteEndElement();
            }

            if ((sectionSpecs & ThingTypeSections.Transforms) != ThingTypeSections.None)
            {
                writer.WriteStartElement("section");
                writer.WriteString(ThingTypeSections.Transforms.ToString().ToLowerInvariant());
                writer.WriteEndElement();
            }

            if ((sectionSpecs & ThingTypeSections.TransformSource) != ThingTypeSections.None)
            {
                writer.WriteStartElement("section");
                writer.WriteString(ThingTypeSections.TransformSource.ToString().ToLowerInvariant());
                writer.WriteEndElement();
            }

            if ((sectionSpecs & ThingTypeSections.Versions) != ThingTypeSections.None)
            {
                writer.WriteStartElement("section");
                writer.WriteString(ThingTypeSections.Versions.ToString().ToLowerInvariant());
                writer.WriteEndElement();
            }

            if ((sectionSpecs & ThingTypeSections.EffectiveDateXPath) != ThingTypeSections.None)
            {
                writer.WriteStartElement("section");
                writer.WriteString(ThingTypeSections.EffectiveDateXPath.ToString().ToLowerInvariant());
                writer.WriteEndElement();
            }
        }
Example #5
0
 /// <summary>
 /// Gets the definitions for one or more thing type definitions
 /// supported by HealthVault.
 /// </summary>
 ///
 /// <param name="typeIds">
 /// A collection of health item type IDs whose details are being requested. Null
 /// indicates that all health item types should be returned.
 /// </param>
 ///
 /// <param name="sections">
 /// A collection of ThingTypeSections enumeration values that indicate the type
 /// of details to be returned for the specified health item records(s).
 /// </param>
 ///
 /// <param name="imageTypes">
 /// A collection of strings that identify which health item record images should be
 /// retrieved.
 ///
 /// This requests an image of the specified mime type should be returned. For example,
 /// to request a GIF image, "image/gif" should be specified. For icons, "image/vnd.microsoft.icon"
 /// should be specified. Note, not all health item records will have all image types and
 /// some may not have any images at all.
 ///
 /// If '*' is specified, all image types will be returned.
 /// </param>
 ///
 /// <param name="lastClientRefreshDate">
 /// An <see cref="Instant"/> that specifies the time of the last refresh
 /// made by the client.
 /// </param>
 ///
 /// <param name="connection">
 /// A connection to the HealthVault service.
 /// </param>
 ///
 /// <returns>
 /// The type definitions for the specified types, or empty if the
 /// <paramref name="typeIds"/> parameter does not represent a known unique
 /// type identifier.
 /// </returns>
 ///
 /// <remarks>
 /// This method calls the HealthVault service if the types are not
 /// already in the client-side cache.
 /// </remarks>
 ///
 /// <exception cref="ArgumentException">
 /// If <paramref name="typeIds"/> is <b>null</b> and empty, or
 /// <paramref name="typeIds"/> is <b>null</b> and member in <paramref name="typeIds"/> is
 /// <see cref="System.Guid.Empty"/>.
 /// </exception>
 ///
 /// <exception cref="ArgumentNullException">
 /// If <paramref name="connection"/> parameter is <b>null</b>.
 /// </exception>
 ///
 public static async Task <IDictionary <Guid, ThingTypeDefinition> > GetHealthRecordItemTypeDefinitionAsync(
     IList <Guid> typeIds,
     ThingTypeSections sections,
     IList <string> imageTypes,
     Instant?lastClientRefreshDate,
     IConnectionInternal connection)
 {
     return(await HealthVaultPlatform.GetHealthRecordItemTypeDefinitionAsync(
                typeIds,
                sections,
                imageTypes,
                lastClientRefreshDate,
                connection).ConfigureAwait(false));
 }
Example #6
0
        private Dictionary <Guid, ThingTypeDefinition> CreateThingTypesFromResponse(
            string cultureName,
            HealthServiceResponseData response,
            ThingTypeSections sections,
            Dictionary <Guid, ThingTypeDefinition> cachedThingTypes)
        {
            Dictionary <Guid, ThingTypeDefinition> thingTypes;

            if (cachedThingTypes != null && cachedThingTypes.Count > 0)
            {
                thingTypes = new Dictionary <Guid, ThingTypeDefinition>(cachedThingTypes);
            }
            else
            {
                thingTypes = new Dictionary <Guid, ThingTypeDefinition>();
            }

            XPathNodeIterator thingTypesIterator =
                response.InfoNavigator.Select("thing-type");

            lock (_sectionCache)
            {
                if (!_sectionCache.ContainsKey(cultureName))
                {
                    _sectionCache.Add(cultureName, new Dictionary <ThingTypeSections, Dictionary <Guid, ThingTypeDefinition> >());
                }

                if (!_sectionCache[cultureName].ContainsKey(sections))
                {
                    _sectionCache[cultureName].Add(sections, new Dictionary <Guid, ThingTypeDefinition>());
                }

                foreach (XPathNavigator navigator in thingTypesIterator)
                {
                    ThingTypeDefinition thingType =
                        ThingTypeDefinition.CreateFromXml(navigator);

                    _sectionCache[cultureName][sections][thingType.TypeId] = thingType;
                    thingTypes[thingType.TypeId] = thingType;
                }
            }

            return(thingTypes);
        }
Example #7
0
        private async Task <IDictionary <Guid, ThingTypeDefinition> > GetHealthRecordItemTypeDefinitionByDateAsync(
            IList <Guid> typeIds,
            ThingTypeSections sections,
            IList <string> imageTypes,
            Instant lastClientRefreshDate,
            IHealthVaultConnection connection)
        {
            StringBuilder     requestParameters = new StringBuilder();
            XmlWriterSettings settings          = SDKHelper.XmlUnicodeWriterSettings;

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

            using (XmlWriter writer = XmlWriter.Create(requestParameters, settings))
            {
                if ((typeIds != null) && (typeIds.Count > 0))
                {
                    foreach (Guid id in typeIds)
                    {
                        writer.WriteStartElement("id");

                        writer.WriteString(id.ToString("D"));

                        writer.WriteEndElement();
                    }
                }

                WriteSectionSpecs(writer, sections);

                if ((imageTypes != null) && (imageTypes.Count > 0))
                {
                    foreach (string imageType in imageTypes)
                    {
                        writer.WriteStartElement("image-type");

                        writer.WriteString(imageType);

                        writer.WriteEndElement();
                    }
                }

                writer.WriteElementString(
                    "last-client-refresh",
                    SDKHelper.XmlFromInstant(lastClientRefreshDate));

                writer.Flush();

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

                Dictionary <Guid, ThingTypeDefinition> result =
                    CreateThingTypesFromResponse(
                        CultureInfo.CurrentCulture.Name,
                        responseData,
                        sections,
                        null);

                lock (_sectionCache)
                {
                    _sectionCache[CultureInfo.CurrentCulture.Name][sections] = result;
                }

                return(result);
            }
        }
Example #8
0
        private async Task <IDictionary <Guid, ThingTypeDefinition> > GetHealthRecordItemTypeDefinitionNoDateAsync(
            IList <Guid> typeIds,
            ThingTypeSections sections,
            IList <string> imageTypes,
            IHealthVaultConnection connection)
        {
            StringBuilder     requestParameters = new StringBuilder();
            XmlWriterSettings settings          = SDKHelper.XmlUnicodeWriterSettings;

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

            Dictionary <Guid, ThingTypeDefinition> cachedThingTypes = null;

            string cultureName = CultureInfo.CurrentCulture.Name;
            bool   sendRequest = false;

            using (XmlWriter writer = XmlWriter.Create(requestParameters, settings))
            {
                if ((typeIds != null) && (typeIds.Count > 0))
                {
                    foreach (Guid id in typeIds)
                    {
                        lock (_sectionCache)
                        {
                            if (!_sectionCache.ContainsKey(cultureName))
                            {
                                _sectionCache.Add(
                                    cultureName,
                                    new Dictionary <ThingTypeSections, Dictionary <Guid, ThingTypeDefinition> >());
                            }

                            if (!_sectionCache[cultureName].ContainsKey(sections))
                            {
                                _sectionCache[cultureName].Add(sections, new Dictionary <Guid, ThingTypeDefinition>());
                            }

                            if (_sectionCache[cultureName][sections].ContainsKey(id))
                            {
                                if (cachedThingTypes == null)
                                {
                                    cachedThingTypes =
                                        new Dictionary <Guid, ThingTypeDefinition>();
                                }

                                cachedThingTypes[id] = _sectionCache[cultureName][sections][id];
                            }
                            else
                            {
                                sendRequest = true;

                                writer.WriteStartElement("id");

                                writer.WriteString(id.ToString("D"));

                                writer.WriteEndElement();
                            }
                        }
                    }
                }
                else
                {
                    lock (_sectionCache)
                    {
                        if (!_sectionCache.ContainsKey(cultureName))
                        {
                            _sectionCache.Add(
                                cultureName,
                                new Dictionary <ThingTypeSections, Dictionary <Guid, ThingTypeDefinition> >());
                        }

                        if (!_sectionCache[cultureName].ContainsKey(sections))
                        {
                            _sectionCache[cultureName].Add(sections, new Dictionary <Guid, ThingTypeDefinition>());
                        }
                        else
                        {
                            cachedThingTypes = _sectionCache[cultureName][sections];
                        }
                    }

                    sendRequest = true;
                }

                if (!sendRequest)
                {
                    return(cachedThingTypes);
                }

                WriteSectionSpecs(writer, sections);

                if ((imageTypes != null) && (imageTypes.Count > 0))
                {
                    foreach (string imageType in imageTypes)
                    {
                        writer.WriteStartElement("image-type");

                        writer.WriteString(imageType);

                        writer.WriteEndElement();
                    }
                }

                writer.Flush();

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

                Dictionary <Guid, ThingTypeDefinition> result =
                    CreateThingTypesFromResponse(
                        cultureName,
                        responseData,
                        sections,
                        cachedThingTypes);

                lock (_sectionCache)
                {
                    foreach (Guid id in result.Keys)
                    {
                        _sectionCache[cultureName][sections][id] = result[id];
                    }
                }

                return(result);
            }
        }