public bool Cancel() { try { myPISocket = new PI_Lib.PIClient(); } catch (System.Net.Sockets.SocketException ex) { log.InfoFormat(String.Format("Error on PI socket {0}", ex.Message)); Console.WriteLine("Error on PI socket ({0})", ex.Message); return(false); } myPISocket.SetType(MessageTypes.PI_CANCEL_CALL); PI_Lib.PI_CANCEL_CALL myCancelCall = new PI_CANCEL_CALL(); myPISocket.sendBuf = myCancelCall.ToByteArray(Convert.ToInt32(call_nbr)); try { myPISocket.SendMessage(); myPISocket.CloseMe(); } catch (Exception ex) { log.InfoFormat("Error cancelling trip in TaxiPak {0} {1}", call_nbr.ToString(), ex.Message); return(false); } log.InfoFormat("Trip cancelled {0}", this.call_nbr.ToString()); return(true); }
public Cancel(XmlNode confirmNode, int msgCounter, XmlDocument xDoc) { XmlAttributeCollection msgAttr = confirmNode.Attributes; sSrc = msgAttr.GetNamedItem("src").InnerXml; sID = msgAttr.GetNamedItem("id").InnerXml; msgCount = msgCounter; XmlNode idOrder = xDoc.SelectSingleNode("/SUTI/msg/referencesTo/idOrder"); if (idOrder != null) { XmlAttributeCollection idOrderAttr = idOrder.Attributes; sOrderID = idOrderAttr.GetNamedItem("id").InnerXml; } if (sOrderID.Length > 0) // cancel the order in TaxiPak { // Cancel trip using PI interface if (System.Configuration.ConfigurationSettings.AppSettings["TPak_dispatch"].Equals("YES")) { log.InfoFormat("<-- initiating socket connect"); try { myPISocket = new PI_Lib.PIClient(); log.InfoFormat("<-- Successful PI socket connection"); } catch (System.Net.Sockets.SocketException ex) { log.InfoFormat("Error on PI socket ({0})", ex.Message); return; } myPISocket.SetType(MessageTypes.PI_CANCEL_CALL); PI_CANCEL_CALL myCall = new PI_CANCEL_CALL(); myPISocket.sendBuf = myCall.ToByteArray(Int32.Parse(sOrderID)); try { log.InfoFormat("<-- Starting PI Socket SEND"); myPISocket.SendMessage(); log.InfoFormat("<-- Done with PI Socket SEND"); log.InfoFormat("<-- Starting PI Socket RECV"); myPISocket.ReceiveMessage(); log.InfoFormat("<-- Done with PI Socket RECV"); myCall.Deserialize(myPISocket.recvBuf); myPISocket.CloseMe(); log.InfoFormat("<-- success send PI socket"); } catch { log.InfoFormat("<--- error on PI socket send"); return; } } } }
private void CheckOrderStatus(OrderMonitor om) { string callNbr = om.tpak_id; PI_GET_CALL checkCall = new PI_GET_CALL(); PI_DISPATCH_CALL returnedCall = new PI_DISPATCH_CALL(); checkCall.call_number = Int32.Parse(callNbr); // Send to PI handler try { myPISocket = new PI_Lib.PIClient(); } catch (System.Net.Sockets.SocketException ex) { log.InfoFormat("Error on PI socket ({0})", ex.Message); return; } myPISocket.SetType(MessageTypes.PI_GET_CALL); myPISocket.sendBuf = checkCall.ToByteArray(); try { //log.InfoFormat("<-- Starting PI Socket SEND"); myPISocket.SendMessage(); //log.InfoFormat("<-- Done with PI Socket SEND"); //log.InfoFormat("<-- Starting PI Socket RECV"); myPISocket.ReceiveMessage(); //log.InfoFormat("<-- Done with PI Socket RECV"); //#define PENDING 1 /* The call is a future-call (waiting) */ //#define UNASSIGNED 2 /* The call is not connected to a taxi yet */ //#define ASSIGNED 3 /* The taxi is driver to the customer */ //#define PICKUP 4 /* The taxi-trip is going on */ //#define COMPLETE 5 /* The taxi-trip has ended */ //#define CANCELLED 6 /* The call has been cancelled */ //#define NOEXIST 7 /* The call does not exist */ checkCall.Deserialize(ref returnedCall, myPISocket.recvBuf); myPISocket.CloseMe(); //log.InfoFormat("<-- success send PI socket"); // ahead of ourselves. We'll get the order confirm first and pick this up on the next cycle if ((OrderMonitor.CallStatus)(returnedCall.call_status) == OrderMonitor.CallStatus.ASSIGNED && om.orderStatus == OrderMonitor.CallStatus.NEW) { return; } om.orderStatus = (OrderMonitor.CallStatus)(returnedCall.call_status); om.veh_nbr = returnedCall.car_number.ToString(); return; } catch (Exception exc) { log.InfoFormat("<--- error on PI socket send " + exc.Message); return; } }
public void Send() { PI_Lib.PIClient myPISocket = new PI_Lib.PIClient(); myPISocket.SetType(MessageTypes.PI_SEND_MESSAGE); PI_SEND_MESSAGE mySendMessage = new PI_SEND_MESSAGE(); mySendMessage.Fleet = Char.Parse(fleet); mySendMessage.ReceiveGroup = Convert.ToChar(type); mySendMessage.ReceiveID = destination.ToCharArray(); try { if (Msg.Length > 200) { //split up into multiple messages for (int i = 0; i < Msg.Length; i += 199) { mySendMessage.MessageText = Msg.Substring(i, ((i + 199 < Msg.Length)?i + 199:(Msg.Length - i))).ToCharArray(); myPISocket.sendBuf = mySendMessage.ToByteArray(); myPISocket.SendMessage(); System.Threading.Thread.Sleep(1000); } } else { mySendMessage.MessageText = Msg.ToCharArray(); myPISocket.sendBuf = mySendMessage.ToByteArray(); myPISocket.SendMessage(); } } catch (Exception exc) { log.InfoFormat("Error - TPakMsg.Send - {0}", exc.Message); } myPISocket.CloseMe(); System.Threading.Thread.Sleep(1000); }
public CallMonitor Dispatch() { if (System.Configuration.ConfigurationSettings.AppSettings["TPak_dispatch"].Equals("YES")) { log.Info(String.Format("Dispatch ACTIVE. Sending to TaxiPak {0}", ConfigurationSettings.AppSettings["PIServer"])); try { myPISocket = new PI_Lib.PIClient(); } catch (System.Net.Sockets.SocketException ex) { log.Error(String.Format("Error on PI socket {0}", ex.Message)); Console.WriteLine("Error on PI socket ({0})", ex.Message); return(null); } myPISocket.SetType(MessageTypes.PI_DISPATCH_CALL); PI_DISPATCH_CALL myCall = new PI_DISPATCH_CALL(); myCall.call_type = "MPK ".ToCharArray(); myCall.fleet = Convert.ToChar("H"); myCall.priority = Convert.ToInt16("25"); myCall.number_of_calls = Convert.ToChar("1"); myCall.from_addr_street = this.from_addr_street.ToCharArray(); myCall.call_comment = (this.call_comment + " " + this.route_id).ToCharArray(); try { myCall.from_addr_number = Convert.ToInt32(this.from_addr_number); if (this.from_addr_suffix != null) { myCall.from_addr_apart = this.from_addr_suffix.ToCharArray(); } } catch (FormatException) { //addr number must contain a non-numeric this.from_addr_suffix = this.from_addr_number.Substring(this.from_addr_number.Length - 1, 1); string tmp_from_addr_number = this.from_addr_number.Substring(0, this.from_addr_number.Length - 1); try { myCall.from_addr_number = Convert.ToInt32(tmp_from_addr_number); myCall.from_addr_apart = this.from_addr_suffix.ToCharArray(); } catch { myCall.from_addr_street = this.from_addr_number.ToCharArray(); myCall.from_addr_number = 0; } } myCall.to_addr_cmnt = (String.Format("{0}:{1}", this.estimate, this.trip_summary)).ToCharArray(); myCall.to_addr_street = (String.Format("{0}:{1}", this.estimate, this.trip_summary)).ToCharArray(); myCall.from_addr_city = this.from_addr_city.ToCharArray(); myCall.passenger = this.passenger.ToCharArray(); myCall.car_attrib = ConfigurationSettings.AppSettings["Vehicle_Attr"].ToCharArray(); // Set the 'wheelchair' attribute if required if (Convert.ToInt32(this.wheelchairs) > 0) { myCall.car_attrib[30] = 'K'; } myPISocket.sendBuf = myCall.ToByteArray(); try { myPISocket.SendMessage(); myPISocket.ReceiveMessage(); myCall.Deserialize(myPISocket.recvBuf); myPISocket.CloseMe(); } catch { log.InfoFormat("Error entering TaxiPak trip for route {0}", this.route_id); return(null); } this.call_nbr = myCall.call_number.ToString(); // Update route record with trip number SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings.Get("ConnString2")); try { conn.Open(); using (SqlCommand ct = conn.CreateCommand()) { string sqlQuery = "update route set tpak_id=" + this.call_nbr + " where route_id='" + this.route_id + "'"; ct.CommandText = sqlQuery; ct.ExecuteNonQuery(); } conn.Close(); } catch (Exception exc) { conn.Close(); log.InfoFormat("Error accessing DB {0}", exc.Message); } CallMonitor cm = new CallMonitor(Convert.ToInt32(this.call_nbr), this.route_id); return(cm); } else { log.Info("Dispatch INACTIVE - set by config parameter"); return(null); } }
public Int32 Dispatch() { if (System.Configuration.ConfigurationSettings.AppSettings["TPak_dispatch"].Equals("YES")) { log.InfoFormat("<-- initiating socket connect"); try { myPISocket = new PI_Lib.PIClient(); log.InfoFormat("<-- Successful PI socket connection"); } catch (System.Net.Sockets.SocketException ex) { log.InfoFormat("Error on PI socket ({0})", ex.Message); return(-1); } myPISocket.SetType(MessageTypes.PI_DISPATCH_CALL); PI_DISPATCH_CALL myCall = new PI_DISPATCH_CALL(); myCall.call_type = ConfigurationSettings.AppSettings["CallType"].ToCharArray(); myCall.fleet = Convert.ToChar(ConfigurationSettings.AppSettings["FleetID"]); myCall.priority = Convert.ToInt16("25"); myCall.number_of_calls = Convert.ToChar("1"); myCall.from_addr_street = this.from_addr_street.ToCharArray(); if (this.from_addr_apart != null) { myCall.from_addr_apart = this.from_addr_apart.ToCharArray(); } //myCall.from_addr_cmnt = this.from_addr_cmnt.ToCharArray(); myCall.call_comment = (this.call_comment + " " + this.route_id).ToCharArray(); if (this.telephone != null) { myCall.phone = this.telephone.ToCharArray(); } try { myCall.from_addr_number = Convert.ToInt32(this.from_addr_number); if (this.from_addr_suffix != null) { myCall.from_addr_apart = this.from_addr_suffix.ToCharArray(); } } catch (FormatException) { //addr number must contain a non-numeric this.from_addr_suffix = this.from_addr_number.Substring(this.from_addr_number.Length - 1, 1); string tmp_from_addr_number = this.from_addr_number.Substring(0, this.from_addr_number.Length - 1); try { myCall.from_addr_number = Convert.ToInt32(tmp_from_addr_number); myCall.from_addr_apart = this.from_addr_suffix.ToCharArray(); } catch { myCall.from_addr_street = this.from_addr_number.ToCharArray(); myCall.from_addr_number = 0; } } myCall.from_addr_city = this.from_addr_city.ToCharArray(); myCall.from_addr_zone = Convert.ToInt16(this.from_zone); if (this.to_addr_street != null) { myCall.to_addr_street = this.to_addr_street.ToCharArray(); if (this.to_addr_apart != null) { myCall.to_addr_apart = this.to_addr_apart.ToCharArray(); } try { myCall.to_addr_number = Convert.ToInt32(this.to_addr_number); if (this.to_addr_suffix != null) { myCall.to_addr_apart = this.to_addr_suffix.ToCharArray(); } } catch (FormatException) { this.to_addr_suffix = this.to_addr_number.Substring(this.to_addr_number.Length - 1, 1); string tmp_to_addr_number = this.to_addr_number.Substring(0, this.to_addr_number.Length - 1); try { myCall.to_addr_number = Convert.ToInt32(tmp_to_addr_number); myCall.to_addr_apart = this.to_addr_suffix.ToCharArray(); } catch { myCall.to_addr_street = this.to_addr_number.ToCharArray(); myCall.to_addr_number = 0; } } myCall.to_addr_city = this.to_addr_city.ToCharArray(); } if (this.passenger != null) { myCall.passenger = this.passenger.ToCharArray(); } myCall.car_attrib = ConfigurationSettings.AppSettings["Vehicle_Attr"].ToCharArray(); if (this.veh_attributes.Count > 0) { foreach (string vehAttr in this.veh_attributes) { int at_nbr = Int32.Parse(vehAttr); if (at_nbr > 0 && at_nbr <= 32) { myCall.car_attrib[at_nbr - 1] = 'K'; } } } // Set the 'wheelchair' attribute if required if (Convert.ToInt32(this.wheelchairs) > 0) { myCall.car_attrib[30] = 'K'; } myPISocket.sendBuf = myCall.ToByteArray(); try { log.InfoFormat("<-- Starting PI Socket SEND"); myPISocket.SendMessage(); log.InfoFormat("<-- Done with PI Socket SEND"); log.InfoFormat("<-- Starting PI Socket RECV"); myPISocket.ReceiveMessage(); log.InfoFormat("<-- Done with PI Socket RECV"); myCall.Deserialize(myPISocket.recvBuf); myPISocket.CloseMe(); log.InfoFormat("<-- success send PI socket"); } catch { log.InfoFormat("<--- error on PI socket send"); return(-1); } this.call_nbr = myCall.call_number.ToString(); // Update route record with trip number return(Int32.Parse(this.call_nbr)); } else { return(-1); } }
public void GetAllStops() { if (GetVehInfo() == false) // couldn't find any data for this vehicle in MPK tables { return; } string msgText = ""; string pickupAddr = ""; OdbcConnection conn = new OdbcConnection(ConfigurationSettings.AppSettings.Get("MPKODBC")); try { conn.Open(); using (OdbcCommand ct = conn.CreateCommand()) { string sqlQuery = "select * from stop,passenger,route where stop.route_id='" + this.routeID + "' and (pickup=stop_id or dropoff=stop_id) and route.route_id='" + this.routeID + "' order by sequence_nbr"; ct.CommandText = sqlQuery; OdbcDataReader dr = ct.ExecuteReader(); int count = 0; while (dr.Read()) { PI_Lib.PIClient myPISocket = new PI_Lib.PIClient(); myPISocket.SetType(MessageTypes.PI_SEND_MESSAGE); PI_SEND_MESSAGE mySendMessage = new PI_SEND_MESSAGE(); mySendMessage.Fleet = Char.Parse("H"); mySendMessage.ReceiveGroup = Convert.ToChar("Q"); mySendMessage.ReceiveID = this.vehID.ToString().ToCharArray(); if (count == 0) { log.InfoFormat("Sending all stops for route {0} vehicle {1}", dr["route_id"].ToString(), this.vehID.ToString()); } ++count; if (dr["arrive"].ToString().Length > 0 && dr["depart"].ToString().Length > 0) { continue; } // Pickup Node if (dr["pickup"].ToString().Equals(dr["stop_id"].ToString())) { pickupAddr = String.Format("{0} {1}%R", dr["ad_str_name"].ToString(), dr["ad_city"].ToString()); msgText = VehFormatPickup(dr); msgText = String.Format("{0}{1}", pickupAddr, msgText); //if ( msgText.Length > 200 ) // msgText = msgText.Substring(0, 200); // have to 'trim' it msgText += "%.L" + String.Format("{0:X4}", Int32.Parse(dr["tpak_id"].ToString()) % 65535) + dr["sequence_nbr"].ToString() + dr["total_stops"].ToString() + "."; mySendMessage.MessageText = msgText.ToCharArray(); } // Dropoff Node else { pickupAddr = String.Format("{0} {1}%R", dr["ad_str_name"].ToString(), dr["ad_city"].ToString()); msgText = VehFormatDropoff(dr); msgText = String.Format("{0}{1}", pickupAddr, msgText); //if ( msgText.Length > 200 ) // msgText = msgText.Substring(0, 200); // have to 'trim' it msgText += "%.L" + String.Format("{0:X4}", Int32.Parse(dr["tpak_id"].ToString()) % 65535) + dr["sequence_nbr"].ToString() + dr["total_stops"].ToString() + "."; mySendMessage.MessageText = msgText.ToCharArray(); } myPISocket.sendBuf = mySendMessage.ToByteArray(); myPISocket.SendMessage(); myPISocket.CloseMe(); System.Threading.Thread.Sleep(1000); //myPISocket.ReceiveMessage(); } // end while loop if (count == 0) // No stops for this taxi { PI_Lib.PIClient myPISocket = new PI_Lib.PIClient(); myPISocket.SetType(MessageTypes.PI_SEND_MESSAGE); PI_SEND_MESSAGE mySendMessage = new PI_SEND_MESSAGE(); mySendMessage.Fleet = Char.Parse("H"); mySendMessage.ReceiveGroup = Convert.ToChar("T"); mySendMessage.ReceiveID = this.vehID.ToString().ToCharArray(); mySendMessage.MessageText = "NO STOPS FOUND".ToCharArray(); myPISocket.sendBuf = mySendMessage.ToByteArray(); myPISocket.SendMessage(); myPISocket.CloseMe(); } dr.Close(); } conn.Close(); } catch (OdbcException exc) { conn.Close(); log.InfoFormat("Error accessing DB {0}", exc.Message); } catch (Exception exc) { conn.Close(); log.InfoFormat("Error in GetAllStops - {0}", exc.Message); } }
public void Monitor() { while (true) { PI_Lib.PIClient myPISocket1 = new PI_Lib.PIClient(); ArrayList myExcepts = new ArrayList(); myPISocket1.SetType(MessageTypes.PI_GET_EXCEPTIONS); myPISocket1.sendBuf = PI_GET_EXCEPTS.ToByteArray(16, 0L); myPISocket1.SendMessage(); myPISocket1.ReceiveMessage(); if (myPISocket1.recvBuf[0] != 0x2a) { log.DebugFormat("DEBUG:Error with exception polling"); myPISocket1.CloseMe(); System.Threading.Thread.Sleep(10000); continue; } PI_GET_EXCEPTS.Deserialize(ref myExcepts, myPISocket1.recvBuf); myPISocket1.CloseMe(); foreach (PI_Data.Except excpt in myExcepts) { if (excpt.exception_type.Equals("12") && excpt.message_number.Equals("99")) { log.InfoFormat("Resolving exception #{0} NO_SHOW #{1}", excpt.exception_number, excpt.message_number); PI_Lib.PIClient myPISocket = new PI_Lib.PIClient(); myPISocket.SetType(MessageTypes.PI_ACCEPT_EXCEPTION); myPISocket.sendBuf = PI_ACCEPT_EXCEPTION.ToByteArray(Convert.ToInt32(excpt.exception_number), Convert.ToChar("K")); myPISocket.SendMessage(); myPISocket.ReceiveMessage(); myPISocket.CloseMe(); Vehicle myVehicle = new Vehicle(Int32.Parse(excpt.car_number)); myVehicle.NoShow(); } if (excpt.exception_type.Equals("16") && (((MsgDrvType)Enum.Parse(typeof(MsgDrvType), excpt.message_number) == MsgDrvType.ARRIVE) || ((MsgDrvType)Enum.Parse(typeof(MsgDrvType), excpt.message_number) == MsgDrvType.DEPART) || ((MsgDrvType)Enum.Parse(typeof(MsgDrvType), excpt.message_number) == MsgDrvType.SEND_ALL))) { // resolve the exception log.Info(String.Format("Resolving exception #{0} MSG_FROM_DRV #{1}", excpt.exception_number, excpt.message_number)); Console.WriteLine("Resolving exception #{0} MSG_FROM_DRV #{1}", excpt.exception_number, excpt.message_number); PI_Lib.PIClient myPISocket = new PI_Lib.PIClient(); myPISocket.SetType(MessageTypes.PI_ACCEPT_EXCEPTION); myPISocket.sendBuf = PI_ACCEPT_EXCEPTION.ToByteArray(Convert.ToInt32(excpt.exception_number), Convert.ToChar("K")); myPISocket.SendMessage(); myPISocket.ReceiveMessage(); myPISocket.CloseMe(); Vehicle myVehicle = new Vehicle(Int32.Parse(excpt.car_number)); // temp: send out a text message to this car switch ((MsgDrvType)Enum.Parse(typeof(MsgDrvType), excpt.message_number)) { case MsgDrvType.ARRIVE: myVehicle.ConfirmArrive(); break; case MsgDrvType.DEPART: myVehicle.ConfirmDepart(); break; case MsgDrvType.SEND_ALL: myVehicle.GetAllStops(); break; default: break; } } } myExcepts.Clear(); // Check for new exceptions every 10 secs System.Threading.Thread.Sleep(10000); } }
private void Page_Load(object sender, System.EventArgs e) { string opcode = Request.Params["op"]; string reqXml = ""; string sqlConnSQL = ConfigurationSettings.AppSettings.Get("SUTIODBC"); XmlTextReader xRdr; XmlDocument xDoc; XmlNode idMsgNode; SUTI smsg; SUTI rmsg; Stream reqStream = Request.InputStream; StreamReader rdr = new StreamReader(reqStream, Encoding.GetEncoding("utf-8")); XmlSerializer mySerializer = new XmlSerializer(typeof(SUTI)); try { XPathNavigator nav; XPathDocument docNav; string xPath; reqXml = rdr.ReadToEnd(); //log.InfoFormat("SOAP Received: " + reqXml); using (StringReader sr = new StringReader(reqXml)) { docNav = new XPathDocument(sr); nav = docNav.CreateNavigator(); xPath = "//*[local-name()='xmlstring']"; reqXml = nav.SelectSingleNode(xPath).Value; } smsg = SUTI.Deserialize(reqXml); //SUTIMsg msgResponse = new SUTIMsg(); //idType id = new idType(); //id.id = "1234"; //msgResponse.idMsg = id; //msgResponse.msgName = "Keep alive"; //rmsg = new SUTI(); //rmsg.msg = new System.Collections.Generic.List<SUTIMsg>(); //rmsg.msg.Add(msgResponse); //log.InfoFormat(rmsg.Serialize().ToString()); } catch (Exception exc) { Console.WriteLine(exc.Message); log.InfoFormat(exc.Message); Response.Redirect(@".\SUTI_2014_MessageXSD.xsd"); return; } if (reqXml.Length == 0) { Session.Clear(); Session.Abandon(); Response.Redirect(@".\SUTI_2014_MessageXSD.xsd"); return; } if (smsg.msg != null) { List <SUTIMsg> messagesIn = smsg.msg; messagesIn.ForEach(delegate(SUTIMsg theMsg) { if (theMsg.msgType.Equals("7000")) // Keep alive { if (theMsg.idMsg != null) { Ping myPing = new Ping(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.ContentType = "text/xml"; //Response.Write(myPing.ReplyPing().ToCharArray(), 0, myPing.ReplyPing().Length); Response.Filter = new HDIResponseFilter(Response.Filter); Response.Write(myPing.QuickReply()); //sends just the ACK back. lock (Global.lockObject) { Global.MsgHashTable.Add(theMsg.idMsg.id, smsg); } } } if (theMsg.msgType.Equals("5020")) // Location request { Ping myPing = new Ping(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.ContentType = "text/xml"; Response.Filter = new HDIResponseFilter(Response.Filter); Response.Write(myPing.QuickReply()); //sends just the ACK back. // Send to PI handler // Then acknowledge receipt PI_RQST_GPS myRqstGPS = new PI_RQST_GPS(); // myRqstGPS.veh_nbr = 465; idType idVehicle = theMsg.referencesTo.idVehicle; myRqstGPS.veh_nbr = Int32.Parse(idVehicle.id); SUTI_svc.locationRequest theRequest = ((SUTI_svc.locationRequest)theMsg.Item); if (myRqstGPS.veh_nbr != 9800) { //try //{ // myPISocket = new PI_Lib.PIClient(); // log.InfoFormat("<-- Successful PI socket connection"); //} //catch (System.Net.Sockets.SocketException ex) //{ // log.InfoFormat("Error on PI socket ({0})", ex.Message); // return; //} //myPISocket.SetType(MessageTypes.PI_RQST_GPS); //myPISocket.sendBuf = myRqstGPS.ToByteArray(Int32.Parse(idVehicle.id)); ////myPISocket.sendBuf = myRqstGPS.ToByteArray(Int32.Parse("9996")); //try //{ // log.InfoFormat("<-- PI_RQST_GPS"); // myPISocket.SendMessage(); // myPISocket.CloseMe(); //} //catch (Exception exc) //{ // log.InfoFormat("<-- error on PI socket send (PI_RQST_GPS) " + exc.Message); // return; //} } try { lock (Global.lockObject) { //smsg.timestamp = DateTime.Now; Global.MsgHashTable.Add(theMsg.idMsg.id, smsg); } } catch (Exception exc) { log.InfoFormat("<-- duplicate PI_RQST_GPS hashtable value " + exc.Message); } } else if (theMsg.msgType.Equals("7099")) { Ping myPing = new Ping(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.ContentType = "text/xml"; Response.Filter = new HDIResponseFilter(Response.Filter); Response.Write(myPing.QuickReply()); //sends just the ACK back. } else if (theMsg.msgType.Equals("7032")) { // ACK handler - just provide a response OrderKELA myOrderKELA = new OrderKELA(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); Response.Filter = new HDIResponseFilter(Response.Filter); Response.Write(myOrderKELA.QuickReply()); } else if (theMsg.msgType.Equals("2003")) // Order Reject Confirm { log.InfoFormat("HUT -> HTD: " + reqXml); OrderKelaRejectConfirm myOrderKELARejectConfirm = new OrderKelaRejectConfirm(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); Response.Filter = new HDIResponseFilter(Response.Filter); Response.Write(myOrderKELARejectConfirm.QuickReply()); } else if (theMsg.msgType.Equals("2000")) { log.InfoFormat("HUT -> HTD: " + reqXml); // Order handler OrderKELA myOrderKELA = new OrderKELA(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); SUTI_svc.order theOrder = ((SUTI_svc.order)theMsg.Item); OdbcConnection connIfx = new OdbcConnection(ConfigurationManager.AppSettings.Get("MadsODBC")); try { connIfx.Open(); String rteID = theOrder.idOrder.id; OdbcCommand myCommand = new OdbcCommand("select * from vpu_node where rte_id='" + rteID + "'", connIfx); OdbcDataReader myReader = myCommand.ExecuteReader(); try { if (myReader.Read()) // route exists....reject!! { // SEND ORDER REJECT 2002 OrderKELAReject or = new OrderKELAReject(rteID, "0000", smsg, Int32.Parse(Application["msgCount"].ToString())); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; or.ReplyOrderCancel(); myReader.Close(); connIfx.Close(); Response.Filter = new HDIResponseFilter(Response.Filter); Response.Write(myOrderKELA.QuickReply()); return; } myReader.Close(); connIfx.Close(); } catch (Exception exc) { connIfx.Close(); } } catch (Exception exc) { System.Diagnostics.Debug.WriteLine(exc.Message); } PI_DISPATCH_CALL myCall = new PI_DISPATCH_CALL(); myCall.call_type = ConfigurationSettings.AppSettings["CallType"].ToCharArray(); myCall.fleet = Convert.ToChar(ConfigurationSettings.AppSettings["FleetID"]); myCall.priority = Convert.ToInt16("25"); myCall.number_of_calls = Convert.ToChar("1"); List <routeNode> rteList = theOrder.route; resourceType ro = theOrder.resourceOrder; if (ro.vehicle != null) { List <attribute> attrList = ro.vehicle.attributesVehicle; string veh_attr = ConfigurationSettings.AppSettings["Vehicle_Attr"]; string drv_attr = ConfigurationSettings.AppSettings["Driver_Attr"]; if (attrList.Count > 0) { foreach (var idAttr in attrList) { if (idAttr.idAttribute.id.Equals("1618")) //EB { veh_attr = "EEEEEEEKEKEEEEEEEEEEEEEEEKEEEEEE"; } else if (idAttr.idAttribute.id.Equals("1601")) //FA (4) { veh_attr = "EEEKEEEEKKEEEEEEEEEEEEEEEKEEEEEE"; } else if (idAttr.idAttribute.id.Equals("1619")) //8H (2) { veh_attr = "EKEEEEEEKKEEEEEEEEEEEEEEEKEEEEEE"; } else if (idAttr.idAttribute.id.Equals("1614")) //IN { veh_attr = "EEEEEEEEEKEEEEEEEEEEEEEEEKEEKEKE"; } else if (idAttr.idAttribute.id.Equals("1615")) //IN { veh_attr = "EEEEEEEEEKEEEEEEEEEEEEEEEKEEKEKE"; } else if (idAttr.idAttribute.id.Equals("1613")) //PA-19 { veh_attr = "EEEEEEEEEKEEEEEEEEKEEEEEEKEEKEEE"; } else if (idAttr.idAttribute.id.Equals("1620")) //TEST { veh_attr = "EKEEEEEKEKEEEEEEEEEEEEEEEKEEEEEE"; } } } capacity cap = ro.vehicle.capacity; if (cap != null) { if (cap.seats != null) { int nbrSeats = Int16.Parse(cap.seats.noOfSeats); if (nbrSeats == 4 || nbrSeats == 5) { veh_attr = "K" + veh_attr.Substring(1, 31); } else if (nbrSeats > 5) { veh_attr = "EK" + veh_attr.Substring(2, 30); } } } manualDescriptionType md = ro.manualDescriptionResource[0]; if (md != null) { String sComment = md.manualText.Replace("Ennakkotilaus:", "").ToUpper(); if (sComment.Length > 64) { sComment = sComment.Substring(0, 64); } myCall.call_comment = sComment.ToCharArray(); } myCall.car_attrib = veh_attr.ToCharArray(); myCall.driver_attrib = drv_attr.ToCharArray(); myCall.car_number = Convert.ToInt16(ro.vehicle.idVehicle.id); } int pickupCount = 0; int totalCount = 0; int orderCount = 0; Dictionary <int, string> sm = new Dictionary <int, string>(); foreach (var rte in rteList) { totalCount++; System.Diagnostics.Debug.WriteLine(rte.addressNode.street); List <idType> subOrderContent = rte.contents[0].subOrderContent; foreach (var idOrder in subOrderContent) { if (idOrder.src.Contains("SUBORDERID")) //this is booking_ID { //myCall.to_addr_street = idOrder.id.ToCharArray(); if (!sm.ContainsValue(idOrder.id)) { ++orderCount; sm.Add(orderCount, idOrder.id); } } } // Translation table for 'community' rte.addressNode.community = CityTranslate(rte.addressNode.community.ToUpper()); if (rte.nodeType == nodeNodeType.pickup && pickupCount == 0) { ++pickupCount; if (rte.addressNode.community.Length < 3) { // attempt to get city from Nominatim server //String nomcity = NomCity([email protected](), // rte.addressNode.geographicLocation.lat.ToString()); //nomcity = CityTranslate(nomcity.ToUpper()); //myCall.from_addr_city = nomcity.ToCharArray(); myCall.from_addr_city = " ".ToCharArray(); } else { myCall.from_addr_city = rte.addressNode.community.ToCharArray(); } myCall.from_addr_street = rte.addressNode.street.ToUpper().ToCharArray(); myCall.from_addr_number = Convert.ToInt32(rte.addressNode.streetNo); // Customer phone number List <contactInfo> contactList = rte.contents[0].contactInfosContent; foreach (var idContact in contactList) { if (idContact.contactType == contactInfoContactType.phone) { String tmpPhone = idContact.contactInfo1; tmpPhone = tmpPhone.Replace("+358", "0"); myCall.phone = tmpPhone.ToCharArray(); } } // time call or immediate call? List <timesTypeTime> timesList = rte.timesNode; if (timesList.Count > 0) { myCall.due_date = String.Format("{0}", timesList[0].time1.ToString("ddMMyy")).ToCharArray(); myCall.due_time = String.Format("{0}", timesList[0].time1.ToString("HHmm")).ToCharArray(); } // get coordinates and convert... //LLUtm llconverter = new LLUtm(); //double utm_east = 0.0; //double utm_north = 0.0; //string utm_zone = ""; //llconverter.LLtoUTM(rte.addressNode.geographicLocation.lat, // rte.addressNode.geographicLocation.@long, out utm_east, out utm_north, out utm_zone); myCall.gpsx = [email protected]().ToCharArray(); myCall.gpsy = rte.addressNode.geographicLocation.lat.ToString().ToCharArray(); myCall.to_addr_city = String.Empty.ToCharArray(); myCall.to_addr_street = String.Empty.ToCharArray(); myCall.to_addr_zone = 0; } else if (rte.nodeType == nodeNodeType.destination) { if (rte.addressNode.community.Length < 3) { myCall.to_addr_city = " ".ToCharArray(); } else { myCall.to_addr_city = rte.addressNode.community.ToCharArray(); } myCall.to_addr_street = rte.addressNode.street.ToUpper().ToCharArray(); myCall.to_addr_number = Convert.ToInt32(rte.addressNode.streetNo); } } if (totalCount > 0) { //myCall.to_addr_street = " ".ToCharArray(); myCall.to_addr_city = String.Empty.ToCharArray(); } myCall.to_addr_street = String.Empty.ToCharArray(); myCall.to_addr_zone = 0; // Send to PI handler // Then acknowledge receipt try { myPISocket = new PI_Lib.PIClient(); log.InfoFormat("<-- Successful PI socket connection"); } catch (System.Net.Sockets.SocketException ex) { log.InfoFormat("Error on PI socket ({0})", ex.Message); return; } myPISocket.SetType(MessageTypes.PI_DISPATCH_CALL); myPISocket.sendBuf = myCall.ToByteArray(); try { log.InfoFormat("<-- Starting PI Socket SEND"); //System.Threading.Thread.Sleep(30000); myPISocket.SendMessage(); log.InfoFormat("<-- Done with PI Socket SEND"); log.InfoFormat("<-- Starting PI Socket RECV"); myPISocket.ReceiveMessage(); log.InfoFormat("<-- Done with PI Socket RECV"); myCall.Deserialize(myPISocket.recvBuf); myPISocket.CloseMe(); log.InfoFormat("<-- success send PI socket"); } catch (Exception exc) { log.InfoFormat("<--- error on PI socket send " + exc.Message); return; } myOrderKELA.LoadKelaOrderDB(smsg, theMsg, theMsg.idMsg.id, myCall.call_number); myOrderKELA.CallNbr = myCall.call_number.ToString(); lock (Global.lockObject) { SUTI_svc.order od = ((SUTI_svc.order)theMsg.Item); OrderMonitor om = new OrderMonitor(smsg, myOrderKELA.CallNbr, od.idOrder.id); om.due_date_time = myOrderKELA._UnixTime; //log.InfoFormat("OrderMonitor created: {0} - {1}", myOrderKELA.CallNbr, myCall.call_number); om.orderStatus = OrderMonitor.CallStatus.NEW; Global.CallHashTable.Add(om, myOrderKELA.CallNbr); } log.InfoFormat("*** Call {0} ***", myOrderKELA.CallNbr); //Response.Write(myCall.call_number.ToString()); Response.Filter = new HDIResponseFilter(Response.Filter); lock (Global.lockObject) { Global.MsgHashTable.Add(theMsg.idMsg.id, smsg); } Response.Write(myOrderKELA.QuickReply()); } else if (theMsg.msgType.Equals("2010")) { log.InfoFormat("HUT -> HTD: " + reqXml); OrderKelaCancel myOrderCancel = new OrderKelaCancel(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); SUTI_svc.referencesTo refTo = ((SUTI_svc.referencesTo)theMsg.referencesTo); string routeID = refTo.idOrder[0].id; // Lookup tpak_nbr in vpu_node table int tpak_id = 0; OdbcConnection connIfx = new OdbcConnection(ConfigurationSettings.AppSettings.Get("MadsODBC")); try { connIfx.Open(); OdbcCommand myCommand = new OdbcCommand("select tpak_id from vpu_node where rte_id='" + routeID + "'", connIfx); OdbcDataReader myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { tpak_id = myReader.GetInt32(0); } } catch (Exception exc) { } connIfx.Close(); } catch (Exception exc) { } lock (Global.lockObject) { Global.MsgHashTable.Add(theMsg.idMsg.id, smsg); foreach (DictionaryEntry de in Global.CallHashTable) { OrderMonitor om = (OrderMonitor)de.Key; if (Int32.Parse(om.tpak_id) == tpak_id) { Global.CallHashTable.Remove(de.Key); break; } } } PI_CANCEL_CALL canxCall = new PI_CANCEL_CALL(); try { myPISocket = new PI_Lib.PIClient(); log.InfoFormat("<-- Successful PI socket connection"); } catch (System.Net.Sockets.SocketException ex) { log.InfoFormat("Error on PI socket ({0})", ex.Message); return; } myPISocket.SetType(MessageTypes.PI_CANCEL_CALL); myPISocket.sendBuf = canxCall.ToByteArray(tpak_id); try { log.InfoFormat("Cancelling TaxiPak order {0}", tpak_id.ToString()); myPISocket.SendMessage(); myPISocket.ReceiveMessage(); canxCall.Deserialize(myPISocket.recvBuf); myPISocket.CloseMe(); } catch (Exception exc) { log.InfoFormat("<--- error on PI socket send " + exc.Message); return; } Response.Filter = new HDIResponseFilter(Response.Filter); Response.Write(myOrderCancel.QuickReply()); } else if (theMsg.msgType.Equals("5000")) { log.InfoFormat("HUT -> HTD: " + reqXml); // Message to Vehicle handler MsgToVehicle myMsgToVehicle = new MsgToVehicle(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString())); SUTI_svc.msgManualDescriptionMsg msgToSend = ((SUTI_svc.msgManualDescriptionMsg)theMsg.Item); // Send to PI handler // Then acknowledge receipt try { myPISocket = new PI_Lib.PIClient(); log.InfoFormat("<-- Successful PI socket connection"); } catch (System.Net.Sockets.SocketException ex) { log.InfoFormat("Error on PI socket ({0})", ex.Message); return; } myPISocket.SetType(MessageTypes.PI_SEND_MESSAGE); PI_SEND_MESSAGE myMsg = new PI_SEND_MESSAGE(); myMsg.Fleet = Convert.ToChar(ConfigurationSettings.AppSettings["FleetID"]); myMsg.ReceiveGroup = 'Q'; myMsg.ReceiveID = "3007".ToCharArray(); myMsg.MessageText = msgToSend.manualText.ToCharArray(); myPISocket.sendBuf = myMsg.ToByteArray(); try { log.InfoFormat("<-- Starting PI Socket SEND"); myPISocket.SendMessage(); log.InfoFormat("<-- Done with PI Socket SEND"); log.InfoFormat("<-- Starting PI Socket RECV"); myPISocket.ReceiveMessage(); log.InfoFormat("<-- Done with PI Socket RECV"); myMsg.Deserialize(myPISocket.recvBuf); myPISocket.CloseMe(); log.InfoFormat("<-- success send PI socket"); } catch { log.InfoFormat("<--- error on PI socket send"); return; } myPISocket.Close(); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.Write(myMsgToVehicle.QuickReply()); lock (Global.lockObject) { Global.MsgHashTable.Add(theMsg.idMsg.id, smsg); } } }); Session.Clear(); Session.Abandon(); return; } int endXml = reqXml.LastIndexOf("</msg>"); string xmlFragment = reqXml.Substring(0, endXml); xRdr = new XmlTextReader(reqXml, XmlNodeType.Element, null); xDoc = new XmlDocument(); try { xDoc.Load(xRdr); } catch (Exception exc) { Console.WriteLine(exc.Message); } idMsgNode = xDoc.SelectSingleNode("/SUTI/msg"); if (idMsgNode != null) { XmlNode idMsg; XmlAttributeCollection msgAttr = idMsgNode.Attributes; Int32 msgType = Int32.Parse(msgAttr.GetNamedItem("msgType").InnerXml); string msgName = (msgAttr.GetNamedItem("msgName").InnerXml); idMsg = xDoc.SelectSingleNode("/SUTI/msg/idMsg"); XmlAttributeCollection idAttr = idMsg.Attributes; string sSrc = idAttr.GetNamedItem("src").InnerXml; string sID = idAttr.GetNamedItem("id").InnerXml; switch (msgType) { case 6000: // Report -- DONE! if (idMsg != null) { Report myReport = new Report(idMsg, Int32.Parse(Application["msgCount"].ToString()), xDoc); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.Write(myReport.ReportConfirm()); } break; case 2002: //Order reject idMsg = xDoc.SelectSingleNode("/SUTI/msg/idMsg"); if (idMsg != null) { Reject myReject = new Reject(idMsg, Int32.Parse(Application["msgCount"].ToString()), xDoc); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.Write(myReject.ReplyReject()); } break; case 2010: // Order cancel idMsg = xDoc.SelectSingleNode("/SUTI/msg/idMsg"); if (idMsg != null) { Cancel myCancel = new Cancel(idMsg, Int32.Parse(Application["msgCount"].ToString()), xDoc); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.Write(myCancel.ReplyCancel()); } break; case 3003: //Dispatch Confirmation - trip is assigned idMsg = xDoc.SelectSingleNode("/SUTI/msg/idMsg"); if (idMsg != null) { Confirm myConfirm = new Confirm(idMsg, Int32.Parse(Application["msgCount"].ToString()), xDoc); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; Response.Write(myConfirm.ReplyConfirm()); } break; case 2000: //ORDER if (idMsgNode != null) { Order myOrder = new Order(reqXml, Int32.Parse(Application["msgCount"].ToString())); TPakTrip theTrip = new TPakTrip(); if (theTrip.Fill(myOrder) == false) { SyntaxError mySyntaxError = new SyntaxError(sID, "Unable to process. Comment length exceeded", Int32.Parse(Application["msgCount"].ToString())); Response.Write(mySyntaxError.ReplySyntaxError()); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; } else { if (theTrip.ValidateVehicleAttr() == false) { SyntaxError mySyntaxError = new SyntaxError(sID, "Unable to process. Bad vehicle attribute", Int32.Parse(Application["msgCount"].ToString())); Response.Write(mySyntaxError.ReplySyntaxError()); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; } else { if (((RteNode)(myOrder._route._nodes[0])).Zone != "-1" && ((RteNode)(myOrder._route._nodes[0])).Locality.Length != 0) { myOrder.TPakID = theTrip.Dispatch(); if (myOrder.TPakID > 0) { myOrder.UpdateTPakID(myOrder.TPakID); } else { myOrder.UpdateTPakID(32142); } Response.Write(myOrder.ReplyOrder()); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; } else if (((RteNode)(myOrder._route._nodes[0])).Locality.Length == 0) { SyntaxError mySyntaxError = new SyntaxError(sID, "Address error: No CITY", Int32.Parse(Application["msgCount"].ToString())); Response.Write(mySyntaxError.ReplySyntaxError()); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; } else // Return error message { SyntaxError mySyntaxError = new SyntaxError(sID, "Zone translation error", Int32.Parse(Application["msgCount"].ToString())); Response.Write(mySyntaxError.ReplySyntaxError()); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; } } } } else { SyntaxError mySyntaxError = new SyntaxError(sID, "Order error", Int32.Parse(Application["msgCount"].ToString())); Response.Write(mySyntaxError.ReplySyntaxError()); Application["msgCount"] = Convert.ToInt32(Application["msgCount"]) + 1; } break; case 2003: // ORDER_REJECT_CONFIRMATION break; } } Session.Clear(); Session.Abandon(); }