Ejemplo n.º 1
0
        /// <summary>
        /// Ensures all the authorized people for the application are returned
        /// </summary>
        ///
        /// <param name="connection">Connection</param>
        /// <param name="settings">Settings</param>
        /// <returns>List of persons</returns>
        public virtual async Task <IList <PersonInfo> > EnsureGetAuthorizedPeopleAsync(
            IHealthVaultConnection connection,
            GetAuthorizedPeopleSettings settings)
        {
            var peopleTasks = GetAuthorizedPeopleAsync(connection, settings);
            var people      = new List <PersonInfo>();

            foreach (var personTask in peopleTasks)
            {
                await personTask;
                people.Add(personTask.Result);
            }

            return(people);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets information about people authorized for an application.
        /// </summary>
        ///
        /// <remarks>
        /// The returned IEnumerable iterator will access the HealthVault service
        /// across the network. See <see cref="GetAuthorizedPeopleSettings"/> for applicable
        /// settings.
        /// </remarks>
        ///
        /// <param name="connection">The connection to use to perform the operation. This connection
        /// must be application-level. </param>
        ///
        /// <param name="settings">
        /// The <see cref="GetAuthorizedPeopleSettings" /> object used to configure the
        /// IEnumerable iterator returned by this method.
        /// </param>
        ///
        /// <returns>
        /// An IEnumerable iterator of <see cref="PersonInfo"/> objects representing
        /// people authorized for the application.
        /// </returns>
        ///
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error. The retrieval can be retried from the
        /// current position by calling this method again and using the last successfully
        /// retrieved person Id for <see cref="GetAuthorizedPeopleSettings.StartingPersonId"/>.
        /// </exception>
        ///
        /// <exception cref="ArgumentNullException">
        /// <paramref name="settings"/> is null.
        /// </exception>
        ///
        public virtual IEnumerable <Task <PersonInfo> > GetAuthorizedPeopleAsync(
            IHealthVaultConnection connection,
            GetAuthorizedPeopleSettings settings)
        {
            Validator.ThrowIfArgumentNull(settings, nameof(settings), Resources.GetAuthorizedPeopleSettingsNull);

            bool    moreResults          = true;
            Guid    cursor               = settings.StartingPersonId;
            Instant?authCreatedSinceDate = settings.AuthorizationsCreatedSince;
            int     batchSize            = settings.BatchSize;

            while (moreResults)
            {
                Collection <PersonInfo> personInfos = null;

                // For the first one in the batch we need to go out and get it, then return the first item
                yield return(Task.Run(async() =>
                {
                    GetAuthorizedPeopleResult getPeopleResult = await GetAuthorizedPeopleAsync(
                        connection,
                        cursor,
                        authCreatedSinceDate,
                        batchSize).ConfigureAwait(false);

                    personInfos = getPeopleResult.People;
                    moreResults = getPeopleResult.MoreResults;

                    if (personInfos.Count > 0)
                    {
                        cursor = personInfos[personInfos.Count - 1].PersonId;
                    }

                    return personInfos[0];
                }));

                // For the rest in the batch, we can immediately return a result.
                for (int i = 1; i < personInfos.Count; i++)
                {
                    yield return(Task.FromResult(personInfos[i]));
                }
            }
        }
        /// <summary>
        /// Gets information about people authorized for an application.
        /// </summary>                
        /// 
        /// <remarks>
        /// The returned IEnumerable iterator will access the HealthVault service 
        /// across the network. See <see cref="GetAuthorizedPeopleSettings"/> for applicable 
        /// settings.
        /// </remarks>
        /// 
        /// <param name="connection">The connection to use to perform the operation. This connection
        /// must be application-level. </param>
        ///
        /// <param name="settings">
        /// The <see cref="GetAuthorizedPeopleSettings" /> object used to configure the 
        /// IEnumerable iterator returned by this method.
        /// </param>
        /// 
        /// <returns>
        /// An IEnumerable iterator of <see cref="PersonInfo"/> objects representing 
        /// people authorized for the application.
        /// </returns>        
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error. The retrieval can be retried from the 
        /// current position by calling this method again and using the last successfully 
        /// retrieved person Id for <see cref="GetAuthorizedPeopleSettings.StartingPersonId"/>.        
        /// </exception>
        /// 
        /// <exception cref="ArgumentNullException">
        /// <paramref name="settings"/> is null.
        /// </exception>
        /// 
        public virtual IEnumerable<PersonInfo> GetAuthorizedPeople(
            ApplicationConnection connection,
            GetAuthorizedPeopleSettings settings)
        {
            Validator.ThrowIfArgumentNull(settings, "settings", "GetAuthorizedPeopleSettingsNull");

            Boolean moreResults = true;
            Guid cursor = settings.StartingPersonId;
            DateTime authCreatedSinceDate = settings.AuthorizationsCreatedSince;
            Int32 batchSize = settings.BatchSize;

            while (moreResults)
            {
                Collection<PersonInfo> personInfos =
                    GetAuthorizedPeople(
                        connection,
                        cursor,
                        authCreatedSinceDate,
                        batchSize,
                        out moreResults);

                if (personInfos.Count > 0)
                {
                    cursor = personInfos[personInfos.Count - 1].PersonId;
                }

                for (int i = 0; i < personInfos.Count; i++)
                {
                    yield return personInfos[i];
                }
            }
        }
 public IEnumerable <Task <PersonInfo> > GetAuthorizedPeople(GetAuthorizedPeopleSettings settings)
 {
     return(HealthVaultPlatform.GetAuthorizedPeopleAsync(_connection, settings));
 }