/// <summary>
        /// Generate the to-be signed content for the credential.
        /// </summary>
        ///
        /// <returns>
        /// Raw XML representing the ContentSection of the info secttion.
        /// </returns>
        ///
        internal string GetContentSection()
        {
            StringBuilder     requestXml = new StringBuilder(2048);
            XmlWriterSettings settings   = SDKHelper.XmlUnicodeWriterSettings;

            XmlWriter writer = null;

            try
            {
                writer = XmlWriter.Create(requestXml, settings);

                writer.WriteStartElement("content");

                writer.WriteStartElement("app-id");
                writer.WriteString(_webHealthVaultConfiguration.MasterApplicationId.ToString());
                writer.WriteEndElement();

                writer.WriteElementString("hmac", HealthVaultConstants.Cryptography.HmacAlgorithm);

                writer.WriteStartElement("signing-time");
                writer.WriteValue(SDKHelper.XmlFromInstant(SystemClock.Instance.GetCurrentInstant()));
                writer.WriteEndElement();

                writer.WriteEndElement(); // content
            }
            finally
            {
                writer?.Close();
            }

            return(requestXml.ToString());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the XML representation of the set.
 /// </summary>
 ///
 /// <returns>
 /// The XML representation of the set as a string.
 /// </returns>
 ///
 /// <remarks>
 /// The XML representation adheres to the schema required by the
 /// HealthVault methods.
 /// </remarks>
 ///
 public override string GetXml()
 {
     return
         ("<date-range>" +
          "<date-min>" +
          (DateMin == null ? "1000-01-01T00:00:00.000Z" : SDKHelper.XmlFromInstant(DateMin.Value)) +
          "</date-min>" +
          "<date-max>" +
          (DateMax == null ? "9999-12-31T23:59:59.999Z" : SDKHelper.XmlFromInstant(DateMax.Value)) +
          "</date-max>" +
          "</date-range>");
 }
Exemplo n.º 3
0
        private static string CreateServiceDefinitionRequestParameters(
            ServiceInfoSections responseSections,
            Instant?lastUpdatedTime)
        {
            StringBuilder requestBuilder = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(requestBuilder, SDKHelper.XmlUnicodeWriterSettings))
            {
                if (lastUpdatedTime != null)
                {
                    writer.WriteElementString(
                        "updated-date",
                        SDKHelper.XmlFromInstant(lastUpdatedTime.Value));
                }

                writer.WriteStartElement("response-sections");

                if ((responseSections & ServiceInfoSections.Platform) == ServiceInfoSections.Platform)
                {
                    writer.WriteElementString("section", "platform");
                }

                if ((responseSections & ServiceInfoSections.Shell) == ServiceInfoSections.Shell)
                {
                    writer.WriteElementString("section", "shell");
                }

                if ((responseSections & ServiceInfoSections.Topology) == ServiceInfoSections.Topology)
                {
                    writer.WriteElementString("section", "topology");
                }

                if ((responseSections & ServiceInfoSections.XmlOverHttpMethods) == ServiceInfoSections.XmlOverHttpMethods)
                {
                    writer.WriteElementString("section", "xml-over-http-methods");
                }

                if ((responseSections & ServiceInfoSections.MeaningfulUse) == ServiceInfoSections.MeaningfulUse)
                {
                    writer.WriteElementString("section", "meaningful-use");
                }

                writer.WriteEndElement();

                writer.Flush();
            }

            return(requestBuilder.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets information about the HealthVault service only if it has been updated since
        /// the specified update time.
        /// </summary>
        ///
        /// <param name="connection">The connection to use to perform the operation.</param>
        ///
        /// <param name="lastUpdatedTime">
        /// The time of the last update to an existing cached copy of <see cref="ServiceInfo"/>.
        /// </param>
        ///
        /// <remarks>
        /// Gets the latest information about the HealthVault service, if there were updates
        /// since the specified <paramref name="lastUpdatedTime"/>.  If there were no updates
        /// the method returns <b>null</b>.
        /// This includes:<br/>
        /// - The version of the service.<br/>
        /// - The SDK assembly URLs.<br/>
        /// - The SDK assembly versions.<br/>
        /// - The SDK documentation URL.<br/>
        /// - The URL to the HealthVault Shell.<br/>
        /// - The schema definition for the HealthVault method's request and
        ///   response.<br/>
        /// - The common schema definitions for types that the HealthVault methods
        ///   use.<br/>
        /// - Information about all available HealthVault instances.<br/>
        /// </remarks>
        ///
        /// <returns>
        /// If there were updates to the service information since the specified <paramref name="lastUpdatedTime"/>,
        /// a <see cref="ServiceInfo"/> instance that contains the service version, SDK
        /// assemblies versions and URLs, method information, and so on.  Otherwise, if there were no updates,
        /// returns <b>null</b>.
        /// </returns>
        ///
        /// <exception cref="ArgumentNullException">
        /// <paramref name="connection"/> is <b>null</b>.
        /// </exception>
        ///
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error.
        /// </exception>
        ///
        /// <exception cref="UriFormatException">
        /// One or more URL strings returned by HealthVault is invalid.
        /// </exception>
        ///
        public virtual async Task <ServiceInfo> GetServiceDefinitionAsync(IHealthVaultConnection connection, Instant lastUpdatedTime)
        {
            Validator.ThrowIfArgumentNull(connection, nameof(connection), Resources.ConnectionNull);

            StringBuilder requestBuilder = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(requestBuilder, SDKHelper.XmlUnicodeWriterSettings))
            {
                writer.WriteElementString(
                    "updated-date",
                    SDKHelper.XmlFromInstant(lastUpdatedTime));

                writer.Flush();
            }

            string requestParams = requestBuilder.ToString();

            return(await GetServiceDefinitionAsync(connection, requestParams).ConfigureAwait(false));
        }
Exemplo n.º 5
0
 private string GetUpdateDateParameters(Instant?updateDate)
 {
     return(updateDate == null ? null : $"<update-date>{SDKHelper.XmlFromInstant(updateDate.Value)}</update-date>");
 }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        internal void WriteXml(string nodeName, XmlWriter writer)
        {
            writer.WriteStartElement(nodeName);

            writer.WriteAttributeString("id", Id.ToString());

            if (Location != null)
            {
                writer.WriteAttributeString("location-country", Location.Country);
                if (!string.IsNullOrEmpty(Location.StateProvince))
                {
                    writer.WriteAttributeString("location-state-province", Location.StateProvince);
                }
            }

            writer.WriteAttributeString(
                "record-custodian",
                XmlConvert.ToString(_custodian));

            writer.WriteAttributeString(
                "rel-type",
                XmlConvert.ToString((int)_relationshipType));

            if (!string.IsNullOrEmpty(_relationshipName))
            {
                writer.WriteAttributeString(
                    "rel-name",
                    _relationshipName);
            }

            writer.WriteAttributeString(
                "auth-expires",
                DateAuthorizationExpires == null ? "9999-12-31T23:59:59.999Z" : SDKHelper.XmlFromInstant(DateAuthorizationExpires.Value));

            writer.WriteAttributeString(
                "auth-expired",
                SDKHelper.XmlFromBool(_authExpired));

            if (!string.IsNullOrEmpty(_displayName))
            {
                writer.WriteAttributeString(
                    "display-name",
                    _displayName);
            }

            writer.WriteAttributeString(
                "state",
                State.ToString());

            writer.WriteAttributeString(
                "date-created",
                SDKHelper.XmlFromInstant(DateCreated));

            if (QuotaInBytes.HasValue)
            {
                writer.WriteAttributeString(
                    "max-size-bytes",
                    XmlConvert.ToString(QuotaInBytes.Value));
            }

            if (QuotaUsedInBytes.HasValue)
            {
                writer.WriteAttributeString(
                    "size-bytes",
                    XmlConvert.ToString(QuotaUsedInBytes.Value));
            }

            writer.WriteAttributeString(
                "app-record-auth-action",
                HealthRecordAuthorizationStatus.ToString());

            writer.WriteAttributeString(
                "app-specific-record-id",
                ApplicationSpecificRecordId);

            writer.WriteAttributeString(
                "date-updated",
                SDKHelper.XmlFromInstant(DateUpdated));

            writer.WriteValue(_name);

            writer.WriteEndElement();
        }
Exemplo n.º 8
0
 private void WriteUpdatedDate(XmlWriter writer)
 {
     writer.WriteElementString(
         "updated-date",
         SDKHelper.XmlFromInstant(LastUpdated));
 }
Exemplo n.º 9
0
        private void AddFilterSection(XmlWriter writer)
        {
            if (AreFiltersPresent())
            {
                // <filter>
                writer.WriteStartElement("filter");

                if (_typeIds.Count > 0)
                {
                    // <type-id>
                    foreach (Guid typeId in _typeIds)
                    {
                        writer.WriteElementString(
                            "type-id", typeId.ToString());
                    }
                }

                if ((States & ThingStates.Active) != 0)
                {
                    // <thing-state>
                    writer.WriteElementString(
                        "thing-state",
                        ThingState.Active.ToString());
                }

                if ((States & ThingStates.Deleted) != 0)
                {
                    // <thing-state>
                    writer.WriteElementString(
                        "thing-state",
                        ThingState.Deleted.ToString());
                }

                if (EffectiveDateMin != null)
                {
                    // <eff-date-min>
                    writer.WriteStartElement("eff-date-min");
                    writer.WriteValue(SDKHelper.XmlFromLocalDateTime(EffectiveDateMin.Value));
                    writer.WriteEndElement();
                }

                if (EffectiveDateMax != null)
                {
                    // <eff-date-max>
                    writer.WriteStartElement("eff-date-max");
                    writer.WriteValue(SDKHelper.XmlFromLocalDateTime(EffectiveDateMax.Value));
                    writer.WriteEndElement();
                }

                if (_createdApplication != null)
                {
                    // <created-application>
                    writer.WriteStartElement("created-app-id");
                    writer.WriteValue(CreatedApplication.ToString());
                    writer.WriteEndElement();
                }

                if (_createdPerson != null)
                {
                    // <created-person>
                    writer.WriteStartElement("created-person-id");
                    writer.WriteValue(CreatedPerson.ToString());
                    writer.WriteEndElement();
                }

                if (_updatedApplication != null)
                {
                    // <updated-application>
                    writer.WriteStartElement("updated-app-id");
                    writer.WriteValue(UpdatedApplication.ToString());
                    writer.WriteEndElement();
                }

                if (_updatedPerson != null)
                {
                    // <updated-person>
                    writer.WriteStartElement("updated-person-id");
                    writer.WriteValue(UpdatedPerson.ToString());
                    writer.WriteEndElement();
                }

                if (_createdDateMin != null && _createdDateMin.HasValue)
                {
                    // <created-date-min>
                    writer.WriteStartElement("created-date-min");
                    writer.WriteValue(SDKHelper.XmlFromInstant(CreatedDateMin.Value));
                    writer.WriteEndElement();
                }

                if (_createdDateMax != null && _createdDateMax.HasValue)
                {
                    // <created-date-max>
                    writer.WriteStartElement("created-date-max");
                    writer.WriteValue(SDKHelper.XmlFromInstant(CreatedDateMax.Value));
                    writer.WriteEndElement();
                }

                if (_updatedDateMin != null && _updatedDateMin.HasValue)
                {
                    // <updated-date-min>
                    writer.WriteStartElement("updated-date-min");
                    writer.WriteValue(SDKHelper.XmlFromInstant(UpdatedDateMin.Value));
                    writer.WriteEndElement();
                }

                if (_updatedDateMax != null && _updatedDateMax.HasValue)
                {
                    // <updated-date-max>
                    writer.WriteStartElement("updated-date-max");
                    writer.WriteValue(SDKHelper.XmlFromInstant(UpdatedDateMax.Value));
                    writer.WriteEndElement();
                }

                if (!string.IsNullOrEmpty(XPath))
                {
                    // <xpath>
                    writer.WriteStartElement("xpath");
                    writer.WriteValue(XPath);
                    writer.WriteEndElement();
                }

                if (_updatedEndDateMax != null && _updatedDateMax.HasValue)
                {
                    // <updated-end-date-max>
                    writer.WriteStartElement("updated-end-date-max");
                    writer.WriteValue(SDKHelper.XmlFromLocalDateTime(UpdatedEndDateMax.Value));
                    writer.WriteEndElement();
                }

                if (_updatedEndDateMin != null && _updatedEndDateMin.HasValue)
                {
                    // <updated-end-date-min>
                    writer.WriteStartElement("updated-end-date-min");
                    writer.WriteValue(SDKHelper.XmlFromLocalDateTime(UpdatedEndDateMin.Value));
                    writer.WriteEndElement();
                }

                // </filter>
                writer.WriteEndElement();
            }
        }
Exemplo n.º 10
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);
            }
        }