Exemple #1
0
        public string SendOrderKELA()
        {
            SUTI    smsg    = new SUTI();
            SUTIMsg msgSend = new SUTIMsg();

            orgType sender   = new orgType();
            orgType receiver = new orgType();

            sender.name         = "HTD";
            sender.idOrg.id     = "902:HTD_KELA_SVC";
            sender.idOrg.src    = "SUTI";
            sender.idOrg.unique = true;

            receiver.name         = "Testiyhtio 1";
            receiver.idOrg.id     = "901:Systemsupplier1_System_owner1_001";
            receiver.idOrg.src    = "SUTI";
            receiver.idOrg.unique = true;

            smsg.orgSender   = sender;
            smsg.orgReceiver = receiver;
            smsg.msg         = new System.Collections.Generic.List <SUTIMsg>();

            idType id = new idType();

            id.src          = "902:HTD_KELA_SVC";
            id.id           = System.DateTime.Now.Ticks.ToString();
            id.unique       = true;
            msgSend.msgName = "Keep alive";
            msgSend.msgType = "5000";
            msgSend.idMsg   = id;
            smsg.msg.Add(msgSend);
            System.Diagnostics.Debug.WriteLine(smsg.Serialize().ToString());

            return(smsg.Serialize());
        }
Exemple #2
0
        public string SendPing()
        {
            SUTI    smsg    = new SUTI();
            SUTIMsg msgSend = new SUTIMsg();

            orgType sender   = new orgType();
            orgType receiver = new orgType();

            sender.name         = "HTD";
            sender.idOrg.id     = "902:HTD_KELA_SVC";
            sender.idOrg.src    = "SUTI";
            sender.idOrg.unique = true;

            receiver.name         = "Testiyhtio 1";
            receiver.idOrg.id     = "901:Systemsupplier1_System_owner1_001";
            receiver.idOrg.src    = "SUTI";
            receiver.idOrg.unique = true;

            smsg.orgSender   = sender;
            smsg.orgReceiver = receiver;
            smsg.msg         = new System.Collections.Generic.List <SUTIMsg>();

            idType id = new idType();

            id.src          = "902:HTD_KELA_SVC";
            id.id           = System.DateTime.Now.Ticks.ToString();
            id.unique       = true;
            msgSend.msgName = "Keep alive";
            msgSend.msgType = "7000";
            msgSend.idMsg   = id;
            smsg.msg.Add(msgSend);
            //System.Diagnostics.Debug.WriteLine(smsg.Serialize().ToString());

            String SoapSend = "<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ZSI='http://www.zolera.com/schemas/ZSI/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body xmlns:ns1='http://tempuri.org/'><ns1:ReceiveSutiMsgResponse><ns1:xmlstring>" +
                              System.Web.HttpUtility.HtmlEncode(smsg.Serialize()) + "</ns1:xmlstring></ns1:ReceiveSutiMsgResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>";

            return(SoapSend);
        }
Exemple #3
0
        public void ReplyPing()
        {
            SUTI    rmsg        = new SUTI();
            SUTIMsg msgResponse = new SUTIMsg();
            SUTIMsg msgReceived = this.inSUTImsg;

            orgType sender   = this.inSUTI.orgReceiver;
            orgType receiver = this.inSUTI.orgSender;

            rmsg.orgReceiver = receiver;
            rmsg.orgSender   = sender;

            rmsg.msg = new System.Collections.Generic.List <SUTIMsg>();

            idType id = new idType();

            id.src                         = "104:TaxiPak_HTD_002:MSGID";
            id.id                          = System.DateTime.Now.Ticks.ToString();
            msgResponse.idMsg              = id;
            msgResponse.msgName            = "Keep alive confirmation";
            msgResponse.msgType            = "7001";
            msgResponse.referencesTo       = new msgReferencesTo();
            msgResponse.referencesTo.idMsg = this.inSUTImsg.idMsg;

            rmsg.msg.Add(msgResponse);
            System.Diagnostics.Debug.WriteLine(rmsg.Serialize().ToString());

            try
            {
                //WebRequest request = WebRequest.Create("http://10.100.113.33:8202/default.aspx");
                string response = "<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ZSI='http://www.zolera.com/schemas/ZSI/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body xmlns:ns1='http://tempuri.org/'><ns1:ReceiveSutiMsg><ns1:xmlstring>" +
                                  System.Web.HttpUtility.HtmlEncode(rmsg.Serialize().ToString()) +
                                  "</ns1:xmlstring></ns1:ReceiveSutiMsg></SOAP-ENV:Body></SOAP-ENV:Envelope>";

                byte[] buffer = Encoding.UTF8.GetBytes(response);

                WebRequest request = WebRequest.Create(ConfigurationManager.AppSettings.Get("VPUendpoint"));
                request.Credentials = CredentialCache.DefaultCredentials;
                ((HttpWebRequest)request).UserAgent                 = "ASP.NET from HTD KELA SVC";
                ((HttpWebRequest)request).KeepAlive                 = false;
                ((HttpWebRequest)request).Timeout                   = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ReadWriteTimeout          = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ProtocolVersion           = HttpVersion.Version10;
                ((HttpWebRequest)request).AllowWriteStreamBuffering = false;
                ((HttpWebRequest)request).ContentLength             = buffer.Length;

                request.Method      = "POST";
                request.ContentType = "application/xml";
                Stream writer = request.GetRequestStream();

                //log.InfoFormat("HTD->HUT " + response);
                writer.Write(buffer, 0, buffer.Length);
                writer.Close();

                // Response
                WebResponse resp = request.GetResponse();
                writer = resp.GetResponseStream();
                StreamReader rdr = new StreamReader(writer);
                //log.InfoFormat("HUT->HTD " + rdr.ReadToEnd());
                rdr.Close();
                writer.Close();
                resp.Close();
            }
            catch (WebException exc)
            {
                log.InfoFormat("Error with KEEP ALIVE - {0}", exc.Message);
            }
            catch (ProtocolViolationException exc)
            {
                log.InfoFormat("Error with KEEP ALIVE - {0}" + exc.Message);
            }

            return;
        }
Exemple #4
0
        private void CallBackgroundWorkThread()
        {
            while (true)
            {
                List <DictionaryEntry> removeList    = new List <DictionaryEntry>();
                List <DictionaryEntry> msgRemoveList = new List <DictionaryEntry>();


                lock (lockObject)
                {
                    foreach (DictionaryEntry de in MsgHashTable)
                    {
                        SUTI smsg = (SUTI)de.Value;

                        List <SUTIMsg> messagesIn = smsg.msg;
                        SUTIMsg        theMsg     = messagesIn[0];

                        if (theMsg.msgType.Equals("7000")) // Keep Alive
                        {
                            msgRemoveList.Add(de);
                            Ping daPing = new Ping(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            daPing.ReplyPing();
                        }
                        else if (theMsg.msgType.Equals("5000")) // Message to Vehicle
                        {
                            msgRemoveList.Add(de);
                            MsgToVehicle daMsgToVehicle = new MsgToVehicle(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            daMsgToVehicle.ReplyMsgToVehicle();
                        }
                        else if (theMsg.msgType.Equals("2000")) // Order
                        {
                            msgRemoveList.Add(de);
                            OrderKELA daOrder         = new OrderKELA(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            order     theOrderDetails = (order)theMsg.Item;
                            //Find the TaxiPak ID for the order
                            String tpakID = "";
                            foreach (DictionaryEntry de2 in CallHashTable)
                            {
                                OrderMonitor om = (OrderMonitor)de2.Key;
                                if (om.kela_id.Equals(theOrderDetails.idOrder.id))
                                {
                                    tpakID         = om.tpak_id;
                                    om.orderStatus = OrderMonitor.CallStatus.ORDERCONFIRMED;
                                    break;
                                }
                            }
                            daOrder.ReplyOrderKELA(tpakID);
                        }
                        else if (theMsg.msgType.Equals("2010")) // Order cancel
                        {
                            msgRemoveList.Add(de);
                            OrderKelaCancel daCancel = new OrderKelaCancel(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            daCancel.CancelConfirm(theMsg);
                        }
                        else if (theMsg.msgType.Equals("5020")) // Location request
                        {
                            msgRemoveList.Add(de);
                            //DateTime requestTime = (DateTime)de.Key;  // time that location request received
                            //DateTime thisTime = DateTime.Now;
                            //bool isSummertime = TimeZoneInfo.Local.IsDaylightSavingTime(thisTime);
                            //double currentTime;
                            //if (isSummertime)
                            //    currentTime = (DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds + 3600;
                            //else
                            //    currentTime = (DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;

                            //System.Diagnostics.Debug.WriteLine("Time difference: " + ((thisTime - requestTime).TotalSeconds).ToString());
                            //Not operational message
                            //_7031Response resp = new _7031Response(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            //resp.ReplyNotOperational(theMsg);


                            idType idVehicle   = theMsg.referencesTo.idVehicle;
                            float  utmNorthing = 0.0F;
                            float  utmEasting  = 0.0F;
                            float  gpsLat      = 0.0F;
                            float  gpsLon      = 0.0F;
                            int    gpsTime     = 0;
                            if (idVehicle != null)
                            {
                                //Retrieve last GPS position from this vehicle
                                VehicleLastGPS(idVehicle.id, out utmNorthing, out utmEasting, out gpsTime);
                                System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc).AddSeconds(10800);
                                //if (isSummertime)
                                //    dtDateTime = dtDateTime.AddSeconds(gpsTime) + 3600;
                                //else
                                dtDateTime = dtDateTime.AddSeconds(gpsTime);

                                //System.Diagnostics.Debug.WriteLine("Now: " + thisTime.ToString() + " Vehicle: " + gpsTime);
                                //if ((thisTime - dtDateTime).TotalSeconds < 60)
                                //{
                                LLUtm llutm = new LLUtm();
                                llutm.UTMtoLL(0, (double)utmNorthing, (double)utmEasting, out gpsLat, out gpsLon);
                                LocationResponse locationResponse = new LocationResponse(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                                locationResponse.ReplyLocation(theMsg, gpsLat, gpsLon);
                                //}
                                msgRemoveList.Add(de);
                            }
                        }
                    }

                    foreach (DictionaryEntry de in msgRemoveList)
                    {
                        MsgHashTable.Remove(de.Key);
                    }

                    msgRemoveList.Clear();


                    // Check status of all Calls in List
                    removeList.Clear();
                    int count        = 0;
                    int countChecked = 0;
                    foreach (DictionaryEntry de in CallHashTable)
                    {
                        DateTime thisTime     = DateTime.Now;
                        bool     isSummertime = TimeZoneInfo.Local.IsDaylightSavingTime(thisTime);
                        double   currentTime;
                        if (isSummertime)
                        {
                            currentTime = (DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds + 3600;
                        }
                        else
                        {
                            currentTime = (DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds;
                        }

                        OrderMonitor om = (OrderMonitor)de.Key;

                        try
                        {
                            //if (om.due_date_time - currentTime < 2100)  // 35 minutes?
                            //{
                            CheckOrderStatus(om);
                            ++countChecked;
                            log.InfoFormat("Checking order " + om.tpak_id + " status " + om.orderStatus + " veh_nbr " + om.veh_nbr);
                            if (currentTime - om.due_date_time > 10800)     // more than 3 hours old
                            {
                                removeList.Add(de);
                            }
                            //}
                            ++count;
                            //log.InfoFormat("Checking order " + om.tpak_id + " status " + om.orderStatus + " veh_nbr " + om.veh_nbr);

                            if (om.orderStatus == OrderMonitor.CallStatus.CANCELED)
                            {
                                // SEND ORDER REJECT REQUEST (New message Jan 13 2016 2005
                                OrderKELAReject or = new OrderKELAReject(om.kela_id, om.tpak_id, om.inSUTImsg,
                                                                         Int32.Parse(Application["msgCount"].ToString()));
                                or.ReplyOrderRequestCancel();
                                removeList.Add(de);
                            }
                            else if ((om.orderStatus == OrderMonitor.CallStatus.PICKUP) && (!om.bSentPickup))
                            {
                                PickupConfirm pc = new PickupConfirm(om.kela_id, om.veh_nbr, om.tpak_id, om.inSUTImsg,
                                                                     Int32.Parse(Application["msgCount"].ToString()));
                                om.bSentPickup = true;
                                if (!restart)
                                {
                                    pc.ReplyPickupConfirm();
                                }
                            }
                            else if ((om.orderStatus == OrderMonitor.CallStatus.ASSIGNED || om.orderStatus == OrderMonitor.CallStatus.PICKUP) &&
                                     (!om.bSentAccept))
                            {
                                // SEND DISPATCH CONFIRMATION 3003

                                DispatchConfirm dc = new DispatchConfirm(om.kela_id, om.veh_nbr,
                                                                         om.inSUTImsg,
                                                                         Int32.Parse(Application["msgCount"].ToString()));
                                om.bSentAccept = true;
                                if (!restart)
                                {
                                    dc.ReplyDispatchConfirm();
                                }
                                //okr.SendOrderKELAReject(this.inSUTImsg);
                            }
                            else if ((om.orderStatus == OrderMonitor.CallStatus.COMPLETE))
                            {
                                // ORDER REPORT 6001
                                DispatchReport dr = new DispatchReport(om.kela_id, om.veh_nbr, om.tpak_id, om.inSUTImsg, Int32.Parse(Application["msgCount"].ToString()));
                                dr.ReplyDispatchReport();
                                removeList.Add(de);
                            }
                        }
                        catch (Exception exc)
                        {
                            log.InfoFormat(exc.Message);
                        }
                    }
                    log.Info("Total VPU orders  " + count + " Orders checked " + countChecked);
                    restart = false;
                    foreach (DictionaryEntry de in removeList)
                    {
                        CallHashTable.Remove(de.Key);
                    }

                    removeList.Clear();
                }

                Thread.Sleep(5000);
            }
        }
        public void ReplyDispatchConfirm()
        {
            SUTI rmsg = new SUTI();

            orgType sender = new orgType();

            sender.name      = ConfigurationManager.AppSettings.Get("localOrgName"); // "Helsingin Taksi-Data Oy";
            sender.idOrg.id  = ConfigurationManager.AppSettings.Get("localOrgID");   // "104:TaxiPak_HTD_002";
            sender.idOrg.src = "SUTI";

            orgType receiver = new orgType();

            receiver.name      = ConfigurationManager.AppSettings.Get("remoteOrgName"); // "Taksiliiton Yrityspalvelu Oy";
            receiver.idOrg.id  = ConfigurationManager.AppSettings.Get("remoteOrgID");   // "801:Valopilkku_TYP_002";
            receiver.idOrg.src = "SUTI";

            rmsg.orgReceiver = receiver;
            rmsg.orgSender   = sender;

            rmsg.msg = new List <SUTIMsg>();

            SUTIMsg msgResponse = new SUTIMsg();
            idType  id          = new idType();

            id.src                   = "104:TaxiPak_HTD_002:MSGID";
            id.id                    = System.DateTime.Now.Ticks.ToString();
            msgResponse.idMsg        = id;
            msgResponse.msgName      = "Dispatch Confirmation";
            msgResponse.msgType      = "3003";
            msgResponse.referencesTo = new msgReferencesTo();
            idType idOrder = new idType();

            idOrder.src = "801:Valopilkku_TYP_002:MISSIONID";
            idOrder.id  = this.kela_id.Trim();
            List <idType> idList = new List <idType>();

            idList.Add(idOrder);
            //idList.Add(smsg.msg[0].idMsg);
            msgResponse.referencesTo.idOrder = idList;
            if (smsg != null)
            {
                msgResponse.referencesTo.idMsg = smsg.msg[0].idMsg;
            }
            else
            {
                idType idMsg = new idType();
                idMsg.src = "901:HUT:MSGID";
                idMsg.id  = "12345";
                msgResponse.referencesTo.idMsg = idMsg;
            }

            idType idVehicle = new idType();

            idVehicle.id     = this.veh_nbr;
            idVehicle.src    = "104:HTD_001:VEHICLEID";
            idVehicle.unique = true;
            msgResponse.referencesTo.idVehicle = idVehicle;

            resourceType resDispatch = new resourceType();

            resDispatch.vehicle                  = new vehicle();
            resDispatch.vehicle.idVehicle        = new idType();
            resDispatch.vehicle.idVehicle.id     = this.veh_nbr;
            resDispatch.vehicle.idVehicle.src    = "104:TaxiPak_HTD_002:VEHICLEID";
            resDispatch.vehicle.idVehicle.unique = true;

            msgResponse.Item = resDispatch;
            //= new List<resourceType>;
            rmsg.msg.Add(msgResponse);

            try
            {
                log.InfoFormat("HTD->HUT " + rmsg.Serialize().ToString());
                //WebRequest request = WebRequest.Create("http://10.100.113.33:8202/default.aspx");
                string response = "<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ZSI='http://www.zolera.com/schemas/ZSI/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body xmlns:ns1='http://tempuri.org/'><ns1:ReceiveSutiMsg><ns1:xmlstring>" +
                                  System.Web.HttpUtility.HtmlEncode(rmsg.Serialize().ToString()) +
                                  "</ns1:xmlstring></ns1:ReceiveSutiMsg></SOAP-ENV:Body></SOAP-ENV:Envelope>";

                byte[] buffer = Encoding.UTF8.GetBytes(response);

                WebRequest request = WebRequest.Create(ConfigurationManager.AppSettings.Get("VPUendpoint")); //"http://10.190.90.1:7871/SutiService/");
                request.Credentials = CredentialCache.DefaultCredentials;
                ((HttpWebRequest)request).UserAgent                 = "ASP.NET from HTD KELA SVC";
                ((HttpWebRequest)request).KeepAlive                 = false;
                ((HttpWebRequest)request).Timeout                   = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ReadWriteTimeout          = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ProtocolVersion           = HttpVersion.Version10;
                ((HttpWebRequest)request).AllowWriteStreamBuffering = false;
                ((HttpWebRequest)request).ContentLength             = buffer.Length;

                request.Method      = "POST";
                request.ContentType = "application/xml";
                Stream writer = request.GetRequestStream();

                log.InfoFormat("HTD->HUT " + response);
                writer.Write(buffer, 0, buffer.Length);
                writer.Close();

                // Response
                WebResponse resp = request.GetResponse();
                writer = resp.GetResponseStream();
                StreamReader rdr = new StreamReader(writer);
                log.InfoFormat("HUT->HTD " + rdr.ReadToEnd());
                rdr.Close();
                writer.Close();
                resp.Close();
            }
            catch (WebException exc)
            {
                log.InfoFormat("Error with DISPATCH CONFIRMATION - {0}", exc.Message);
            }
            catch (ProtocolViolationException exc)
            {
                log.InfoFormat("Error with DISPATCH CONFIRMATION - {0}" + exc.Message);
            }

            // *** Test Phase ***
            // ** Cancel Order and Notify *** //


            return;
        }
        public void CancelConfirm(SUTIMsg msgFrom)
        {
            SUTI    rmsg        = new SUTI();
            SUTIMsg msgResponse = new SUTIMsg();
            SUTIMsg msgReceived = this.inSUTImsg;

            orgType sender   = this.inSUTI.orgReceiver;
            orgType receiver = this.inSUTI.orgSender;

            rmsg.orgReceiver = receiver;
            rmsg.orgSender   = sender;

            rmsg.msg = new List <SUTIMsg>();

            idType id = new idType();

            id.src                         = "104:HTD_001";
            id.id                          = System.DateTime.Now.Ticks.ToString();
            msgResponse.idMsg              = id;
            msgResponse.msgName            = "OrderCancellationAccepted";
            msgResponse.msgType            = "2011";
            msgResponse.referencesTo       = new msgReferencesTo();
            msgResponse.referencesTo.idMsg = this.inSUTImsg.idMsg;
            List <idType> idList = this.inSUTImsg.referencesTo.idOrder;

            SUTI_svc.order theOrder = ((SUTI_svc.order) this.inSUTImsg.Item);

            msgResponse.referencesTo.idOrder = idList;
            cancellationConsequence cc = new cancellationConsequence();

            cc.cancellationAcceptance   = true;
            cc.cancellationConsequence1 = true;

            msgResponse.Item = cc;
            rmsg.msg.Add(msgResponse);

            try
            {
                log.InfoFormat("HTD->HUT " + rmsg.Serialize().ToString());
                //WebRequest request = WebRequest.Create("http://10.100.113.33:8202/default.aspx");
                string response = "<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ZSI='http://www.zolera.com/schemas/ZSI/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body xmlns:ns1='http://tempuri.org/'><ns1:ReceiveSutiMsg><ns1:xmlstring>" +
                                  System.Web.HttpUtility.HtmlEncode(rmsg.Serialize().ToString()) +
                                  "</ns1:xmlstring></ns1:ReceiveSutiMsg></SOAP-ENV:Body></SOAP-ENV:Envelope>";

                byte[] buffer = Encoding.UTF8.GetBytes(response);

                WebRequest request = WebRequest.Create(ConfigurationManager.AppSettings.Get("VPUendpoint"));
                request.Credentials = CredentialCache.DefaultCredentials;
                ((HttpWebRequest)request).UserAgent                 = "ASP.NET from HTD KELA SVC";
                ((HttpWebRequest)request).KeepAlive                 = false;
                ((HttpWebRequest)request).Timeout                   = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ReadWriteTimeout          = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ProtocolVersion           = HttpVersion.Version10;
                ((HttpWebRequest)request).AllowWriteStreamBuffering = false;
                ((HttpWebRequest)request).ContentLength             = buffer.Length;

                request.Method      = "POST";
                request.ContentType = "application/xml";
                Stream writer = request.GetRequestStream();

                log.InfoFormat("HTD->HUT " + response);
                writer.Write(buffer, 0, buffer.Length);
                writer.Close();

                // Response
                WebResponse resp = request.GetResponse();
                writer = resp.GetResponseStream();
                StreamReader rdr = new StreamReader(writer);
                log.InfoFormat("HUT->HTD " + rdr.ReadToEnd());
                rdr.Close();
                writer.Close();
                resp.Close();
            }
            catch (WebException exc)
            {
                log.InfoFormat("Error with ORDER CONFIRMATION - {0}", exc.Message);
            }
            catch (ProtocolViolationException exc)
            {
                log.InfoFormat("Error with ORDER CONFIRMATION - {0}" + exc.Message);
            }

            // Reject orders during TEST
            //OrderKELAReject okr = new OrderKELAReject(this.inSUTI, this.inSUTImsg, sID, msgCount);
            //okr.SendOrderKELAReject(this.inSUTImsg);

            return;
        }
Exemple #7
0
        public void ReplyNotOperational(SUTIMsg msgFrom)
        {
            SUTI    rmsg        = new SUTI();
            SUTIMsg msgResponse = new SUTIMsg();
            SUTIMsg msgReceived = this.inSUTImsg;

            orgType sender   = this.inSUTI.orgReceiver;
            orgType receiver = this.inSUTI.orgSender;

            rmsg.orgReceiver = receiver;
            rmsg.orgSender   = sender;

            rmsg.msg = new List <SUTIMsg>();

            idType id = new idType();

            id.src            = "104:TaxiPak_HTD_002:MSGID";
            id.id             = System.DateTime.Now.Ticks.ToString();
            msgResponse.idMsg = id;

            msgResponse.msgName = "Not Operational";
            msgResponse.msgType = "7031";

            idType idVehicle = this.inSUTImsg.referencesTo.idVehicle;

            msgResponse.referencesTo       = new msgReferencesTo();
            msgResponse.referencesTo.idMsg = this.inSUTImsg.idMsg;

            msgManualDescriptionMsg md = new msgManualDescriptionMsg();

            md.sendtoInvoice       = false;
            md.sendtoVehicle       = false;
            md.sendtoOperator      = false;
            md.manualText          = "Tässä selvitystä, miksi viestin pyyntöä ei voitu käsitellä";
            md.vehicleConfirmation = false;
            msgResponse.Item       = md;

            rmsg.msg.Add(msgResponse);

            try
            {
                log.InfoFormat("HTD->HUT " + rmsg.Serialize().ToString());

                string response = "<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ZSI='http://www.zolera.com/schemas/ZSI/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body xmlns:ns1='http://tempuri.org/'><ns1:ReceiveSutiMsg><ns1:xmlstring>" +
                                  System.Web.HttpUtility.HtmlEncode(rmsg.Serialize().ToString()) +
                                  "</ns1:xmlstring></ns1:ReceiveSutiMsg></SOAP-ENV:Body></SOAP-ENV:Envelope>";

                byte[] buffer = Encoding.UTF8.GetBytes(response);

                WebRequest request = WebRequest.Create(ConfigurationManager.AppSettings.Get("VPUendpoint"));
                request.Credentials = CredentialCache.DefaultCredentials;
                ((HttpWebRequest)request).UserAgent                 = "ASP.NET from HTD KELA SVC";
                ((HttpWebRequest)request).KeepAlive                 = false;
                ((HttpWebRequest)request).Timeout                   = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ReadWriteTimeout          = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ProtocolVersion           = HttpVersion.Version10;
                ((HttpWebRequest)request).AllowWriteStreamBuffering = false;
                ((HttpWebRequest)request).ContentLength             = buffer.Length;

                request.Method      = "POST";
                request.ContentType = "application/xml";
                Stream writer = request.GetRequestStream();

                log.InfoFormat("HTD->HUT " + response);
                writer.Write(buffer, 0, buffer.Length);
                writer.Close();

                // Response
                WebResponse resp = request.GetResponse();
                writer = resp.GetResponseStream();
                StreamReader rdr = new StreamReader(writer);
                log.InfoFormat("HUT->HTD " + rdr.ReadToEnd());
                rdr.Close();
                writer.Close();
                resp.Close();
            }
            catch (WebException exc)
            {
                log.InfoFormat("Error with Location Response - {0}", exc.Message);
            }
            catch (ProtocolViolationException exc)
            {
                log.InfoFormat("Error with ORDER CONFIRMATION - {0}" + exc.Message);
            }

            // Reject orders during TEST
            //OrderKELAReject okr = new OrderKELAReject(this.inSUTI, this.inSUTImsg, sID, msgCount);
            //okr.SendOrderKELAReject(this.inSUTImsg);

            return;
        }
        public void ReplyOrderCancel()
        {
            SUTI rmsg = new SUTI();


            orgType sender = new orgType();

            sender.name      = "HTD";
            sender.idOrg.id  = "104:HTD_001";
            sender.idOrg.src = "SUTI";

            orgType receiver = new orgType();

            receiver.name      = "HUT";
            receiver.idOrg.id  = "801:HUT_001";
            receiver.idOrg.src = "SUTI";

            rmsg.orgReceiver = receiver;
            rmsg.orgSender   = sender;

            rmsg.msg = new List <SUTIMsg>();

            SUTIMsg msgResponse = new SUTIMsg();
            idType  id          = new idType();

            id.src                   = "104:HTD_001:MSGID";
            id.id                    = System.DateTime.Now.Ticks.ToString();
            msgResponse.idMsg        = id;
            msgResponse.msgName      = "OrderReject";
            msgResponse.msgType      = "2002";
            msgResponse.referencesTo = new msgReferencesTo();
            idType idOrder = new idType();

            idOrder.src = "KELA_ROUTEID";
            idOrder.id  = this.kela_id;
            List <idType> idList = new List <idType>();

            idList.Add(idOrder);

            msgResponse.referencesTo.idOrder = idList;
            if (smsg != null)
            {
                msgResponse.referencesTo.idMsg = smsg.msg[0].idMsg;
            }
            else
            {
                idType idMsg = new idType();
                idMsg.src = "901:HUT:MSGID";
                idMsg.id  = "12345";
                msgResponse.referencesTo.idMsg = idMsg;
            }

            msgResponse.referencesTo.idOrder = idList;

            msgOrderReject or = new msgOrderReject();

            //orderReject or = new orderReject();
            or.resourceReject = new resourceType();

            manualDescriptionType md = new manualDescriptionType();

            md.manualText          = "";
            md.sendtoInvoice       = false;
            md.sendtoVehicle       = false;
            md.sendtoOperator      = false;
            md.vehicleConfirmation = false;

            or.resourceReject.manualDescriptionResource.Add(md);

            if (smsg != null)
            {
                orderRejectOrderSentBefore osb = new orderRejectOrderSentBefore();
                osb.idMsg = this.smsg.msg[0].idMsg;

                or.orderSentBefore = osb;
            }
            else
            {
                orderRejectOrderSentBefore osb = new orderRejectOrderSentBefore();
                idType idMsg = new idType();
                idMsg.src          = "901:HUT:MSGID";
                idMsg.id           = "12345";
                osb.idMsg          = idMsg;
                or.orderSentBefore = osb;
            }

            msgResponse.Item = or;

            rmsg.msg.Add(msgResponse);

            try
            {
                log.InfoFormat("HTD->HUT " + rmsg.Serialize().ToString());
                //WebRequest request = WebRequest.Create("http://10.100.113.33:8202/default.aspx");
                string response = "<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ZSI='http://www.zolera.com/schemas/ZSI/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body xmlns:ns1='http://tempuri.org/'><ns1:ReceiveSutiMsg><ns1:xmlstring>" +
                                  System.Web.HttpUtility.HtmlEncode(rmsg.Serialize().ToString()) +
                                  "</ns1:xmlstring></ns1:ReceiveSutiMsg></SOAP-ENV:Body></SOAP-ENV:Envelope>";

                byte[] buffer = Encoding.UTF8.GetBytes(response);

                WebRequest request = WebRequest.Create("http://192.168.222.11:7202/SUTI");
                request.Credentials = CredentialCache.DefaultCredentials;
                ((HttpWebRequest)request).UserAgent                 = "ASP.NET from HTD KELA SVC";
                ((HttpWebRequest)request).KeepAlive                 = false;
                ((HttpWebRequest)request).Timeout                   = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ReadWriteTimeout          = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ProtocolVersion           = HttpVersion.Version10;
                ((HttpWebRequest)request).AllowWriteStreamBuffering = false;
                ((HttpWebRequest)request).ContentLength             = buffer.Length;

                request.Method      = "POST";
                request.ContentType = "application/xml";
                Stream writer = request.GetRequestStream();

                log.InfoFormat("HTD->HUT " + response);
                writer.Write(buffer, 0, buffer.Length);
                writer.Close();

                // Response
                WebResponse resp = request.GetResponse();
                writer = resp.GetResponseStream();
                StreamReader rdr = new StreamReader(writer);
                log.InfoFormat("HUT->HTD " + rdr.ReadToEnd());
                rdr.Close();
                writer.Close();
                resp.Close();
            }
            catch (WebException exc)
            {
                log.InfoFormat("Error with KEEP ALIVE - {0}", exc.Message);
            }
            catch (ProtocolViolationException exc)
            {
                log.InfoFormat("Error with KEEP ALIVE - {0}" + exc.Message);
            }

            // *** Test Phase ***
            // ** Cancel Order and Notify *** //


            return;
        }
        public void ReplyLocation(SUTIMsg msgFrom, float gpsLat, float gpsLon)
        {
            SUTI    rmsg        = new SUTI();
            SUTIMsg msgResponse = new SUTIMsg();
            SUTIMsg msgReceived = this.inSUTImsg;

            orgType sender   = this.inSUTI.orgReceiver;
            orgType receiver = this.inSUTI.orgSender;

            rmsg.orgReceiver = receiver;
            rmsg.orgSender   = sender;

            rmsg.msg = new List <SUTIMsg>();

            idType id = new idType();

            id.src            = "104:TaxiPak_HTD_002:MSGID";
            id.id             = System.DateTime.Now.Ticks.ToString();
            msgResponse.idMsg = id;

            msgResponse.msgName = "Requested Location";
            msgResponse.msgType = "5021";

            List <timesTypeTime> lt           = new List <timesTypeTime>();
            timesTypeTime        msgtimestamp = new timesTypeTime();

            msgtimestamp.time1 = System.DateTime.Now;
            lt.Add(msgtimestamp);
            msgResponse.msgTimeStamp = lt;

            List <timesTypeTime> ltinfo        = new List <timesTypeTime>();
            timesTypeTime        infotimestamp = new timesTypeTime();

            infotimestamp.time1 = System.DateTime.Now;
            ltinfo.Add(infotimestamp);
            msgResponse.infoTimeStamp = ltinfo;

            idType idVehicle = this.inSUTImsg.referencesTo.idVehicle;

            msgResponse.referencesTo           = new msgReferencesTo();
            msgResponse.referencesTo.idVehicle = idVehicle;

            addressType        al = new addressType();
            geographicLocation gl = new geographicLocation();

            gl.lat              = gpsLat;
            gl.@long            = gpsLon;
            gl.typeOfCoordinate = "WGS-84";
            gl.precision        = "0";

            al.geographicLocation = gl;
            msgResponse.Item      = al;

            rmsg.msg.Add(msgResponse);

            try
            {
                //log.InfoFormat("HTD->HUT " + rmsg.Serialize().ToString());

                string response = "<SOAP-ENV:Envelope xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ZSI='http://www.zolera.com/schemas/ZSI/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body xmlns:ns1='http://tempuri.org/'><ns1:ReceiveSutiMsg><ns1:xmlstring>" +
                                  System.Web.HttpUtility.HtmlEncode(rmsg.Serialize().ToString()) +
                                  "</ns1:xmlstring></ns1:ReceiveSutiMsg></SOAP-ENV:Body></SOAP-ENV:Envelope>";

                byte[] buffer = Encoding.UTF8.GetBytes(response);

                WebRequest request = WebRequest.Create(ConfigurationManager.AppSettings.Get("VPUendpoint"));
                request.Credentials = CredentialCache.DefaultCredentials;
                ((HttpWebRequest)request).UserAgent                 = "ASP.NET from HTD KELA SVC";
                ((HttpWebRequest)request).KeepAlive                 = false;
                ((HttpWebRequest)request).Timeout                   = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ReadWriteTimeout          = System.Threading.Timeout.Infinite;
                ((HttpWebRequest)request).ProtocolVersion           = HttpVersion.Version10;
                ((HttpWebRequest)request).AllowWriteStreamBuffering = false;
                ((HttpWebRequest)request).ContentLength             = buffer.Length;

                request.Method      = "POST";
                request.ContentType = "application/xml";
                Stream writer = request.GetRequestStream();

                //log.InfoFormat("HTD->HUT " + response);
                writer.Write(buffer, 0, buffer.Length);
                writer.Close();

                // Response
                WebResponse resp = request.GetResponse();
                writer = resp.GetResponseStream();
                StreamReader rdr = new StreamReader(writer);
                //log.InfoFormat("HUT->HTD " + rdr.ReadToEnd());
                rdr.Close();
                writer.Close();
                resp.Close();
            }
            catch (WebException exc)
            {
                log.InfoFormat("Error with Location Response - {0}", exc.Message);
            }
            catch (ProtocolViolationException exc)
            {
                log.InfoFormat("Error with ORDER CONFIRMATION - {0}" + exc.Message);
            }

            // Reject orders during TEST
            //OrderKELAReject okr = new OrderKELAReject(this.inSUTI, this.inSUTImsg, sID, msgCount);
            //okr.SendOrderKELAReject(this.inSUTImsg);

            return;
        }
Exemple #10
0
        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();
        }