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 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);
            }
        }
        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;
        }