public void TargetTimeout(string console, string codingID, CodingUnits[] dispatchUnits)
        {
            //Debug.WriteLine("TargetTimeout");
            //Cross thread 
            SendOrPostCallback callback = delegate (object state)
            {
                if (CheckNoDelayMsg(codingID, console))
                {
                    //Check against Pending number in coding tab, If there is any pending
                    //remove those which had respond base on message tab with codingID
                    foreach (CodingStatus codingstatus in _CodingStatusList)
                    {
                        if (codingstatus.CodingID.Equals(codingID))
                        {
                            if (codingstatus.Pending != "0")
                            {
                                //Remove those station that already reply in the list
                                bool nomatchinmsgstatus = true;
                                foreach (MessageStatus msgstatus in _MessageStatusList)
                                {
                                    if (msgstatus.CodingID.Equals(codingID) && msgstatus.AckFrom.Equals(console))
                                    {
                                        nomatchinmsgstatus = false; //console already acknowledge
                                    }
                                }

                                if (nomatchinmsgstatus)
                                {
                                    //Notify those failed msg to console
                                    _CallOut_CodingService.RemovefromMsgQueue(console, codingID);

                                    //update coding status
                                    UpdateCodingStatus(codingID, "Failed");
                                    //update message status
                                    MessageStatus messagestatus = UpdateMessageStatus(codingID, console, "Failed");

                                    List<string> unitcallsign = new List<string>();
                                    //To give relevant station units callsign
                                    foreach (CodingUnits unit in dispatchUnits)
                                    {
                                        if (unit.UnitCurrentStation.Equals(console))
                                        {
                                            unitcallsign.Add(unit.Callsign);
                                        }

                                        //For Test message
                                        if (unit.UnitCurrentStation.Equals("Test"))
                                        {
                                            unitcallsign.Add(unit.Callsign);
                                        }
                                    }

                                    //Broadcast Coding status back to CAD (failed)
                                    SendBroadcastIncidentCoding(console, "Failed", unitcallsign.ToArray(), messagestatus);
                                }
                            }
                        }
                    }
                }
            };

            _uiSyncContext.Post(callback, "target timeout");
        }
        public CodingIncidentMessage ConvertDispatchedIncidentToCoding(gCAD.Shared.IntegrationContract.DispatchedIncident CADincidentMsg)
        {
            string codingID = _CallOut_CodingService.GetCodingID();

            CodingLocation incidentLocation = new CodingLocation();
            incidentLocation.Name = "N.A. Name";
            //incidentLocation.Name = CADincidentMsg.IncidentLocation.Name;
            incidentLocation.Street = CADincidentMsg.IncidentLocation.Street;
            incidentLocation.Unit = CADincidentMsg.IncidentLocation.Unit;
            incidentLocation.State = CADincidentMsg.IncidentLocation.State;
            incidentLocation.City = CADincidentMsg.IncidentLocation.City;
            incidentLocation.Country = "N.A. Country";
            //incidentLocation.Country = CADincidentMsg.IncidentLocation.Country;
            incidentLocation.PostalCode = CADincidentMsg.IncidentLocation.PostalCode;

            List<CodingUnits> tmpcodingunitList = new List<CodingUnits>();
            foreach (gCAD.Shared.IntegrationContract.DispatchedUnit unit in CADincidentMsg.ListOfUnits)
            {
                CodingUnits newUnit = new CodingUnits();
                newUnit.ID = unit.ID;
                newUnit.Callsign = unit.CallSign;
                newUnit.UnitType = "N.A. Unit Type";
                //newUnit.UnitType = unit.UnitType;
                newUnit.FromStatus = unit.Status;
                newUnit.UnitLocation = unit.Location;
                newUnit.UnitHomeStation = unit.HomeStation;
                newUnit.UnitCurrentStation = unit.CurrentStation;

                tmpcodingunitList.Add(newUnit);
            }

            CodingUnits[] dispatchUnits = tmpcodingunitList.ToArray();

            CodingIncidentMessage codingIncidentMsg = new CodingIncidentMessage();
            codingIncidentMsg.CodingID = codingID;
            codingIncidentMsg.IncidentNo = CADincidentMsg.IncidentNumber;
            codingIncidentMsg.IncidentTitle = "N.A. Incident Title";
            //codingIncidentMsg.IncidentTitle = CADincidentMsg.IncidentTitle;
            codingIncidentMsg.IncidentLocation = incidentLocation;
            codingIncidentMsg.IncidentType = CADincidentMsg.IncidentType;
            codingIncidentMsg.IncidentAlarm = CADincidentMsg.AlarmLevel;
            codingIncidentMsg.IncidentPriority = CADincidentMsg.Priority;
            codingIncidentMsg.DispatchDateTime = CADincidentMsg.DateTime;
            codingIncidentMsg.DispatchUnits = dispatchUnits;

            return codingIncidentMsg;
        }
        private CodingIncidentMessage TestMessageTemplate2()
        {
            string testID = _CallOut_CodingService.GetTestID();
            string testNo = testID;
            string testTitle = this.txtTestMsg.Text; //Test Message

            CodingLocation testlocation = new CodingLocation();
            testlocation.Name = "Test Location";
            testlocation.Street = "Test Address";
            testlocation.Unit = "Test Unit";
            testlocation.State = "Test State";
            testlocation.City = "Test City";
            testlocation.Country = "Test Country";
            testlocation.PostalCode = "123456";

            string testType = "Test Type";
            int testAlarm = 0;
            string testPriority = "0";
            DateTime testDateTime = DateTime.Now;

            CodingUnits testUnit1 = new CodingUnits();
            testUnit1.ID = 123;
            testUnit1.Callsign = "T100";
            testUnit1.UnitType = "Test Unit 1";
            testUnit1.FromStatus = "";
            testUnit1.UnitLocation = "";
            testUnit1.UnitHomeStation = "";
            testUnit1.UnitCurrentStation = "Test";

            CodingUnits testUnit2 = new CodingUnits();
            testUnit1.ID = 456;
            testUnit2.Callsign = "T200";
            testUnit2.UnitType = "Test Unit 2";
            testUnit2.FromStatus = "";
            testUnit2.UnitLocation = "";
            testUnit2.UnitHomeStation = "";
            testUnit2.UnitCurrentStation = "Test";

            CodingUnits testUnit3 = new CodingUnits();
            testUnit3.ID = 123;
            testUnit3.Callsign = "T300";
            testUnit3.UnitType = "Test Unit 3";
            testUnit3.FromStatus = "";
            testUnit3.UnitLocation = "";
            testUnit3.UnitHomeStation = "";
            testUnit3.UnitCurrentStation = "Test";

            CodingUnits testUnit4 = new CodingUnits();
            testUnit4.ID = 456;
            testUnit4.Callsign = "T400";
            testUnit4.UnitType = "Test Unit 4";
            testUnit4.FromStatus = "";
            testUnit4.UnitLocation = "";
            testUnit4.UnitHomeStation = "";
            testUnit4.UnitCurrentStation = "Test";

            CodingUnits[] testUnitList = new CodingUnits[4];
            testUnitList[0] = testUnit1;
            testUnitList[1] = testUnit2;
            testUnitList[2] = testUnit3;
            testUnitList[3] = testUnit4;

            CodingIncidentMessage testIncidentMsg = new CodingIncidentMessage();
            testIncidentMsg.CodingID = testID;
            testIncidentMsg.IncidentNo = testNo;
            testIncidentMsg.IncidentTitle = testTitle;
            testIncidentMsg.IncidentLocation = testlocation;
            testIncidentMsg.IncidentType = testType;
            testIncidentMsg.IncidentAlarm = testAlarm;
            testIncidentMsg.IncidentPriority = testPriority;
            testIncidentMsg.DispatchDateTime = testDateTime;
            testIncidentMsg.DispatchUnits = testUnitList;

            return testIncidentMsg;
        }