public static int AddEvent(string action, string request, string filepath, string tm)
        {
            if (curLessonEvents == null)
            {
                curLessonEvents          = new LessonEvents();
                curLessonEvents.lessonid = Global.getLessonID();//之前有网,上课过程中突然中断。。。
            }

            LessonEvent     ev       = new LessonEvent(action, request, filepath, tm);
            string          strEvent = ev.toJson();
            LessonEventType type     = (LessonEventType)ev.type;

            if (type == LessonEventType.Unknown)
            {
                Log.Info("Offline LessonEvent_Ignore: " + strEvent);
                return(0);
            }

            Log.Info("Offline LessonEvent: " + strEvent);
            if (type == LessonEventType.ClassOn)
            {
                if (curLessonEvents != null)
                {
                    WriteFile(curLessonEvents);
                    curLessonEvents = null;
                }
                curLessonEvents = new LessonEvents();
                curLessonEvents.addEvent(ev);
            }
            else if (type == LessonEventType.ClassOff)
            {
                curLessonEvents.addEvent(ev);
                //TODO: 写文件
                WriteFile(curLessonEvents);
                curLessonEvents = null;
            }
            else
            {
                curLessonEvents.addEvent(ev);
            }
            return(0);
        }
        private static int WriteFile(LessonEvents le)
        {
            if (le.eventlist == null)
            {
                return(0);
            }

            if (le.eventlist.Count < 3)
            {
                return(0);
            }

            string   data      = le.toJson();
            string   strBase64 = RueHelper.util.Util.toBase64(data);
            string   filename  = "lesson_" + curLessonEvents.createtime.Replace(" ", "").Replace("-", "").Replace(":", "") + ".txt";
            string   filepath  = Application.StartupPath + "\\" + DateTime.Now.ToString("yyyyMMdd");
            FileOper fo        = new FileOper(filepath, filename);

            fo.WriteFile(data);
            return(0);
        }
        public static int UploadHistoryData()
        {
            //遍历近七天的目录
            int count = 0;

            for (int i = 0; i < 7; i++)
            {
                string dir = Application.StartupPath + "\\" + DateTime.Now.AddDays(0 - i).ToString("yyyyMMdd");
                if (!Directory.Exists(dir))
                {
                    continue;
                }
                string[] szPath = Directory.GetFiles(dir);
                int      result = 0;
                foreach (string path in szPath)
                {
                    string filename = Path.GetFileName(path);
                    if (filename.StartsWith("lesson_") && filename.EndsWith(".txt"))
                    {
                        FileOper fo   = new FileOper(dir, filename);
                        string   data = fo.ReadFile();

                        //base64
                        LessonEvents le = JsonOper.DeserializeJsonToObject <LessonEvents>(data);
                        if (le.eventlist == null || le.eventlist.Count < 3)
                        {
                            File.Delete(path);
                            continue;
                        }
                        int ret = Common.uploadOfflineData(le);
                        if (ret > 0)
                        {
                            File.Delete(path);
                        }
                    }
                }
            }
            return(count);
        }