Exemple #1
0
        private static void setIncident(string data)
        {
            try
            {
                //IS.2943217.DT/022315.TM/095226.T/FSP.B/A618-052.L/I880 N I80 W Onr - Over I80 W.ST/A
                string[] splitter = data.Split('.');
                string shift = string.Empty;
                /*************
                 * DT
                 * **********/

                string tm = Array.Find(splitter, t => t.StartsWith("TM"));
                string dt = Array.Find(splitter, d => d.StartsWith("DT"));
                DateTime dtIncident = makeDateTime(dt, tm);
                int incIndex = Array.IndexOf(splitter, "IS");
                string IncidentID = splitter[incIndex + 1];

                /************
                 * Find Truck
                 * **********/
                //string _callSign = splitter[5].Replace("B/", "");
                string _beatData = Array.Find(splitter, b => b.StartsWith("B/")).ToString().Replace("B/", "");
                string _callSign = string.Empty;
                if (_beatData.Substring(0, 1) == "A" || _beatData.Substring(0, 1) == "*" || _beatData.Substring(0, 1) == "B")
                {
                    switch (_beatData.Substring(0, 1))
                    {
                        case "A":
                            shift = "AM";
                            break;
                        case "*":
                            shift = "MID";
                            break;
                        case "B":
                            shift = "PM";
                            break;
                    }
                    _callSign = _beatData.Substring(1, _beatData.Length - 1);
                }
                else
                {
                    _callSign = _beatData;
                }
                /*
                if (_callSign.Substring(_callSign.Length - 1, 1) == "A" || _callSign.Substring(_callSign.Length - 1, 1) == "B") //we don't track a/b stuff
                {
                    _callSign = _callSign.Substring(0, _callSign.Length - 1);
                }
                */
                //string[] beatSplit = _beatData.Split('-');
                //string _callSign = beatSplit[0].ToString();
                TowTruck.TowTruck truck;
                if (!string.IsNullOrEmpty(shift))
                {
                    truck = DataClasses.GlobalData.currentTrucks.Find(delegate(TowTruck.TowTruck find)
                    {
                        return find.Driver.callSign == _callSign && find.Driver.AssignedShift.ToUpper().Contains(shift);
                    });
                }
                else
                {
                    truck = DataClasses.GlobalData.currentTrucks.Find(delegate(TowTruck.TowTruck find)
                    {
                        return find.Driver.callSign == _callSign;
                    });
                }

                if (truck != null)
                {

                    //first see if we already have an incident
                    MTCIncident i = DataClasses.GlobalData.Incidents.Find(delegate(MTCIncident find) { return find.IncidentID == truck.currentIncidentID ; });

                    MTCPreAssistData pad = new MTCPreAssistData();
                    //string[] beatSplit = _callSign.Split('-');
                    string beat = truck.beatNumber;
                    //build the preassist data
                    pad.Beat = beat;
                    pad.CHPLogNumber = IncidentID.ToString();
                    //pad.LocationofInitialDispatch = Array.Find(splitter, l => l.StartsWith("L/")).ToString().Replace("L/", "");
                    pad.FSPLocation = Array.Find(splitter, l => l.StartsWith("L/")).ToString().Replace("L/", "");
                    string[] typeSplitter = Array.Find(splitter, t => t.StartsWith("T/")).Split('.');
                    string incidentType = string.Empty;
                    if (typeSplitter[0].Contains("1126"))
                    {
                        incidentType = "Disabled Vehicle-Occupied (11-26)";
                    }
                    else if (typeSplitter[0].Contains("1182"))
                    {
                        incidentType = "Accident-Property Damage (11-82)";
                    }
                    else if (typeSplitter[0].Contains("1125"))
                    {
                        incidentType = "Traffic Hazard (11-25)";
                    }
                    else if (typeSplitter[0].Contains("1124"))
                    {
                        incidentType = "Abandoned Vehicle (11-24)";
                    }
                    else if (typeSplitter[0].Contains("1183"))
                    {
                        incidentType = "Accident-No Details (11-83)";
                    }
                    else
                    {
                        incidentType = "OTHER";
                    }

                    if (truck.currentIncident != null) {
                        truck.currentIncident.chpIncidentType = incidentType;

                    }

                    pad.CHPIncidentType = incidentType;
                    truck.incidentID = IncidentID;
                    //new way
                    if (truck.currentIncident == null) {
                        Incident iNew = new Incident();
                        iNew.incidentDatePosted = DateTime.Now;
                        iNew.incidentID = Guid.NewGuid();
                        iNew.userPosted = "CHP CAD";
                        if (data.Contains("S/1097")) {
                            //this is a response message to a self-assigned incident
                            iNew.sentToTruck = true;
                        }
                        if (data.Contains("S/ENRT")) {
                            //this is a CAD assigned message
                            iNew.sentToTruck = false;
                        }
                        iNew.chpIncidentType = incidentType;
                        iNew.FSPLocation = Array.Find(splitter, l => l.StartsWith("L/")).ToString().Replace("L/", "");
                        iNew.CHPLogNumber = IncidentID.ToString();
                        iNew.logID = cadMsgID;
                        iNew.requestSent = true;
                        truck.addIncident(iNew);
                    }
                    else {
                        Incident iNew = new Incident();
                        iNew.sentToTruck = false;
                        iNew.chpIncidentType = incidentType;
                        iNew.incidentID = truck.currentIncident.incidentID;
                        iNew.beat = truck.beatNumber;
                        iNew.logID = cadMsgID;
                        iNew.CHPLogNumber = IncidentID.ToString();
                        iNew.FSPLocation = Array.Find(splitter, l => l.StartsWith("L/")).ToString().Replace("L/", "");
                        iNew.requestSent = true;
                        truck.updateIncident(iNew);
                    }

                    if (i == null)
                    {
                        //brand new incident, build from scratch
                        /************
                        * Build
                        * *********/
                        MTCIncident mi = new MTCIncident();
                        mi.assistList = new List<MTCAssist>();
                        mi.DatePosted = dtIncident;
                        mi.fromTruck = 0;
                        mi.preAssist = pad;
                        mi.UserPosted = "CHP CAD";
                        if (data.Contains("S/1097")) //this is a response message to a self-assigned incident
                        {
                            mi.Acked = true;
                            mi.sentToTruck = true;
                        }
                        if (data.Contains("S/ENRT")) //this is a CAD assigned message
                        {
                            mi.Acked = false;
                            mi.sentToTruck = false;
                        }

                        mi.IPAddr = truck.Identifier;
                        mi.incidentComplete = false;
                        if (!data.Contains("T/FSP"))
                        {
                            if (truck.currentIncidentID != new Guid("00000000-0000-0000-0000-000000000000"))
                            {
                                //we have an unclosed incident, discard this message

                            }
                            else
                            {
                                MTCIncident iHave = DataClasses.GlobalData.Incidents.Find(delegate(MTCIncident find) { return find.preAssist.CHPLogNumber == IncidentID; });
                                if (iHave == null)
                                {
                                    SQL.SQLCode mySQL = new SQL.SQLCode();
                                    mi.IncidentID = mySQL.PostMTCIncident("CHP CAD", truck.TruckNumber, "0", 0, 0.0, 0.0);
                                    DataClasses.GlobalData.addIncident(mi);
                                }
                            }
                        }
                    }
                    else
                    {
                        //already got one
                        i.preAssist = pad;
                        i.incidentComplete = false;
                        i.sentToTruck = false;
                        i.Acked = false;
                        i.preAssist.CHPIncidentType = incidentType;
                        i.preAssist.DispatchCode = incidentType;
                        truck.incidentID = IncidentID;
                        truck.currentIncidentID = i.IncidentID;
                    }
                }
            }
            catch (Exception ex)
            {
                //throw new Exception("ERROR ADDING INCIDENT: " + ex.Message);
                string err = ex.ToString();
            }
        }
Exemple #2
0
        public ActionResult DoDispatch(DispatchViewModel model)
        {
            var returnValue = new MtcReturnValue {
                OperationSuccess = true, Message = string.Empty
            };

            try
            {
                using (var service = new TowTruckServiceClient())
                {
                    if (model?.Trucks != null)
                    {
                        using (var db = new MTCDBEntities())
                        {
                            foreach (var truck in model.Trucks)
                            {
                                var assist = new MTCPreAssistData();


                                var dispatchCode = string.Empty;

                                using (var dc = new MTCDbContext())
                                {
                                    dispatchCode = dc.DispatchCodes.Find(model.DispatchCodeId).Code;
                                }


                                assist.LaneNumber   = model.LaneNumber;
                                assist.DispatchCode = dispatchCode;
                                assist.Direction    = model.Direction;
                                assist.FSPLocation  = model.Location;
                                assist.CrossStreet  = model.CrossStreet1;
                                assist.Comment      = model.Comments;
                                assist.Freeway      = model.Freeway;


                                assist.Beat                 = string.Empty;
                                assist.CHPIncidentType      = string.Empty;
                                assist.CHPLogNumber         = string.Empty;
                                assist.IncidentSurveyNumber = string.Empty;
                                assist.Lat = double.MinValue;
                                assist.Lon = double.MinValue;
                                assist.LocationofInitialDispatch = string.Empty;
                                assist.Position = string.Empty;


                                var dbTruck = db.FleetVehicles.FirstOrDefault(p => p.VehicleNumber == truck.truckNumber);

                                if (dbTruck != null)
                                {
                                    service.addAssist(HttpContext.User.Identity.Name, truck.ipAddress, assist);
                                }
                                else
                                {
                                    returnValue.OperationSuccess = false;
                                    returnValue.Message          = "Truck Not Found";
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnValue.OperationSuccess = false;
                returnValue.Message          = ex.Message;
            }


            return(Json(returnValue, JsonRequestBehavior.AllowGet));
        }
Exemple #3
0
        private static void processCADMessage(string data)
        {
            try
            {
                string bodyData = string.Empty;
                string shift = string.Empty;
                string[] splitBody = data.Split('.');
                if (splitBody[0] == "SM") //I don't think this is what the CAD actually sends for a message to a truck, it should be TO (see further down)
                {
                    sendMessageToTruck(data);
                }
                if (splitBody[0] == "US")
                {
                    //check to see if there's any incident information in the packet
                    string[] splitData = data.Split('.');

                    //int incIndex = Array.IndexOf(splitData, "II");
                    string incNumber = string.Empty;
                    if (data.Contains("II/"))
                    {
                        incNumber = Array.Find(splitData, i => i.StartsWith("II/")).ToString().Replace("II/", "");
                    }
                    if (!string.IsNullOrEmpty(incNumber))
                    {
                        string _callSign = splitData[1];

                        if (_callSign.Substring(0, 1) == "A" || _callSign.Substring(0, 1) == "*" || _callSign.Substring(0, 1) == "B")
                        {
                            switch (_callSign.Substring(0, 1))
                            {
                                case "A":
                                    shift = "AM";
                                    break;
                                case "B":
                                    shift = "PM";
                                    break;
                                case "*":
                                    shift = "MID";
                                    break;
                            }
                            _callSign = _callSign.Substring(1, _callSign.Length - 1);

                        }
                        /*
                        if (_callSign.Substring(_callSign.Length - 1, 1) == "A" || _callSign.Substring(_callSign.Length - 1, 1) == "B")
                        {
                            _callSign = _callSign.Substring(0, _callSign.Length - 1);
                        }
                        */
                        TowTruck.TowTruck truck;
                        if (!string.IsNullOrEmpty(shift))
                        {
                            truck = DataClasses.GlobalData.currentTrucks.Find(delegate(TowTruck.TowTruck find)
                            {
                                return find.Driver.callSign == _callSign && find.Driver.AssignedShift.ToUpper().Contains(shift);
                            });
                        }
                        else
                        {
                            truck = DataClasses.GlobalData.currentTrucks.Find(delegate(TowTruck.TowTruck find)
                            {
                                return find.Driver.callSign == _callSign;
                            });
                        }
                        if (truck != null)
                        {
                            //if a truck is currently on an incident or en route to an incident, reject the CAD message
                            if (truck.Status.VehicleStatus.ToUpper() == "ON INCIDENT" || truck.Status.VehicleStatus.ToUpper() == "EN ROUTE" ||
                                truck.Status.VehicleStatus.ToUpper() == "ENROUTE")
                            {
                                //TODO add reject message code
                            }
                            //Got a truck, check Incident Status
                            //incident is created when the truck enters the scene, check to see if we've got a current incidentid
                            MTCIncident i = null; //old
                            Incident iNew = null;
                            if (truck.currentIncidentID != new Guid("00000000-0000-0000-0000-000000000000"))
                            {
                                i = DataClasses.GlobalData.Incidents.Find(delegate(MTCIncident iFind) { return iFind.IncidentID == truck.currentIncidentID; });
                            }
                            if (truck.currentIncident != null) {
                                //nothing we can do, the truck is currently on incident
                                iNew = truck.currentIncident;
                                if (!string.IsNullOrEmpty(incNumber) && string.IsNullOrEmpty(truck.currentIncident.CHPLogNumber)) {
                                    truck.currentIncident.CHPLogNumber = incNumber;
                                }
                            }

                            //new incident and assist code
                            if (truck.currentIncident == null && data.Contains("ENRT")) {
                                //This is a CAD Dispatched message. 1097 means a self-dispatch message. Self
                                //dispatches are handled elsewhere but the CAD still sends a CHP Incident Log Number that we have to process
                                iNew = new Incident();
                                // this is new stuff
                                iNew.incidentID = Guid.NewGuid();
                                iNew.fromTruck = false;
                                iNew.incidentDatePosted = DateTime.Now;
                                iNew.CHPLogNumber = incNumber;
                                iNew.logID = cadMsgID;
                                iNew.userPosted = "CHP CAD";

                                truck.addIncident(iNew);
                            }
                            else if (truck.currentIncident == null && !data.Contains("ENRT")) {
                                //this is usually a response message from CAD
                                /*
                                i = new MTCIncident();
                                List<MTCAssist> assistList = new List<MTCAssist>();
                                MTCPreAssistData pad = new MTCPreAssistData();
                                i.assistList = assistList;
                                i.preAssist = pad;
                                i.preAssist.CHPLogNumber = incNumber;
                                i.Acked = true;
                                i.sentToTruck = true;
                                iNew = new Incident();
                                iNew.incidentID = cadMsgID;

                                SQL.SQLCode mySQL = new SQL.SQLCode();
                                i.IncidentID = mySQL.PostMTCIncident("CHP CAD", i.TruckNumber, "0", 0, 0.0, 0.0);
                                DataClasses.GlobalData.addIncident(i);
                                truck.currentIncidentID = i.IncidentID;
                                truck.incidentID = incNumber;
                                 */
                                iNew = new Incident();
                                iNew.incidentID = Guid.NewGuid();
                                iNew.fromTruck = false;
                                iNew.incidentDatePosted = DateTime.Now;
                                iNew.CHPLogNumber = incNumber;
                                iNew.logID = cadMsgID;
                                iNew.userPosted = "CHP CAD";
                                iNew.logID = cadMsgID;
                                truck.addIncident(iNew);
                            }

                            if (i == null && data.Contains("ENRT"))//enrt means it's a CAD dispatched message, 1097 means a self-dispatch message.  Self
                            //dispatches are handled elsewhere but the CAD still sends a CHP Incident Log Number that we have to process
                            {
                                //brand new incident
                                Guid g = Guid.NewGuid();
                                i = new MTCIncident(); //old

                                /* this is old stuff */
                                List<MTCAssist> assistList = new List<MTCAssist>();
                                MTCPreAssistData pad = new MTCPreAssistData();
                                i.IncidentID = g;
                                i.assistList = assistList;
                                i.DatePosted = DateTime.Now;
                                i.fromTruck = 0;
                                i.preAssist = pad;
                                i.preAssist.CHPLogNumber = incNumber;
                                i.UserPosted = "CHP CAD";
                                i.Acked = true;
                                i.sentToTruck = true;
                                i.IPAddr = truck.Identifier;
                                i.TruckNumber = truck.TruckNumber;
                                i.incidentComplete = false;
                                SQL.SQLCode mySQL = new SQL.SQLCode();
                                i.IncidentID = mySQL.PostMTCIncident("CHP CAD", i.TruckNumber, "0", 0, 0.0, 0.0);
                                DataClasses.GlobalData.addIncident(i);
                                truck.incidentID = incNumber;
                                truck.currentIncidentID = i.IncidentID;

                            }
                            else if (i == null && !data.Contains("ENRT")) //this is usually a response message
                            {
                                i = new MTCIncident();
                                List<MTCAssist> assistList = new List<MTCAssist>();
                                MTCPreAssistData pad = new MTCPreAssistData();
                                i.assistList = assistList;
                                i.preAssist = pad;
                                i.preAssist.CHPLogNumber = incNumber;
                                i.Acked = true;
                                i.sentToTruck = true;
                                iNew = new Incident();
                                iNew.incidentID = cadMsgID;

                                SQL.SQLCode mySQL = new SQL.SQLCode();
                                i.IncidentID = mySQL.PostMTCIncident("CHP CAD", i.TruckNumber, "0", 0, 0.0, 0.0);
                                DataClasses.GlobalData.addIncident(i);
                                truck.currentIncidentID = i.IncidentID;
                                truck.incidentID = incNumber;
                            }
                            else
                            {
                                if (i.preAssist != null)
                                {
                                    i.preAssist.CHPLogNumber = incNumber;
                                }
                            }
                        }
                    }
                    setTruckStatus(data); //if .II/x we need to create an incident and hold on to the Incident ID number from the ./II data
                }
                if (splitBody[0] == "IS") //this should just set up the incident, not create it.
                {

                    //should never have an IS message without an II first setting up the incident.  If an IS message comes through that relates to
                    //an incident that we don't have, bag it.
                    TowTruck.TowTruck t = DataClasses.GlobalData.currentTrucks.Find(delegate(TowTruck.TowTruck find) {
                        return find.currentIncident != null && find.currentIncident.CHPLogNumber == splitBody[1];
                    });
                    if (t != null) {
                        //this is the new way
                        setIncident(data);
                    }
                    MTCIncident check = DataClasses.GlobalData.Incidents.Find(delegate(MTCIncident finder) { return finder.preAssist.CHPLogNumber == splitBody[1]; });
                    if (check != null)
                    {
                        setIncident(data);
                    }
                    else
                    {
                        string[] splitter = data.Split('.');
                        string _beatData = Array.Find(splitter, b => b.StartsWith("B/")).ToString().Replace("B/", "");
                        string _callSign = string.Empty;
                        if (_beatData.Substring(0, 1) == "A" || _beatData.Substring(0, 1) == "*" || _beatData.Substring(0, 1) == "B")
                        {
                            switch (_beatData.Substring(0, 1))
                            {
                                case "A":
                                    shift = "AM";
                                    break;
                                case "*":
                                    shift = "MID";
                                    break;
                                case "B":
                                    shift = "PM";
                                    break;
                            }
                            _callSign = _beatData.Substring(1, _beatData.Length - 1);
                        }
                        else
                        {
                            _callSign = _beatData;
                        }

                        TowTruck.TowTruck truck;
                        if (!string.IsNullOrEmpty(shift))
                        {
                            truck = DataClasses.GlobalData.currentTrucks.Find(delegate(TowTruck.TowTruck find)
                            {
                                return find.Driver.callSign == _callSign && find.Driver.AssignedShift.ToUpper().Contains(shift);
                            });
                        }
                        else
                        {
                            truck = DataClasses.GlobalData.currentTrucks.Find(delegate(TowTruck.TowTruck find)
                            {
                                return find.Driver.callSign == _callSign;
                            });
                        }

                        if (truck != null)
                        {
                            MTCIncident mi = DataClasses.GlobalData.Incidents.Find(delegate(MTCIncident finder) { return
                                finder.TruckNumber == truck.TruckNumber &&
                                finder.incidentComplete == false;
                            });
                            if (mi != null)
                            {
                                int incIndex = Array.IndexOf(splitter, "IS");
                                string IncidentID = splitter[incIndex + 1];
                                truck.incidentID = IncidentID;
                                truck.currentIncident.CHPLogNumber = IncidentID;
                                //test for CAD Assigned incident id
                                string cadMSG = "US." + truck.shiftType + truck.Driver.callSign + ".S/1097.II/" + truck.currentIncident.CHPLogNumber + makeCADDate(DateTime.Now) + makeCADTime(DateTime.Now);
                                //this was removed, it doesn't appear we need it. In fact, it might be breaking things.
                                Global.cSender.sendMessage(cadMSG);
                                if (mi.preAssist != null)
                                {
                                    mi.preAssist.CHPLogNumber = IncidentID;
                                }
                                else
                                {
                                    MTCPreAssistData pad = new MTCPreAssistData();
                                    pad.CHPLogNumber = IncidentID;
                                    mi.preAssist = pad;
                                }
                            }
                        }
                    }
                }
                if (splitBody[0] == "AM")
                {
                    //message accept from CAD
                    //Don't worry about it
                }
                if (splitBody[0] == "TO")
                {
                    //this is a message from CAD to the tablet
                    sendAMessage(data);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("ERROR PROCESSING INCOMING CAD MESSAGE: " + ex.Message + Environment.NewLine + data);
            }
        }