Exemple #1
0
        /// <summary>
        /// Synchronously 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>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static TMapping AddAccountStore <T, TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalSyncDataStore internalDataStore,
            Func <IQueryable <T>, IQueryable <T> > query)
            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 <IQueryable <IDirectory>, IQueryable <IDirectory> >;
                foundAccountStore = GetSingleTenantDirectory(container, directoryQuery);
            }
            else if (typeof(T) == typeof(IGroup))
            {
                var groupQuery = query as Func <IQueryable <IGroup>, IQueryable <IGroup> >;
                foundAccountStore = GetSingleTenantGroup(container, groupQuery);
            }

            if (foundAccountStore != null)
            {
                return(AddAccountStore(container, internalDataStore, foundAccountStore));
            }

            // No account store can be added
            return(null);
        }
Exemple #2
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;
 }
        public static IAccount CreateAccount(IInternalSyncDataStore dataStoreSync, string accountsHref, IAccount account, Action<AccountCreationOptionsBuilder> creationOptionsAction)
        {
            var builder = new AccountCreationOptionsBuilder();
            creationOptionsAction(builder);
            var options = builder.Build();

            return dataStoreSync.Create(accountsHref, account, options);
        }
        public ResourceData(IInternalDataStore dataStore)
        {
            this.internalDataStore = dataStore;
            this.internalDataStoreAsync = dataStore as IInternalAsyncDataStore;
            this.internalDataStoreSync = dataStore as IInternalSyncDataStore;

            this.Update();
        }
        public static IGroup CreateGroup(IInternalSyncDataStore internalDataStore, string groupsHref, IGroup group, Action<GroupCreationOptionsBuilder> creationOptionsAction)
        {
            var builder = new GroupCreationOptionsBuilder();
            creationOptionsAction(builder);
            var options = builder.Build();

            return internalDataStore.Create(groupsHref, group, options);
        }
        public ResourceData(IInternalDataStore dataStore)
        {
            this.internalDataStore      = dataStore;
            this.internalDataStoreAsync = dataStore as IInternalAsyncDataStore;
            this.internalDataStoreSync  = dataStore as IInternalSyncDataStore;

            this.Update();
        }
Exemple #7
0
        public static IGroup CreateGroup(IInternalSyncDataStore internalDataStore, string groupsHref, string name, string description)
        {
            var group = internalDataStore.Instantiate <IGroup>()
                        .SetName(name)
                        .SetDescription(description)
                        .SetStatus(GroupStatus.Enabled);

            return(internalDataStore.Create(groupsHref, group));
        }
        public static IGroup CreateGroup(IInternalSyncDataStore internalDataStore, string groupsHref, string name, string description)
        {
            var group = internalDataStore.Instantiate<IGroup>()
                .SetName(name)
                .SetDescription(description)
                .SetStatus(GroupStatus.Enabled);

            return internalDataStore.Create(groupsHref, group);
        }
Exemple #9
0
        public static IGroup CreateGroup(IInternalSyncDataStore internalDataStore, string groupsHref, IGroup group, Action <GroupCreationOptionsBuilder> creationOptionsAction)
        {
            var builder = new GroupCreationOptionsBuilder();

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

            return(internalDataStore.Create(groupsHref, group, options));
        }
Exemple #10
0
        public static IAccount CreateAccount(IInternalSyncDataStore dataStoreSync, string accountsHref, IAccount account, Action <AccountCreationOptionsBuilder> creationOptionsAction)
        {
            var builder = new AccountCreationOptionsBuilder();

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

            return(dataStoreSync.Create(accountsHref, account, options));
        }
Exemple #11
0
        /// <summary>
        /// Synchronously 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>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static TMapping CreateAccountStoreMapping <TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalSyncDataStore internalDataStore,
            IAccountStoreMapping <TMapping> mapping)
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            SetContainer(mapping, container);
            var href = ResolveEndpointHref(container);

            return((TMapping)internalDataStore.Create(href, mapping));
        }
Exemple #12
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.");
            }
        }
        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.");
            }
        }
Exemple #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;
            }
        }
Exemple #15
0
        /// <summary>
        /// Synchronously gets the default Account or Group Store at the given <c>href</c>, if it exists.
        /// </summary>
        /// <param name="accountStoreMappingHref">The AccountStoreMapping <c>href</c>.</param>
        /// <param name="internalDataStore">The <see cref="IInternalAsyncDataStore"/>.</param>
        /// <returns>The <see cref="IAccountStore">Account Store</see>, or <see langword="null"/>.</returns>
        public static IAccountStore GetDefaultStore(string accountStoreMappingHref, IInternalSyncDataStore internalDataStore)
        {
            if (string.IsNullOrEmpty(accountStoreMappingHref))
            {
                return(null);
            }

            var accountStoreMapping = internalDataStore
                                      .GetResource <IAccountStoreMapping>(accountStoreMappingHref);

            return(accountStoreMapping == null
                ? null
                : accountStoreMapping.GetAccountStore());
        }
Exemple #16
0
        /// <summary>
        /// Synchronously 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>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static TMapping AddAccountStore <TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalSyncDataStore internalDataStore,
            IAccountStore accountStore)
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            var accountStoreMapping = internalDataStore
                                      .Instantiate <IAccountStoreMapping <TMapping> >()
                                      .SetAccountStore(accountStore)
                                      .SetListIndex(int.MaxValue);

            SetContainer(accountStoreMapping, container);

            return(CreateAccountStoreMapping(container, internalDataStore, accountStoreMapping));
        }
        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;
        }
Exemple #18
0
        public static IGroupMembership Create(IAccount account, IGroup group, IInternalSyncDataStore dataStore)
        {
            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 as IDataStore).Instantiate <IGroupMembership>();

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

            var href = "/groupMemberships";

            return(dataStore.Create <IGroupMembership>(href, groupMembership));
        }
Exemple #19
0
 internal DefaultSynchronousFilterChain(IInternalSyncDataStore dataStore, IEnumerable <ISynchronousFilter> filters)
 {
     this.dataStore = dataStore;
     this.filters   = new List <ISynchronousFilter>(filters);
 }
Exemple #20
0
 public static IAccount CreateAccount(IInternalSyncDataStore dataStoreSync, string accountsHref, IAccount account)
 => dataStoreSync.Create(accountsHref, account);
Exemple #21
0
 public static IGroup CreateGroup(IInternalSyncDataStore internalDataStore, string groupsHref, IGroup group, IGroupCreationOptions creationOptions)
 => internalDataStore.Create(groupsHref, group, creationOptions);
Exemple #22
0
 public DefaultSynchronousFilterChain(IInternalSyncDataStore dataStore)
     : this(dataStore, Enumerable.Empty <ISynchronousFilter>())
 {
 }
        public static IGroupMembership Create(IAccount account, IGroup group, IInternalSyncDataStore dataStore)
        {
            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 as IDataStore).Instantiate<IGroupMembership>();
            groupMembership.SetGroup(group);
            groupMembership.SetAccount(account);

            var href = "/groupMemberships";

            return dataStore.Create<IGroupMembership>(href, groupMembership);
        }
 public static IGroup CreateGroup(IInternalSyncDataStore internalDataStore, string groupsHref, IGroup group, IGroupCreationOptions creationOptions)
     => internalDataStore.Create(groupsHref, group, creationOptions);
 public ProviderAccountResolver(IInternalDataStore dataStore)
 {
     this.dataStoreAsync = dataStore as IInternalAsyncDataStore;
     this.dataStoreSync  = dataStore as IInternalSyncDataStore;
 }
 public ProviderAccountResolver(IInternalDataStore dataStore)
 {
     this.dataStoreAsync = dataStore as IInternalAsyncDataStore;
     this.dataStoreSync = dataStore as IInternalSyncDataStore;
 }
Exemple #27
0
        public static IAccount CreateAccount(IInternalSyncDataStore dataStoreSync, string accountsHref, string givenName, string surname, string email, string password, object customData = null)
        {
            var account = CreateAccountWith(dataStoreSync, givenName, surname, email, password, customData);

            return(CreateAccount(dataStoreSync, accountsHref, account));
        }
        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;
        }
Exemple #29
0
        /// <summary>
        /// Synchronously 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>
        /// <returns>The new <see cref="IAccountStoreMapping"/>.</returns>
        public static TMapping AddAccountStore <TMapping>(
            IAccountStoreContainer <TMapping> container,
            IInternalSyncDataStore internalDataStore,
            string hrefOrName)
            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 = internalDataStore.GetResource <IDirectory>(hrefOrName);
                        }
                        else if (isDirectoryType == false)
                        {
                            accountStore = internalDataStore.GetResource <IGroup>(hrefOrName);
                        }
                    }
                    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 = GetSingleTenantDirectory(container, x => x.Where(d => d.Name == hrefOrName));
                var group     = GetSingleTenantGroup(container, x => x.Where(g => g.Name == hrefOrName));

                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(AddAccountStore(container, internalDataStore, accountStore));
            }

            // Could not find any resource matching the hrefOrName value
            return(null);
        }
 public DefaultSynchronousFilterChain(IInternalSyncDataStore dataStore)
     : this(dataStore, Enumerable.Empty<ISynchronousFilter>())
 {
 }
        public static IAccount CreateAccount(IInternalSyncDataStore dataStoreSync, string accountsHref, string givenName, string surname, string email, string password, object customData = null)
        {
            var account = CreateAccountWith(dataStoreSync, givenName, surname, email, password, customData);

            return CreateAccount(dataStoreSync, accountsHref, account);
        }
 internal DefaultSynchronousFilterChain(IInternalSyncDataStore dataStore, IEnumerable<ISynchronousFilter> filters)
 {
     this.dataStore = dataStore;
     this.filters = new List<ISynchronousFilter>(filters);
 }
 public static IAccount CreateAccount(IInternalSyncDataStore dataStoreSync, string accountsHref, IAccount account)
     => dataStoreSync.Create(accountsHref, account);