/// <summary> /// Request information about the Traffic Management Center /// </summary> /// <returns>The organization id</returns> private string SubmitCenterActiveVerificationRequest() { var client = new TmddEnhancedServiceClient(); var request = new CenterActiveVerificationRequest { authentication = new Authentication { userid = Username, password = Password }, organizationrequesting = new OrganizationInformation { organizationid = 1.ToString() } }; try { var response = client.dlCenterActiveVerificationRequest(request); return(response.organizationinformation.organizationid); } catch (Exception ex) { LogError(ex.Message); return(null); } }
/// <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> /// Gets the signal inventory for all intersection. Signal inventory = name and id of each intersection /// </summary> /// <returns>List of intersection inventory items</returns> public List <IntersectionInventoryItem> GetSignalInventory() { if (inventory.Count == 0) { // Create the client var client = new TmddEnhancedServiceClient(); // Create the inventory request. var request = 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 }, }; try { var response = client.dlIntersectionSignalInventoryRequest(request); for (int i = 0; i < response.intersectionsignalinventoryitem.Length; i++) { IntersectionInventoryItem inv = new IntersectionInventoryItem(); inv.Name = response.intersectionsignalinventoryitem[i].deviceinventoryheader.devicename; inv.ID = response.intersectionsignalinventoryitem[i].deviceinventoryheader.deviceid; inventory.Add(inv); } } catch (Exception ex) { inventory = null; LogError(ex.Message); } } return(inventory); }
/// <summary> /// Create a subscription for intersection signal status. In this request, we will ask /// for new status to be sent to our External Center (at the specified returnAddress) /// on status change. /// /// In our example, we will only request status for the first traffic controller /// received in the prior service call; however, this subscription could easily have /// requested for multiple controllers or all controllers (blank devicefilter). /// </summary> /// <param name="orgId"></param> /// <param name="action"></param> private static void SubmitIntersectionStatusSubscriptionRequest(string orgId, SubscriptionActionEnum action) { try { var c2CMessageSubscription = new C2cMessageSubscription() { informationalText = "Example informationalText", subscriptionID = $"{SubscriptionId}", returnAddress = MyExternalCenterUrl, subscriptionAction = new SubscriptionAction { subscriptionActionitem = new[] { action.ToString(), } }, subscriptionType = new SubscriptionType() { subscriptionTypeitem = SubscriptionTypeEnum.Periodic.ToString() }, subscriptionFrequency = 5 }; var deviceInformationRequest = new DeviceInformationRequest() { organizationinformation = new OrganizationInformation() { organizationid = $"{orgId}" }, authentication = new Authentication() { userid = Username, password = Password }, //devicefilter = new DeviceInformationRequestFilter() //{ // deviceidlist = new DeviceInformationRequestFilterDeviceidlist() // { // deviceid = new[] { _firstIntersectionSignalId.ToString() } // } //}, devicetype = Constants.DeviceTypes.SignalController, deviceinformationtype = Constants.DeviceInformationTypes.Status }; // Create the client var client = new TmddEnhancedServiceClient(); var response = client.dlDeviceInformationSubscription(c2CMessageSubscription, deviceInformationRequest); Console.WriteLine($"Response: {response.informationalText}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <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); } } }
/// <summary> /// Request information about the Traffic Management Center /// </summary> /// <returns></returns> private static string SubmitCenterActiveVerificationRequest() { Console.WriteLine("\nSubmitting CenterActiveVerification request..."); var client = new TmddEnhancedServiceClient(); var request = new CenterActiveVerificationRequest { authentication = new Authentication { userid = Username, password = Password }, organizationrequesting = new OrganizationInformation { organizationid = 1.ToString() } }; try { var response = client.dlCenterActiveVerificationRequest(request); Console.WriteLine("Center Id: {0}\nCenter Name: {1}", response.organizationinformation.organizationid, response.organizationinformation.organizationname); return(response.organizationinformation.organizationid); } catch (FaultException fe) { Console.WriteLine("Fault exception encountered: {0}", fe.Message); return(null); } catch (Exception ex) { Console.WriteLine("Exception encountered: {0}", ex.Message); return(null); } }
/// <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> /// Queries the TMDD service for the current status of the specified intersections /// </summary> /// <param name="id">The intersections ID to query</param> /// <param name="client">The TMDD client</param> /// <returns>The intersection status</returns> private IntersectionSignalStatus[] PerformStatusQuery(string[] id, TmddEnhancedServiceClient client) { IntersectionSignalStatus[] status = null; // Create the inventory request. var request = new DeviceInformationRequest { deviceinformationtype = Constants.DeviceInformationTypes.Status, 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 }, // Filter the request to only get information about the desired intersection id devicefilter = new DeviceInformationRequestFilter() { deviceidlist = new DeviceInformationRequestFilterDeviceidlist() { deviceid = id } }, }; try { var response = client.dlIntersectionSignalStatusRequest(request); // What this message returns is an array of IntersectionSignalStatus items. // Iterate through the collection to inspect the objects. if (response.intersectionsignalstatusitem != null) { status = response.intersectionsignalstatusitem; } } catch (Exception ex) { LogError(ex.Message); status = null; } return(status); }
private static void SubmitInventorySignalTimingInventoryRequest(string orgId) { Console.WriteLine("\nSubmitting InventorySignalTimingInventoryRequest..."); // Create the client var client = new TmddEnhancedServiceClient(); 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[] { "b3c0fe11-bbe0-4dd2-9a6d-a77700e13754" } } }, } }; try { var response = client.dlIntersectionSignalTimingInventoryRequest(request); // What this message returns is an array of IntersectionSignalTimingPatternInventory items. // Iterate through the collection to inspect the objects. foreach (var item in response.intersectionsignaltiminginventoryitem) { // Print out some retrieved data if (item.intervals?.intervals != null && item.intervals.intervals.Any()) { Console.WriteLine( "\nOrganization ID: {0}\nOrganization Name: {1}\nDevice Id: {2}\nInterval #: {3}\nInterval Time: {4}", item.organizationinformation.organizationid, item.organizationinformation.organizationname, item.deviceid, item.intervals.intervals[0].intervalidentifier, item.intervals.intervals[0].IntervalTime); } else if (item.phases != null && item.phases.phases.Any()) { Console.WriteLine( @"\nOrganization ID: {0}\nOrganization Name: {1}\nDevice Id: {2}\Phase 1 Min Green: {3}", item.organizationinformation.organizationid, item.organizationinformation.organizationname, item.deviceid, item.phases.phases[0].MinGreen); } } } catch (FaultException fe) { Console.WriteLine("Fault exception encountered: {0}", fe.Message); } catch (Exception ex) { Console.WriteLine("Exception encountered: {0}", ex.Message); } }
/// <summary> /// Request list of traffic controller status from Traffic Management Center /// </summary> /// <param name="orgId"></param> private static void SubmitIntersectionSignalStatusRequest(string orgId) { Console.WriteLine("\nSubmitting IntersectionSignalStatusRequest..."); // Create the client var client = new TmddEnhancedServiceClient(); // Create the inventory request. var request = new DeviceInformationRequest { deviceinformationtype = Constants.DeviceInformationTypes.Status, 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[] { "b3c0fe11-bbe0-4dd2-9a6d-a77700e13754" } } }, }; try { var response = client.dlIntersectionSignalStatusRequest(request); // What this message returns is an array of IntersectionSignalStatus items. // Iterate through the collection to inspect the objects. if (response.intersectionsignalstatusitem == null) { Console.WriteLine("No intersection signal status found."); return; } for (int i = 0; i < response.intersectionsignalstatusitem.Length; i++) { var item = response.intersectionsignalstatusitem[i]; // Save this ID so we can create a subscription using it later. if (i == 0 && Guid.TryParse(item.devicestatusheader.deviceid, out var intersectionId)) { _firstIntersectionSignalId = intersectionId; } Console.WriteLine( "\nOrganization ID: {0}\nOrganization Name: {1}\nDevice Id: {2}\nStatus: {3}\nCurrent Pattern: {4}\nPhase Greens: {5}", item.devicestatusheader.organizationinformation.organizationid, item.devicestatusheader.organizationinformation.organizationname, item.devicestatusheader.deviceid, item.devicestatusheader.devicestatus, item.timingpatternidcurrent, (item.phasestatus?.phasestatusgroup != null && item.phasestatus.phasestatusgroup.Any()) ? item.phasestatus.phasestatusgroup[0].phasestatusgroupgreens.ToString() : "Unknown" ); } } catch (FaultException fe) { Console.WriteLine("Fault exception encountered: {0}", fe.Message); } catch (Exception ex) { Console.WriteLine("Exception encountered: {0}", ex.Message); } }
/// <summary> /// Request list of traffic controllers from Traffic Management Center /// </summary> /// <param name="orgId"></param> private static void SubmitIntersectionSignalInventoryRequest(string orgId) { Console.WriteLine("\nSubmitting IntersectionSignalInventoryRequest..."); // Create the client var client = new TmddEnhancedServiceClient(); // Create the inventory request. var request = 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 }, }; try { var response = client.dlIntersectionSignalInventoryRequest(request); // What this message returns is an array of IntersectionSignalInventory items. // Iterate through the collection to inspect the objects. for (int i = 0; i < response.intersectionsignalinventoryitem.Length; i++) { var item = response.intersectionsignalinventoryitem[i]; // Save this ID so we can create a subscription using it later. if (i == 0 && Guid.TryParse(item.deviceinventoryheader.deviceid, out var intersectionId)) { _firstIntersectionSignalId = intersectionId; } Console.WriteLine( "\nOrganization ID: {0}\nOrganization Name: {1}\nDevice Id: {2}\nDevice Name: {3}\nDevice Location: {4}, {5}", item.deviceinventoryheader.organizationinformation.organizationid, item.deviceinventoryheader.organizationinformation.organizationname, item.deviceinventoryheader.deviceid, item.deviceinventoryheader.devicename, item.deviceinventoryheader.devicelocation.latitude, item.deviceinventoryheader.devicelocation.longitude); } } catch (FaultException fe) { Console.WriteLine("Fault exception encountered: {0}", fe.Message); } catch (Exception ex) { Console.WriteLine("Exception encountered: {0}", ex.Message); } }
private static void SubmitInventorySignalTimingPatternRequest(string orgId) { Console.WriteLine("\nSubmitting InventorySignalTimingPatternRequest..."); // Create the client var client = new TmddEnhancedServiceClient(); var request = new IntersectionSignalTimingPatternInventoryRequest { 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 }, } }; try { var response = client.dlIntersectionSignalTimingPatternInventoryRequest(request); // What this message returns is an array of IntersectionSignalTimingPatternInventory items. // Iterate through the collection to inspect the objects. foreach (var item in response.intersectionsignaltimingpatterninventoryitem) { // Print out some retrieved data if (item.stagestplist?.stages != null && item.stagestplist.stages.Any()) { Console.WriteLine( "\nOrganization ID: {0}\nOrganization Name: {1}\nDevice Id: {2}\nPattern: {3}\nCycle Length: {4},\nOffset: {5}\nStage 1 Duration: {6}", item.organizationinformation.organizationid, item.organizationinformation.organizationname, item.deviceid, item.timingpatternid, item.cyclelength, item.offsettime, item.stagestplist.stages[0].Duration); } else { // Gather sequence info, if any var r1B1 = string.Empty; if (item.sequenceinformation?.sequenceinformation != null && item.sequenceinformation.sequenceinformation.Any() && item.sequenceinformation.sequenceinformation[0].sequencedata.BarrierData != null && item.sequenceinformation.sequenceinformation[0].sequencedata.BarrierData.Any()) { r1B1 = string.Join(",", item.sequenceinformation.sequenceinformation[0].sequencedata.BarrierData[0].phaseidentifier); } if (r1B1 != string.Empty) { Console.WriteLine( $"\nOrganization ID: {item.organizationinformation.organizationid}\nOrganization Name: {item.organizationinformation.organizationname}\nDevice Id: {item.deviceid}\nPattern: {item.timingpatternid}\nCycle Length: {item.cyclelength},\nOffset: {item.offsettime}\nRing 1 Barrier 1 Sequence: {r1B1}"); } else { Console.WriteLine( $"\nOrganization ID: {item.organizationinformation.organizationid}\nOrganization Name: {item.organizationinformation.organizationname}\nDevice Id: {item.deviceid}\nPattern: {item.timingpatternid}\nCycle Length: {item.cyclelength},\nOffset: {item.offsettime}"); } } } } catch (FaultException fe) { Console.WriteLine("Fault exception encountered: {0}", fe.Message); } catch (Exception ex) { Console.WriteLine("Exception encountered: {0}", ex.Message); } }