示例#1
0
 protected virtual void OnTwitterLoaded(LoadEventArgs e)
 {
     if (ServiceLoaded != null)
     {
         ServiceLoaded(this, e);
     }
 }
示例#2
0
 protected virtual void OnFinalScoresLoaded(LoadEventArgs e)
 {
     if (FinalScoresLoaded != null)
     {
         FinalScoresLoaded(this, e);
     }
 }
示例#3
0
        public NewsFeature GetFeatures(string team, string pageSize)
        {
            _features = new NewsFeature();
            _features.FeatureItems.Clear();
            var loadedEventArgs = new LoadEventArgs();

            string qS = string.Format("{0}?feed={1}&pageSize={2}", Settings.FeaturesUrl, team ?? "",
                                      pageSize ?? "");

            var wb = new SharpGIS.GZipWebClient();
            Observable.FromEvent<DownloadStringCompletedEventArgs>(wb, "DownloadStringCompleted")
                .ObserveOn(Scheduler.ThreadPool)
                .Select(newString => ProcessFeatures(newString.EventArgs.Result))
                .Subscribe(s =>
                               {
                                   loadedEventArgs.IsLoaded = true;
                                   loadedEventArgs.Message = "";

                                   _features.Copyright = s.Copyright;
                                   _features.Description = s.Description;
                                   _features.Language = s.Language;
                                   _features.Link = s.Link;
                                   _features.Title = s.Title;

                                   for (int i = 0; i < s.FeatureItems.Count; i++)
                                   {
                                       NewsFeatureItem newsFeatureItem = s.FeatureItems[i];
                                       Deployment.Current.Dispatcher.BeginInvoke(() => _features.FeatureItems.Add(newsFeatureItem));

                                   }

                                  Deployment.Current.Dispatcher.BeginInvoke(() => OnFeaturesLoaded(loadedEventArgs));
                                   if (!(App.isoSettings.Contains("Features")))
                                   {
                                       ThreadPool.QueueUserWorkItem(o =>
                                       {
                                           var json = JsonHelpers.SerializeJson(_features);
                                           App.isoSettings.Add("Features", json);
                                       });
                                   }
                                   else
                                   {
                                       ThreadPool.QueueUserWorkItem(o =>
                                       {
                                           var json = JsonHelpers.SerializeJson(_features);
                                           App.isoSettings["Features"] = json;
                                       });
                                   }
                               }, e =>
                                      {
                                          loadedEventArgs.IsLoaded = false;
                                          loadedEventArgs.Message = e.Message.ToString(CultureInfo.InvariantCulture);
                                      }
                );
            wb.DownloadStringAsync(new Uri(qS));
            return _features;
        }
示例#4
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;
        }
示例#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;
        }
示例#6
0
 private static void ServiceUpcomingLoaded(object sender, LoadEventArgs e)
 {
     GlobalLoading.Instance.IsLoading = !e.IsLoaded;
 }
 protected virtual void OnUpcomingScheduleLoaded(LoadEventArgs e)
 {
     if (ServiceLoaded != null)
     {
         ServiceLoaded(this, e);
     }
 }
示例#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);
        }
示例#9
0
 private void ServiceNewsStreamLoaded(object sender, LoadEventArgs e)
 {
     GlobalLoading.Instance.IsLoading = !e.IsLoaded;
     NewsStreamItems = e.Message;
 }
示例#10
0
 protected virtual void OnRecentFeaturesLoaded(LoadEventArgs e)
 {
     if (RecentFeaturesLoaded != null)
     {
         RecentFeaturesLoaded(this, e);
     }
 }
示例#11
0
 protected virtual void OnNewsStreamLoaded(LoadEventArgs e)
 {
     if (NewsStreamLoaded != null)
     {
         NewsStreamLoaded(this, e);
     }
 }
示例#12
0
        public ObservableCollection<NewsStreamItem> GetNewsStream(string team, string start, string pageSize)
        {
            _newsStream = new ObservableCollection<NewsStreamItem>();
            var loadedEventArgs = new LoadEventArgs();
            string queryString = string.Format("{0}?team={1}&start={2}&pageSize={3}", Settings.StreamUrl,
                                               team ?? "", start ?? "", pageSize ?? "");

            var wb = new SharpGIS.GZipWebClient();
            Observable.FromEvent<DownloadStringCompletedEventArgs>(wb, "DownloadStringCompleted")

                // Let's make sure that we’re on the thread pool
                .ObserveOn(Scheduler.ThreadPool)

                // When the event fires, just select the string and make
                // an IObservable<string> instead
                .Select(newString => ProcessNewsStreamItems(newString.EventArgs.Result))

                // Now go back to the UI Thread
                .ObserveOn(Scheduler.Dispatcher)

                // Subscribe to the observable
                .Subscribe(s =>
                               {
                                   loadedEventArgs.IsLoaded = true;
                                   loadedEventArgs.Message = "";
                                   for (int index = 0; index < s.Count; index++)
                                   {
                                       NewsStreamItem newsStreamItem = s[index];
                                       newsStreamItem.Title = Regex.Replace(newsStreamItem.Title, "");
                                       _newsStream.Add(newsStreamItem);
                                   }
                                   OnNewsStreamLoaded(loadedEventArgs);
                                   if (!(App.isoSettings.Contains("NewStream")))
                                   {
                                       ThreadPool.QueueUserWorkItem(o =>
                                                                        {
                                                                            var json= JsonHelpers.SerializeJson(_newsStream);
                                                                            App.isoSettings.Add("NewStream", json);
                                                                        });
                                   }
                                   else
                                   {
                                       ThreadPool.QueueUserWorkItem(o =>
                                       {
                                           var json = JsonHelpers.SerializeJson(_newsStream);
                                           App.isoSettings["NewStream"] = json;
                                       });
                                   }

                               }, e =>
                                      {
                                          loadedEventArgs.IsLoaded = false;
                                          //TODO: LOG Error
                                          loadedEventArgs.Message =
                                              "We were unable to retrieve the news feed. Please refresh";
                                          OnNewsStreamLoaded(loadedEventArgs);
                                      }
                );

            wb.DownloadStringAsync(new Uri(queryString));
            return _newsStream;
        }
示例#13
0
        public NewsFeedModel GetNews(string newsFeed, string storyCount)
        {
            _news = new NewsFeedModel();
            var loadedEventArgs = new LoadEventArgs();
            string queryString = string.Format("{0}?feed={1}&pageSize={2}", Settings.NewsUrl, newsFeed ?? "",
                                               storyCount ?? "");
            var webClient = new SharpGIS.GZipWebClient();

            Observable.FromEvent<DownloadStringCompletedEventArgs>(webClient, "DownloadStringCompleted")
                .ObserveOn(Scheduler.ThreadPool)
                .Select(x => ProcessNews(x.EventArgs.Result))
                .ObserveOn(Scheduler.Dispatcher)
                .Subscribe(s =>
                               {
                                   BuildNewsFeedModel(s);
                                   loadedEventArgs.IsLoaded = true;
                                   loadedEventArgs.Message = "";
                                   OnNewsLoaded(loadedEventArgs);
                               }, e =>
                                      {
                                          loadedEventArgs.IsLoaded = false;
                                          loadedEventArgs.Message = e.Message.ToString(CultureInfo.InvariantCulture);
                                          OnNewsLoaded(loadedEventArgs);
                                      });
            webClient.DownloadStringAsync(new Uri(queryString));
            return _news;
        }