public UpdateResult CheckUpdate() { var response = this.Send(this.Config.GetString("UPDATEURL"), new Dictionary <string, string>(), new Dictionary <string, byte[]>()); var result = IPSCMJsonConvert.Parse <UpdateResult>(response); return(result); }
public ImageUpdateTransaction(String plateNumber, String time, String type, Byte[] image, Stream responseStream) { this.ProcessThread = new Thread(() => { try { StreamUtils.WriteToStreamWithUF8(responseStream, IPSCMJsonConvert.ConvertToJson(new Result() { ResultCode = ResultCode.Success })); responseStream.Flush(); responseStream.Close(); Engine.GetEngine().CloudParking.ImageUpload(plateNumber, time, type, image); this.Status = TransactionStatus.Exhausted; } catch (Exception ex) { Logging.Log.Error("Image upload encountered a bad error!", ex); this.Status = TransactionStatus.Errored; } finally { responseStream.Flush(); responseStream.Close(); } }); }
public SurplusSpaceUpdateTransaction(UInt16 surplusSpace, Stream responseStream) { this.SurplusSpace = surplusSpace; this.WorkThread = new Thread(() => { try { StreamUtils.WriteToStreamWithUF8(responseStream, IPSCMJsonConvert.ConvertToJson(new Result { ResultCode = ResultCode.Success })); responseStream.Flush(); responseStream.Close(); var result = Engine.GetEngine().CloudParking.SurplusSpaceUpdate(surplusSpace); if (result.ResultCode != ResultCode.Success) { throw new NotSupportedException("Surplus SpaceUpdate Transaction do not support result code:" + result.ResultCode); } this.Status = TransactionStatus.Exhausted; } catch (Exception ex) { Log.Error("Surplus SpaceUpdate Transaction encountered a bad error!", ex); this.Status = TransactionStatus.Errored; } finally { responseStream.Flush(); responseStream.Close(); } }); }
public Result SurplusSpaceUpdate(UInt16 surplusSpace) { var stringData = new Dictionary <string, string> { { this.Config.GetString("SURPLUSSPACE"), surplusSpace.ToString() } }; var response = this.Send(this.Config.GetString("UPDATEURL"), stringData, null); var result = IPSCMJsonConvert.Parse <Result>(response); return(result); }
public ParkingTransaction(String plateNum, DateTime inTime, Byte[] inImage, Stream responseStream) { this.plateNumber = plateNum; this.InTime = inTime; this.InImage = inImage; this.ResponseStream = responseStream; this.WorkThread = new Thread(i => { try { var json = IPSCMJsonConvert.ConvertToJson(new Result { ResultCode = ResultCode.Success }); StreamUtils.WriteToStreamWithUF8(this.ResponseStream, json); this.ResponseStream.Flush(); this.ResponseStream.Close(); var Id = Engine.GetEngine().Storage.PreCarPark(this.plateNumber, this.InTime); var result = Engine.GetEngine().CloudParking.Parking(plateNum, inTime, inImage); switch (result.ResultCode) { case ResultCode.Success: { Engine.GetEngine().Storage.PostCarPark(Id, this.plateNumber, result); break; } case ResultCode.SuccessButNoBinding: { break; } default: { Log.Error(String.Format("Unexpected result code:{0}", result.ResultCode)); break; } } this.Status = TransactionStatus.Exhausted; } catch (Exception ex) { Log.Error("Parking Transaction encountered a exception", ex); this.Status = TransactionStatus.Errored; } finally { this.ResponseStream.Flush(); this.ResponseStream.Close(); } }); }
public ParkingResult Parking(String plateNumber, DateTime inTime, Byte[] inImg) { var stringData = new Dictionary <string, string>(); var binaryData = new Dictionary <String, Byte[]>(); stringData.Add(Config.GetString("PlateNumber"), plateNumber); stringData.Add(Config.GetString("InTime"), inTime.ToString("yyyy-MM-dd HH:mm:ss")); binaryData.Add(Config.GetString("InImage"), inImg); var responseJson = this.Send(this.Config.GetString("ParkUrl"), stringData, binaryData); var parkingRes = IPSCMJsonConvert.Parse <ParkingResult>(responseJson); return(parkingRes); }
public Result ImageUpload(String plateNumber, String time, String type, Byte[] image) { var stringData = new Dictionary <string, string>(); var binaryData = new Dictionary <String, Byte[]>(); stringData.Add(Config.GetString("PlateNumber"), plateNumber); stringData.Add(Config.GetString("IMAGETIME"), time); stringData.Add(Config.GetString("IMAGETYPE"), type); binaryData.Add(Config.GetString("IMAGE"), image); var response = this.Send(this.Config.GetString("IMAGEUPDATEURL"), stringData, binaryData); var result = IPSCMJsonConvert.Parse <Result>(response); return(result); }
public HeartBeatResult HeartBeat() { var response = this.Send ( this.Config.GetString("HEARTBEATURL"), new Dictionary <string, string>(), new Dictionary <string, byte[]>() ); var heartBeatResult = IPSCMJsonConvert.Parse <HeartBeatResult>(response); var trigger = this.OnHeartBeat; if (trigger != null) { trigger(this, new HeartBeatEventArgs(heartBeatResult)); } return(heartBeatResult); }
public ExtractCouponTransaction(String plateNumber, Stream responseStream) { this.PlateNumber = plateNumber; this.ProcessThread = new Thread(() => { try { var result = new CouponResult { ResultCode = ResultCode.Success }; var ticket = Engine.GetEngine().Storage.GetTicketByPlateNumber(plateNumber); if (ticket == null) { StreamUtils.WriteToStreamWithUF8(responseStream, IPSCMJsonConvert.ConvertToJson(new Result { ResultCode = ResultCode.SuccessButNoBinding })); } else { result.Info = new CouponInfo { TicketId = ticket.TicketId, Type = ticket.Type, Value = ticket.Value }; StreamUtils.WriteToStreamWithUF8(responseStream, IPSCMJsonConvert.ConvertToJson(result)); } responseStream.Flush(); responseStream.Close(); this.Status = TransactionStatus.Exhausted; } catch (Exception ex) { this.Status = TransactionStatus.Errored; Log.Error("Extract Coupon Transaction encountered a bad error!", ex); } finally { responseStream.Flush(); responseStream.Close(); } }); }
public LeavingResult Leaving(UInt64 recordId, String plateNumber, DateTime outTime, Byte[] outImg, Decimal copeMoney, Decimal actualMoney, UInt64 ticketId) { var stringData = new Dictionary <string, string>(); var binaryData = new Dictionary <String, Byte[]>(); stringData.Add(Config.GetString("RecordId"), recordId.ToString()); stringData.Add(Config.GetString("PlateNumber"), plateNumber); stringData.Add(Config.GetString("OutTime"), outTime.ToString("yyyy-MM-dd HH:mm:ss")); binaryData.Add(Config.GetString("OutImage"), outImg); stringData.Add(Config.GetString("CopeMoney"), copeMoney.ToString()); stringData.Add(Config.GetString("ActualMoney"), actualMoney.ToString()); stringData.Add(Config.GetString("TicketId"), ticketId.ToString()); var responseJson = this.Send(this.Config.GetString("LeaveUrl"), stringData, binaryData); var leavingResult = IPSCMJsonConvert.Parse <LeavingResult>(responseJson); return(leavingResult); }
public LoginResult LogIn(String userName, String password) { var data = new Dictionary <string, string>(); data.Add(Config.GetString("UserName"), userName); data.Add(Config.GetString("Password"), password); var responseJson = this.Send(this.Config.GetString("LoginUrl"), data, new Dictionary <string, byte[]>()); var loginRes = IPSCMJsonConvert.Parse <LoginResult>(responseJson); if (loginRes.ResultCode == ResultCode.Success) { Log.Info(String.Format("Cloud parking login successful. Preserved token:{0}", loginRes.Info.Token)); this.Token = loginRes.Info.Token; } var trigger = this.OnLoggedin; if (trigger != null) { trigger(this, new LoginEvenArgs(loginRes)); } return(loginRes); }
public LeavingTransaction(String plateNumber, DateTime outTime, Byte[] outImg, Decimal copeMoney, Decimal actualMoney, UInt32 ticketId, Stream responseStream) { //TODO:Using record id which readed from db this.RecordId = 0x00; this.PlateNumber = plateNumber; this.OutTime = outTime; this.OutImg = outImg; this.CopeMoney = copeMoney; this.ActualMoney = actualMoney; this.TicketId = ticketId; this.ResponseStream = responseStream; this.FullOutput = FileConfig.FindConfig("Transaction.cfg").GetBoolean("FullOutput"); this.WorkThread = new Thread(() => { try { DateTime start = DateTime.Now; if (this.FullOutput) { Log.Info(String.Format("Leave started[+0ms]")); } //Pre-Storage messages and get record id this.RecordId = Engine.GetEngine() .Storage.PreCarLeave(this.PlateNumber, this.OutTime, this.CopeMoney, this.ActualMoney, this.TicketId); if (this.FullOutput) { Log.Info(String.Format("Leave pre-leaved[+{0}ms]", (DateTime.Now - start).TotalMilliseconds)); } //Calculate action var successfullyChargedByUserBalance = this.RecordId != 0 && Engine.GetEngine() .Storage.TryDeductBalance(this.RecordId, this.ActualMoney); Log.Info(String.Format("Leave Educted Balance[+{0}ms]", (DateTime.Now - start).TotalMilliseconds)); //Response F3! String json; if (successfullyChargedByUserBalance) { json = IPSCMJsonConvert.ConvertToJson(new Result { ResultCode = ResultCode.Success }); } else { json = IPSCMJsonConvert.ConvertToJson(new Result { ResultCode = ResultCode.SuccessButInsufficientFunds }); } StreamUtils.WriteToStreamWithUF8(this.ResponseStream, json); this.ResponseStream.Flush(); this.ResponseStream.Close(); if (this.FullOutput) { Log.Info(String.Format("Leave responded to F3[+{0}ms]", (DateTime.Now - start).TotalMilliseconds)); } //Used ticket if (successfullyChargedByUserBalance && this.TicketId != 0) { Engine.GetEngine().Storage.UsedTicket(ticketId, outTime); } if (this.FullOutput) { Log.Info(String.Format("Leave ticket processed[+{0}ms]", (DateTime.Now - start).TotalMilliseconds)); } //Send message to cloud if (!successfullyChargedByUserBalance) { this.CopeMoney = 0; this.TicketId = 0; this.ActualMoney = 0; } var result = Engine.GetEngine() .CloudParking.Leaving(this.RecordId, this.PlateNumber, this.OutTime, this.OutImg, this.CopeMoney, this.ActualMoney, this.TicketId); if (this.FullOutput) { Log.Info(String.Format("Leave result received[+{0}ms]", (DateTime.Now - start).TotalMilliseconds)); } switch (result.ResultCode) { case ResultCode.Success: { Engine.GetEngine().Storage.PostCarLeaved(this.PlateNumber, result); break; } default: { Log.Error("Leaving transaction do not support Result code:" + result.ResultCode + " and wrong message is:" + result.ErrorMsg); break; } } this.Status = TransactionStatus.Exhausted; } catch (Exception ex) { this.Status = TransactionStatus.Errored; Log.Error("Leaving transtraction encountered a bad error!", ex); } finally { this.ResponseStream.Flush(); this.ResponseStream.Close(); } }); }