/// <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>
        /// 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>
        /// 
        /// <param name="matchingVocabulary">
        /// A <see cref="VocabularyItemCollection"/> populated with entries matching 
        /// the search criteria.
        /// </param>
        /// 
        /// <param name="matchingKeys">
        /// A <b>ReadOnlyCollection</b> of <see cref="VocabularyKey"/> with entries
        /// matching the search criteria.
        /// </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 void SearchVocabulary(
            HealthServiceConnection connection, 
            VocabularyKey vocabularyKey,
            string searchValue,
            VocabularySearchType searchType,
            int? maxResults,
            out VocabularyItemCollection matchingVocabulary,
            out ReadOnlyCollection<VocabularyKey> matchingKeys)
        {
            Validator.ThrowArgumentExceptionIf(
                String.IsNullOrEmpty(searchValue) || searchValue.Length > 255,
                "searchString",
                "VocabularySearchStringInvalid");

            Validator.ThrowArgumentExceptionIf(
                !Enum.IsDefined(typeof(VocabularySearchType), searchType),
                "searchType",
                "VocabularySearchTypeUnknown");

            Validator.ThrowArgumentExceptionIf(
                maxResults.HasValue && maxResults.Value < 1,
                "maxResults",
                "VocabularySearchMaxResultsInvalid");

            matchingVocabulary = null;
            matchingKeys = null;

            string methodName = "SearchVocabulary";
            HealthServiceRequest request = new HealthServiceRequest(connection, methodName, 1);
            StringBuilder requestParameters = new StringBuilder(256);
            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;
            settings.OmitXmlDeclaration = true;
            settings.ConformanceLevel = ConformanceLevel.Fragment;

            using (XmlWriter writer = XmlWriter.Create(requestParameters, settings))
            {
                if (vocabularyKey != null)
                {
                    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(); //<text-search-parameters>
                writer.Flush();
            }
            request.Parameters = requestParameters.ToString();

            request.Execute();

            if (vocabularyKey != null)
            {
                matchingVocabulary = CreateVocabularyItemCollectionFromResponse(
                                        methodName, request.Response);
            }
            else
            {
                matchingKeys = CreateVocabularyKeysFromResponse(methodName, request.Response);
            }
        }
 /// <summary>
 /// Searches the keys of vocabularies defined by the HealthVault service.
 /// </summary>
 /// 
 /// <remarks>
 /// This method does a text search of vocabulary names and descriptions.
 /// </remarks>
 /// 
 /// <param name="searchString">
 /// 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>
 /// 
 /// <returns>
 /// A <b>ReadOnlyCollection</b> of <see cref="VocabularyKey"/> with entries
 /// matching the search criteria.
 /// </returns>
 ///
 /// <exception cref="ArgumentException">
 /// If <paramref name="searchString"/> 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.        
 /// </exception>
 /// 
 //[Obsolete("Use HealthServicePlatform.SearchVocabularyKeys() instead.")]
 public ReadOnlyCollection<VocabularyKey> SearchVocabularyKeys(
     string searchString,
     VocabularySearchType searchType,
     int? maxResults)
 {
     return HealthVaultPlatform.SearchVocabularyKeys(this, searchString, searchType, maxResults);
 }
 /// <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="searchString"/> is a string of characters in the specified 
 /// culture. 
 /// </remarks>
 /// 
 /// <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="searchString">
 /// 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>
 /// 
 /// <returns>
 /// A <see cref="VocabularyItemCollection"/> populated with entries matching 
 /// the search criteria.
 /// </returns>
 /// 
 /// <exception cref="ArgumentException">
 /// If <paramref name="vocabularyKey"/> is <b>null</b>.
 /// <br></br>
 /// -Or-
 /// <br></br>
 /// If <paramref name="searchString"/> 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>        
 /// 
 //[Obsolete("Use HealthServicePlatform.SearchVocabulary() instead.")]
 public VocabularyItemCollection SearchVocabulary(
     VocabularyKey vocabularyKey,
     string searchString,
     VocabularySearchType searchType,
     int? maxResults)
 {
     return HealthVaultPlatform.SearchVocabulary(this, vocabularyKey, searchString, searchType, maxResults);
 }
示例#5
0
 public async Task <ReadOnlyCollection <VocabularyKey> > SearchVocabularyAsync(string searchValue, VocabularySearchType searchType, int?maxResults)
 {
     return((await HealthVaultPlatformVocabulary.Current.SearchVocabularyAsync(_connection, null, searchValue, searchType, maxResults).ConfigureAwait(false)).MatchingKeys);
 }
        /// <summary>
        /// Searches the keys of vocabularies defined by the HealthVault service.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use for this operation. The connection
        /// must have application capability. 
        /// </param>
        /// 
        /// <remarks>
        /// This method does a text search of vocabulary names and descriptions.
        /// </remarks>
        /// 
        /// <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>
        /// 
        /// <returns>
        /// A <b>ReadOnlyCollection</b> of <see cref="VocabularyKey"/> with entries
        /// matching the search criteria.
        /// </returns>
        ///
        /// <exception cref="ArgumentException">
        /// 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.        
        /// </exception>
        /// 
        public static ReadOnlyCollection<VocabularyKey> SearchVocabularyKeys(
            HealthServiceConnection connection,
            string searchValue,
            VocabularySearchType searchType,
            int? maxResults)
        {
            ReadOnlyCollection<VocabularyKey> matchingKeys;
            VocabularyItemCollection matchingVocabulary;

            HealthVaultPlatformVocabulary.Current.SearchVocabulary(
                connection,
                null,
                searchValue,
                searchType,
                maxResults,
                out matchingVocabulary,
                out matchingKeys);

            return matchingKeys;
        }
        /// <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>
        /// 
        /// <returns>
        /// A <see cref="VocabularyItemCollection"/> populated with entries matching 
        /// the search criteria.
        /// </returns>
        /// 
        /// <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 static VocabularyItemCollection SearchVocabulary(
            HealthServiceConnection connection, 
            VocabularyKey vocabularyKey,
            string searchValue,
            VocabularySearchType searchType,
            int? maxResults)
        {
            Validator.ThrowIfArgumentNull(vocabularyKey, "vocabularyKey", "VocabularyKeyNullOrEmpty");

            VocabularyItemCollection matchingVocabulary;
            ReadOnlyCollection<VocabularyKey> matchingKeys;

            HealthVaultPlatformVocabulary.Current.SearchVocabulary(
                connection,
                vocabularyKey,
                searchValue,
                searchType,
                maxResults,
                out matchingVocabulary,
                out matchingKeys);

            return matchingVocabulary;
        }