Esempio n. 1
0
        /// <summary>
        /// Synchronously gets a single <see cref="IGroup">Group</see> from a query.
        /// </summary>
        /// <param name="parent">The parent resource that contains a link to a <see cref="ITenant">Tenant</see>.</param>
        /// <param name="queryAction">The query.</param>
        /// <returns>The located <see cref="IGroup">Group</see>.</returns>
        private static IGroup GetSingleTenantGroup(
            IHasTenant parent,
            Func <IQueryable <IGroup>, IQueryable <IGroup> > queryAction)
        {
            if (queryAction == null)
            {
                throw new ArgumentNullException(nameof(queryAction));
            }

            var tenant    = parent.GetTenant();
            var queryable = tenant.GetGroups().Synchronously();

            queryable = queryAction(queryable);

            IGroup foundGroup = null;

            foreach (var group in queryable)
            {
                if (foundGroup != null)
                {
                    throw new ArgumentException("The provided query matched more than one Directory in the current Tenant.", nameof(queryAction));
                }

                foundGroup = group;
            }

            return(foundGroup);
        }
Esempio n. 2
0
        /// <summary>
        /// Synchronously gets a single <see cref="IDirectory">Directory</see> from a query.
        /// </summary>
        /// <param name="parent">The parent resource that contains a link to a <see cref="ITenant">Tenant</see>.</param>
        /// <param name="queryAction">The query.</param>
        /// <returns>The located <see cref="IDirectory">Directory</see>.</returns>
        private static IDirectory GetSingleTenantDirectory(
            IHasTenant parent,
            Func <IQueryable <IDirectory>, IQueryable <IDirectory> > queryAction)
        {
            if (queryAction == null)
            {
                throw new ArgumentNullException(nameof(queryAction));
            }

            var tenant    = parent.GetTenant();
            var queryable = tenant.GetDirectories().Synchronously();

            queryable = queryAction(queryable);

            IDirectory foundDirectory = null;

            foreach (var dir in queryable)
            {
                if (foundDirectory != null)
                {
                    throw new ArgumentException("The provided query matched more than one Directory in the current Tenant.", nameof(queryAction));
                }

                foundDirectory = dir;
            }

            return(foundDirectory);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets a single <see cref="IGroup">Group</see> from a query.
        /// </summary>
        /// <param name="parent">The parent resource that contains a link to a <see cref="ITenant">Tenant</see>.</param>
        /// <param name="queryAction">The query.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The located <see cref="IGroup">Group</see>.</returns>
        private static async Task <IGroup> GetSingleTenantGroupAsync(
            IHasTenant parent,
            Func <IAsyncQueryable <IGroup>, IAsyncQueryable <IGroup> > queryAction,
            CancellationToken cancellationToken)
        {
            if (queryAction == null)
            {
                throw new ArgumentNullException(nameof(queryAction));
            }

            var tenant = await parent.GetTenantAsync(cancellationToken).ConfigureAwait(false);

            var queryable = tenant.GetGroups();

            queryable = queryAction(queryable);

            IGroup foundGroup = null;
            await queryable.ForEachAsync(
                group =>
            {
                if (foundGroup != null)
                {
                    throw new ArgumentException("The provided query matched more than one Directory in the current Tenant.", nameof(queryAction));
                }

                foundGroup = group;
            }, cancellationToken).ConfigureAwait(false);

            return(foundGroup);
        }
 /// <summary>
 /// Synchronously gets the Stormpath <see cref="ITenant">Tenant</see> that owns this resource.
 /// </summary>
 /// <param name="resource">The resource.</param>
 /// <returns>The tenant.</returns>
 public static ITenant GetTenant(this IHasTenant resource)
 => (resource as IHasTenantSync).GetTenant();