public static void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) //定时程序 { // 得到 hour minute second 如果等于某个值就开始执行某个程序。 int intHour = e.SignalTime.Hour; int intMinute = e.SignalTime.Minute; int intSecond = e.SignalTime.Second; if (intSecond == 0)//每分钟执行脚本 { LuaEnv.RunLua("", "envent/TimerMinute.lua"); } //删除过期图片文件 DirectoryInfo downloadDir = new DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "data/image/"); FileSystemInfo[] downloadFiles = downloadDir.GetFileSystemInfos(); for (int i = 0; i < downloadFiles.Length; i++) { FileInfo file = downloadFiles[i] as FileInfo; //是文件 if (file != null && file.Name.IndexOf(".luatemp") == file.Name.Length - (".luatemp").Length) { TimeSpan time = DateTime.Now - file.CreationTime; if (time.TotalSeconds > 60) { file.Delete(); } } } //删除过期语音文件 DirectoryInfo recordDir = new DirectoryInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "data/record/"); FileSystemInfo[] recordFiles = recordDir.GetFileSystemInfos(); for (int i = 0; i < recordFiles.Length; i++) { FileInfo file = recordFiles[i] as FileInfo; //是文件 if (file != null) { TimeSpan time = DateTime.Now - file.CreationTime; if (time.TotalSeconds > 60) { file.Delete(); } } } }
public static void Start() { try { server.StringEncoder = Encoding.UTF8; server.Start(23333); Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Info, "tcp server", "tcp server started!"); server.DataReceived += (sender, msg) => { LuaEnv.RunLua( $"message=[[{msg.MessageString.Replace("]", "] ")}]] ", "envent/ReceiveTcp.lua"); }; } catch (Exception e) { Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "tcp server", "tcp server start failed!\r\n" + e.ToString()); } //消息发送队列 Task.Run(() => { try { while (true) { while (toSend.Count > 0) { string temp; toSend.TryTake(out temp); server.Broadcast(temp); Task.Delay(packTime).Wait(); } Task.Delay(200).Wait();//等等,防止卡死 } } catch (Exception e) { Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Fatal, "tcp server", "tcp server loop failed!\r\n" + e.Message); } }); }
private static void HttpPostRequestHandle() { while (true) { HttpListenerContext requestContext = httpPostRequest.GetContext(); Thread threadsub = new Thread(new ParameterizedThreadStart((requestcontext) => { HttpListenerContext request = (HttpListenerContext)requestcontext; //获取Post请求中的参数和值帮助类 HttpListenerPostParaHelper httppost = new HttpListenerPostParaHelper(request); //获取Post过来的参数和数据 string lst = httppost.GetHttpListenerPostValue(); //Response request.Response.StatusCode = 200; request.Response.Headers.Add("Access-Control-Allow-Origin", "*"); request.Response.ContentType = "application/json"; requestContext.Response.ContentEncoding = Encoding.UTF8; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(new { success = "true", msg = "" })); request.Response.ContentLength64 = buffer.Length; var output = request.Response.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); //处理数据 lst = lst.Substring(lst.IndexOf("{"), lst.LastIndexOf("}") - lst.IndexOf("{") + 1); LuaEnv.RunLua( "", "envent/ReceiveExpressPush.lua", new ArrayList() { "data", lst, }); })); threadsub.Start(requestContext); } }
public static void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) //1s定时程序 { // 得到 hour minute second 如果等于某个值就开始执行某个程序。 int intHour = e.SignalTime.Hour; int intMinute = e.SignalTime.Minute; int intSecond = e.SignalTime.Second; count++; if (count >= luaWait)//每分钟执行脚本 { count = 0; LuaEnv.RunLua("", "envent/TimerMinute.lua"); } //检查升级 if (intSecond == 0 && intMinute == 0 && intHour == 3) { //检查是否开启了检查更新 if (XmlApi.xml_get("settings", "autoUpdate").ToUpper() != "TRUE") { return; } Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Info, "lua脚本更新检查", "正在检查脚本更新"); string gitPath = Common.AppDirectory + "git/"; if (!Repository.IsValid(gitPath)) { Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Error, "lua脚本更新检查", "未检测到git仓库!"); return;//工程不存在 } using (var repo = new Repository(gitPath)) { string lastCommit = repo.Commits.First().Sha;//当前提交的特征值 // Credential information to fetch LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions(); options.FetchOptions = new FetchOptions(); // User information to create a merge commit var signature = new LibGit2Sharp.Signature( new Identity("MERGE_USER_NAME", "MERGE_USER_EMAIL"), DateTimeOffset.Now); // Pull try { Commands.Pull(repo, signature, options); } catch { Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Warning, "lua脚本更新检查", "代码拉取失败,请检查网络!"); return; } string newCommit = repo.Commits.First().Sha;//pull后的特征值 if (lastCommit != newCommit) { Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Info, "lua脚本更新检查", "检测到更新内容,正在替换脚本\r\n" + "注意可能会出现消息报错,无视就好"); Directory.Delete(Common.AppDirectory + "lua", true); Tools.CopyDirectory(gitPath + "appdata/lua", Common.AppDirectory + "lua"); Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Info, "lua脚本更新检查", "脚本更新完成!"); } else { Common.CqApi.AddLoger(Sdk.Cqp.Enum.LogerLevel.Info, "lua脚本更新检查", "没有检测到脚本更新"); } } } }