Exemplo n.º 1
0
        private static GeneralData loadGeneralData(string[] dataLines)
        {
            int pos;

            for (pos = 0; pos < dataLines.Length; pos++)
            {
                if (string.Equals(dataLines[pos].Trim(), GeneralSectionHeader, StringComparison.Ordinal))
                {
                    break;
                }
            }

            if (pos >= dataLines.Length)
            {
                throw new Exception("Could not find General section in data feed.");
            }

            // We could use the property name as keys, but there's no heirarchy to the data, so we have no idea where the line is coming from. Just because a line starts with
            // 'VERSION =' doesn't mean it's the version field of the general section. IMO it's safer to assume that the properties are always in the same order
            // and just access them by line index. This is why JSON is a thing.
            string version             = getGeneralLineValue(dataLines, ++pos);
            string reload              = getGeneralLineValue(dataLines, ++pos);
            string update              = getGeneralLineValue(dataLines, ++pos);
            string atisRefresh         = getGeneralLineValue(dataLines, ++pos);
            string numConnectedClients = getGeneralLineValue(dataLines, ++pos);

            DateTime reloadUtc = !string.IsNullOrWhiteSpace(reload) ? DateTime.UtcNow.AddMinutes(Convert.ToDouble(reload)) : DateTime.MinValue;
            DateTime updateUtc = !string.IsNullOrWhiteSpace(update) ? DateTime.ParseExact(update, DateTimeFormat, CultureInfo.CurrentCulture.DateTimeFormat) : DateTime.MinValue;

            GeneralData general = new GeneralData(version, reloadUtc, updateUtc,
                                                  !string.IsNullOrWhiteSpace(atisRefresh) ? Convert.ToInt32(atisRefresh) : 0,
                                                  !string.IsNullOrWhiteSpace(numConnectedClients) ? Convert.ToInt32(numConnectedClients) : 0);

            return(general);
        }
Exemplo n.º 2
0
        private async Task refreshIfDataExpired()
        {
            if (_lastRefresh < (_general?.ReloadUtc ?? DateTime.MinValue))
            {
                return;
            }

            string[] dataLines = (await Loader.LoadData(Status.GetDataUrl().ToString()))
                                 .Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)
                                 .Where(s => !s.StartsWith(CommentCharacter)).ToArray();

            _general = loadGeneralData(dataLines);
            _clients = loadClientData(dataLines);

            _lastRefresh = DateTime.UtcNow;
        }