private Ephemeris decadeEphemerisOf(DateTimeOffset date) { int startYear = 10 * (date.Year / 10); string fileName = String.Format("{0}{1}.eph", Name, startYear); FileInfo[] files = EphemerisDirectory.GetFiles(fileName, SearchOption.AllDirectories); Ephemeris decadeEphe = null; if (files.Length != 0) { IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(EphemerisDirectory + fileName, FileMode.Open, FileAccess.Read, FileShare.Read); decadeEphe = (Ephemeris)formatter.Deserialize(stream); stream.Close(); } if (decadeEphe == null) { decadeEphe = new Ephemeris(Name + startYear.ToString(), PositionDelegate); DateTimeOffset start = new DateTimeOffset(startYear, 1, 1, 0, 0, 0, TimeSpan.Zero); DateTimeOffset end = new DateTimeOffset(startYear + 10, 1, 1, 0, 0, 0, TimeSpan.Zero); decadeEphe.calculate(start, end); decadeEphe.save(); } return(decadeEphe); }
private void save() { string fileName = Name + ".eph"; FileInfo[] files = EphemerisDirectory.GetFiles(fileName, SearchOption.AllDirectories); if (files.Length != 0) { throw new Exception("Ephemeris already existed: " + fileName + " in " + EphemerisDirectory.Name); } IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream(EphemerisDirectory + fileName, FileMode.Create, FileAccess.Write); formatter.Serialize(stream, this); stream.Close(); }