public void DispatchResources(ExecutingDispatch action) { var rawUrl = request.RawUrl; try { if (request.Headers.Get("request_code").Contains("realtime_glog")) { StreamReader sr = new StreamReader(request.InputStream); string requestBody = sr.ReadToEnd(); if (label.InvokeRequired) { label.Invoke(new Action <String>(s => { SaveFaceLog(s); }), requestBody); } else { SaveFaceLog(requestBody); } } } catch { action.Invoke(405); return; } action.Invoke(404); }
public void DispatchResources(ExecutingDispatch action) { var rawUrl = request.RawUrl; try { string deviceId = request.Headers.Get("dev_id"); StreamReader sr = new StreamReader(request.InputStream); string requestBody = sr.ReadToEnd(); if (requestBody.Contains("VerifyPush")) { OutText(requestBody); } else if (requestBody.Contains("CardVerify")) { //MyDelegate myDelegateLambda = (string str) => { // SaveCardLog(requestBody); //}; } else if (requestBody.Contains("SnapPush")) { OutTextE(requestBody); } else if (requestBody.Contains("RemoteOpenDoorPush")) { OutText(requestBody); } } catch { return; } action.Invoke(404); }
public void DispatchResources(ExecutingDispatch action) { var rawUrl = request.RawUrl; try { string deviceId = request.Headers.Get("dev_id"); StreamReader sr = new StreamReader(request.InputStream); string requestBody = sr.ReadToEnd(); if (requestBody.Contains("VerifyPush")) { if (label.InvokeRequired) { label.Invoke(new Action <String>(s => { SaveFaceLog(s); }), requestBody); } else { SaveFaceLog(requestBody); } } else if (requestBody.Contains("CardVerify")) { if (label.InvokeRequired) { label.Invoke(new Action <String>(s => { SaveCardLog(s); }), requestBody); } else { SaveCardLog(requestBody); } } else if (requestBody.Contains("IDCardInfoPus")) { if (label.InvokeRequired) { label.Invoke(new Action <String>(s => { SaveFaceLog(s); }), requestBody); } else { SaveFaceLog(requestBody); } } else if (requestBody.Contains("SnapPush")) { if (label.InvokeRequired) { label.Invoke(new Action <String>(s => { SaveSnapLog(s); }), requestBody); } else { SaveSnapLog(requestBody); } } else if (requestBody.Contains("RemoteOpenDoorPush")) { if (label.InvokeRequired) { label.Invoke(new Action <String>(s => { SaveFaceLog(s); }), requestBody); } else { SaveFaceLog(requestBody); } } } catch { return; } action.Invoke(404); }
public void DispatchResources(ExecutingDispatch action) { var rawUrl = request.RawUrl; try { string deviceId = request.Headers.Get("dev_id"); StreamReader sr = new StreamReader(request.InputStream); string requestBody = sr.ReadToEnd(); string sql = ""; int faceCount = 0; int fpsCount = 0; int palmCount = 0; bool isUpdate = false; if (true) { if (request.Headers.Get("request_code").Contains("realtime_glog")) { MonitoringLogs logs = JsonConvert.DeserializeObject <MonitoringLogs>(requestBody); string dataTime = Ole.stringToTimeStr(logs.time); Ole.SaveLogsData(deviceId, logs.userId, dataTime, logs.verifyMode, logs.ioMode.ToString(), logs.inOut); if (recordDataGrid.InvokeRequired) { recordDataGrid.Invoke(new Action <MonitoringLogs>(s => { DataTable dt = (DataTable)recordDataGrid.DataSource; dt.Rows.Add(new object[] { 0, deviceId, s.userId, dataTime, s.verifyMode, s.ioMode.ToString(), s.inOut }); recordDataGrid.DataSource = dt; recordDataGrid.Rows[recordDataGrid.Rows.Count - 1].Selected = true; recordDataGrid.CurrentCell = recordDataGrid.Rows[recordDataGrid.Rows.Count - 1].Cells[0]; Application.DoEvents(); }), logs); } else { DataTable dt = (DataTable)recordDataGrid.DataSource; dt.Rows.Add(new object[] { 0, deviceId, logs.userId, dataTime, logs.verifyMode, logs.ioMode.ToString(), logs.inOut }); recordDataGrid.DataSource = dt; recordDataGrid.Rows[recordDataGrid.Rows.Count - 1].Selected = true; recordDataGrid.CurrentCell = recordDataGrid.Rows[recordDataGrid.Rows.Count - 1].Cells[0]; Application.DoEvents(); } } else if (request.Headers.Get("request_code").Contains("realtime_enroll_data")) { GetUsers UserInfo = JsonConvert.DeserializeObject <GetUsers>(requestBody); if (Ole.SaveUser(UserInfo.userId, UserInfo.name, UserInfo.privilege.ToString(), UserInfo.card, UserInfo.pwd, UserInfo.vaildStart, UserInfo.vaildEnd, ref isUpdate) > 0) { if (UserInfo.photo != null) { sql = "update personlist set [photo]=@photo where [user_id]='" + UserInfo.userId + "'"; string photoStr = UserInfo.photo; Ole.UpdateByteData(sql, "photo", Convert.FromBase64String(photoStr)); } if (UserInfo.face != null) { faceCount++; sql = "update personlist set [face00]=@face00 where [user_id]='" + UserInfo.userId + "'"; string faceStr = UserInfo.face; Ole.UpdateByteData(sql, "face00", Convert.FromBase64String(faceStr)); } if (UserInfo.palm != null) { palmCount++; sql = "update personlist set [palm00]=@palm00 where [user_id]='" + UserInfo.userId + "'"; string palmStr = UserInfo.palm; Ole.UpdateByteData(sql, "palm00", Convert.FromBase64String(palmStr)); } if (UserInfo.fps != null) { for (int j = 0; j < UserInfo.fps.Count; j++) { if (UserInfo.fps[j] != null) { fpsCount++; sql = "update personlist set [fps0" + j + "]=@fps0" + j + " where [user_id]='" + UserInfo.userId + "'"; string fpsStr = UserInfo.fps[j].Replace(" ", "+"); Ole.UpdateByteData(sql, "fps0" + j, Convert.FromBase64String(fpsStr)); } } } } if (!isUpdate) { if (personDataGrid.InvokeRequired) { personDataGrid.Invoke(new Action <GetUsers>(s => { DataTable dt = (DataTable)personDataGrid.DataSource; dt.Rows.Add(new object[] { 0, s.userId, s.name, s.privilege.ToString(), s.card, s.pwd, fpsCount, faceCount, palmCount, s.vaildStart, s.vaildEnd }); personDataGrid.DataSource = dt; personDataGrid.Rows[personDataGrid.Rows.Count - 1].Selected = true; personDataGrid.CurrentCell = personDataGrid.Rows[personDataGrid.Rows.Count - 1].Cells[0]; Application.DoEvents(); }), UserInfo); } else { DataTable dt = (DataTable)personDataGrid.DataSource; dt.Rows.Add(new object[] { 0, UserInfo.userId, UserInfo.name, UserInfo.privilege.ToString(), UserInfo.card, UserInfo.pwd, fpsCount, faceCount, palmCount, UserInfo.vaildStart, UserInfo.vaildEnd }); personDataGrid.DataSource = dt; personDataGrid.Rows[personDataGrid.Rows.Count - 1].Selected = true; personDataGrid.CurrentCell = personDataGrid.Rows[personDataGrid.Rows.Count - 1].Cells[0]; Application.DoEvents(); } } } else { if (request.Headers.Get("request_code").Contains("receive_cmd")) { httpTime time = JsonConvert.DeserializeObject <httpTime>(requestBody); string dataTime = Ole.stringToTimeStr(time.time); if (label.InvokeRequired) { label.Invoke(new Action <String>(s => { label.Text = s; }), dataTime); } else { label.Text = dataTime; } } } } } catch { action.Invoke(405); return; } action.Invoke(404); }
public void DispatchResources(ExecutingDispatch action) { ExchangeData data = new ExchangeData(); try { var rawUrl = request.RawUrl; if (request.Url.Segments.Length == 3 && request.Url.Segments[0] == "/" && request.Url.Segments[1].ToLower() == "api/") {//Filter url UserInfo userInfo = null; MsgInfo msgInfo = null; if (request.HttpMethod == "POST" && request.InputStream.CanRead) { StreamReader reader = new StreamReader(request.InputStream); string bodyContent = reader.ReadToEnd(); userInfo = JsonConvert.DeserializeObject <UserInfo>(bodyContent); msgInfo = JsonConvert.DeserializeObject <MsgInfo>(bodyContent); } if (userInfo == null && userInfo == null && request.HttpMethod == "POST") { data.Data = "No Data!"; } else { data.IsSuccess = true; switch (request.Url.Segments[2].ToLower()) { case "register": var obj = SQLiteHelper.ExecuteScalar(string.Format("Select Id From UserInfo Where Name='{0}'", userInfo.Name)); if (obj != null) { data.IsSuccess = false; data.Data = "The User Has Exist!"; } else { var idObj = SQLiteHelper.ExecuteScalar(string.Format("Insert Into UserInfo(Name,Password,DateTimeStamp)Values('{0}','{1}',{2});select last_insert_rowid() from UserInfo;", userInfo.Name, userInfo.Password, userInfo.DateTimeStamp)); var id = Convert.ToInt32(idObj); data.Data = id; } break; case "login": var tb = SQLiteHelper.ExecuteDataTable(string.Format("Select Id,Name,Password From UserInfo Where Name='{0}' And Password='******'", userInfo.Name, userInfo.Password)); if (tb != null && tb.Rows.Count > 0 && tb.Rows[0]["Id"] != null) { data.Data = tb.Rows[0]["Id"]; } else { data.IsSuccess = false; data.Data = "Login Error"; } break; case "frinds": var dataTable = SQLiteHelper.ExecuteDataTable(string.Format("Select * From UserInfo Where Id!={0}", userInfo.Id)); var users = ConvertDtToModels(dataTable); foreach (var user in users) { var countObj = SQLiteHelper.ExecuteScalar( string.Format("Select count(1) From Message Where SendId={0} AND ReceiveId={1}", user.Id, userInfo.Id)); user.IsNeverChat = Convert.ToInt32(countObj) == 0; } data.Data = users; break; case "online": var OnNum = SQLiteHelper.ExecuteNonQuery(string.Format("Update UserInfo Set OnLine=1 Where Id={0}", userInfo.Id)); data.Data = OnNum > 0; break; case "offline": var num = SQLiteHelper.ExecuteNonQuery(string.Format("Update UserInfo Set OnLine=0 Where Id={0}", userInfo.Id)); data.Data = num > 0; break; case "message": if (msgInfo == null) { data.IsSuccess = false; data.Data = "No Data!"; } else { var mnum = SQLiteHelper.ExecuteNonQuery(string.Format("Insert Into Message(SendId,ReceiveId,Content,DateTimeStamp)Values({0},{1},'{2}',{3})", msgInfo.SendId, msgInfo.ReceiveId, msgInfo.Content, msgInfo.DateTimeStamp)); data.Data = mnum > 0; } break; case "getmessage": var localUserId = request.QueryString["lId"]; var remoteUserId = request.QueryString["rId"]; var dt = SQLiteHelper.ExecuteDataTable(string.Format("Select * from Message where sendId={0} and ReceiveId={1} order by DateTimeStamp desc limit 0,10", remoteUserId, localUserId)); var list = new List <MsgInfo>(); for (int i = dt.Rows.Count - 1; i >= 0; i--) { var item = new MsgInfo(); item.Id = Convert.ToInt32(dt.Rows[i]["Id"]); item.DateTimeStamp = Convert.ToInt32(dt.Rows[i]["DateTimeStamp"]); item.SendId = Convert.ToInt32(dt.Rows[i]["SendId"]); item.ReceiveId = Convert.ToInt32(dt.Rows[i]["ReceiveId"]); item.Content = dt.Rows[i]["Content"].ToString(); // item.IsRead = (int)dt.Rows[i]["IsRead"]; list.Add(item); } data.Data = list; break; default: data.IsSuccess = false; break; } } } else { data.IsSuccess = false; } } catch (Exception ex) { data.IsSuccess = false; data.Data = ex; } action?.Invoke(data); }
public void DispatchResources(ExecutingDispatch action) { var rawUrl = request.RawUrl; try { string expStr = ""; StreamReader sr = new StreamReader(request.InputStream); String requestBody = sr.ReadToEnd(); //String[] requestData = requestBody.Split(new char[1] { '=' }); if (true /*requestData.Length == 2 && requestData[0] == "data"*/) { if (Regex.IsMatch(rawUrl, "/attendance*")) { IdentityCallBack renshi; expStr = HttpUtility.UrlDecode(requestBody /*requestData[1]*/); renshi = JsonConvert.DeserializeObject <IdentityCallBack>(expStr); expStr = "人脸识别=> IP:" + renshi.ip + ", 人员ID:" + renshi.personId + ",识别结果:" + renshi.type + ", 识别照片:" + renshi.path; if (Regex.IsMatch(renshi.type, "face_?")) { int si = renshi.path.LastIndexOf("/") + 1; int el = renshi.path.Length; string fname = renshi.path.Substring(si, el - si); string localfile = "ShiBieimages" + @"\" + fname; if (!Directory.Exists("ShiBieimages")) { Directory.CreateDirectory("ShiBieimages"); } System.Net.FtpWebRequest ftp = GetRequest(renshi.path, "", ""); ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; ftp.UseBinary = true; ftp.UsePassive = false; using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (FileStream fs = new FileStream(localfile, FileMode.CreateNew)) { try { byte[] buffer = new byte[2048]; int read = 0; do { read = responseStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, read); } while (!(read == 0)); responseStream.Close(); fs.Flush(); fs.Close(); } catch (Exception) { //catch error and delete file only partially downloaded fs.Close(); //delete target file as it's incomplete File.Delete(localfile); } } } } /*byte[] bImg = Convert.FromBase64String(renshi.feature); * string createionPath = "ShiBieimages/" + renshi.personId + ".jpg"; * FileStream _fs = File.Create(createionPath); * _fs.Write(bImg, 0, bImg.Length); * _fs.Close();*/ if (picBox.InvokeRequired) { picBox.Invoke(new Action <String>(s => { picBox.ImageLocation = s; }), "ShiBieimages/" + fname); } else { picBox.ImageLocation = "ShiBieimages/" + fname; } } } else if (Regex.IsMatch(rawUrl, "/heartbeat*")) { DeviceHeartBeat heartbeat; expStr = HttpUtility.UrlDecode(requestBody /*requestData[1]*/); heartbeat = JsonConvert.DeserializeObject <DeviceHeartBeat>(expStr); expStr = "设备动态=> 设备序列号:" + heartbeat.deviceKey + ",IP:" + heartbeat.ip + ",人员数量:" + heartbeat.personCount + ",人脸数量:" + heartbeat.faceCount + ",设备时间:" + heartbeat.time + ", 版本:" + heartbeat.version; } else if (Regex.IsMatch(rawUrl, "/imgreg*")) { ImgRegCallBack zhaopian; expStr = HttpUtility.UrlDecode(requestBody /*requestData[1]*/); zhaopian = JsonConvert.DeserializeObject <ImgRegCallBack>(expStr); expStr = "人脸登录=> 设备序列号:" + zhaopian.deviceKey + ",IP:" + zhaopian.ip + ",人员ID:" + zhaopian.personId + ",照片ID:" + zhaopian.faceId + " 照片文件名:" + zhaopian.newImgPath; if (!Directory.Exists("images")) { Directory.CreateDirectory("images"); } int si = zhaopian.newImgPath.LastIndexOf("/") + 1; int el = zhaopian.newImgPath.Length; string fname = zhaopian.newImgPath.Substring(si, el - si); string localfile = "images" + @"\" + fname; if (!Directory.Exists("images")) { Directory.CreateDirectory("images"); } System.Net.FtpWebRequest ftp = GetRequest(zhaopian.newImgPath, "", ""); ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; ftp.UseBinary = true; ftp.UsePassive = false; using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (FileStream fs = new FileStream(localfile, FileMode.CreateNew)) { try { byte[] buffer = new byte[2048]; int read = 0; do { read = responseStream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, read); } while (!(read == 0)); responseStream.Close(); fs.Flush(); fs.Close(); } catch (Exception) { //catch error and delete file only partially downloaded fs.Close(); //delete target file as it's incomplete File.Delete(localfile); } } } } /* byte[] bImg = Convert.FromBase64String(zhaopian.feature); * string createionPath = "images/" + zhaopian.faceId + ".jpg"; * FileStream _fs = File.Create(createionPath); * _fs.Write(bImg, 0, bImg.Length); * _fs.Close();*/ } // parse is sucessed if (expStr != "") { try { if (logText.InvokeRequired) { logText.Invoke(new Action <String>(s => { logText.AppendText(s + Environment.NewLine); logText.ScrollToCaret(); }), expStr); } else { logText.AppendText(expStr + Environment.NewLine); logText.ScrollToCaret(); } action.Invoke(200); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } //else //{ // action.Invoke(404); //} } catch (Exception e) { action.Invoke(405); Console.WriteLine(e.Message); return; } action.Invoke(404); /*string filePath = string.Format(@"{0}/wwwroot{1}", Environment.CurrentDirectory, rawUrl);//这里对应请求其他类型资源,如图片,文本等 * if (rawUrl.Length==1) * filePath = string.Format(@"{0}/wwwroot/index.html", Environment.CurrentDirectory);//默认访问文件 * try { * if (File.Exists(filePath)) * { * FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite); * action.Invoke(fs); * * } * } * catch { return; }*/ }