예제 #1
0
        public IStore BuildStore(string storeName, IStoreOptions storeOptions)
        {
            if (storeOptions.ProviderType != this.Name)
            {
                throw new Exceptions.BadStoreProviderException(this.Name, storeName);
            }

            return(this.BuildStoreInternal(
                       storeName,
                       storeOptions.ParseStoreOptions <TParsedOptions, TInstanceOptions, TStoreOptions, TScopedStoreOptions>(options)));
        }
예제 #2
0
        private IStorageProvider GetProvider(IStoreOptions configuration, bool throwIfNotFound = true)
        {
            string providerTypeName = null;

            if (!string.IsNullOrEmpty(configuration.ProviderType))
            {
                providerTypeName = configuration.ProviderType;
            }
            else if (!string.IsNullOrEmpty(configuration.ProviderName))
            {
                this.options.ParsedProviderInstances.TryGetValue(configuration.ProviderName, out var providerInstanceOptions);
                if (providerInstanceOptions != null)
                {
                    providerTypeName = providerInstanceOptions.Type;
                }
                else if (throwIfNotFound)
                {
                    throw new Exceptions.BadProviderConfiguration(configuration.ProviderName, "Unable to find it in the configuration.");
                }
            }
            else if (throwIfNotFound)
            {
                throw new Exceptions.BadStoreConfiguration(configuration.Name, "You have to set either 'ProviderType' or 'ProviderName' on Store configuration.");
            }

            if (string.IsNullOrEmpty(providerTypeName))
            {
                return(null);
            }

            this.storageProviders.TryGetValue(providerTypeName, out var provider);
            if (provider == null && throwIfNotFound)
            {
                throw new Exceptions.ProviderNotFoundException(providerTypeName);
            }

            return(provider);
        }
예제 #3
0
        public static TStoreOptions ParseStoreOptions <TParsedOptions, TInstanceOptions, TStoreOptions, TScopedStoreOptions>(this IStoreOptions storeOptions, TParsedOptions options)
            where TParsedOptions : class, IParsedOptions <TInstanceOptions, TStoreOptions, TScopedStoreOptions>, new()
            where TInstanceOptions : class, IProviderInstanceOptions, new()
            where TStoreOptions : class, IStoreOptions, new()
            where TScopedStoreOptions : class, TStoreOptions, IScopedStoreOptions
        {
            if (!(storeOptions is TStoreOptions parsedStoreOptions))
            {
                parsedStoreOptions = new TStoreOptions
                {
                    Name         = storeOptions.Name,
                    ProviderName = storeOptions.ProviderName,
                    ProviderType = storeOptions.ProviderType,
                    AccessLevel  = storeOptions.AccessLevel,
                    FolderName   = storeOptions.FolderName,
                };
            }

            parsedStoreOptions.Compute <TParsedOptions, TInstanceOptions, TStoreOptions, TScopedStoreOptions>(options);
            return(parsedStoreOptions);
        }
 public IStore BuildStore(string storeName, IStoreOptions storeOptions)
 {
     return(this.BuildStoreInternal(
                storeName,
                storeOptions.ParseStoreOptions <TParsedOptions, TInstanceOptions, TStoreOptions, TScopedStoreOptions>(options)));
 }
예제 #5
0
 public IStore GetStore(string storeName, IStoreOptions configuration)
 {
     return(this.GetProvider(configuration).BuildStore(storeName, configuration));
 }