Esempio n. 1
0
 public ClientForm()
 {
     InitializeComponent();
     m_context = SynchronizationContext.Current;
     InstanceContext callbackContext = new InstanceContext(this);
     m_proxy = new CounterClient(callbackContext);
 }
Esempio n. 2
0
        public OARedEnvelopeCacheManager(int officialAccountType, DateTime now)
        {
            _officialAccountType = officialAccountType;
            _now = now;
            var cacheName = GlobalConstant.OARedEnvelopeCacheHeader;

            _cacheClient   = CacheHelper.CreateCacheClient(cacheName);
            _counterClient = CacheHelper.CreateCounterClient(cacheName, TimeSpan.FromDays(2));
            _today         = _now.ToString("yyyyMMdd");
            _hashClient    = CacheHelper.CreateHashClient(cacheName + $":{officialAccountType}:{_today}", TimeSpan.FromDays(1));
        }
Esempio n. 3
0
        public CounterForm()
        {
            InitializeComponent();

            m_SynchronizationContext = SynchronizationContext.Current;

            Thread.CurrentThread.Name = "Form Thread";

            string address = "net.pipe://localhost/" + Guid.NewGuid().ToString();
            ServiceHost<Service.Counter> host;
            host = new ServiceHost<CodeRunner.Service.Counter>();
            this.FormClosed += delegate { proxy.Close(); host.Close(); };
            host.AddServiceEndpoint<Service.ICounter>(new NetNamedPipeBinding(), address);
            host.Open();

            proxy = new CounterClient(new NetNamedPipeBinding(), address);
        }
        private static async Task <OrderCountResponse> SetCountValue(OrderCountResponse model, string key, int num, CounterClient client)
        {
            var getcount = await client.CountAsync(key);

            if (!getcount.Success && !getcount.Message.Equals("Key不存在"))
            {
                model.RedisField = true;
                model.RedisMsg   = getcount.Message;
                return(model);
            }
            else
            {
                IResult <long> setcount;
                if (getcount.Message != null && getcount.Message.Equals("Key不存在"))
                {
                    setcount = await client.IncrementAsync(key, num);

                    if (!setcount.Success)
                    {
                        model.RedisField = true;
                        model.RedisMsg   = getcount.Message;
                        return(model);
                    }
                }
                else
                {
                    var discountcounter = await client.DecrementAsync(key, getcount.Value);

                    if (!discountcounter.Success)
                    {
                        model.RedisField = true;
                        model.RedisMsg   = getcount.Message;
                        return(model);
                    }
                    else
                    {
                        setcount = await client.IncrementAsync(key, num);

                        if (!setcount.Success)
                        {
                            model.RedisField = true;
                            model.RedisMsg   = getcount.Message;
                            return(model);
                        }
                    }
                }
            }

            return(model);
        }
        private static async Task <OrderCountResponse> GetCountValue(OrderCountResponse model, KeyType type, string key, CounterClient client)
        {
            switch (type)
            {
            case KeyType.PlaceUserIdKey:
                var counterpu = await client.CountAsync(key);

                if (counterpu.Success)
                {
                    model.PlaceUserIdCountCacheNum = (int)counterpu.Value;
                }
                else
                {
                    model.RedisField = true;
                    model.RedisMsg   = $"{counterpu.Message}key==>{key},";
                    //  return model;
                }
                break;

            case KeyType.PlaceDeviceIdKey:
                var counterpd = await client.CountAsync(key);

                if (counterpd.Success)
                {
                    model.PlaceDeviceCountCacheNum = (int)counterpd.Value;
                }
                else
                {
                    model.RedisField = true;
                    model.RedisMsg  += $"{counterpd.Message}key==>{key},";
                    // return model;
                }
                break;

            case KeyType.PlaceUserTelKey:
                var counterpt = await client.CountAsync(key);

                if (counterpt.Success)
                {
                    model.PlaceUserTelCountCacheNum = (int)counterpt.Value;
                }
                else
                {
                    model.RedisField = true;
                    model.RedisMsg  += $"{counterpt.Message}key==>{key},";
                    // return model;
                }
                break;

            case KeyType.PersonUserIdKey:
                var counterpu2 = await client.CountAsync(key);

                if (counterpu2.Success)
                {
                    model.PersonUserIdCountCacheNum = (int)counterpu2.Value;
                }
                else
                {
                    model.RedisField = true;
                    model.RedisMsg  += $"{counterpu2.Message}key==>{key},";
                    return(model);
                }
                break;

            case KeyType.PersonDeviceIdKey:
                var counterpd2 = await client.CountAsync(key);

                if (counterpd2.Success)
                {
                    model.PersonDeviceCountCacheNum = (int)counterpd2.Value;
                }
                else
                {
                    model.RedisField = true;
                    model.RedisMsg  += $"{counterpd2.Message}key==>{key},";
                    //  return model;
                }
                break;

            case KeyType.PersonUserTelKey:
                var counterpt2 = await client.CountAsync(key);

                if (counterpt2.Success)
                {
                    model.PersonUserTelCountCacheNum = (int)counterpt2.Value;
                }
                else
                {
                    model.RedisField = true;
                    model.RedisMsg  += $"{counterpt2.Message}key==>{key}";
                    // return model;
                }
                break;

            default:
                return(model);
            }
            return(model);
        }