internal override async Task <Dictionary <int, Tle> > FetchNewTles() { if (File.Exists(_localFilename)) { using (var file = File.OpenRead(_localFilename)) { using (var sr = new StreamReader(file)) { var dateLine = sr.ReadLine(); if (DateTime.TryParse(dateLine, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var date) && DateTime.UtcNow - date < MaxAge) { LastRefresh = date; var restOfFile = sr.ReadToEnd() .Replace("\r\n", "\n") // normalize line endings .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // split into lines var elementSets = Tle.ParseElements(restOfFile, ThreeLine); return(elementSets.ToDictionary(elementSet => (int)elementSet.NoradNumber)); } } } } var tles = await base.FetchNewTles(); WriteOutNewTles(tles); return(tles); }
internal virtual async Task <Dictionary <int, Tle> > FetchNewTles() { var tles = new Dictionary <int, Tle>(); using (var wc = new HttpClient()) { foreach (var source in _sources) { var str = await wc.GetStringAsync(source); var file = str .Replace("\r\n", "\n") // normalize line endings .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // split into lines var elementSets = Tle.ParseElements(file, true); foreach (var elementSet in elementSets) { tles.Add((int)elementSet.NoradNumber, elementSet); } } } return(tles); }
protected static void PopulateTleTable(string str, Dictionary <int, Tle> tles) { var file = str .Replace("\r\n", "\n") // normalize line endings .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // split into lines var elementSets = Tle.ParseElements(file, true); foreach (var elementSet in elementSets) { tles.Add((int)elementSet.NoradNumber, elementSet); } }
/// <summary> /// Create a new Tle as a copy of the specified one /// </summary> /// <param name="tle">Object to copy from</param> public Tle(Tle tle) { Name = tle.Name; Line1 = tle.Line1; Line2 = tle.Line2; NoradNumber = tle.NoradNumber; IntDesignator = tle.IntDesignator; Epoch = tle.Epoch; _meanMotionDt2 = tle._meanMotionDt2; _meanMotionDdt6 = tle._meanMotionDdt6; _bstar = tle._bstar; _inclination = tle._inclination; _rightAscendingNode = tle._rightAscendingNode; _eccentricity = tle._eccentricity; _argumentPerigee = tle._argumentPerigee; _meanAnomaly = tle._meanAnomaly; _meanMotion = tle._meanMotion; _orbitNumber = tle._orbitNumber; }
private void LoadTles(bool threeLine, IEnumerable <string> sourceFilenames) { _tles = new Dictionary <int, Tle>(); foreach (var sourceFilename in sourceFilenames) { using (var file = File.OpenRead(sourceFilename)) { using (var sr = new StreamReader(file)) { var restOfFile = sr.ReadToEnd() .Replace("\r\n", "\n") // normalize line endings .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // split into lines var elementSets = Tle.ParseElements(restOfFile, threeLine); var tempSet = elementSets.ToDictionary(elementSet => (int)elementSet.NoradNumber); _tles = _tles.Concat(tempSet.Where(kvp => !_tles.ContainsKey(kvp.Key))) .ToDictionary(x => x.Key, x => x.Value); } } } }
/// <inheritdoc /> protected bool Equals(Tle other) { return(string.Equals(Line1, other.Line1) && string.Equals(Line2, other.Line2)); }