Example #1
0
        public void Initialize(ProviderRepositoryBase repository)
        {
            ProviderRepositoryInfo info = repository.GetProviderRepositoryInfo(Key);

            providerSettings    = info.ProviderSettings;
            defaultProviderName = info.DefaultProviderName;
        }
Example #2
0
        public static S GetInstance <S>(ProviderRepositoryBase repository) where S : ProviderFactory, new()
        {
            m_StaticCacheLock.EnterUpgradeableReadLock();
            string key = String.Format("{0}^_^{1}", repository.Name, typeof(S).Name);

            try {
                if (_StaticCache.ContainsKey(key))
                {
                    return(_StaticCache[key] as S);
                }
                else
                {
                    m_StaticCacheLock.EnterWriteLock();
                    try {
                        S result = new S();
                        result.Initialize(repository);
                        _StaticCache.Add(key, result);
                        return(result);
                    } finally {
                        m_StaticCacheLock.ExitWriteLock();
                    }
                }
            } finally {
                m_StaticCacheLock.ExitUpgradeableReadLock();
            }
        }
Example #3
0
        public void SaveInstance(ProviderRepositoryBase repository)
        {
            ProviderRepositoryInfo info = new ProviderRepositoryInfo();

            foreach (var item in providerSettings)
            {
                info.ProviderSettings.Add(item);
            }
            info.DefaultProviderName = defaultProviderName;
            repository.SaveProviderRepositoryInfo(this.Key, info);
        }
Example #4
0
        private ProviderRepositoryBase InstantiateProvider(ProviderSettings providerSettings, Type providerType)
        {
            if (providerSettings == null)
            {
                throw new ArgumentNullException("providerSettings");
            }
            if (providerType == null)
            {
                throw new ArgumentNullException("providerType");
            }

            ProviderRepositoryBase providerBase = null;

            try
            {
                string providerBaseTypeName = (providerSettings.Type == null) ? null : providerSettings.Type.Trim();
                if (string.IsNullOrEmpty(providerBaseTypeName))
                {
                    throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "ProviderNoTypeName", new object[] { providerBaseTypeName }));
                }
                Type providerBaseType = Type.GetType(providerBaseTypeName, true, true);

                if (!providerType.IsAssignableFrom(providerBaseType))
                {
                    throw new ArgumentException(String.Format(System.Globalization.CultureInfo.InvariantCulture, "ProviderMustImplementType", new object[] { providerType.ToString() }));
                }

                providerBase = (ProviderRepositoryBase)Activator.CreateInstance(providerBaseType);

                NameValueCollection providerSettingParameters    = providerSettings.Parameters;
                NameValueCollection newProviderSettingParameters = new NameValueCollection(providerSettingParameters.Count, StringComparer.Ordinal);
                foreach (string parameter in providerSettingParameters)
                {
                    newProviderSettingParameters[parameter] = providerSettingParameters[parameter];
                }
                providerBase.Initialize(providerSettings.Name, newProviderSettingParameters);
            }
            catch (Exception ex)
            {
                if (ex is CoreException)
                {
                    throw;
                }
                throw new CoreException(ex.Message);
            }
            return(providerBase);
        }