private int callback(IntPtr usrdata, string record_id, int type, byte[] message, int size) { if (stop == "is") { return(0); } int score = 0; if (type == AIENGINE_MESSAGE_TYPE_JSON) { IndexForm aiEngine = (IndexForm)GCHandle.FromIntPtr(usrdata).Target; aiEngine.result = Encoding.UTF8.GetString(message); string mess = Encoding.UTF8.GetString(message); message messg = JsEvent.DecodeJson <message>(mess); if (messg.result != null) { score = int.Parse(messg.result.overall); } } try { if (JsEvent.parameter != null && JsEvent.parameter.zimu != null && JsEvent.parameter.zimu != "") { if (JsEvent.cbId != "-1") { mesage msag = new mesage(); msag.code = 0; msag.msg = ""; msag.data = new data(); msag.data.score = score; string res = JsEvent.EnSerialize <mesage>(msag); JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + JsEvent.cbId + "','" + res + "');"); } else { JsEvent.wb.ExecuteScriptAsync("cpgetScore('" + score + "');"); } } } catch (Exception ee) { new Helper().InsertErrorMsg("窗体关闭" + ee.StackTrace, ee.Message); throw; } return(0); }
//http请求会自动将对象转为json传输,本地化方法不行 \\192.168.3.116 大军共享页面 /// <summary> /// 获取页面水滴json /// </summary> /// <param name="s">userid:book:pageid</param> public void selBookPageData_n(string s) { IndexForm.getJson(s); //clr_pageInit nam = DecodeJson<clr_pageInit>(s); //string Func = nam.cbId; //string jsons = null; //try //{ // string[] pagenum = Regex.Split(nam.Pages, ","); // List<int> pages2 = new List<int>(); // List<string> contents = new List<string>(); // foreach (var p in pagenum) // { // if (!string.IsNullOrWhiteSpace(p)) // { // pages2.Add(int.Parse(p)); // } // } // foreach (var p in pages2) // { // string pgn = "page" + p.ToString().PadLeft(3, '0'); // string folderFullName = AppDomain.CurrentDomain.BaseDirectory + "Page\\data\\" + nam.UserID + "\\" + nam.BookID + "\\resource\\" + pgn + "\\" + pgn + ".json"; // if (File.Exists(folderFullName)) // { // string str = GetConfigStr(folderFullName); // contents.Add(str); // } // } // if (contents.Count != 0) // { // jsons = EnSerialize<List<string>>(contents); // } // string re = EnSerialize<LocalFunMsg>(GetLocalFunMsg(jsons)); // JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + Func + "'," + re + ");"); //} //catch (Exception ex) //{ // LocalFunMsg fas = GetLocalFunMsg("", 1,false, ex.Message); // JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + Func + "'," + fas + ");"); //} }
/// <summary> /// 写本地用户操作日志 /// </summary> /// <param name="operatorInfo"></param> /// <param name="Func"></param> public void userOperLog_n(string s) { IndexForm.getJson(s); //operatorInfo = "{\"UserID\":\"49a92e48-1f39-4382-9273-0a0d521162c6\",\"UserType\":12,\"OperID\":1102,\"Content\":\"备课模块\"}"; string folderFullName = AppDomain.CurrentDomain.BaseDirectory + @"Page\data\userLog.json"; FileStream fs; StreamWriter sw; if (File.Exists(folderFullName)) //验证文件是否存在,有则追加,无则创建 { fs = new FileStream(folderFullName, FileMode.Append, FileAccess.Write); } else { fs = new FileStream(folderFullName, FileMode.Create, FileAccess.Write); } sw = new StreamWriter(fs); sw.WriteLine(s + ";"); sw.Close(); fs.Close(); }
/// <summary> /// 获取教学地图 /// </summary> /// <param name="s"></param> public void getCurTeachMap_n(string s) { IndexForm.getJson(s); //clr_pageInit nam = DecodeJson<clr_pageInit>(s); //string Func = nam.cbId; //try //{ // string folderFullName = AppDomain.CurrentDomain.BaseDirectory + @"Page\data\" + nam.UserID + "\\" + nam.BookID + "\\resource\\" + nam.UnitID + ".json"; // string json = ""; // if (File.Exists(folderFullName)) // { // json = GetConfigStr(folderFullName); // } // // string re = EnSerialize<LocalFunMsg>(GetLocalFunMsg(json)); // LocalFunMsg re = GetLocalFunMsg(json); // string res = EnSerialize<LocalFunMsg>(re); // JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + Func + "'," + res + ");"); //} //catch (Exception ex) //{ // LocalFunMsg fas = GetLocalFunMsg("", 1,false, ex.Message); // JsEvent.wb.ExecuteScriptAsync("sClassJSBridge.handleMessage('" + Func + "'," + fas + ");"); //} }
/// <summary> /// 创建或更新本地老师授课翻页记录 /// </summary> /// <param name="s"></param> /// <param name="Func"></param> public void postTeachPage_n(string s) { IndexForm.getJson(s); //bool ishave = false; ////page = "{\"UserID\":\"49a92e48-1f39-4382-9273-0a0d521162c6\",\"BookType\":null,\"Stage\":null,\"SubjectID\":1,\"EditionID\":27,\"GradeID\":3,\"BookID\":3107,\"UnitID\":290075,\"PageNum\":15,\"PageInitID\":\"A61C09F1-E387-71B1-2E13-0D01E93E5D27\",\"ClassID\":-1,\"CreateTime\":\"/Date(1520579894000)/\",\"AspxName\":\"Teaching\",\"UnitName\":\"2 秋天的图画\"}"; //try //{ // clr_pageInit clr_pageInit = DecodeJson<clr_pageInit>(s); // string folderFullName = AppDomain.CurrentDomain.BaseDirectory + @"Page\data\teachData.json"; // FileStream fs; // StreamWriter sw; // if (File.Exists(folderFullName)) // //验证文件是否存在,有则追加,无则创建 // { // string json = GetConfigStr(folderFullName); // if (json == "") // { // fs = new FileStream(folderFullName, FileMode.Append, FileAccess.Write); // } // else // { // List<string> ss = Regex.Split(json, ";").ToList(); // for (int i = 0; i < ss.Count - 1; i++) // { // clr_pageInit clr_pageInit1 = DecodeJson<clr_pageInit>(ss[i]); // if (clr_pageInit.UserID == clr_pageInit1.UserID && clr_pageInit.ClassID == clr_pageInit1.ClassID && clr_pageInit.BookID.ToString() == clr_pageInit1.BookID.ToString() && clr_pageInit.AspxName == clr_pageInit1.AspxName) // { // ss[i] = s; // ishave = true; // break; // } // } // if (ishave) // { // string strTemp1 = string.Join(";", ss.ToArray()); // s = strTemp1; // fs = new FileStream(folderFullName, FileMode.Create, FileAccess.Write); // } // else // { // fs = new FileStream(folderFullName, FileMode.Append, FileAccess.Write); // } // } // } // else // { // fs = new FileStream(folderFullName, FileMode.Create, FileAccess.Write); // } // sw = new StreamWriter(fs,Encoding.UTF8); // if (ishave) // { // sw.WriteLine(s); // } // else // { // sw.WriteLine(s + ";"); // } // sw.Close(); // fs.Close(); //} //catch (Exception ex) //{ // throw; //} }
public JsEvent(ChromiumWebBrowser wb, IndexForm indexForm) { JsEvent.wb = wb; this.indexForm = indexForm; }
static void Main(string[] args) { try { Process[] allProcess = Process.GetProcesses(); foreach (Process p in allProcess) { if (p.ProcessName == "CefSharp.BrowserSubprocess") { for (int i = 0; i < p.Threads.Count; i++) { p.Threads[i].Dispose(); } p.Kill(); } } } catch (Exception ex) { new Helper().InsertErrorMsg(ex.Message, "关闭进程错误"); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //if (args.Length == 0) //{ // IndexForm inFm = new IndexForm(null); // inFm.Activate(); // Application.Run(inFm); //} //else //{ // IndexForm inFm = new IndexForm(args); // inFm.Activate(); // Application.Run(inFm); //} #region 原主窗体运行块 bool createdNew;//返回是否赋予了使用线程的互斥体初始所属权 System.Threading.Mutex mutex = new System.Threading.Mutex(true, "SmarterClassroomWindows", out createdNew); //该程序一次只能运行一个 if (mutex.WaitOne(0, false)) { if (createdNew) //赋予了线程初始所属权,也就是首次使用互斥体 { //MessageBox.Show("第一个实例"); if (args.Length == 0) { IndexForm inFm = new IndexForm(null); inFm.Activate(); Application.Run(inFm); mutex.ReleaseMutex(); //MessageBox.Show("请使用互动课堂打开!"); //Application.Exit(); } else { try { IndexForm inFm = new IndexForm(args); inFm.Activate(); Application.Run(inFm); mutex.ReleaseMutex(); } catch (Exception ee) { new Helper().InsertErrorMsg(ee.StackTrace, ee.Message); } } } else { Application.Exit(); } } else { //try //{ // Process[] allProcess = Process.GetProcesses(); // foreach (Process p in allProcess) // { // if (p.ProcessName == "SmarterClassroomWindows") // { // for (int i = 0; i < p.Threads.Count; i++) // p.Threads[i].Dispose(); // if (!p.HasExited) // p.Kill(); // } // } // if (args.Length == 0) // { // IndexForm inFm = new IndexForm(null); // inFm.Activate(); // Application.Run(inFm); // mutex.ReleaseMutex(); // } // else // { // IndexForm inFm = new IndexForm(args); // inFm.Activate(); // Application.Run(inFm); // mutex.ReleaseMutex(); // } //} //catch (Exception ee) //{ // new Helper().InsertErrorMsg(ee.StackTrace, ee.Message); //} MessageBox.Show("已经运行一个实例"); Application.Exit(); } #endregion }