Пример #1
0
 private bool HasMAPDataForIntersection(string intersectionId)
 {
     return(MAPDataStore != null && MAPDataStore.ContainsKey(intersectionId) == true);
 }
Пример #2
0
        private async Task MAPRequest(string intersectionId)
        {
            if (_mapRequestActive == true)
            {
                return;
            }

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

            _mapRequestActive = true;
            var    before        = DateTime.Now;
            var    requestMethod = "GET";
            var    URL           = $"{Constants.API_GLOSA_MAP_ENDPPOINT_URL}&param={intersectionId}";
            int    statusCode    = 0;
            string value         = null;

            try
            {
                var map = MAPDataStore.ContainsKey(intersectionId) ? MAPDataStore[intersectionId] : null;
                if (map == null)
                {
                    Envelope envelope = await GLOSACommunicateAsync <Envelope>(intersectionId, Constants.API_GLOSA_MAP_ENDPPOINT_URL);

                    MapData data = envelope.Body.MapData;
                    statusCode = 200;
                    if (data != null)
                    {
                        if (MAPDataStore.ContainsKey(intersectionId))
                        {
                            MAPDataStore[intersectionId] = data;
                        }
                        else
                        {
                            MAPDataStore.Add(intersectionId, data);
                        }

                        MAPDataLastSyncTime = DateTime.Now;
                    }
                }
            }
            catch (Exception e)
            {
                if (MAPRequestErrors.ContainsKey(intersectionId))
                {
                    MAPRequestErrors[intersectionId]++;
                }
                else
                {
                    MAPRequestErrors.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);
                    }
                }

                _mapRequestActive = false;
            }
        }