示例#1
0
        public async Task SaveMonitoringLogAsync(GLOSAMonitoringLog item)
        {
            try
            {
                // Insert the new item into the local store.
                await _monitoringLogTable.InsertAsync(item);

#if OFFLINE_SYNC_ENABLED
                // Send changes to the mobile app backend.
                await SyncAsync();
#endif
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message.ToString());
            }
        }
示例#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;
            }
        }
示例#3
0
 public static void LogMonitoring(IDataAnalyticsService dataService, GLOSAMonitoringLog monitoringLog)
 {
     Task.Run(() => dataService.SaveMonitoringLogAsync(monitoringLog));
 }
示例#4
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;
            }
        }