Пример #1
0
        private static void NewMethod3()
        {
            StudyOnlineEntities entities = new StudyOnlineEntities();
            DateTime            now      = DateTime.Now;

            for (int i = 1; i <= 150; i++)
            {
                //创建帐号
                NimUser nimuser = new NimUser()
                {
                    Accid = Guid.NewGuid().ToString().Replace("-", ""), Category = 0, IsActive = 1, IsEnable = 1, Username = String.Format("CFFD{0:D3}", i), Password = EncryptionUtil.Md5Encode("00000000"), CreateDate = now, NimUserEx = new NimUserEx()
                    {
                        Coins = 600
                    }
                };

                //同步云信
                String json = NimUtil.UserCreate(nimuser.Accid, null, null, null);
                Answer a    = JsonConvert.DeserializeObject <Answer>(json);
                if (a.code == 200)
                {
                    nimuser.Token = a.info.token;
                }

                //保存数据
                entities.NimUser.Add(nimuser);
                Console.WriteLine("帐号:{0},密码:{2},学币:{1},accid={3},token={4}", nimuser.Username, nimuser.NimUserEx.Coins, nimuser.Password, nimuser.Accid, nimuser.Token);
            }

            entities.SaveChanges();
        }
Пример #2
0
        public void Execute(IJobExecutionContext context)
        {
            //log.Info("现在异步处理教师在线情况");
            StudyOnlineEntities entities = new StudyOnlineEntities();
            //只刷新安卓端,手机系统,安卓为1,苹果为2,其它为0
            var a = DateTime.Now.AddMinutes(-5);
            //Console.WriteLine(a.ToString("yyyy-MM-dd HH:mm:ss"));
            var teacher = entities.NimUser.Where(o => o.Category == 1 && o.IsOnline == 1 && o.IsEnable == 1 && o.Refresh < a && o.System == 1).ToList();

            foreach (var item in teacher)
            {
                log.Debug("让教师下线:" + item.Username + " 最后刷新时间:" + item.Refresh.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                //Console.WriteLine(item.Username + "  " + item.Refresh.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                item.IsOnline = 0;
                item.IsQueue  = 0;
                item.IsEnable = 0;
            }

            entities.SaveChanges();
            entities.Dispose();
        }
Пример #3
0
        public void Execute(IJobExecutionContext context)
        {
            log.Info("----------now sync calllog----------");
            StudyOnlineEntities entities = new StudyOnlineEntities();

            //过滤条件要求是在当前时间2个小时之前的数据才处理,防止和现在的正在进行的通话冲突处理,因为如果此时正有一个通话,那么他的学生平衡就是不为1的
            DateTime       deadlineTime = DateTime.Now.AddHours(-2);
            List <CallLog> chats        = entities.CallLog.OrderByDescending(o => o.Start).Where(o => o.Start < deadlineTime && o.Finish == null && o.Refresh != null).ToList();

            log.Info("deadlineTime" + deadlineTime.ToString("yyyy-MM-dd HH:mm:ss"));

            foreach (var item in chats)
            {
                //记录下这记录的原始开始时间和结束时间
                log.Info(item.Id + " start:" + item.Start.Value.ToString("yyyy-MM-dd HH:mm:ss") + " refersh:" + item.Refresh.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                item.Finish = item.Refresh;//当结束标记为空的时候,用最后的刷新时间代替
                CallLogController.Balance(item);
            }
            entities.SaveChanges();
            entities.Dispose();
        }
Пример #4
0
        public void Execute(IJobExecutionContext context)
        {
            log.Info("now sync teacher");
            try
            {
                StudyOnlineEntities   entities = new StudyOnlineEntities();
                List <Teacherreginfo> teachers = entities.Teacherreginfo.Where(o => o.IsEnable == 1 && o.IsSync != 1).ToList();
                foreach (var item in teachers)
                {
                    //先创建云信帐号
                    //同步云信帐号系统
                    String json = NimUtil.UserCreate(Guid.NewGuid().ToString().Replace("-", ""), null, null, HttpUtility.UrlEncode(item.Truename));
                    Answer a    = JsonConvert.DeserializeObject <Answer>(json);
                    if (a.code == 200)
                    {
                        //修改数据库状态
                        item.IsSync = 1;

                        //创建新用户
                        NimUser nimUser = new NimUser()
                        {
                            Username = item.Username, Password = item.Password, Category = 1, Accid = a.info.accid, Token = a.info.token, CreateDate = DateTime.Now, IsActive = 1, IsOnline = 0
                        };
                        nimUser.NimUserEx = new NimUserEx()
                        {
                            Email = item.Username, Mobile = item.Phonenumber, Spoken = item.ForeignLanguages, School = item.Education, About = item.Note
                        };
                        entities.NimUser.Add(nimUser);
                    }
                    log.Info(String.Format("Syncint the teacher:{0}", item.Username));
                }

                entities.SaveChanges();
            }
            catch (Exception)
            {
                log.Info("sync failure");
            }
        }