using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO; using System.Reflection; using System.Collections; namespace HardWareInteface.Handle { /// /// XCZDCarRec 的摘要说明 //新城中队 /// public class XCZDCarRec : IHttpHandler { string UpFileAddr = System.Configuration.ConfigurationManager.AppSettings["SqlConnectionStr"]; FangYar.BLL.TBL_CARACCESS bll = new FangYar.BLL.TBL_CARACCESS(); FangYar.BLL.TBL_SYS_CAR car_bll = new FangYar.BLL.TBL_SYS_CAR(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string returnStr = ""; returnStr = ReceiveAlarmInfoPlate(context); context.Response.Write(returnStr); } private string ReceiveAlarmInfoPlate(HttpContext context) { WriteLog("进入!"); HttpRequest request = context.Request; Stream stream = request.InputStream; string data = string.Empty; string response = string.Empty; bool isadd = false; if (stream.Length != 0) { try { StreamReader streamReader = new StreamReader(stream); data = streamReader.ReadToEnd(); WriteLog(data.ToString()); #region 用于传递数据的输出 if (stream.Length != 0) { WriteLog(data.ToString()); } #endregion string[] sArray = data.Split('&'); FangYar.Model.TBL_CARACCESS model = new FangYar.Model.TBL_CARACCESS(); for (int i = 0; i < sArray.Length; i++) { string[] keyValue = sArray[i].Split('='); PropertyInfo[] propertys = model.GetType().GetProperties(); Hashtable ht = new Hashtable(); if (keyValue[0].ToUpper() == "TYPE" && keyValue[1] != "online") { isadd = false; break; } else if (keyValue[0].ToUpper() == "TYPE") { model.TYPE = keyValue[1]; } else if (keyValue[0].ToUpper() == "PLATE_NUM") { model.CAR_PLATE = keyValue[1]; } else if (keyValue[0].ToUpper() == "PLATE_COLOR") { model.COLOR = keyValue[1]; } else if (keyValue[0].ToUpper() == "CAR_COLOR") { model.CAR_COLOR = keyValue[1]; } else if (keyValue[0].ToUpper() == "CAR_LOGO") { model.CAR_LOGO = keyValue[1]; } else if (keyValue[0].ToUpper() == "PARK_ID") { model.PARK_ID = keyValue[1]; } else if (keyValue[0].ToUpper() == "CAM_ID") { model.CAMERA_ID = keyValue[1]; if (keyValue[1] == "18030004bdef")//进 { model.INOROUT = "0"; } else { model.INOROUT = "1"; } } else if (keyValue[0].ToUpper() == "START_TIME") { string str = keyValue[1]; long unixTimeStamp = long.Parse(str); System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区 DateTime dt = startTime.AddSeconds(unixTimeStamp); model.START_TIME = dt; } else if (keyValue[0].ToUpper() == "PICTURE") { string str = keyValue[1].Replace('-', '+').Replace('_', '/').Replace('.', '='); string dummyData = str.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+"); if (dummyData.Length % 4 > 0) { dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '='); } byte[] byteArray = Convert.FromBase64String(dummyData); //model.PICTURE = byteArray; model.EXTEND2 = GetFilePath(byteArray, "0"); //string str123 = GetFilePath(byteArray,"0"); } else if (keyValue[0].ToUpper() == "CLOSEUP_PIC") { string str = keyValue[1].Replace('-', '+').Replace('_', '/').Replace('.', '='); string dummyData = str.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+"); if (dummyData.Length % 4 > 0) { dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '='); } byte[] byteArray = Convert.FromBase64String(dummyData); //model.CLOSEUP_PIC = byteArray; model.EXTEND3 = GetFilePath(byteArray, "1"); //string str123 = GetFilePath(byteArray, "1"); } isadd = true; } if (isadd) { model.ID = Guid.NewGuid().ToString("N"); model.ORG_ID = "87AE04BCA76F4DD29F470FDBAF8483A8"; FangYar.Model.TBL_SYS_CAR car_model = car_bll.CarNumGetModel(model.ORG_ID, model.CAR_PLATE); if (car_model != null) { model.CLASS = car_model.CLASS; } else { model.CLASS = "2"; } isadd = bll.Add(model); } } catch (Exception e) { WriteLog(e.Message); } } else { WriteLog("输入流的长度为0!"); } if (isadd == true) { return "true"; } else { return "false"; } } /// /// base转图片保存到服务器 /// /// private string GetFilePath(byte[] bytes,string strType) { string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();//年月 string ImageFilePath = "/Attachment" + "/Car/xczd/" + DateTime.Now.Year.ToString() + "/"+DateTime.Now.Month.ToString(); if (System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(ImageFilePath)) == false)//如果不存在就创建文件夹 { System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(ImageFilePath)); } string ImagePath , DbImagePath; //string str = System.DateTime.Now.ToString("yyyyHHddHHmmss"); string str = System.DateTime.Now.ToString("yyyyHHddHHmmssfff") + Guid.NewGuid().ToString(); if (strType == "0")//全景图 { DbImagePath=ImageFilePath + "/" + str;//定义图片名称 ImagePath = HttpContext.Current.Server.MapPath(ImageFilePath) + "/" + str;//定义图片名称 } else { DbImagePath=ImageFilePath + "/Plate" + str;//定义图片名称 ImagePath = HttpContext.Current.Server.MapPath(ImageFilePath) + "/Plate" + str;//定义图片名称 } File.WriteAllBytes(ImagePath + ".png", bytes); //保存图片到服务器,然后获取路径 return DbImagePath + ".png";//获取保存后的路径 } private void WriteLog(string msg) { FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = msg, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "caraccess_xczd" }); //string path = AppDomain.CurrentDomain.BaseDirectory + "log\\caraccess_xczd\\"; //string filename = DateTime.Now.ToString("yyyyMMdd") + ".txt"; //if (Directory.Exists(path) == false)//如果不存在就创建文件夹 //{ // Directory.CreateDirectory(path); //} //FileInfo file = new FileInfo(path + filename); //if (!file.Exists) //{ // FileStream fs; // fs = File.Create(path + filename); // fs.Close(); //} //using (FileStream fs = new FileStream(path + filename, FileMode.Append, FileAccess.Write)) //{ // using (StreamWriter sw = new StreamWriter(fs)) // { // sw.WriteLine("时间:" + DateTime.Now.ToString() + " 信息:" + msg); // } //} } public bool IsReusable { get { return false; } } } }