/// <summary> /// Gets the status of on an intersection without acquiring a lock. /// This should only be called if the lock has already been acquired /// </summary> /// <param name="id">The ID the intersection to query</param> /// <returns>The intersection status</returns> private List <IntersectionStatus> GetIntersectionStatusNoLock(string[] id) { var client = new TmddEnhancedServiceClient(); List <IntersectionStatus> returnStatus = new List <IntersectionStatus>(); IntersectionSignalStatus[] status = PerformStatusQuery(id, client); foreach (IntersectionSignalStatus s in status) { IntersectionStatus curStatus = new IntersectionStatus(); curStatus.ID = s.devicestatusheader.deviceid; IntersectionSignalTimingInventory inventory = PerformTimingInventoryQuery(s.devicestatusheader.deviceid, client); curStatus.Name = ""; curStatus.GroupGreens = s.phasestatus.phasestatusgroup[0].phasestatusgroupgreens; curStatus.AllPhases = new List <PhaseInfo>(); curStatus.ActivePhases = GetActivePhases(s.phasestatus.phasestatusgroup[0].phasestatusgroupgreens); foreach (var phase in inventory.phases.phases) { PhaseInfo item = new PhaseInfo(); item.PhaseID = phase.phaseidentifier; item.MinGreen = phase.MinGreen; item.MaxGreen = phase.MaxLimit; item.LastActiveTime = 0; item.CurrentlyActive = curStatus.ActivePhases.Contains(item.PhaseID); curStatus.AllPhases.Add(item); } returnStatus.Add(curStatus); } return(returnStatus); }
/// <summary> /// Queries the TMDD client for the timing inventory of an intersection /// </summary> /// <param name="id">ID of the intersection</param> /// <param name="client">TMDD client</param> /// <returns>The instersection signal timing inventory</returns> private IntersectionSignalTimingInventory PerformTimingInventoryQuery(string id, TmddEnhancedServiceClient client) { IntersectionSignalTimingInventory returnValue = null; var request = new IntersectionSignalTimingInventoryRequest { deviceinformationrequestheader = new DeviceInformationRequest { deviceinformationtype = Constants.DeviceInformationTypes.Inventory, devicetype = Constants.DeviceTypes.SignalController, authentication = new Authentication { userid = Username, password = Password }, // This is the caller's "organization id". In a production environment, // this should be assigned by the Traffic Management Center administrator. organizationrequesting = new OrganizationInformation { organizationid = 1.ToString() }, // This is the organization id of the organization you are requesting // inventory for. This is found by inspecting the // centerActiveVerification response or the organizationInformation response. // If you omit this, you will receive inventory for all organizations // at this endpoint. This endpoint is specific to this test server and // contains only a sample city's data. // Here we are simply passing it what was passed to this method. organizationinformation = new OrganizationInformation() { organizationid = orgId }, devicefilter = new DeviceInformationRequestFilter() { deviceidlist = new DeviceInformationRequestFilterDeviceidlist() { deviceid = new[] { id } } }, } }; try { var response = client.dlIntersectionSignalTimingInventoryRequest(request); if (response.intersectionsignaltiminginventoryitem.Length > 0) { returnValue = response.intersectionsignaltiminginventoryitem[0]; } } catch (Exception ex) { LogError(ex.Message); } return(returnValue); }
/// <summary> /// Gets the status of an intersection. The status is returned from the statusDictionary if it is getting continuous updates /// </summary> /// <param name="id">ID of the intersection to get the status of</param> /// <param name="forceQuery">If true the status will not be returned from the statusDictionary even if it exists in it</param> /// <returns>The intersection status</returns> public IntersectionStatus GetIntersectionStatus(string id, bool forceQuery = false) { lock (statusLock) { // If we are already tracking the status of the intersection return that value if (statusDictionary.ContainsKey(id) && !forceQuery && statusDictionary[id] != null) { IntersectionStatus status = new IntersectionStatus(); status.ActivePhases = statusDictionary[id].ActivePhases; status.AllPhases = statusDictionary[id].AllPhases; status.GroupGreens = statusDictionary[id].GroupGreens; status.ID = statusDictionary[id].ID; status.Name = statusDictionary[id].Name; return(status); } // If we are not tracking still return the intersection status else { var client = new TmddEnhancedServiceClient(); IntersectionStatus returnStatus = new IntersectionStatus(); IntersectionSignalStatus status = PerformStatusQuery(new string[] { id }, client)[0]; IntersectionSignalTimingInventory inventory = PerformTimingInventoryQuery(id, client); returnStatus.ID = status.devicestatusheader.deviceid; returnStatus.Name = ""; returnStatus.GroupGreens = status.phasestatus.phasestatusgroup[0].phasestatusgroupgreens; returnStatus.AllPhases = new List <PhaseInfo>(); returnStatus.ActivePhases = GetActivePhases(status.phasestatus.phasestatusgroup[0].phasestatusgroupgreens); foreach (var phase in inventory.phases.phases) { PhaseInfo item = new PhaseInfo(); item.PhaseID = phase.phaseidentifier; item.MinGreen = phase.MinGreen; item.MaxGreen = phase.MaxLimit; item.LastActiveTime = 0; item.CurrentlyActive = returnStatus.ActivePhases.Contains(item.PhaseID); returnStatus.AllPhases.Add(item); } return(returnStatus); } } }