Пример #1
0
 private bool HasSignalPhaseAndTimingForIntersection(string intersectionId)
 {
     return(SPATDataStore != null && SPATDataStore.ContainsKey(intersectionId) == true);
 }
Пример #2
0
        private async Task SPATRequest(string intersectionId)
        {
            // Should request every 10 seconds
            if (ShouldSyncSPATData(intersectionId) == false)
            {
                return;
            }

            if (_spatRequestActive == true)
            {
                return;
            }

            if (SPATRequestErrors.ContainsKey(intersectionId) && SPATRequestErrors[intersectionId] > 5)
            {
                return;
            }

            var before = DateTime.Now;

            _spatRequestActive = true;
            var    requestMethod = "GET";
            var    URL           = $"{Constants.API_GLOSA_SPAT_ENDPPOINT_URL}&param={intersectionId}";
            int    statusCode    = 0;
            string value         = null;

            try
            {
                Envelope envelope = await GLOSACommunicateAsync <Envelope>(intersectionId, Constants.API_GLOSA_SPAT_ENDPPOINT_URL);

                SPAT data = envelope.Body.SPAT;
                if (data != null)
                {
                    if (SPATDataStore.ContainsKey(intersectionId))
                    {
                        SPATDataStore[intersectionId] = data;
                    }
                    else
                    {
                        SPATDataStore.Add(intersectionId, data);
                    }

                    UpdateSPATSyncTime(intersectionId);
                }
                statusCode = 200;
            }
            catch (Exception e)
            {
                if (SPATRequestErrors.ContainsKey(intersectionId))
                {
                    SPATRequestErrors[intersectionId]++;
                }
                else
                {
                    SPATRequestErrors.Add(intersectionId, 1);
                }

                var result = new GLOSAResult();
                result.Errors = GLOSAErrors.WebServiceError;
                if (e.GetType() == typeof(XmlException))
                {
                    result.Errors = GLOSAErrors.WebServiceXMLParsingError;
                }
                else
                {
                    statusCode = 500;
                    value      = e.Message;
                }
            }
            finally
            {
                if (statusCode > 0)
                {
                    var    after   = DateTime.Now;
                    double latency = (after - before).TotalMilliseconds;

                    var log = new GLOSAMonitoringLog()
                    {
                        URL        = URL,
                        StatusCode = statusCode,
                        Method     = requestMethod,
                        Latency    = latency,
                        Value      = value,
                    };

                    if (_dataAnalyticsService != null)
                    {
                        Logger.LogMonitoring(_dataAnalyticsService, log);
                    }
                }
                _spatRequestActive = false;
            }
        }