Ejemplo n.º 1
0
        /// <summary>
        /// 获取对应于指定平台的授权提供程序
        /// </summary>
        /// <param name="etpName">平台名称。</param>
        public IAuthorizationProvider GetProvider(EtpName etpName)
        {
            IAuthorizationProvider provider = null;
            if (dicCatheProvider.ContainsKey(etpName.Name.ToLower().Trim()))
            {
                //从缓存中取
                provider = dicCatheProvider[etpName.Name.ToLower().Trim()];
            }
            else
            {
                lock (lockO)
                {
                    if (!dicCatheProvider.ContainsKey(etpName.Name.ToLower().Trim()))
                    {
                        //从配置文件创建
                        OAuthLoginConfig freepEtp = (OAuthLoginConfig)ConfigurationManager.GetSection("OAuthLogin");

                        var authorizationProvider = freepEtp.AuthorizationProvider[etpName.Name.ToLower().Trim()];

                        Assembly assembly = Assembly.Load(authorizationProvider.Assembly);
                        //反射创建提供程序实例
                        object obj = assembly.CreateInstance(authorizationProvider.Type);
                        //添加缓存
                        authorizationProviderContainer.dicCatheProvider.Add(authorizationProvider.Etp, (IAuthorizationProvider)obj);

                        provider = (IAuthorizationProvider)obj;
                    }
                }
            }
            return provider;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取适用于指定平台的EtpException构造器。
        /// </summary>
        /// <param name="etpName"></param>
        public IEtpExceptionBuilder GetBuilder(EtpName etpName)
        {

            //有则从缓存中取
            if (dicCatheBuilder.ContainsKey(etpName.Name.ToLower().Trim()))
            {
                return dicCatheBuilder[etpName.Name.ToLower().Trim()];
            }
            else
            {
                //反射创建
                OAuthLoginConfig authLoginConfig = (OAuthLoginConfig)ConfigurationManager.GetSection("OAuthLogin");

                var builder = authLoginConfig.EtpExceptionBuilder[etpName.Name.ToLower().Trim()];
                Assembly assembly = Assembly.Load(builder.Assembly);

                //反射创建构造器实例
                object obj = assembly.CreateInstance(builder.Type);
                //添加缓存
                etpExceptionBuilderContainer.dicCatheBuilder.Add(builder.Etp, (IEtpExceptionBuilder)obj);
                return (IEtpExceptionBuilder)obj;
            }
        }