Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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;
                        msgRemoveList.Add(de);
                        List <SUTIMsg> messagesIn = smsg.msg;
                        SUTIMsg        theMsg     = messagesIn[0];

                        //System.Diagnostics.Debug.WriteLine(theMsg.idMsg.id + "," + de.Key);
                        //log.InfoFormat(theMsg.idMsg.id + "," + de.Key);

                        if (theMsg.msgType.Equals("7000")) // Keep Alive
                        {
                            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
                        {
                            MsgToVehicle daMsgToVehicle = new MsgToVehicle(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            daMsgToVehicle.ReplyMsgToVehicle();
                        }
                        else if (theMsg.msgType.Equals("2000")) // Order
                        {
                            OrderKELA daOrder         = new OrderKELA(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            order     theOrderDetails = (order)theMsg.Item;
                            daOrder.ReplyOrderKELA(theOrderDetails.idOrder.id);
                        }
                        else if (theMsg.msgType.Equals("2010")) // Order cancel
                        {
                            OrderKelaCancel daCancel = new OrderKelaCancel(smsg, theMsg, theMsg.idMsg.id, Int32.Parse(Application["msgCount"].ToString()));
                            daCancel.CancelConfirm(theMsg);
                        }
                    }

                    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 2002
                                OrderKELAReject or = new OrderKELAReject(om.kela_id, om.tpak_id, om.inSUTImsg,
                                                                         Int32.Parse(Application["msgCount"].ToString()));

                                or.ReplyOrderCancel();
                                removeList.Add(de);
                            }
                            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;
                                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 Kela orders  " + count + " Orders checked " + countChecked);
                    foreach (DictionaryEntry de in removeList)
                    {
                        CallHashTable.Remove(de.Key);
                    }

                    removeList.Clear();
                }

                Thread.Sleep(10000);
            }
        }