private void SettingButton_Click(object sender, RoutedEventArgs e) { SettingWindow settingWindow = new SettingWindow(); settingWindow.ShowDialog(); if (settingWindow.DialogResult == true) { TempWarning.Instance().SetLength(AIThermometerAPP.Instance().config.warning_bar_length); } }
public AppMainWindow() { InitializeComponent(); ServerHelper.Instance().ewHandler += ErrorWindowShow; ServerHelper.Instance().captureHandler += Shot; VclCamInit(); TempWarning tmp = TempWarning.Instance(); tmp.SetLength(warning_bar_length); tmp.addedWarningInfo += new TempWarning.AddedQueueEventHandler(AddTemp); aTimer = new System.Timers.Timer(); aTimer.Elapsed += new System.Timers.ElapsedEventHandler(dt_Tick); aTimer.Interval = 1000;//每秒执行一次 aTimer.Enabled = true; aTimer.Start(); SetLabel(); CultureInfo ci = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; }
private void HttpThread(object c) { var context = c as HttpListenerContext; string endPoint = context.Request.RemoteEndPoint.ToString(); int spIndex = endPoint.IndexOf(":"); endPoint = endPoint.Substring(0, spIndex); using (HttpListenerResponse response = context.Response) { if (!context.Request.HasEntityBody)//无数据 { response.StatusCode = 403; return; } string attachValue = ""; //post 的方式有文件上传的在如下解析即可得到客户端参数及值 HttpListenerRequest request = context.Request; if (request.ContentType.Length > 20 && string.Compare(request.ContentType.Substring(0, 20), "multipart/form-data;", true) == 0) { List <Values> lst = new List <Values>(); Encoding Encoding = request.ContentEncoding; string[] values = request.ContentType.Split(';').Skip(1).ToArray(); string boundary = string.Join(";", values).Replace("boundary=", "").Trim(); byte[] ChunkBoundary = Encoding.GetBytes("--" + boundary + "\r\n"); byte[] EndBoundary = Encoding.GetBytes("--" + boundary + "--\r\n"); Stream SourceStream = request.InputStream; var resultStream = new MemoryStream(); bool CanMoveNext = true; Values data = null; while (CanMoveNext) { byte[] currentChunk = ReadLineAsBytes(SourceStream); if (!Encoding.GetString(currentChunk).Equals("\r\n")) { resultStream.Write(currentChunk, 0, currentChunk.Length); } if (CompareBytes(ChunkBoundary, currentChunk)) { byte[] result = new byte[resultStream.Length - ChunkBoundary.Length]; resultStream.Position = 0; resultStream.Read(result, 0, result.Length); CanMoveNext = true; if (result.Length > 0) { data.datas = result; } data = new Values(); lst.Add(data); resultStream.Dispose(); resultStream = new MemoryStream(); } else if (Encoding.GetString(currentChunk).Contains("Content-Disposition")) { byte[] result = new byte[resultStream.Length - 2]; resultStream.Position = 0; resultStream.Read(result, 0, result.Length); CanMoveNext = true; data.name = Encoding.GetString(result).Replace("Content-Disposition: form-data; name=\"", "").Replace("\"", "").Split(';')[0]; resultStream.Dispose(); resultStream = new MemoryStream(); } else if (Encoding.GetString(currentChunk).Contains("Content-Type")) { CanMoveNext = true; data.type = 1; resultStream.Dispose(); resultStream = new MemoryStream(); } else if (CompareBytes(EndBoundary, currentChunk)) { byte[] result = new byte[resultStream.Length - EndBoundary.Length - 2]; resultStream.Position = 0; resultStream.Read(result, 0, result.Length); data.datas = result; resultStream.Dispose(); CanMoveNext = false; } } TempMessage tm = new TempMessage(); foreach (var key in lst) { if (key.type == 0) { string value = Encoding.GetString(key.datas).Replace("\r\n", ""); if (key.name == "attachValue") { attachValue = value; } } if (key.type == 1) { tm.bytes = key.datas; /* * FileStream fs = new FileStream("c:\\3.jpg", FileMode.Create); * fs.Write(key.datas, 0, key.datas.Length); * fs.Close(); * fs.Dispose(); */ } } LogHelper.WriteLog(attachValue); CameraWarning items = JsonHelper.FromJSON <CameraWarning>(attachValue); tm.cam = AIThermometerAPP.Instance().cameras_config.GetNameByIP(endPoint); if (items.Code == 0 && !AIThermometerAPP.Instance().blackcell_pos_error) { tm.temp = items.Reports[0].Temperature; tm.id = items.Reports[0].objId; tm.date = DateTime.Now; string file_name = tm.date.ToString("yyMMdd") + "\\"; if (tm.temp > AIThermometerAPP.Instance().TempLimit()) { file_name = file_name + "nopass\\"; AIThermometerAPP.Instance().AddNoPassFace(); VoicePlayer.Instance().Play(); } else { file_name = file_name + "pass\\"; AIThermometerAPP.Instance().AddPassFace(); } if (AIThermometerAPP.Instance().CanCapture()) { captureHandler?.Invoke(AIThermometerAPP.Instance().CapturePath() + "\\" + DateTime.Now.ToString("yyMMddHHmmssffff") + ".jpeg", CamMode.NORMAL); } Common.CreateDir(image_dir_path + "\\" + file_name); file_name = file_name + tm.date.ToString("HHmmssffff") + tm.temp.ToString().Replace(".", "_") + ".jpeg"; tm.photo_path = image_dir_path + "\\" + file_name; TempWarning.Instance().Push(tm); } else { // 黑体位置错误 if (!AIThermometerAPP.Instance().blackcell_pos_error) { AIThermometerAPP.Instance().blackcell_pos_error = true; ewHandler?.Invoke(Application.Current.FindResource("errorText").ToString(), Application.Current.FindResource("error8").ToString()); AIThermometerAPP.Instance().ResetBlackCell(); } } } response.ContentType = "text/html;charset=utf-8"; response.StatusCode = 200; return; try { using (System.IO.Stream output = response.OutputStream) using (StreamWriter writer = new StreamWriter(output, Encoding.UTF8)) writer.WriteLine("接收完成!"); } catch { } response.Close(); } }