/// <summary> /// Load the Cached State from a file, or create a new one. /// </summary> /// <param name="app">The application object.</param> public static void LoadState(this IDeckAdvisorApp app) { if (File.Exists("state.json")) { string stateJson = File.ReadAllText("state.json"); app.State = JsonConvert.DeserializeObject <CachedState>(stateJson); bool saveState = false; if (app.State.Fingerprint == Guid.Empty) { app.State.Fingerprint = Guid.NewGuid(); saveState = true; } if (app.State.Filters == null) { app.State.Filters = new DeckFilters(); saveState = true; } if (saveState) { app.SaveState(); } } else { app.State = new CachedState(); } }
/// <summary> /// Handle clicks of the Apply Button. /// </summary> /// <param name="sender">The button that was clicked.</param> /// <param name="e">The routed event arguments.</param> private void Apply_Click(object sender, RoutedEventArgs e) { IDeckAdvisorApp application = (IDeckAdvisorApp)Application.Current; if (application.State.Filters != Filters) { application.State.Filters.SetAllFields(Filters); application.SaveState(); ((MainWindow)Owner).ApplyFilters(Filters); } Close(); }