public async Task CreateNewThingsAsync <T>(Guid recordId, ICollection <T> things) where T : IThing { Validator.ThrowIfArgumentNull(recordId, nameof(recordId), Resources.NewItemsNullItem); Validator.ThrowIfArgumentNull(things, nameof(things), Resources.NewItemsNullItem); StringBuilder infoXml = new StringBuilder(); XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings; using (XmlWriter infoXmlWriter = XmlWriter.Create(infoXml, settings)) { foreach (IThing thing in things) { Validator.ThrowIfArgumentNull(thing, nameof(thing), Resources.NewItemsNullItem); thing.WriteItemXml(infoXmlWriter); } infoXmlWriter.Flush(); } HealthServiceResponseData responseData = await _connection.ExecuteAsync( HealthVaultMethods.PutThings, 2, infoXml.ToString(), recordId, CorrelationId); // Now update the Id for the new item XPathNodeIterator thingIds = responseData.InfoNavigator.Select( GetThingIdXPathExpression(responseData.InfoNavigator)); int thingIndex = 0; foreach (XPathNavigator thingIdNav in thingIds) { var thing = things.ElementAt(thingIndex) as ThingBase; if (thing != null) { thing.Key = new ThingKey( new Guid(thingIdNav.Value), new Guid(thingIdNav.GetAttribute( "version-stamp", string.Empty))); } thingIndex++; } }
/// <summary> /// Gets the <see cref="HealthRecordInfo"/> for the records identified /// by the specified <paramref name="recordIds"/>. /// </summary> /// /// <param name="connection">The connection to use to perform the operation. This connection /// must be authenticated. </param> /// /// <param name="recordIds"> /// The unique identifiers for the records to retrieve. /// </param> /// /// <returns> /// A collection of the records matching the specified record /// identifiers and authorized for the authenticated person. /// </returns> /// /// <remarks> /// This method is useful in cases where the application is storing /// record identifiers and needs access to the functionality provided /// by the object model. /// </remarks> /// public virtual async Task <Collection <HealthRecordInfo> > GetAuthorizedRecordsAsync( IHealthVaultConnection connection, IList <Guid> recordIds) { StringBuilder parameters = new StringBuilder(128); foreach (Guid id in recordIds) { parameters.Append( "<id>" + id + "</id>"); } HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.GetAuthorizedRecords, 1, parameters.ToString()).ConfigureAwait(false); Collection <HealthRecordInfo> results = new Collection <HealthRecordInfo>(); XPathNodeIterator records = responseData.InfoNavigator.Select( GetRecordXPathExpression(responseData.InfoNavigator)); foreach (XPathNavigator recordNav in records) { results.Add(HealthRecordInfo.CreateFromXml(connection, recordNav)); } return(results); }
/// <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); }
/// <summary> /// Gets the information about the person specified. /// </summary> /// /// <param name="connection">The connection to use to perform the operation. This connection /// must be authenticated. </param> /// /// <returns> /// Information about the person's HealthVault account. /// </returns> /// /// <remarks> /// This method always calls the HealthVault service to get the latest /// information. It is recommended that the calling application cache /// the return value and only call this method again if it needs to /// refresh the cache. /// </remarks> /// /// <exception cref="HealthServiceException"> /// The HealthVault service returned an error. /// </exception> /// public virtual async Task <PersonInfo> GetPersonInfoAsync(IHealthVaultConnection connection) { HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.GetPersonInfo, 1).ConfigureAwait(false); XPathExpression personPath = GetPersonXPathExpression(responseData.InfoNavigator); XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode(personPath); return(PersonInfo.CreateFromXml(infoNav)); }
/// <summary> /// Gets a list of <see cref="HealthRecordUpdateInfo"/> objects for the current application, /// that optionally have been updated since a specified date. /// </summary> /// /// <param name="connection">The connection to use to perform the operation. This connection /// must be application level. </param> /// /// <param name="updatedDate"> /// Date that is used to filter health record IDs according to whether or not they have /// been updated since the specified date. /// </param> /// /// <returns> /// List of <see cref="HealthRecordUpdateInfo"/> objects filtered by any specified input parameters. /// </returns> /// public virtual async Task <IList <HealthRecordUpdateInfo> > GetUpdatedRecordInfoForApplicationAsync( IHealthVaultConnection connection, Instant?updatedDate) { string parameters = GetUpdateDateParameters(updatedDate); HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.GetUpdatedRecordsForApplication, 2, parameters).ConfigureAwait(false); return(ParseGetUpdatedRecordsForApplicationResponseHealthRecordUpdateInfos(responseData)); }
/// <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); }
public virtual async Task <ApplicationSettings> GetApplicationSettingsAsync() { HealthServiceResponseData responseData = await _connection .ExecuteAsync(HealthVaultMethods.GetApplicationSettings, 1, null) .ConfigureAwait(false); XPathExpression xPathExpression = GetPersonAppSettingsXPathExpression(responseData.InfoNavigator); XPathNavigator appSettingsNav = responseData.InfoNavigator.SelectSingleNode(xPathExpression); ApplicationSettings settings = null; if (appSettingsNav != null) { settings = new ApplicationSettings(); settings.ParseXml(appSettingsNav); } return(settings); }
/// <summary> /// Retrieves a collection of key information for identifying and /// describing the vocabularies in the system. /// </summary> /// /// <param name="connection"> /// The connection to use for this operation. The connection /// must have application capability. /// </param> /// /// <returns> /// A collection of keys identifying the vocabularies in the system. /// </returns> /// public virtual async Task <ReadOnlyCollection <VocabularyKey> > GetVocabularyKeysAsync(IHealthVaultConnection connection) { var method = HealthVaultMethods.GetVocabulary; int methodVersion = 1; HealthServiceResponseData responseData = await connection.ExecuteAsync(method, methodVersion).ConfigureAwait(false); ReadOnlyCollection <VocabularyKey> keys = CreateVocabularyKeysFromResponse(method.ToString(), responseData); return(keys); }
/// <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); }
/// <summary> /// Retrieves lists of vocabulary items for the specified /// vocabularies and culture. /// </summary> /// /// <param name="connection"> /// The connection to use for this operation. The connection /// must have application capability. /// </param> /// /// <param name="vocabularyKeys"> /// A list of keys identifying the requested vocabularies. /// </param> /// /// <param name="cultureIsFixed"> /// HealthVault looks for the vocabulary items for the culture info /// specified using <see cref="HealthServiceConnection.Culture"/>. /// If <paramref name="cultureIsFixed"/> is set to <b>false</b> and if /// items are not found for the specified culture, items for the /// default fallback culture are returned. If /// <paramref name="cultureIsFixed"/> is set to <b>true</b>, /// fallback will not occur, and if items are not found for the /// specified culture, empty strings are returned. /// </param> /// /// <returns> /// The specified vocabularies and their items, or empty strings. /// </returns> /// /// <exception cref="ArgumentException"> /// The <paramref name="vocabularyKeys"/> list is empty. /// </exception> /// /// <exception cref="ArgumentNullException"> /// The <paramref name="vocabularyKeys"/> list is <b>null</b> /// or contains a <b>null</b> entry. /// </exception> /// /// <exception cref="HealthServiceException"> /// There is an error in the server request. /// <br></br> /// -Or- /// <br></br> /// One of the requested vocabularies is not found on the server. /// <br></br> /// -Or- /// <br></br> /// One of the requested vocabularies does not contain representations /// for its items for the specified culture when /// <paramref name="cultureIsFixed"/> is <b>true</b>. /// <br></br> /// -Or- /// <br></br> /// There is an error loading the vocabulary. /// </exception> /// public virtual async Task <ReadOnlyCollection <Vocabulary> > GetVocabularyAsync( IHealthVaultConnection connection, IList <VocabularyKey> vocabularyKeys, bool cultureIsFixed) { Validator.ThrowIfArgumentNull(vocabularyKeys, nameof(vocabularyKeys), Resources.VocabularyKeysNullOrEmpty); if (vocabularyKeys.Count == 0) { throw new ArgumentException(Resources.VocabularyKeysNullOrEmpty, nameof(vocabularyKeys)); } var method = HealthVaultMethods.GetVocabulary; int methodVersion = 2; StringBuilder requestParameters = new StringBuilder(256); XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings; settings.OmitXmlDeclaration = true; settings.ConformanceLevel = ConformanceLevel.Fragment; using (XmlWriter writer = XmlWriter.Create(requestParameters, settings)) { writer.WriteStartElement("vocabulary-parameters"); for (int i = 0; i < vocabularyKeys.Count; i++) { Validator.ThrowIfArgumentNull(vocabularyKeys[i], "vocabularyKeys[i]", Resources.VocabularyKeysNullOrEmpty); vocabularyKeys[i].WriteXml(writer); } writer.WriteElementString( "fixed-culture", SDKHelper.XmlFromBool(cultureIsFixed)); writer.WriteEndElement(); writer.Flush(); } string parameters = requestParameters.ToString(); HealthServiceResponseData responseData = await connection.ExecuteAsync(method, methodVersion, parameters).ConfigureAwait(false); ReadOnlyCollection <Vocabulary> vocabularies = CreateVocabulariesFromResponse(method.ToString(), responseData); return(vocabularies); }
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> /// Gets the permissions which the authenticated person /// has when using the calling application for the specified item types /// in this health record as well as the other permission settings such as MeaningfulUseOptIn. /// </summary> /// <param name="connection"> /// The connection to use to access the data. /// </param> /// <param name="accessor"> /// The record to use. /// </param> /// <param name="healthRecordItemTypeIds"> /// A collection of uniqueidentifiers to identify the health record /// item types, for which the permissions are being queried. /// </param> /// <returns> /// A <see cref="HealthRecordPermissions"/> object /// which contains a collection of <see cref="ThingTypePermission"/> objects and /// other permission settings. /// </returns> /// /// <remarks> /// If the list of thing types is empty, an empty list is /// returned for <see cref="HealthRecordPermissions"/> object's ItemTypePermissions property. /// If for a thing type, the person has /// neither online access nor offline access permissions, /// ThingTypePermission object is not returned for that /// thing type. /// </remarks> /// /// <exception cref="ArgumentNullException"> /// If <paramref name="healthRecordItemTypeIds"/> is <b>null</b>. /// </exception> /// /// <exception cref="HealthServiceException"> /// There is an error in the server request. /// </exception> /// public virtual async Task <HealthRecordPermissions> QueryRecordPermissionsAsync( IHealthVaultConnection connection, HealthRecordAccessor accessor, IList <Guid> healthRecordItemTypeIds) { Validator.ThrowIfArgumentNull(healthRecordItemTypeIds, nameof(healthRecordItemTypeIds), Resources.CtorhealthRecordItemTypeIdsArgumentNull); string parameters = GetQueryPermissionsParametersXml(healthRecordItemTypeIds); HealthServiceResponseData responseData = await connection.ExecuteAsync(HealthVaultMethods.QueryPermissions, 1, parameters).ConfigureAwait(false); XPathNavigator infoNav = responseData.InfoNavigator.SelectSingleNode( GetQueryPermissionsInfoXPathExpression( responseData.InfoNavigator)); HealthRecordPermissions recordPermissions = new HealthRecordPermissions(); XPathNodeIterator thingTypePermissionsNodes = infoNav.Select("thing-type-permission"); foreach (XPathNavigator nav in thingTypePermissionsNodes) { ThingTypePermission thingTypePermissions = ThingTypePermission.CreateFromXml(nav); recordPermissions.ItemTypePermissions.Add(thingTypePermissions); } XPathNavigator valueNav = infoNav.SelectSingleNode("other-settings/meaningfuluse-opt-in"); if (valueNav != null) { recordPermissions.MeaningfulUseOptIn = valueNav.ValueAsBoolean; } else { recordPermissions.MeaningfulUseOptIn = null; } return(recordPermissions); }
/// <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); }
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); } }
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); } }
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)); }
/// <summary> /// Sets the application settings for the current application and /// person. /// </summary> /// /// <param name="connection">The connection to use to perform the operation. This connection /// must be authenticated. </param> /// /// <param name="requestParameters"> /// The request parameters. /// </param> /// /// <remarks> /// This may be <b>null</b> if no application settings have been /// stored for the application or user. /// </remarks> /// public virtual async Task SetApplicationSettingsAsync( IHealthVaultConnection connection, string requestParameters) { await connection.ExecuteAsync(HealthVaultMethods.SetApplicationSettings, 1, requestParameters).ConfigureAwait(false); }
/// <summary> /// Searches a specific vocabulary and retrieves the matching vocabulary items. /// </summary> /// /// <remarks> /// This method does text search matching of display text and abbreviation text /// for the culture defined by the <see cref="HealthServiceConnection.Culture"/>. /// The <paramref name="searchValue"/> is a string of characters in the specified /// culture. /// </remarks> /// /// <param name="connection"> /// The connection to use for this operation. The connection /// must have application capability. /// </param> /// /// <param name="vocabularyKey"> /// The <see cref="VocabularyKey"/> defining the vocabulary to search. If the /// family is not specified, the default HealthVault vocabulary family is used. /// If the version is not specified, the most current version of the vocabulary /// is used. /// </param> /// /// <param name="searchValue"> /// The search string to use. /// </param> /// /// <param name="searchType"> /// The type of search to perform. /// </param> /// /// <param name="maxResults"> /// The maximum number of results to return. If null, all matching results /// are returned, up to a maximum number defined by the service config /// value with key maxResultsPerVocabularyRetrieval. /// </param> /// /// <exception cref="ArgumentException"> /// If <paramref name="vocabularyKey"/> is <b>null</b>. /// <br></br> /// -Or- /// <br></br> /// If <paramref name="searchValue"/> is <b>null</b> or empty or greater /// than <b>255</b> characters. /// <br></br> /// -Or- /// <br></br> /// if <paramref name="searchType"/> is not a known /// <see cref="VocabularySearchType"/> value. /// <br></br> /// -Or- /// <br></br> /// when <paramref name="maxResults"/> is defined but has a value less than 1. /// </exception> /// /// <exception cref="HealthServiceException"> /// There is an error in the server request. /// <br></br> /// -Or- /// <br></br> /// The requested vocabulary is not found on the server. /// <br></br> /// -Or- /// The requested search culture is not supported. /// </exception> /// public virtual async Task <VocabularySearchResult> SearchVocabularyAsync( IHealthVaultConnection connection, VocabularyKey vocabularyKey, string searchValue, VocabularySearchType searchType, int?maxResults) { if (string.IsNullOrEmpty(searchValue) || searchValue.Length > 255) { throw new ArgumentException(Resources.VocabularySearchStringInvalid, nameof(searchValue)); } if (!Enum.IsDefined(typeof(VocabularySearchType), searchType)) { throw new ArgumentException(Resources.VocabularySearchTypeUnknown, nameof(searchType)); } if (maxResults.HasValue && maxResults.Value < 1) { throw new ArgumentException(Resources.SearchMaxResultsInvalid, nameof(maxResults)); } var method = HealthVaultMethods.SearchVocabulary; int methodVersion = 1; StringBuilder requestParameters = new StringBuilder(256); XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings; settings.OmitXmlDeclaration = true; settings.ConformanceLevel = ConformanceLevel.Fragment; using (XmlWriter writer = XmlWriter.Create(requestParameters, settings)) { vocabularyKey?.WriteXml(writer); writer.WriteStartElement("text-search-parameters"); writer.WriteStartElement("search-string"); writer.WriteAttributeString("search-mode", searchType.ToString()); writer.WriteString(searchValue); writer.WriteEndElement(); // <search-string> if (maxResults.HasValue) { writer.WriteElementString("max-results", maxResults.Value.ToString(CultureInfo.InvariantCulture)); } writer.WriteEndElement(); writer.Flush(); } string parameters = requestParameters.ToString(); HealthServiceResponseData responseData = await connection.ExecuteAsync(method, methodVersion, parameters).ConfigureAwait(false); if (vocabularyKey != null) { return(new VocabularySearchResult(CreateVocabularyItemCollectionFromResponse(method.ToString(), responseData))); } return(new VocabularySearchResult(CreateVocabularyKeysFromResponse(method.ToString(), responseData))); }
/// <summary> /// Releases the authorization of the application on the health record. /// </summary> /// <param name="connection"> /// The connection to use to access the data. /// </param> /// <exception cref="HealthServiceException"> /// Errors during the authorization release. /// </exception> /// /// <remarks> /// Once the application releases the authorization to the health record, /// calling any methods of this <see cref="HealthRecordAccessor"/> will result /// in a <see cref="HealthServiceAccessDeniedException"/>." /// </remarks> public virtual async Task RemoveApplicationAuthorizationAsync(IHealthVaultConnection connection) { await connection.ExecuteAsync(HealthVaultMethods.RemoveApplicationRecordAuthorization, 1).ConfigureAwait(false); }
public async Task <ApplicationCreationInfo> NewApplicationCreationInfoAsync() { HealthServiceResponseData responseData = await _connection.ExecuteAsync(HealthVaultMethods.NewApplicationCreationInfo, 1).ConfigureAwait(false); return(ApplicationCreationInfo.Create(responseData.InfoNavigator)); }