Example #1
0
        /// <summary>
        /// 根据openid获取调用接口的次数。
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static async Task<double> GetLoginCountByOpenidAsync(string openid)
        {
            //string zsetName = RedisManager.GetKeyName<UserLoginRedis, UserLoginBehaviorCountZsetAttribute>();
            //var db = RedisManager.GetRedisDB<UserLoginRedis>();

            var manager =new RedisManager2<WeChatRedisConfig>();
            string zsetName = manager.GetKeyName<UserLoginRedis, UserLoginBehaviorCountZsetAttribute>();
            var db = manager.GetDb<UserLoginRedis>();
            double? value = await db.SortedSetScoreAsync(zsetName, openid);
            return value.GetValueOrDefault();
        }
Example #2
0
 static EKCommentMessageMQOp()
 {
     if (_redis == null)
         _redis = new RedisManager2<WeChatRedisConfig>();
     try
     {
         MQManager.Prepare_All_P_MQ();
     }
     catch (Exception ex)
     {
         LogHelper.LogErrorAsync(typeof(WeChatSendMQHelper), ex);
         throw ex;
     }
 }
Example #3
0
        static void init()
        {
            BK.CommonLib.Util.AsyncHelper.RunAsync(delegate () 
            {
                while(flag)
                {
                    LogHelper.LogInfoAsync(typeof(FindHelper), "开始同步uuid访问记录!");

                    var list = new RedisManager2<WeChatRedisConfig>().GetRangeByRank<NameCardRedis,NameCardCountZsetAttribute>("");

                    foreach(var v in list)
                    {
                        _cacheScore[v.Key] = v.Value;
                    }
                    //System.Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                    LogHelper.LogInfoAsync(typeof(FindHelper), "结束同步uuid访问记录!");
                    Thread.Sleep(TimeSpan.FromMinutes(10));
                }
            }, null);
        }
Example #4
0
        public static async Task<Tuple<List<string>,List<string>,List<string>>> GetThreeSet(bool professor, double univScore, double depScore, double rfScore)
        {
            var _redis = new RedisManager2<WeChatRedisConfig>();

            if (professor)
            {
                var univRedis = await _redis.GetRangeByScoreWithoutScoreAsync<NameCardRedis, UnivProfessorZsetAttribute>("", 0, -1, StackExchange.Redis.Order.Descending, univScore, univScore);
                var depsRedis = await _redis.GetRangeByScoreWithoutScoreAsync<NameCardRedis, DeptProfessorZsetAttribute>("", 0, -1, StackExchange.Redis.Order.Descending, depScore, depScore);

                var rfRedis = await _redis.GetRangeByScoreWithoutScoreAsync<NameCardRedis, ResearchFieldProfessorZsetAttribute>("", 0, -1, StackExchange.Redis.Order.Descending, rfScore, rfScore);

                return Tuple.Create(univRedis, depsRedis, rfRedis);
            }
            else
            {
                var univRedis = await _redis.GetRangeByScoreWithoutScoreAsync<NameCardRedis, UnivStudentZsetAttribute>("", 0, -1, StackExchange.Redis.Order.Descending, univScore, univScore);
                var depsRedis = await _redis.GetRangeByScoreWithoutScoreAsync<NameCardRedis, DeptStudentZsetAttribute>("", 0, -1, StackExchange.Redis.Order.Descending, depScore, depScore);

                var rfRedis = await _redis.GetRangeByScoreWithoutScoreAsync<NameCardRedis, ResearchFieldStudentZsetAttribute>("", 0, -1, StackExchange.Redis.Order.Descending, rfScore, rfScore);
                return Tuple.Create(univRedis, depsRedis, rfRedis);
            }
        }
Example #5
0
        public async Task<HttpResponseMessage> PostIsZaned([FromBody]EKCommentParameter postParameter)
        {
            string openid = postParameter.openID;
            long ekid = postParameter.Id;
            if (string.IsNullOrEmpty(openid) || ekid == 0)
            {
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userR = new UserRepository())
            {
                UserInfo user = await userR.GetUserInfoByOpenid(openid);
                var redis = new RedisManager2<WeChatRedisConfig>();
                double score = await redis.GetScoreEveryKeyAsync<EKTodayRedis, EKZanPepleZsetAttribute>(ekid.ToString(), user.uuid.ToString());
                if(score==0)
                    return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, false, HttpStatusCode.OK, customStatus.Success);
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, true, HttpStatusCode.OK, customStatus.Success);
            }
        }
Example #6
0
 static WeChatReceiveHelper()
 {
     if (_redis == null)
         _redis = new RedisManager2<WeChatRedisConfig>();
 }
Example #7
0
        private void init()
        {
            _redis = new RedisManager2<WeChatRedisConfig>();
            //启动线程
            //BK.data 同步学校,专业与学员信息到zset
            AsyncHelper.RunAsync(delegate ()
            {
                while (!CloseService)
                {

                    try
                    {
                        LogHelper.LogInfoAsync(typeof(Service1), "BK.Data开始整理数据!");

                        ProcessData();
                        LogHelper.LogInfoAsync(typeof(Service1), "BK.Data结束整理数据!");
                        System.Threading.Thread.Sleep(TimeSpan.FromHours(2));
                    }
                    catch(Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }
                }
            }, null);
            System.Threading.Thread.Sleep(10);

            //EK 同步EK的文章,阅读数与赞数。
            AsyncHelper.RunAsync(delegate ()
            {
                while (!CloseService)
                {

                    try
                    {
                        LogHelper.LogInfoAsync(typeof(Service1), "BK.EK开始整理数据!");

                        ProcessEK();

                        LogHelper.LogInfoAsync(typeof(Service1), "BK.EK结束整理数据!");
                        System.Threading.Thread.Sleep(TimeSpan.FromHours(2));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }
                }
            }, null);
            System.Threading.Thread.Sleep(10);

            //EK 赞的人与 读者列表同步
            AsyncHelper.RunAsync(delegate ()
            {
                while (!CloseService)
                {

                    try
                    {
                        LogHelper.LogInfoAsync(typeof(Service1), "BK.ZanerAndReader开始整理数据!");

                        ProcessEKZanerAndReader();

                        LogHelper.LogInfoAsync(typeof(Service1), "BK.ZanerAndReader结束整理数据!");
                        System.Threading.Thread.Sleep(TimeSpan.FromHours(2));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }
                }
            }, null);
            System.Threading.Thread.Sleep(10);

            //Parer 同步
            AsyncHelper.RunAsync(delegate ()
            {
                while (!CloseService)
                {

                    try
                    {
                        LogHelper.LogInfoAsync(typeof(Service1), "BK.Paper开始整理数据!");

                        ProcessPaper();

                        LogHelper.LogInfoAsync(typeof(Service1), "BK.Paper结束整理数据!");
                        System.Threading.Thread.Sleep(TimeSpan.FromHours(2));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }
                }
            }, null);
            System.Threading.Thread.Sleep(10);

            //同步教授信息
            AsyncHelper.RunAsync(delegate ()
            {
                while (!CloseService)
                {

                    try
                    {
                        LogHelper.LogInfoAsync(typeof(Service1), "BK.Professor开始整理数据!");

                        ProcessProfessors();

                        LogHelper.LogInfoAsync(typeof(Service1), "BKBK.Professor结束整理数据!");
                        System.Threading.Thread.Sleep(TimeSpan.FromHours(2));
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }
                }
            }, null);
            System.Threading.Thread.Sleep(10);
        }
Example #8
0
        private void ProcessEK()
        {
            var redis = new RedisManager2<WeChatRedisConfig>();
            //同步articl 数据
            using (UserRepository r = new UserRepository())
            {
                Dictionary<long, int> updateReadDic = new Dictionary<long, int>();
                Dictionary<long, int> updateZanDic = new Dictionary<long, int>();
                foreach(var v in r.GetAllEKToday().Where(ekt => ekt.IsPublic == true))
                {
                    var index = EKArticleManager.CopyFromDB(v);
                    EKArticleManager.AddOrUpdate(index);

                    //更新read count
                    double readScore = redis.GetScore<EKTodayRedis, EKReadCountZsetAttribute>(v.ID.ToString());
                    int rrCount = Convert.ToInt32(readScore);
                    if(rrCount < v.ReadPoint)
                    {
                        EKArticleManager.SetReadCount(v.ID, v.ReadPoint.Value);
                    }
                    else
                    {
                        //r.SetReadCount_TB(v.ID, rrCount);
                        updateReadDic.Add(v.ID, rrCount);
                    }

                    //更新zanshu
                    double zanscore = redis.GetScore<EKTodayRedis, EKZanCountZsetAttribute>(v.ID.ToString());
                    int zrCount = Convert.ToInt32(zanscore);
                    if(zrCount < v.HitPoint)
                    {
                        EKArticleManager.SetZan(v.ID, v.HitPoint.Value);
                    }
                    else
                    {
                        //r.SetZanCount(v.ID, zrCount);
                        updateZanDic.Add(v.ID, zrCount);
                    }
                }

                //update read
                foreach(var pair in updateReadDic)
                {
                    r.SetReadCount_TB(pair.Key, pair.Value);
                }

                //update zan
                foreach(var pair in updateZanDic)
                {
                    r.SetZanCount(pair.Key, pair.Value);
                }
            }
        }
Example #9
0
 public static async Task<bool> SetReadPeopleAsync(long id, Guid user, DateTime time)
 {
     var redis = new RedisManager2<WeChatRedisConfig>();
     double unixTime = CommonHelper.ToUnixTime(time);
     return await redis.SetScoreEveryKeyAsync<EKTodayRedis, EKReadPepleZsetAttribute>(id.ToString(), user.ToString(), unixTime);
 }
Example #10
0
        public async Task<KeyValuePair<string, double>[]> SetEkReadCount(string z,string id="1")
        {
            var redis = new RedisManager2<WeChatRedisConfig>();

            if (z == "z")
                return await redis.GetRangeByRankAsync<EKTodayRedis, EKZanCountZsetAttribute>("");
            if (z == "r")
                return await redis.GetRangeByRankAsync<EKTodayRedis, EKReadCountZsetAttribute>("");
            if (z == "c")
                return await redis.GetRangeByRankAsync<EKTodayRedis, EKCommentCountZsetAttribute>("");
            if (z == "rr")
                return await redis.GetRangeByRankAsync<EKTodayRedis, EKReadPepleZsetAttribute>(id);
            if (z == "zz")
                return await redis.GetRangeByRankAsync<EKTodayRedis, EKZanPepleZsetAttribute>(id);
            return null;
        }
Example #11
0
 public async Task<KeyValuePair<string, double>[]> getRangeByScoredept(string type = "p", long o = 0, int top = 1000, Order order = Order.Descending, double f = double.NegativeInfinity, double t = double.PositiveInfinity)
 {
     var redis = new RedisManager2<WeChatRedisConfig>();
     if(type == "p")
         return await redis.GetRangeByScoreAsync<NameCardRedis, DeptProfessorZsetAttribute>("", o, top, order, f, t);
     else
         return await redis.GetRangeByScoreAsync<NameCardRedis, DeptStudentZsetAttribute>("", o, top, order, f, t);
 }
Example #12
0
 public async Task<KeyValuePair<string, double>[]> getRangeByScoreUnivs(long o, int top, Order order = Order.Descending, double f = double.NegativeInfinity, double t = double.PositiveInfinity)
 {
     var redis = new RedisManager2<WeChatRedisConfig>();
     return await redis.GetRangeByScoreAsync<NameCardRedis, UnivZsetAttribute>("", o, top, order, f, t);
 }
Example #13
0
 public static bool SetZanCount(long id, double score)
 {
     var redis = new RedisManager2<WeChatRedisConfig>();
     return redis.SetScore<PaperRedis, PZanCountZsetAttribute>(id.ToString(), score);
 }
Example #14
0
        private void init()
        {
            _redis = new RedisManager2<WeChatRedisConfig>();
            MQManager.RegisterConsumerProcessor<BK.Model.Configuration.MQ.WeChatMessageMQConfig>(async delegate (BasicDeliverEventArgs ar, IModel channel)
            {
                try
                {
                    var body = ar.Body;
                    var rawObject = BinarySerializationHelper.DeserializeObject(body) as ChatMessageMQ;
                    //log
                    //StringBuilder sb = new StringBuilder();
                    //sb.AppendLine("msg from:" + rawObject.From);
                    //sb.AppendLine("msg to:" + rawObject.To);
                    //sb.AppendLine("msg uuid:" + rawObject.Uuid);
                    //sb.AppendLine("msg sessionid:" + rawObject.SessionId);
                    //sb.AppendLine("msg time:" + CommonHelper.FromUnixTime(Convert.ToDouble(rawObject.TimeStamp)).ToString());
                    //sb.AppendLine("msg message:" + rawObject.PayLoad.ToString());
                    //LogHelper.LogInfoAsync(typeof(Service1), sb.ToString());

                    //记录日志

                    //更新收信方的未读列表数,更新发送方的时间排序
                    //收信人的未读列表加1
                    await MessageRedisOp.AddUnreadScore(rawObject.To, rawObject.SessionId, 1);
                    //LogHelper.LogInfoAsync(typeof(Service1), "数字是:" + d.ToString());

                    //更新双方的session timestamp
                    await MessageRedisOp.SetOrUpdateTimestampToNow(rawObject.From, rawObject.SessionId);

                    await MessageRedisOp.SetOrUpdateTimestampToNow(rawObject.To, rawObject.SessionId);

                    using (MessageRepository r = new MessageRepository())
                    {
                        try
                        {
                            Guid uid = Guid.Parse(rawObject.Uuid);
                            DateTime t = CommonHelper.FromUnixTime(Convert.ToDouble(rawObject.TimeStamp));
                            await r.AddChatLogAsync(uid, rawObject.From, rawObject.To, rawObject.PayLoad.ToString(), rawObject.SessionId, t);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.LogErrorAsync(typeof(Service1), ex);
                        }

                    }

                    //放入redis
                    //uuid:message
                    try
                    {
                        WeChatMessageRedis redisObject = new WeChatMessageRedis();
                        redisObject.SessionId = rawObject.SessionId;
                        redisObject.Message = makeRedisListMessage(rawObject.From, rawObject.TimeStamp, rawObject.PayLoad.ToString());
                        //rawObject.From + ":" + rawObject.PayLoad.ToString();
                        //LogHelper.LogInfoAsync(typeof(Service1), redisObject.Message);
                        await _redis.SaveObjectAsync(redisObject);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }

                }
                catch (Exception ex)
                {
                    LogHelper.LogErrorAsync(typeof(Service1), ex);

                    //TODO:错误处理
                }
                finally
                {
                    channel.BasicAck(ar.DeliveryTag, false);
                    System.Threading.Thread.Sleep(1);
                }
            });

            //EK Comments
            MQManager.RegisterConsumerProcessor<BK.Model.Configuration.MQ.EKCommentMQConfig>(async delegate (BasicDeliverEventArgs ar, IModel channel)
            {
                try
                {
                    var body = ar.Body;
                    var rawObject = BinarySerializationHelper.DeserializeObject(body) as EKCommentMQObject;
                    

                    //TODO Reis update???


                    using (MessageRepository r = new MessageRepository())
                    {
                        try
                        {
                            Guid uid = Guid.Parse(rawObject.uuid);
                            await r.AddEKCommentAsync(uid,Guid.Parse(rawObject.From),rawObject.To,rawObject.Content,rawObject.Timestamp);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.LogErrorAsync(typeof(Service1), ex);
                        }

                    }

                    //放入redis
                    //uuid:message
                    try
                    {
                        EKCommentRedis redisObject = new EKCommentRedis();
                        redisObject.Id = rawObject.To;
                        redisObject.Comment = makeRedisListMessage(rawObject.From, CommonLib.Util.CommonHelper.ToUnixTime(rawObject.Timestamp), rawObject.Content.ToString());
                       
                        await _redis.SaveObjectAsync(redisObject);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }

                }
                catch (Exception ex)
                {
                    LogHelper.LogErrorAsync(typeof(Service1), ex);

                    //TODO:错误处理
                }
                finally
                {
                    channel.BasicAck(ar.DeliveryTag, false);
                    System.Threading.Thread.Sleep(1);
                }
            });

            //Paper Comments
            MQManager.RegisterConsumerProcessor<BK.Model.Configuration.MQ.PaperCommentMQConfig>(async delegate (BasicDeliverEventArgs ar, IModel channel)
            {
                try
                {
                    var body = ar.Body;
                    var rawObject = BinarySerializationHelper.DeserializeObject(body) as PCommentMQObject;

                    //存入数据库
                    using (MessageRepository r = new MessageRepository())
                    {
                        try
                        {
                            Guid uid = Guid.Parse(rawObject.uuid);
                            await r.AddPaperCommentAsync(uid, Guid.Parse(rawObject.From), rawObject.To, rawObject.Content, rawObject.Timestamp);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.LogErrorAsync(typeof(Service1), ex);
                        }

                    }

                    //放入redis
                    //uuid:message
                    try
                    {
                        PaperCommentRedis redisObject = new PaperCommentRedis();
                        redisObject.Id = rawObject.To;
                        redisObject.Comment = makeRedisListMessage(rawObject.From, CommonLib.Util.CommonHelper.ToUnixTime(rawObject.Timestamp), rawObject.Content.ToString());

                        await _redis.SaveObjectAsync(redisObject);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogErrorAsync(typeof(Service1), ex);
                    }

                }
                catch (Exception ex)
                {
                    LogHelper.LogErrorAsync(typeof(Service1), ex);
                }
                finally
                {
                    channel.BasicAck(ar.DeliveryTag, false);
                    System.Threading.Thread.Sleep(1);
                }
            });

            MQManager.Prepare_All_C_MQ();
        }
Example #15
0
        public async Task<HttpResponseMessage> PostGetReadUsers([FromBody]EKCommentParameter postParameter)
        {
            string openid = postParameter.openID;
            long ekid = postParameter.Id;
            int pageIndex = postParameter.pageIndex;
            int pageSize = postParameter.pageSize;
            int fromNo = pageIndex * pageSize;
            int toNo = fromNo + pageSize;

            if (string.IsNullOrEmpty(openid) || ekid == 0)
            {
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            using (UserRepository userR = new UserRepository())
            {
                UserInfo user = await userR.GetUserInfoByOpenid(openid);
                var redis = new RedisManager2<WeChatRedisConfig>();

                var zans = await redis.GetRangeByRankAsync<EKTodayRedis, EKReadPepleZsetAttribute>(ekid.ToString(), from: fromNo, to: toNo);

                List<UserInfo> ret = new List<UserInfo>();
                if (zans != null && zans.Count() > 0)
                {
                    foreach (var v in zans)
                    {
                        UserInfo tmp = await userR.GetUserInfoByUuidAsync(Guid.Parse(v.Key));
                        ret.Add(tmp);
                    }
                }

                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success);
            }
        }
Example #16
0
        public async Task<HttpResponseMessage> PostGetAllCount([FromBody]EKCommentParameter postParameter)
        {
            string openid = postParameter.openID;
            long ekid = postParameter.Id;
            if (string.IsNullOrEmpty(openid) || ekid == 0)
            {
                return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            var redis = new RedisManager2<WeChatRedisConfig>();
            double zanCount = await redis.GetScoreAsync<EKTodayRedis, EKZanCountZsetAttribute>(ekid.ToString());
            double readCount = await redis.GetScoreAsync<EKTodayRedis, EKReadCountZsetAttribute>(ekid.ToString());
            double commentCount = await redis.GetScoreAsync<EKTodayRedis, EKCommentCountZsetAttribute>(ekid.ToString());

            Tuple<double, double, double> ret = Tuple.Create(zanCount, readCount, commentCount);
            return WebApiHelper.HttpRMtoJson(postParameter.jsonpCallback, ret, HttpStatusCode.OK, customStatus.Success);

        }
Example #17
0
        public static async Task<double> AddReadCountAsync(long id)
        {
            var redis = new RedisManager2<WeChatRedisConfig>();

            return await redis.AddScoreAsync<EKTodayRedis, EKReadCountZsetAttribute>(id.ToString(), 1);
        }
Example #18
0
        private void ProcessEKZanerAndReader()
        {
            var redis = new RedisManager2<WeChatRedisConfig>();
            //
            using (UserRepository r = new UserRepository())
            {
                foreach (var v in r.GetAllEKToday())
                {
                    long id = v.ID;
                    #region zan
                    using (UserRepository rzan = new UserRepository())
                    {
                        var listDBZaner = rzan.GetEKZaners(id);
                        var listRedisZaner = redis.GetRangeByRank<EKTodayRedis, EKZanPepleZsetAttribute>(id.ToString());

                        if (listDBZaner == null) listDBZaner = new List<article_praise>();
                        if (listRedisZaner == null) listRedisZaner = new KeyValuePair<string, double>[] { };
                        //LogHelper.LogInfoAsync(typeof(Service1), "zan:" + id.ToString() +" "  +listDBZaner.Count()+" " +listRedisZaner.Count());

                        //DB -> reids
                        if (listDBZaner.Count() > 0 || listRedisZaner.Count() > 0)
                        {
                            if (listDBZaner.Count() > listRedisZaner.Count())
                            {
                                foreach (var p in listDBZaner)
                                {
                                    DateTime t = p.praisetime != null ? p.praisetime.Value : DateTime.Now;
                                    double score = BK.CommonLib.Util.CommonHelper.ToUnixTime(t);
                                    
                                    redis.SetScoreEveryKey<EKTodayRedis, EKZanPepleZsetAttribute>(id.ToString(), p.useraccount_uuid.ToString(), score);

                                    //LogHelper.LogInfoAsync(typeof(Service1), "zan:" + id.ToString()+" uuid:"+p.useraccount_uuid.ToString()+" score:"+score.ToString());
                                }
                            }
                            else
                            {
                                foreach (var p in listRedisZaner)
                                {
                                    Guid uuid = Guid.Parse(p.Key);
                                    double score = p.Value;
                                    rzan.AddEKZaner(id, uuid, score);

                                    //LogHelper.LogInfoAsync(typeof(Service1), "-->zan:" + id.ToString() + " uuid:" + p.Key + " score:" + score.ToString());
                                }
                            }
                        }
                    }


                    #endregion

                    #region reader
                    using (UserRepository rreader = new UserRepository())
                    {
                        var listDBreader = rreader.GetEKReaders(id);
                        var listRedisreader = redis.GetRangeByRank<EKTodayRedis, EKReadPepleZsetAttribute>(id.ToString());

                        if (listDBreader == null) listDBreader = new List<article_reader>();
                        if (listRedisreader == null) listRedisreader = new KeyValuePair<string, double>[] { };

                        //DB -> reids
                        if (listDBreader.Count() > 0 || listRedisreader.Count() > 0)
                        {
                            if (listDBreader.Count() > listRedisreader.Count())
                            {
                                foreach (var p in listDBreader)
                                {
                                    DateTime t = p.readtime != null ? p.readtime.Value : DateTime.Now;
                                    double score = BK.CommonLib.Util.CommonHelper.ToUnixTime(t);

                                    redis.SetScoreEveryKey<EKTodayRedis, EKReadPepleZsetAttribute>(id.ToString(), p.useraccount_uuid.ToString(), score);
                                }
                            }
                            else
                            {
                                foreach (var p in listRedisreader)
                                {
                                    Guid uuid = Guid.Parse(p.Key);
                                    double score = p.Value;
                                    rreader.AddEKReader(id, uuid, score);
                                }
                            }
                        }
                    }
                    #endregion
                }
            }
        }
Example #19
0
        public static async Task<bool> SetReadCountAsync(long id,double score)
        {
            var redis = new RedisManager2<WeChatRedisConfig>();

            return await redis.SetScoreAsync<EKTodayRedis, EKReadCountZsetAttribute>(id.ToString(), score);
        }
Example #20
0
 static MessageRedisOp()
 {
     _redis = new RedisManager2<WeChatRedisConfig>();
 }
Example #21
0
        public static bool SetReadCount(long id, double score)
        {
            var redis = new RedisManager2<WeChatRedisConfig>();

            return redis.SetScore<EKTodayRedis, EKReadCountZsetAttribute>(id.ToString(), score);
        }
Example #22
0
 static NoticeRedisOp()
 {
     _redis = new RedisManager2<WeChatRedisConfig>();
 }
Example #23
0
        public static async Task<double> GetCommentCountAsync(long id)
        {
            var redis = new RedisManager2<WeChatRedisConfig>();

            return await redis.GetScoreAsync<EKTodayRedis, EKCommentCountZsetAttribute>(id.ToString());
        }
Example #24
0
 static NameCardAccessCountOP()
 {
     _redis = new RedisManager2<WeChatRedisConfig>();
 }
Example #25
0
        public async Task<HttpResponseMessage> PostAddContact([FromBody]DualParameter postParameter)
        {
            string openid = postParameter.openID;
            long itemId = postParameter.itemId;

            using(NoticeRepository noticeRepository = new NoticeRepository())
            {
                Message m = await noticeRepository.GetNotice(itemId);

                NoticeMQ rawObject = new NoticeMQ();
                rawObject.Id = m.ID;
                rawObject.MsgType = NoticeType.Contact_Request;
                rawObject.Relation_Uuid = m.RelationID_uuid;
                rawObject.Receiver_Uuid = m.Receiver_uuid;
                rawObject.PayLoad = m.MessageInfo;
                //改了
                rawObject.status = 1;
                rawObject.TimeStamp = m.SendTime;

                var iso = new IsoDateTimeConverter();
                iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";

                RedisManager2<WeChatRedisConfig> _redis = new RedisManager2<WeChatRedisConfig>();
                WeChatNoticeRedis redisObject = new WeChatNoticeRedis();
                redisObject.Uuid = rawObject.Receiver_Uuid.ToString();
                redisObject.Message = JsonConvert.SerializeObject(rawObject, iso);
                //改回
                rawObject.status = 0;
                rawObject.TimeStamp = DateTime.Now;
                WeChatNoticeRedis originalRedisObject = new WeChatNoticeRedis();
                originalRedisObject.Uuid = rawObject.Receiver_Uuid.ToString();
                originalRedisObject.Message = JsonConvert.SerializeObject(rawObject, iso);

                await _redis.ReplaceObjectInListAsync(redisObject, originalRedisObject);
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
            }
        }
Example #26
0
        private void init()
        {
            _redis = new RedisManager2<WeChatRedisConfig>();
            MQManager.RegisterConsumerProcessor<NoticeMQConfig>(async delegate (BasicDeliverEventArgs ar, IModel channel)
            {
                try
                {
                    var rawObject = BinarySerializationHelper.DeserializeObject(ar.Body) as NoticeMQ;


                    var iso = new IsoDateTimeConverter();
                    iso.DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";

                    if(rawObject.Id == 0)
                    {
                        //放入sqlserver 
                        rawObject.Id = await NoticeHelper.SaveNoticeToSql(rawObject);
                        if(rawObject.Id != 0)
                        {
                            //收信人的未读列表加1
                            await NoticeRedisOp.AddUnreadScore(rawObject.Receiver_Uuid, 1);
                            //放入redis
                            try
                            {
                                WeChatNoticeRedis redisObject = new WeChatNoticeRedis();
                                redisObject.Uuid = rawObject.Receiver_Uuid.ToString();
                                redisObject.Message = JsonConvert.SerializeObject(rawObject, iso);
                                //redisObject.Message = BinarySerializationHelper.BytesToHexString(
                                //    BinarySerializationHelper.SerializeObject(rawObject));
                                await _redis.SaveObjectAsync(redisObject);
                            }
                            catch(Exception ex)
                            {
                                LogHelper.LogErrorAsync(typeof(NoticeService), ex);
                            }
                        }
                    }
                    else
                    {
                        //按照id修改sqlserver
                        await NoticeHelper.SaveNoticeToSql(rawObject);
                        //按照id修改redis
                        try
                        {
                            WeChatNoticeRedis redisObject = new WeChatNoticeRedis();
                            redisObject.Uuid = rawObject.Receiver_Uuid.ToString();
                            redisObject.Message = JsonConvert.SerializeObject(rawObject, iso);
                            //redisObject.Message = BinarySerializationHelper.BytesToHexString(
                            //    BinarySerializationHelper.SerializeObject(rawObject));

                            rawObject.status = 0;
                            WeChatNoticeRedis originalRedisObject = new WeChatNoticeRedis();
                            originalRedisObject.Uuid = rawObject.Receiver_Uuid.ToString();
                            originalRedisObject.Message = JsonConvert.SerializeObject(rawObject, iso);
                            //originalRedisObject.Message = BinarySerializationHelper.BytesToHexString(
                            //    BinarySerializationHelper.SerializeObject(rawObject));

                            if(!await _redis.ReplaceObjectInListAsync(redisObject, originalRedisObject))
                                LogHelper.LogInfoAsync(typeof(NoticeService), "替换失败");
                        }
                        catch(Exception ex)
                        {
                            LogHelper.LogErrorAsync(typeof(NoticeService), ex);
                        }
                    }

                }
                catch (Exception ex)
                {
                    LogHelper.LogErrorAsync(typeof(NoticeService), ex);

                    //TODO:错误处理
                }
                finally
                {
                    channel.BasicAck(ar.DeliveryTag, false);
                    System.Threading.Thread.Sleep(1);
                }
            });

            MQManager.Prepare_All_C_MQ();
        }
Example #27
0
 static OpenIdToUserUUIDOp()
 {
     _redis = new RedisManager2<WeChatRedisConfig>();
 }