Ejemplo n.º 1
0
        public DefaultRedisCacheProvider(string appName)
        {
            _context = new Lazy <DefaultRedisContext>(() =>
            {
                return(CachingContainer.IsRegistered <DefaultRedisContext>(appName)
                    ? CachingContainer.GetService <DefaultRedisContext>(appName)
                    : CachingContainer.GetInstances <DefaultRedisContext>(appName));
            });

            _keySuffix         = appName;
            _defaultExpireTime = new Lazy <long>(() => long.Parse(_context.Value._defaultExpireTime));
            _connectTimeout    = new Lazy <int>(() => int.Parse(_context.Value._connectTimeout));

            if (CachingContainer.IsRegistered <ICacheClient <IDatabase> >(CacheTargetType.Redis.ToString()))
            {
                _addressResolver = CachingContainer.GetService <IAddressResolver>();
                _cacheClient     = new Lazy <ICacheClient <IDatabase> >(() =>
                                                                        CachingContainer.GetService <ICacheClient <IDatabase> >(CacheTargetType.Redis.ToString()));
            }
            else
            {
                _cacheClient = new Lazy <ICacheClient <IDatabase> >(() =>
                                                                    CachingContainer.GetInstances <ICacheClient <IDatabase> >(CacheTargetType.Redis.ToString()));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// redis数据上下文
        /// </summary>
        /// <param name="args">参数</param>
        public DefaultRedisContext(params object[] args)
        {
            if (CachingContainer.IsRegistered <IHashAlgorithm>())
            {
                _hashAlgorithm = CachingContainer.GetService <IHashAlgorithm>();
            }
            else
            {
                _hashAlgorithm = CachingContainer.GetInstances <IHashAlgorithm>();
            }
            foreach (var arg in args)
            {
                var properties = arg.GetType().GetProperties();
                var field      = GetType()
                                 .GetField(string.Format("_{0}", properties[0].GetValue(arg)),
                                           BindingFlags.NonPublic |
                                           BindingFlags.Instance | BindingFlags.IgnoreCase);
                if (properties.Count() == 3)
                {
                    _cachingContextPool = new Lazy <Dictionary <string, List <string> > >(
                        () =>
                    {
                        var dataContextPool = new Dictionary <string, List <string> >();
                        var lArg            = arg as List <object>;
                        Debug.Assert(lArg != null, nameof(lArg) + " != null");
                        foreach (var tmpArg in lArg)
                        {
                            var props = tmpArg.GetType().GetTypeInfo().GetProperties();
                            var items = props[2].GetValue(tmpArg) as object[];
                            if (items != null)
                            {
                                var list = (from item in items
                                            let itemProperties = item.GetType().GetProperties()
                                                                 select itemProperties[1].GetValue(item)
                                                                 into value
                                                                 select value.ToString()).ToList();
                                dataContextPool.Add(props[1].GetValue(tmpArg).ToString(), list);
                            }
                        }

                        return(dataContextPool);
                    }
                        );
                }
                else
                {
                    if (field != null)
                    {
                        field.SetValue(this, properties[1].GetValue(arg));
                    }
                }
            }

            dicHash = new ConcurrentDictionary <string, ConsistentHash <ConsistentHashNode> >();
            InitSettingHashStorage();
        }
Ejemplo n.º 3
0
        public DefaultMemoryCacheProvider(string appName)
        {
            _context = new Lazy <DefaultRedisContext>(() =>
            {
                return(CachingContainer.IsRegistered <DefaultRedisContext>(CacheTargetType.Redis.ToString())
                    ? CachingContainer.GetService <DefaultRedisContext>(appName)
                    : CachingContainer.GetInstances <DefaultRedisContext>(appName));
            });

            _keySuffix         = appName;
            _defaultExpireTime = new Lazy <long>(() => long.Parse(_context.Value._defaultExpireTime));
        }
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Create Twitter API
            TwitterApi api = new TwitterApi(
                new ApiCallOptions
                {
                    AuthorizationCallbackUri = new Uri(
                        this.Request.Url, 
                        new VPathResolver().Resolve("~/User.aspx"))
                });

            try
            {
                // Load current user
                // If the user has not yet connected to Twitter, this will
                // throw an AuthorizationRequiredException, handled below
                CachingContainer<ExtendedUser> extendedUserInfoCache
                    = this.Session[UserInfoKey] as CachingContainer<ExtendedUser>;
                
                if (extendedUserInfoCache == null)
                    this.Session[UserInfoKey] = extendedUserInfoCache 
                        = new CachingContainer<ExtendedUser>();

                this.TwitterUser = extendedUserInfoCache.Load(
                    TimeSpan.FromMinutes(5),
                    () => 
                    {
                        ExtendedUser user;
                        if (api.VerifyCredentials(out user))
                            return user;
                        else
                            throw new BadCredentialsException();
                    });

                // Load user timeline
                CachingContainer<IList<Status>> userTimelineCache
                    = this.Session[UserTimelineKey] as CachingContainer<IList<Status>>;

                if (userTimelineCache == null)
                    this.Session[UserTimelineKey] = userTimelineCache
                        = new CachingContainer<IList<Status>>();

                this.UserTimeline = userTimelineCache.Load(
                    TimeSpan.FromSeconds(30),
                    () => api.UserTimeline());
            }
            catch (BadCredentialsException)
            {
                this.Response.Redirect("~/Disconnect.aspx?error=badcredentials", true);
            }
        }
 public DefaultAuthorizationServerProvider()
 {
     _cacheProvider = CachingContainer.GetService <ICacheProvider>(GatewayConfig.CacheMode);
 }
 public DefaultAuthorizationServerProvider(IServiceProxyProvider serviceProxyProvider, IServiceRouteProvider serviceRouteProvider)
 {
     _serviceProxyProvider = serviceProxyProvider;
     _serviceRouteProvider = serviceRouteProvider;
     _cacheProvider        = CachingContainer.GetService <ICacheProvider>(GatewayConfig.CacheMode);
 }