public void Save(AppState state) { using (var stream = new FileStream(_filename, FileMode.Create, FileAccess.Write)) { var serializer = CreateSerializer(); serializer.Serialize(stream, state); } }
public MainViewModel(AppState state) { _state = state; _days = new ObservableCollection<DayViewModel>(); var startDate = DateTime.Today.AddDays(-35); while (startDate.DayOfWeek != DayOfWeek.Monday) { startDate = startDate.AddDays(1); } Enumerable.Range((startDate - DateTime.Today).Days, 62) .Select(i => DateTime.Today.AddDays(i)) .Select(_state.GetOrCreateDay) .Select(d => new DayViewModel(d, () => InvokeChanged(EventArgs.Empty))) .ForEach(_days.Add); GoToToday(); }