Ejemplo n.º 1
0
        private void LoadObservation()
        {
            if (_observation != null && _observation.ObservationAge < _settings.RefreshInterval)
            {
                return;
            }

            var downloaded = false;

            if (!_fileClient.FileExists("cache", "emhi.xml"))
            {
                downloaded = true;
                DownloadObservations();
            }

loadObservations:
            var xml = Encoding.UTF8.GetString(_fileClient.GetFile("cache", "emhi.xml"));
            var xRoot = new XmlRootAttribute {
                ElementName = "observations"
            };
            var serializer = new XmlSerializer(typeof(Observations), xRoot);

            using (var reader = new StringReader(xml))
            {
                _observation = (Observations)serializer.Deserialize(reader);
            }

            if (_observation.ObservationAge > _settings.RefreshInterval && !downloaded)
            {
                downloaded = true;
                DownloadObservations();
                goto loadObservations;
            }
        }