Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
            }
        }