public void LoadChannels(Action onLoaded) { using (var store = new DataStoreDataContext()) { if (store.Channels.Any()) onLoaded.Invoke(); else new DataFetcher().Fetch(ChannelListUrl, x => LoadChannels(x, onLoaded)); } }
public void LoadPrograms(XElement xml) { var programs = xml.Elements("programme").Select(x => Program.Load(x)).ToArray(); using (var store = new DataStoreDataContext()) { store.Programs.InsertAllOnSubmit(programs); store.SubmitChanges(); } }
public void ChannelsLoaded() { using (var store = new DataStoreDataContext()) RequiresSetup = !store.Channels.Where(x => x.IsActive).Any(); FirePropertyChanged("RequiresSetup"); CurrentApp.Status.SetAction("Loading programs..."); new DataLoader().LoadPrograms(DateTime.Today, ProgramsLoaded); }
public void LoadChannels(XElement xml, Action onLoaded) { var elements = xml.Elements("channel").Where(z => z.Elements("datafor").Any()); var channels = elements.Select(x => Channel.Load(x)).ToArray(); using (var store = new DataStoreDataContext()) { store.Channels.InsertAllOnSubmit(channels); store.SubmitChanges(); } onLoaded.Invoke(); }
public void LoadPrograms(DateTime day, Action onLoaded) { using (var store = new DataStoreDataContext()) { store.Programs.DeleteAllOnSubmit(store.Programs.Where(x => x.Timestamp < DateTime.Today)); store.SubmitChanges(); var channels = store.Channels.Where(x => x.IsActive).ToArray() .Where(x => x.Programs.All(y => y.StartTime.Date != DateTime.Today)); var urls = channels.Select(x => x.GetShowsUrl(day)).ToArray(); new DataFetcher().Fetch(urls, LoadPrograms, onLoaded); } }
ProgramDetailsViewModel CreateProgramVM(Program program, DataStoreDataContext store) { var vm = new ProgramDetailsViewModel(program, store.IsFavourite(program)); if (program.StartTime >= CurrentTime.Time && program.EndTime <= CurrentTime.Time.AddMinutes(30)) vm.Status = "Contained"; else if (program.StartTime >= CurrentTime.Time) vm.Status = "Starting"; else if (program.EndTime <= CurrentTime.Time.AddMinutes(30)) vm.Status = "Finishing"; else if (program.StartTime < CurrentTime.Time) vm.Status = "Continuing"; return vm; }
void SendErrorReport(object sender, System.Windows.RoutedEventArgs e) { string message = ""; using (var store = new DataStoreDataContext()) { if (!store.Errors.Any()) return; message = store.Errors.ToArray().Select(x => x.ToString()).Aggregate((a, b) => a + "\n-----------\n\n" + b); store.Errors.DeleteAllOnSubmit(store.Errors); store.SubmitChanges(); } var emailComposeTask = new EmailComposeTask { Subject = "Television Guide Australia Error Report", Body = message, To = "*****@*****.**", }; emailComposeTask.Show(); }
void GlobalUnhandledExceptionHandler(object sender, ApplicationUnhandledExceptionEventArgs e) { if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); if (e.ExceptionObject is WebException && e.ExceptionObject.Message == "The remote server returned an error: NotFound.") { e.Handled = true; return; } var error = new Error { Time = DateTime.Now, Message = e.ExceptionObject.Message, Extended = e.ExceptionObject.ToVerboseString() }; using (var store = new DataStoreDataContext()) { store.Errors.InsertOnSubmit(error); store.SubmitChanges(); } Status.SetAction("Unknown error occurred", true); e.Handled = true; }
void SetPrograms() { using (var store = new DataStoreDataContext()) { Programs = store.Channels.Where(x => x.IsActive) .SelectMany(x => x.Programs) .Where(y => y.StartTime < CurrentTime.Time.AddMinutes(30)) .Where(y => y.EndTime > CurrentTime.Time).ToArray() .OrderBy(y => y.ChannelCode).ThenBy(y => y.StartTime) .Select(y => CreateProgramVM(y, store)) .OrderByDescending(z => z.IsFavourite) .ToArray(); } FirePropertyChanged("Programs", "CurrentTime"); }