/// <summary> /// See interface docs. /// </summary> /// <param name="feed"></param> /// <returns></returns> public SavedPolarPlot Load(IFeed feed) { SavedPolarPlot result = null; var feedName = feed == null ? null : feed.Name; if (!String.IsNullOrEmpty(feedName)) { var fileName = GetFullPath(feedName); string content = null; lock (_SyncLock) { if (File.Exists(fileName)) { content = File.ReadAllText(fileName); } } if (content != null) { result = JsonConvert.DeserializeObject <SavedPolarPlot>(content); } if (result != null && !result.IsForSameFeed(feed)) { result = null; } } return(result); }
public void TestInitialise() { _OriginalFactory = Factory.TakeSnapshot(); _ConfigurationStorage = TestUtilities.CreateMockSingleton <IConfigurationStorage>(); _Configuration = new Configuration(); _ConfigurationStorage.Setup(r => r.Load()).Returns(_Configuration); _Plotter = Factory.Singleton.Resolve <IPolarPlotter>(); _SanityChecker = TestUtilities.CreateMockImplementation <IAircraftSanityChecker>(); _CheckAltitudeResult = Certainty.ProbablyRight; _SanityChecker.Setup(r => r.CheckAltitude(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <int>())).Returns((int id, DateTime date, int alt) => { return(_CheckAltitudeResult); }); _SanityChecker.Setup(r => r.FirstGoodAltitude(It.IsAny <int>())).Returns(() => { throw new InvalidOperationException(); }); _CheckPositionResult = Certainty.ProbablyRight; _SanityChecker.Setup(r => r.CheckPosition(It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <double>(), It.IsAny <double>())).Returns((int id, DateTime date, double lat, double lng) => { return(_CheckPositionResult); }); _SanityChecker.Setup(r => r.FirstGoodPosition(It.IsAny <int>())).Returns(() => { throw new InvalidOperationException(); }); _SavedPolarPlot = new SavedPolarPlot(); }
/// <summary> /// See interface docs. /// </summary> /// <param name="savedPolarPlot"></param> public void LoadFrom(SavedPolarPlot savedPolarPlot) { if (savedPolarPlot == null) { throw new ArgumentNullException("savedPolarPlot"); } RoundToDegrees = savedPolarPlot.RoundToDegrees == 0 ? 1 : savedPolarPlot.RoundToDegrees; lock (_SyncLock) { _Slices.Clear(); _Slices.AddRange(savedPolarPlot.PolarPlotSlices); InitialiseSlices(); } }
/// <summary> /// See interface docs. /// </summary> /// <param name="feed"></param> public void Save(IFeed feed) { var feedName = feed == null ? null : feed.Name; var savedPolarPlot = new SavedPolarPlot(feed); if (!String.IsNullOrEmpty(feedName) && savedPolarPlot.FeedId > 0) { var folder = GetFolder(); var fileName = GetFullPath(feedName); var content = JsonConvert.SerializeObject(savedPolarPlot, Formatting.Indented); lock (_SyncLock) { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } File.WriteAllText(fileName, content); } } }