Inheritance: System.Net.WebClient
        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;
        }
Exemple #2
0
        /// <summary>
        /// GetFullMessageFromMessageId
        /// </summary>
        public void GetFullMessageFromMessageId(Action<MessageModel> callback, Guid conversationId, Guid messageId)
        {
            Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "YapperServiceProxy::GetFullMessageFromMessageId ", "start"));
            Uri uri = new Uri(string.Format(
                YapperServiceProxy.GetFullMessageFromMessageIdRelativeUrl,
                YapperServiceProxy.ServicePrefix,
                conversationId,
                messageId));
            GZipWebClient webClient = new GZipWebClient();
            webClient.Headers["AuthTokenCookie"] = this.GetAuthTokenCookie();
            webClient.Headers["Accept-Encoding"] = "gzip, deflate";

            webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(SingleMessageDownloaded);
            webClient.DownloadStringAsync(uri, callback);
        }
Exemple #3
0
        /// <summary>
        /// GetAllMessagesSinceLastSync
        /// </summary>
        public void GetAllMessagesSinceLastSync(Action<List<MessageModel>> callback, DateTime LastSyncDateTime)
        {
            Debug.WriteLine(string.Format("{0} {1} {2}", DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"), "YapperServiceProxy::GetAllMessagesSinceLastSync ", "start"));
            (Application.Current as App).PerfTrackerStopWatch.Restart();

            DateTime lastSyncUtcTime = LastSyncDateTime.ToUniversalTime();
            Uri uri = new Uri(string.Format(
                YapperServiceProxy.GetAllMessagesSinceLastSyncRelativeUrl,
                YapperServiceProxy.ServicePrefix, lastSyncUtcTime));
            GZipWebClient webClient = new GZipWebClient();
            webClient.Headers["AuthTokenCookie"] = this.GetAuthTokenCookie();
            webClient.Headers["Accept-Encoding"] = "gzip, deflate";

            webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AllMessagesDownloaded);
            webClient.DownloadStringAsync(uri, callback);
        }
Exemple #4
0
 /// <summary>
 /// Methode which downloads the events picture
 /// </summary>
 public void DownloadPicture()
 {
     WebClient DownloadPictureWC = new GZipWebClient();
     DownloadPictureWC.OpenReadCompleted += new OpenReadCompletedEventHandler(DownloadPictureWC_OpenReadCompleted);
     Uri _Uri = new Uri(person.PictureURL + this.PictureName, UriKind.Absolute);
     DownloadPictureWC.OpenReadAsync(_Uri);
 }
Exemple #5
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);
        }
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadQuestion(int id)
        {
            WebClient webClient = new SharpGIS.GZipWebClient();

            webClient.DownloadStringCompleted += onQuestionLoaded;

            webClient.DownloadStringAsync(new Uri("http://api.stackoverflow.com/1.1/questions/" + id + "?body=true&answers=true", UriKind.Absolute));

            this.IsDataLoaded = true;
        }
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData(string query)
        {
            WebClient webClient = new  SharpGIS.GZipWebClient();

            webClient.DownloadStringCompleted += onLoaded;

            query = HttpUtility.UrlEncode(query);

            webClient.DownloadStringAsync(new Uri("http://api.stackexchange.com/2.0/search?order=desc&sort=relevance&pagesize=15&intitle="+query+"&site=stackoverflow", UriKind.Absolute));

            this.IsDataLoaded = true;
        }