コード例 #1
0
 public CollectionResourceExecutor(string collectionHref, IInternalDataStore dataStore, Expression expression)
 {
     this.collectionHref = collectionHref;
     this.asyncDataStore = dataStore as IInternalAsyncDataStore;
     this.syncDataStore  = dataStore as IInternalSyncDataStore;
     this.expression     = expression;
 }
コード例 #2
0
        /// <summary>
        /// Adds an Account Store to this resource based on the result of a query.
        /// </summary>
        /// <typeparam name="T">The Account Store type.</typeparam>
        /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
        /// <param name="container">The Account Store container.</param>
        /// <param name="internalDataStore">The internal data store.</param>
        /// <param name="query">A query that selects a single Account Store.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static async Task <TMapping> AddAccountStoreAsync <T, TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalAsyncDataStore internalDataStore,
            Func <IAsyncQueryable <T>, IAsyncQueryable <T> > query,
            CancellationToken cancellationToken)
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            IAccountStore foundAccountStore = null;

            if (typeof(T) == typeof(IDirectory))
            {
                var directoryQuery = query as Func <IAsyncQueryable <IDirectory>, IAsyncQueryable <IDirectory> >;
                foundAccountStore = await GetSingleTenantDirectoryAsync(container, directoryQuery, cancellationToken).ConfigureAwait(false);
            }
            else if (typeof(T) == typeof(IGroup))
            {
                var groupQuery = query as Func <IAsyncQueryable <IGroup>, IAsyncQueryable <IGroup> >;
                foundAccountStore = await GetSingleTenantGroupAsync(container, groupQuery, cancellationToken).ConfigureAwait(false);
            }

            if (foundAccountStore != null)
            {
                return((TMapping) await AddAccountStoreAsync(container, internalDataStore, foundAccountStore, cancellationToken).ConfigureAwait(false));
            }

            // No account store can be added
            return(null);
        }
コード例 #3
0
        public static Task<IAccount> CreateAccountAsync(IInternalAsyncDataStore dataStore, string accountsHref, IAccount account, Action<AccountCreationOptionsBuilder> creationOptionsAction, CancellationToken cancellationToken)
        {
            var builder = new AccountCreationOptionsBuilder();
            creationOptionsAction(builder);
            var options = builder.Build();

            return dataStore.CreateAsync(accountsHref, account, options, cancellationToken);
        }
コード例 #4
0
        public ResourceData(IInternalDataStore dataStore)
        {
            this.internalDataStore      = dataStore;
            this.internalDataStoreAsync = dataStore as IInternalAsyncDataStore;
            this.internalDataStoreSync  = dataStore as IInternalSyncDataStore;

            this.Update();
        }
コード例 #5
0
        public ResourceData(IInternalDataStore dataStore)
        {
            this.internalDataStore = dataStore;
            this.internalDataStoreAsync = dataStore as IInternalAsyncDataStore;
            this.internalDataStoreSync = dataStore as IInternalSyncDataStore;

            this.Update();
        }
コード例 #6
0
        public static Task<IGroup> CreateGroupAsync(IInternalAsyncDataStore internalDataStore, string groupsHref, IGroup group, Action<GroupCreationOptionsBuilder> creationOptionsAction, CancellationToken cancellationToken)
        {
            var builder = new GroupCreationOptionsBuilder();
            creationOptionsAction(builder);
            var options = builder.Build();

            return internalDataStore.CreateAsync(groupsHref, group, options, cancellationToken);
        }
コード例 #7
0
        public static Task <IGroup> CreateGroupAsync(IInternalAsyncDataStore internalDataStore, string groupsHref, string name, string description, CancellationToken cancellationToken)
        {
            var group = internalDataStore.Instantiate <IGroup>()
                        .SetName(name)
                        .SetDescription(description)
                        .SetStatus(GroupStatus.Enabled);

            return(internalDataStore.CreateAsync(groupsHref, group, cancellationToken));
        }
コード例 #8
0
        public static Task <IGroup> CreateGroupAsync(IInternalAsyncDataStore internalDataStore, string groupsHref, IGroup group, Action <GroupCreationOptionsBuilder> creationOptionsAction, CancellationToken cancellationToken)
        {
            var builder = new GroupCreationOptionsBuilder();

            creationOptionsAction(builder);
            var options = builder.Build();

            return(internalDataStore.CreateAsync(groupsHref, group, options, cancellationToken));
        }
コード例 #9
0
        public static Task<IGroup> CreateGroupAsync(IInternalAsyncDataStore internalDataStore, string groupsHref, string name, string description, CancellationToken cancellationToken)
        {
            var group = internalDataStore.Instantiate<IGroup>()
                .SetName(name)
                .SetDescription(description)
                .SetStatus(GroupStatus.Enabled);

            return internalDataStore.CreateAsync(groupsHref, group, cancellationToken);
        }
コード例 #10
0
        public static Task <IAccount> CreateAccountAsync(IInternalAsyncDataStore dataStore, string accountsHref, IAccount account, Action <AccountCreationOptionsBuilder> creationOptionsAction, CancellationToken cancellationToken)
        {
            var builder = new AccountCreationOptionsBuilder();

            creationOptionsAction(builder);
            var options = builder.Build();

            return(dataStore.CreateAsync(accountsHref, account, options, cancellationToken));
        }
コード例 #11
0
        public BasicAuthenticator(IInternalDataStore dataStore)
        {
            this.dataStore = dataStore;
            this.dataStoreAsync = dataStore as IInternalAsyncDataStore;
            this.dataStoreSync = dataStore as IInternalSyncDataStore;

            if (this.dataStore == null ||
                this.dataStoreSync == null)
            {
                throw new ArgumentNullException("Internal data store could not be initialized.");
            }
        }
コード例 #12
0
        /// <summary>
        /// Creates a new Account Store Mapping.
        /// </summary>
        /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
        /// <param name="container">The Account Store container.</param>
        /// <param name="internalDataStore">The internal data store.</param>
        /// <param name="mapping">The new mapping to create.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static async Task <TMapping> CreateAccountStoreMappingAsync <TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalAsyncDataStore internalDataStore,
            IAccountStoreMapping <TMapping> mapping,
            CancellationToken cancellationToken)
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            SetContainer(mapping, container);
            var href = ResolveEndpointHref(container);

            return((TMapping)(await internalDataStore.CreateAsync(href, mapping, cancellationToken).ConfigureAwait(false)));
        }
コード例 #13
0
        public BasicAuthenticator(IInternalDataStore dataStore)
        {
            this.dataStore      = dataStore;
            this.dataStoreAsync = dataStore as IInternalAsyncDataStore;
            this.dataStoreSync  = dataStore as IInternalSyncDataStore;

            if (this.dataStore == null ||
                this.dataStoreSync == null)
            {
                throw new ArgumentNullException("Internal data store could not be initialized.");
            }
        }
コード例 #14
0
        public CollectionResourceExecutor(IAsyncExecutor <TResult> executor, Expression newExpression)
        {
            this.expression = newExpression;

            var cre = executor as CollectionResourceExecutor <TResult>;

            if (cre != null)
            {
                this.collectionHref = cre.collectionHref;
                this.asyncDataStore = cre.asyncDataStore;
                this.syncDataStore  = cre.syncDataStore;
            }
        }
コード例 #15
0
        /// <summary>
        /// Adds an Account Store to this resource.
        /// </summary>
        /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
        /// <param name="container">The Account Store container.</param>
        /// <param name="internalDataStore">The internal data store.</param>
        /// <param name="accountStore">The Account Store to add.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static async Task <TMapping> AddAccountStoreAsync <TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalAsyncDataStore internalDataStore,
            IAccountStore accountStore,
            CancellationToken cancellationToken)
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            var accountStoreMapping = internalDataStore
                                      .Instantiate <IAccountStoreMapping <TMapping> >()
                                      .SetAccountStore(accountStore)
                                      .SetListIndex(int.MaxValue);

            SetContainer(accountStoreMapping, container);

            return((TMapping)(await CreateAccountStoreMappingAsync(container, internalDataStore, accountStoreMapping, cancellationToken).ConfigureAwait(false)));
        }
コード例 #16
0
        /// <summary>
        /// Gets the default Account or Group Store at the given <c>href</c>, if it exists.
        /// </summary>
        /// <param name="storeMappingHref">The AccountStoreMapping <c>href</c>.</param>
        /// <param name="internalDataStore">The <see cref="IInternalAsyncDataStore"/>.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The <see cref="IAccountStore">Account Store</see>, or <see langword="null"/>.</returns>
        public static async Task <IAccountStore> GetDefaultStoreAsync(
            string storeMappingHref,
            IInternalAsyncDataStore internalDataStore,
            CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(storeMappingHref))
            {
                return(null);
            }

            var accountStoreMapping = await internalDataStore
                                      .GetResourceAsync <IAccountStoreMapping>(storeMappingHref, cancellationToken)
                                      .ConfigureAwait(false);

            return(accountStoreMapping == null
                ? null
                : await accountStoreMapping.GetAccountStoreAsync().ConfigureAwait(false));
        }
コード例 #17
0
        public DefaultClient(
            IClientApiKey apiKey,
            string baseUrl,
            AuthenticationScheme authenticationScheme,
            int connectionTimeout,
            IWebProxy proxy,
            IHttpClient httpClient,
            IJsonSerializer serializer,
            ICacheProvider cacheProvider,
            IUserAgentBuilder userAgentBuilder,
            ILogger logger,
            TimeSpan identityMapExpiration)
        {
            if (apiKey == null || !apiKey.IsValid())
            {
                throw new ArgumentException("API Key is not valid.");
            }

            if (string.IsNullOrEmpty(baseUrl))
            {
                throw new ArgumentNullException("Base URL cannot be empty.");
            }

            if (connectionTimeout < 0)
            {
                throw new ArgumentException("Timeout cannot be negative.");
            }

            this.logger               = logger;
            this.apiKey               = apiKey;
            this.baseUrl              = baseUrl;
            this.connectionTimeout    = connectionTimeout;
            this.proxy                = proxy;
            this.cacheProvider        = cacheProvider;
            this.authenticationScheme = authenticationScheme;
            this.serializer           = serializer;
            this.httpClient           = httpClient;

            var requestExecutor = new DefaultRequestExecutor(httpClient, apiKey, authenticationScheme, this.logger);

            this.dataStore      = new DefaultDataStore(this as IClient, requestExecutor, baseUrl, this.serializer, this.logger, userAgentBuilder, cacheProvider, identityMapExpiration);
            this.dataStoreAsync = this.dataStore as IInternalAsyncDataStore;
            this.dataStoreSync  = this.dataStore as IInternalSyncDataStore;
        }
コード例 #18
0
        public static Task<IGroupMembership> CreateAsync(IAccount account, IGroup group, IInternalAsyncDataStore dataStore, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(account.Href))
            {
                throw new ApplicationException("You must persist the account first before assigning it to a group.");
            }

            if (string.IsNullOrEmpty(group.Href))
            {
                throw new ApplicationException("You must persist the group first because assigning it to a group.");
            }

            var groupMembership = (DefaultGroupMembership)dataStore.Instantiate<IGroupMembership>();
            groupMembership.SetGroup(group);
            groupMembership.SetAccount(account);

            var href = "/groupMemberships";

            return dataStore.CreateAsync<IGroupMembership>(href, groupMembership, cancellationToken);
        }
コード例 #19
0
 public static Task<IAccount> CreateAccountAsync(IInternalAsyncDataStore dataStore, string accountsHref, IAccount account, CancellationToken cancellationToken)
     => dataStore.CreateAsync(accountsHref, account, cancellationToken);
コード例 #20
0
        public static Task <IAccount> CreateAccountAsync(IInternalAsyncDataStore dataStore, string accountsHref, string givenName, string surname, string email, string password, object customData, CancellationToken cancellationToken)
        {
            var account = CreateAccountWith(dataStore, givenName, surname, email, password, customData);

            return(CreateAccountAsync(dataStore, accountsHref, account, cancellationToken: cancellationToken));
        }
コード例 #21
0
 public Directory_options()
 {
     this.dataStore = TestDataStore.Create(new StubRequestExecutor(FakeJson.Directory).Object) as IInternalAsyncDataStore;
 }
コード例 #22
0
        public DefaultClient(
            IClientApiKey apiKey,
            string baseUrl,
            AuthenticationScheme authenticationScheme,
            int connectionTimeout,
            IWebProxy proxy,
            IHttpClient httpClient,
            IJsonSerializer serializer,
            ICacheProvider cacheProvider,
            IUserAgentBuilder userAgentBuilder,
            ILogger logger,
            TimeSpan identityMapExpiration)
        {
            if (apiKey == null || !apiKey.IsValid())
            {
                throw new ArgumentException("API Key is not valid.");
            }

            if (string.IsNullOrEmpty(baseUrl))
            {
                throw new ArgumentNullException("Base URL cannot be empty.");
            }

            if (connectionTimeout < 0)
            {
                throw new ArgumentException("Timeout cannot be negative.");
            }

            this.logger = logger;
            this.apiKey = apiKey;
            this.baseUrl = baseUrl;
            this.connectionTimeout = connectionTimeout;
            this.proxy = proxy;
            this.cacheProvider = cacheProvider;
            this.authenticationScheme = authenticationScheme;
            this.serializer = serializer;
            this.httpClient = httpClient;

            var requestExecutor = new DefaultRequestExecutor(httpClient, apiKey, authenticationScheme, this.logger);

            this.dataStore = new DefaultDataStore(this as IClient, requestExecutor, baseUrl, this.serializer, this.logger, userAgentBuilder, cacheProvider, identityMapExpiration);
            this.dataStoreAsync = this.dataStore as IInternalAsyncDataStore;
            this.dataStoreSync = this.dataStore as IInternalSyncDataStore;
        }
コード例 #23
0
 public DefaultAsynchronousFilterChain(IInternalAsyncDataStore dataStore)
     : this(dataStore, Enumerable.Empty<IAsynchronousFilter>())
 {
 }
コード例 #24
0
 public ProviderAccountResolver(IInternalDataStore dataStore)
 {
     this.dataStoreAsync = dataStore as IInternalAsyncDataStore;
     this.dataStoreSync  = dataStore as IInternalSyncDataStore;
 }
コード例 #25
0
 public ProviderAccountResolver(IInternalDataStore dataStore)
 {
     this.dataStoreAsync = dataStore as IInternalAsyncDataStore;
     this.dataStoreSync = dataStore as IInternalSyncDataStore;
 }
コード例 #26
0
 internal DefaultAsynchronousFilterChain(IInternalAsyncDataStore dataStore, IEnumerable<IAsynchronousFilter> filters)
 {
     this.dataStore = dataStore;
     this.filters = new List<IAsynchronousFilter>(filters);
 }
コード例 #27
0
 public static Task <IGroup> CreateGroupAsync(IInternalAsyncDataStore internalDataStore, string groupsHref, IGroup group, IGroupCreationOptions creationOptions, CancellationToken cancellationToken)
 => internalDataStore.CreateAsync(groupsHref, group, creationOptions, cancellationToken);
コード例 #28
0
        /// <summary>
        /// Adds an Account Store to this resource by <c>href</c> or name.
        /// </summary>
        /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
        /// <param name="container">The Account Store container.</param>
        /// <param name="internalDataStore">The internal data store.</param>
        /// <param name="hrefOrName">The name or <c>href</c> of the Account Store to add.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static async Task <TMapping> AddAccountStoreAsync <TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalAsyncDataStore internalDataStore,
            string hrefOrName,
            CancellationToken cancellationToken)
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            if (string.IsNullOrEmpty(hrefOrName))
            {
                throw new ArgumentNullException(nameof(hrefOrName));
            }

            IAccountStore accountStore = null;

            var  splitHrefOrName = hrefOrName.Split('/');
            bool looksLikeHref   = splitHrefOrName.Length > 4;

            if (looksLikeHref)
            {
                bool?isDirectoryType = null;
                if (splitHrefOrName.Length == container.Href.Split('/').Length)
                {
                    if (splitHrefOrName[4].Equals("directories", StringComparison.InvariantCultureIgnoreCase))
                    {
                        isDirectoryType = true;
                    }
                    else if (splitHrefOrName[4].Equals("groups", StringComparison.InvariantCultureIgnoreCase))
                    {
                        isDirectoryType = false;
                    }
                }

                if (isDirectoryType != null)
                {
                    try
                    {
                        if (isDirectoryType == true)
                        {
                            accountStore = await internalDataStore.GetResourceAsync <IDirectory>(hrefOrName, cancellationToken).ConfigureAwait(false);
                        }
                        else if (isDirectoryType == false)
                        {
                            accountStore = await internalDataStore.GetResourceAsync <IGroup>(hrefOrName, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    catch (ResourceException)
                    {
                        // It looked like an href, but no resource was found.
                        // We'll try looking it up by name.
                    }
                }
            }

            if (accountStore == null)
            {
                // Try to find both a Directory and a Group with the given name
                var directory = await GetSingleTenantDirectoryAsync(container, x => x.Where(d => d.Name == hrefOrName), cancellationToken).ConfigureAwait(false);

                var group = await GetSingleTenantGroupAsync(container, x => x.Where(g => g.Name == hrefOrName), cancellationToken).ConfigureAwait(false);

                if (directory != null && group != null)
                {
                    throw new ArgumentException(
                              "There is both a Directory and a Group matching the provided name in the current tenant. " +
                              "Please provide the href of the intended Resource instead of its name in order to unambiguously identify it.");
                }

                accountStore = directory != null
                    ? directory as IAccountStore
                    : group as IAccountStore;
            }

            if (accountStore != null)
            {
                return((TMapping) await AddAccountStoreAsync(container, internalDataStore, accountStore, cancellationToken).ConfigureAwait(false));
            }

            // Could not find any resource matching the hrefOrName value
            return(null);
        }
コード例 #29
0
 public Application_options()
 {
     this.dataStore = TestDataStore.Create(new StubRequestExecutor(FakeJson.Application).Object) as IInternalAsyncDataStore;
 }
コード例 #30
0
 public Directory_options()
 {
     this.dataStore = TestDataStore.Create(new StubRequestExecutor(FakeJson.Directory).Object) as IInternalAsyncDataStore;
 }
コード例 #31
0
 public static Task <IAccount> CreateAccountAsync(IInternalAsyncDataStore dataStore, string accountsHref, IAccount account, CancellationToken cancellationToken)
 => dataStore.CreateAsync(accountsHref, account, cancellationToken);
コード例 #32
0
 public DefaultAsynchronousFilterChain(IInternalAsyncDataStore dataStore)
     : this(dataStore, Enumerable.Empty <IAsynchronousFilter>())
 {
 }
コード例 #33
0
 public Application_options()
 {
     this.dataStore = TestDataStore.Create(new StubRequestExecutor(FakeJson.Application).Object) as IInternalAsyncDataStore;
 }
コード例 #34
0
 public static Task<IGroup> CreateGroupAsync(IInternalAsyncDataStore internalDataStore, string groupsHref, IGroup group, IGroupCreationOptions creationOptions, CancellationToken cancellationToken)
     => internalDataStore.CreateAsync(groupsHref, group, creationOptions, cancellationToken);
コード例 #35
0
 internal DefaultAsynchronousFilterChain(IInternalAsyncDataStore dataStore, IEnumerable <IAsynchronousFilter> filters)
 {
     this.dataStore = dataStore;
     this.filters   = new List <IAsynchronousFilter>(filters);
 }
コード例 #36
0
        public static Task <IGroupMembership> CreateAsync(IAccount account, IGroup group, IInternalAsyncDataStore dataStore, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(account.Href))
            {
                throw new ApplicationException("You must persist the account first before assigning it to a group.");
            }

            if (string.IsNullOrEmpty(group.Href))
            {
                throw new ApplicationException("You must persist the group first because assigning it to a group.");
            }

            var groupMembership = (DefaultGroupMembership)dataStore.Instantiate <IGroupMembership>();

            groupMembership.SetGroup(group);
            groupMembership.SetAccount(account);

            var href = "/groupMemberships";

            return(dataStore.CreateAsync <IGroupMembership>(href, groupMembership, cancellationToken));
        }
コード例 #37
0
        public static Task<IAccount> CreateAccountAsync(IInternalAsyncDataStore dataStore, string accountsHref, string givenName, string surname, string email, string password, object customData, CancellationToken cancellationToken)
        {
            var account = CreateAccountWith(dataStore, givenName, surname, email, password, customData);

            return CreateAccountAsync(dataStore, accountsHref, account, cancellationToken: cancellationToken);
        }