public void Authorization() { try { LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 收到终端授权请求"); Stream inputStream = Request.GetBufferedInputStream(); Stream outputStream = Response.OutputStream; AuthorizationRequest real = RealTimeAnalysis.analysisAuthorizationReq(inputStream); if (RealTimeThread.dic.ContainsKey(real.TerminalId)) { CarInfo info = RealTimeThread.dic[real.TerminalId] as CarInfo; if (info == null) { info.Power = int.Parse(real.Power); info.Voltage = int.Parse(real.Voltage); info.Current = int.Parse(real.Current); info.Temperature = int.Parse(real.Temperature); RealTimeThread.dic[real.TerminalId] = info; } } else { CarInfo c = new CarInfo(); c.Power = int.Parse(real.Power); c.Voltage = int.Parse(real.Voltage); c.Current = int.Parse(real.Current); c.Temperature = int.Parse(real.Temperature); RealTimeThread.dic.Add(real.TerminalId, c); } if (real != null) { byte[] outs = orderbll.uploadAuthorization(real); Thread.Sleep(1000); if (outs != null) { outputStream.WriteByte(0xd3); outputStream.WriteByte(0xd3); outputStream.Write(outs, 0, outs.Length); LogerHelper.DefaultInfo(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " 下发终端授权响应" + ByteUtils.byteToHexStr(outs)); //修改订单状态为已使用 outputStream.Flush(); } } outputStream.Close(); inputStream.Close(); }catch (Exception e) { LogerHelper.exception("error occured!", e); } }
private string SaveFile(HttpPostedFileBase file, string path) { try { if (file != null) { string legalCard = Guid.NewGuid().ToString().Replace("-", "") + "_" + Path.GetFileName(file.FileName); //string paths=AppDomain.CurrentDomain.BaseDirectory; path = "/upload/images/" + legalCard; file.SaveAs(Server.MapPath("~" + path)); } } catch (Exception ex) { LogerHelper.exception("图片上传失败!", ex); } return(path); }
//异常 public static void Exception(System.Web.Routing.RequestContext requestContext, Exception obj) { LogerHelper.exception(string.Format("异常说明:{0}/{1} {2} {3}", requestContext.RouteData.Values["controller"], requestContext.RouteData.Values["action"], obj.Source, obj.InnerException == null ? obj.Message : obj.InnerException.Message), obj); }