Exemple #1
0
        private void RetrieveTwitterValues(Uri twitterFeed, ObservableCollectionEx <TwitterStatusModel> twitterStatus)
        {
            var wc = new GZipWebClient();

            ErrorService service = new ErrorService("Unable to retrieve the twitter feed.", "").ErrorDialog(true);

            var loadedEventArgs = new LoadEventArgs();
            IObservable <IEvent <DownloadStringCompletedEventArgs> > o = Observable.FromEvent
                                                                         <DownloadStringCompletedEventArgs>(wc, "DownloadStringCompleted");

            o.Subscribe(s =>
            {
                if (s.EventArgs != null)
                {
                    try
                    {
                        string twitterResults = s.EventArgs.Result;
                        if (!String.IsNullOrWhiteSpace(twitterResults))
                        {
                            XDocument doc = XDocument.Parse(twitterResults);
                            ParseTwitterResults(doc, twitterStatus);
                        }
                        else
                        {
                            service.HandleError();
                        }
                    }
                    catch (Exception)
                    {
                        service.HandleError();
                    }
                    finally
                    {
                        loadedEventArgs.IsLoaded = true;
                        OnTwitterLoaded(loadedEventArgs);
                    }
                }
                else
                {
                    service.HandleError();
                    loadedEventArgs.IsLoaded = true;
                    OnTwitterLoaded(loadedEventArgs);
                }
            }, e =>
            {
                loadedEventArgs.IsLoaded = true;
                loadedEventArgs.Message  = e.Message.ToString(CultureInfo.InvariantCulture);
                OnTwitterLoaded(loadedEventArgs);
                service.HandleError();
            }
                        );

            wc.DownloadStringAsync(twitterFeed);
        }
Exemple #2
0
        public ObservableCollection <UpComingViewSchedule> GetUpcomingSchedule(string url, string pageStart,
                                                                               string pageSize)
        {
            _upcoming = new ObservableCollection <UpComingViewSchedule>();
            var upcoming2       = new List <UpComingSchedule>();
            var loadedEventArgs = new LoadEventArgs();

            string queryString = String.Format("{0}?start={1}&pageSize={2}", url, pageStart ?? "",
                                               pageSize ?? "");
            var wb = new GZipWebClient();

            Observable.FromEvent <DownloadStringCompletedEventArgs>(wb, "DownloadStringCompleted")
            .ObserveOn(Scheduler.ThreadPool)
            .Select(x => ProcessUpcomingItems(x.EventArgs.Result))
            .ObserveOn(Scheduler.Dispatcher)
            .Subscribe(s =>
            {
                loadedEventArgs.IsLoaded = true;
                loadedEventArgs.Message  = "";
                foreach (UpComingSchedule upComingSchedule in s)
                {
                    upcoming2.Add(upComingSchedule);
                    _upcoming.Add(ConvertToView(upComingSchedule));
                }

                ThreadPool.QueueUserWorkItem(o =>
                {
                    InsertIntoIS(upcoming2);
                    CacheUpComingSchedule(_upcoming);
                });

                OnUpcomingScheduleLoaded(loadedEventArgs);
            }, e =>
            {
                loadedEventArgs.IsLoaded = true;
                //TODO: LOG Error
                ErrorService error = new ErrorService(
                    "Unable to retrieve any upcoming events", "")
                                     .ErrorDialog(true);
                error.HandleError();
                OnUpcomingScheduleLoaded(loadedEventArgs);
            }
                       );
            wb.DownloadStringAsync(new Uri(queryString));

            //TODO: Add this to the service
            //if (!_upcoming.Any())
            //{
            //    _upcoming.Add(new UpComingViewSchedule{Teams = "Regular season complete", GameDateTime = "Enjoy the playoffs"});
            //}
            return(_upcoming);
        }
        public ObservableCollection<UpComingViewSchedule> GetUpcomingSchedule(string url, string pageStart,
                                                                              string pageSize)
        {
            _upcoming = new ObservableCollection<UpComingViewSchedule>();
            var upcoming2 = new List<UpComingSchedule>();
            var loadedEventArgs = new LoadEventArgs();

            string queryString = String.Format("{0}?start={1}&pageSize={2}", url, pageStart ?? "",
                                               pageSize ?? "");
            var wb = new GZipWebClient();
            Observable.FromEvent<DownloadStringCompletedEventArgs>(wb, "DownloadStringCompleted")
                .ObserveOn(Scheduler.ThreadPool)
                .Select(x => ProcessUpcomingItems(x.EventArgs.Result))
                .ObserveOn(Scheduler.Dispatcher)
                .Subscribe(s =>
                               {
                                   loadedEventArgs.IsLoaded = true;
                                   loadedEventArgs.Message = "";
                                   foreach (UpComingSchedule upComingSchedule in s)
                                   {
                                       upcoming2.Add(upComingSchedule);
                                       _upcoming.Add(ConvertToView(upComingSchedule));
                                   }

                                   ThreadPool.QueueUserWorkItem(o =>
                                                                    {
                                                                        InsertIntoIS(upcoming2);
                                                                        CacheUpComingSchedule(_upcoming);
                                                                    });

                                   OnUpcomingScheduleLoaded(loadedEventArgs);
                               }, e =>
                                      {
                                          loadedEventArgs.IsLoaded = true;
                                          //TODO: LOG Error
                                          ErrorService error = new ErrorService(
                                              "Unable to retrieve any upcoming events", "")
                                              .ErrorDialog(true);
                                          error.HandleError();
                                          OnUpcomingScheduleLoaded(loadedEventArgs);
                                      }
                );
            wb.DownloadStringAsync(new Uri(queryString));

            //TODO: Add this to the service
            //if (!_upcoming.Any())
            //{
            //    _upcoming.Add(new UpComingViewSchedule{Teams = "Regular season complete", GameDateTime = "Enjoy the playoffs"});
            //}
            return _upcoming;
        }
        public ObservableCollection<CompletedViewSchedule> GetFinalScores(string url, string pageStart, string pageSize)
        {
            _finalScores = new ObservableCollection<CompletedViewSchedule>();
            var finalScores2 = new List<CompletedSchedule>();
            var loadedEventArgs = new LoadEventArgs();

            string queryString = string.Format("{0}?start={1}&pageSize={2}", url, pageStart ?? "",
                                               pageSize ?? "");
            var wb = new SharpGIS.GZipWebClient();

            Observable.FromEvent<DownloadStringCompletedEventArgs>(wb, "DownloadStringCompleted")
                .ObserveOn(Scheduler.ThreadPool)
                .Select(x => ProcessFinalItems(x.EventArgs.Result))
                .ObserveOn(Scheduler.Dispatcher)
                .Subscribe(s =>
                               {
                                   loadedEventArgs.IsLoaded = true;
                                   loadedEventArgs.Message = "";
                                   foreach (CompletedSchedule finalScores in s)
                                   {
                                       finalScores2.Add(finalScores);
                                       _finalScores.Add(ConvertToFinalView(finalScores));
                                   }

                                   ThreadPool.QueueUserWorkItem(o =>
                                                                    {
                                                                        InsertIntoIS(finalScores2);
                                                                        CacheFinalScores(_finalScores);
                                                                    });

                                   OnFinalScoresLoaded(loadedEventArgs);
                               }, e =>
                                      {
                                          loadedEventArgs.IsLoaded = true;
                                          //TODO: LOG Error
                                          ErrorService error = new ErrorService(
                                              "Unable to retrieve any upcoming events", "")
                                              .ErrorDialog(true);
                                          error.HandleError();
                                          OnFinalScoresLoaded(loadedEventArgs);
                                      }
                );
            wb.DownloadStringAsync(new Uri(queryString));
            return _finalScores;
        }
Exemple #5
0
        public ObservableCollection <CompletedViewSchedule> GetFinalScores(string url, string pageStart, string pageSize)
        {
            _finalScores = new ObservableCollection <CompletedViewSchedule>();
            var finalScores2    = new List <CompletedSchedule>();
            var loadedEventArgs = new LoadEventArgs();

            string queryString = string.Format("{0}?start={1}&pageSize={2}", url, pageStart ?? "",
                                               pageSize ?? "");
            var wb = new SharpGIS.GZipWebClient();

            Observable.FromEvent <DownloadStringCompletedEventArgs>(wb, "DownloadStringCompleted")
            .ObserveOn(Scheduler.ThreadPool)
            .Select(x => ProcessFinalItems(x.EventArgs.Result))
            .ObserveOn(Scheduler.Dispatcher)
            .Subscribe(s =>
            {
                loadedEventArgs.IsLoaded = true;
                loadedEventArgs.Message  = "";
                foreach (CompletedSchedule finalScores in s)
                {
                    finalScores2.Add(finalScores);
                    _finalScores.Add(ConvertToFinalView(finalScores));
                }

                ThreadPool.QueueUserWorkItem(o =>
                {
                    InsertIntoIS(finalScores2);
                    CacheFinalScores(_finalScores);
                });

                OnFinalScoresLoaded(loadedEventArgs);
            }, e =>
            {
                loadedEventArgs.IsLoaded = true;
                //TODO: LOG Error
                ErrorService error = new ErrorService(
                    "Unable to retrieve any upcoming events", "")
                                     .ErrorDialog(true);
                error.HandleError();
                OnFinalScoresLoaded(loadedEventArgs);
            }
                       );
            wb.DownloadStringAsync(new Uri(queryString));
            return(_finalScores);
        }
Exemple #6
0
        private static List <UpComingSchedule> ProcessUpcomingItems(string result)
        {
            List <UpComingSchedule> returnType;

            try
            {
                returnType = JsonHelpers.DeserializeJson <List <UpComingSchedule> >(result);
            }
            catch (Exception)
            {
                returnType = new List <UpComingSchedule>();
                ErrorService error = new ErrorService("Unable to retrieve any upcoming events", "")
                                     .ErrorDialog(true);
                error.HandleError();
            }

            return(returnType);
        }
        private static List<UpComingSchedule> ProcessUpcomingItems(string result)
        {
            List<UpComingSchedule> returnType;
            try
            {
                returnType = JsonHelpers.DeserializeJson<List<UpComingSchedule>>(result);
            }
            catch (Exception)
            {
                returnType = new List<UpComingSchedule>();
                ErrorService error = new ErrorService("Unable to retrieve any upcoming events", "")
                    .ErrorDialog(true);
                error.HandleError();
            }

            return returnType;
        }
Exemple #8
0
        private void RetrieveTwitterValues(Uri twitterFeed, ObservableCollectionEx<TwitterStatusModel> twitterStatus )
        {
            var wc = new GZipWebClient();

            ErrorService service = new ErrorService("Unable to retrieve the twitter feed.", "").ErrorDialog(true);

            var loadedEventArgs = new LoadEventArgs();
            IObservable<IEvent<DownloadStringCompletedEventArgs>> o = Observable.FromEvent
                <DownloadStringCompletedEventArgs>(wc, "DownloadStringCompleted");

            o.Subscribe(s =>
                            {
                                if (s.EventArgs != null)
                                {
                                    try
                                    {
                                        string twitterResults = s.EventArgs.Result;
                                        if (!String.IsNullOrWhiteSpace(twitterResults))
                                        {
                                            XDocument doc = XDocument.Parse(twitterResults);
                                            ParseTwitterResults(doc, twitterStatus);
                                        }
                                        else
                                        {
                                            service.HandleError();
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        service.HandleError();
                                    }
                                    finally
                                    {
                                        loadedEventArgs.IsLoaded = true;
                                        OnTwitterLoaded(loadedEventArgs);
                                    }
                                }
                                else
                                {
                                    service.HandleError();
                                    loadedEventArgs.IsLoaded = true;
                                    OnTwitterLoaded(loadedEventArgs);
                                }
                            }, e =>
                                   {
                                       loadedEventArgs.IsLoaded = true;
                                       loadedEventArgs.Message = e.Message.ToString(CultureInfo.InvariantCulture);
                                       OnTwitterLoaded(loadedEventArgs);
                                       service.HandleError();
                                   }
                );

            wc.DownloadStringAsync(twitterFeed);
        }
 public void LoadData()
 {
     if (NetworkInterface.GetIsNetworkAvailable())
     {
         IScheduler scheduler = Scheduler.Dispatcher;
         scheduler.Schedule(() =>
                                {
                                    GetTwitterFeed();
                                    GetCanucksGameFeed();
                                    GetCanucksticketsFeed();
                                    GetCanucksStoreFeed();
                                    GetCanucksPromoFeed();
                                    CheckForErrors();
                                });
     }
     else
     {
         var builder = new StringBuilder();
         builder.AppendLine("To update the application a network connection is required.");
         builder.AppendLine("The application will attempt to load saved data");
         builder.AppendLine();
         builder.AppendLine(
             "When a network connection has been re-established tap on the ellipsis at the bottom right hand corner and select ‘refresh’");
         ErrorService errorService = new ErrorService(builder.ToString(), "No network connection detected")
             .ErrorDialog(true);
         errorService.HandleError();
     }
 }
Exemple #10
0
 private void CheckForErrors()
 {
     if (_errors.Count == 0)
     {
         return;
     }
     if (_errors.Count == 1)
     {
         string errorMessage = "We were unable to load: " + _errors.First();
         ErrorService errorService = new ErrorService(errorMessage, "").ErrorDialog(true);
         errorService.HandleError();
     }
     if (_errors.Count > 1)
     {
         string errorMessage = "We were unable to load: " + _errors.Aggregate((i, j) => i + " , " + j);
         ErrorService errorService = new ErrorService(errorMessage, "").ErrorDialog(true);
         errorService.HandleError();
     }
 }
Exemple #11
0
        public void LoadData()
        {
            CheckPlayOff();
            if (!NetworkInterface.GetIsNetworkAvailable())
            {
                var builder = new StringBuilder();
                builder.AppendLine("To update the application a network connection is required.");
                builder.AppendLine("The application will attempt to load saved data");
                builder.AppendLine();
                builder.AppendLine(
                    "When a network connection has been re-established tap on the ellipsis at the bottom right hand corner and select ‘refresh’");
                ErrorService errorService = new ErrorService(builder.ToString(), "No network connection detected")
                    .ErrorDialog(true);
                errorService.HandleError();
                LoadCachedData();
            }
            else
            {

                if (IsPlayoffs)
                {
                    LoadPlayoffScoresAndSchedules();
                }
                LoadScoresAndSchedules();
                IScheduler scheduler = Scheduler.Dispatcher;
                scheduler.Schedule(() =>
                                       {
                                           GetNewsStream();
                                           GetFeatures();
                                           GetTwitterFeed();
                                           GetFeedInfoItems();
                                           CheckForErrors();
                                       });
            }
        }