コード例 #1
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));
        }
コード例 #2
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)));
        }
コード例 #3
0
        /// <summary>
        /// Sets the default Account or Group store.
        /// </summary>
        /// <typeparam name="T">The parent resource type.</typeparam>
        /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
        /// <param name="parent">The parent resource.</param>
        /// <param name="store">The new default Account or Group store.</param>
        /// <param name="isAccountStore">Determines whether this store should be the default Account (<see langword="true"/>) or Group (<see langword="false"/>) Store.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public static async Task SetDefaultStoreAsync <T, TMapping>(
            ISaveable <T> parent,
            IAccountStore store,
            bool isAccountStore,
            CancellationToken cancellationToken)
            where T : IResource, IAccountStoreContainer <TMapping>
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            if (string.IsNullOrEmpty(store?.Href))
            {
                throw new ArgumentNullException(nameof(store.Href));
            }

            var container = parent as IAccountStoreContainer <TMapping>;

            if (parent == null)
            {
                throw new ApplicationException("SetDefaultStore must be used with a supported AccountStoreContainer.");
            }

            IAccountStoreMapping <TMapping> newOrExistingMapping = null;
            await container.GetAccountStoreMappings().ForEachAsync(
                mapping =>
            {
                bool isPassedAccountStore = (mapping as AbstractAccountStoreMapping <TMapping>)?.AccountStore?.Href.Equals(store.Href) ?? false;
                if (isPassedAccountStore)
                {
                    newOrExistingMapping = mapping;
                }

                return(newOrExistingMapping != null);    // break if found
            }, cancellationToken).ConfigureAwait(false);

            if (newOrExistingMapping == null)
            {
                newOrExistingMapping = await container
                                       .AddAccountStoreAsync(store, cancellationToken).ConfigureAwait(false);
            }

            if (isAccountStore)
            {
                newOrExistingMapping.SetDefaultAccountStore(true);
            }
            else
            {
                newOrExistingMapping.SetDefaultGroupStore(true);
            }

            await newOrExistingMapping.SaveAsync(cancellationToken).ConfigureAwait(false);
        }
コード例 #4
0
        /// <summary>
        /// TODO: Remove this when refactoring AbstractAccountStoreMapping (breaking change)
        /// </summary>
        /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
        /// <param name="mapping">The account store mapping.</param>
        /// <param name="container">The container object (an Application or Organization).</param>
        private static void SetContainer <TMapping>(IAccountStoreMapping <TMapping> mapping, IAccountStoreContainer <TMapping> container)
            where TMapping : class, IAccountStoreMapping <TMapping>
        {
            var asApplication = container as IApplication;

            if (asApplication != null)
            {
                mapping.SetApplication(asApplication);
                return;
            }

            var asOrganization = container as IOrganization;

            if (asOrganization != null)
            {
                (mapping as IOrganizationAccountStoreMapping).SetOrganization(asOrganization);
                return;
            }

            throw new NotImplementedException("Unknown container type!");
        }
コード例 #5
0
 /// <summary>
 /// Synchronously gets the <see cref="IApplication">Application</see> represented by this mapping.
 /// </summary>
 /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
 /// <param name="accountStoreMapping">The account store mapping.</param>
 /// <returns>The mapping's <see cref="IApplication">Application</see>.</returns>
 public static IApplication GetApplication <TMapping>(this IAccountStoreMapping <TMapping> accountStoreMapping)
     where TMapping : class, IAccountStoreMapping <TMapping>
 => (accountStoreMapping as IAccountStoreMappingSync <TMapping>).GetApplication();
コード例 #6
0
 /// <summary>
 /// Synchronously gets this mapping's <see cref="IAccountStore">Account Store</see> (either a <see cref="Group.IGroup">Group</see> or <see cref="Directory.IDirectory">Directory</see>), to be assigned to the application.
 /// </summary>
 /// <typeparam name="TMapping">The Account Store Mapping type.</typeparam>
 /// <param name="accountStoreMapping">The account store mapping.</param>
 /// <returns>The mapping's <see cref="IAccountStore">Account Store</see>.</returns>
 public static IAccountStore GetAccountStore <TMapping>(this IAccountStoreMapping <TMapping> accountStoreMapping)
     where TMapping : class, IAccountStoreMapping <TMapping>
 => (accountStoreMapping as IAccountStoreMappingSync <TMapping>).GetAccountStore();