Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
        /// <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);
            }
        }