Пример #1
0
 protected virtual void OnDataLoaded(LoadEventArgs e)
 {
     if (DataLoaded != null)
     {
         DataLoaded(this, e);
     }
 }
Пример #2
0
        public void GetData()
        {
            SessionList = new ObservableCollection <SessionItemModel>();
            SpeakerList = new ObservableCollection <SpeakerItemModel>();
            DateTime sessionLastDownload = DateTime.MinValue;


            // Get the data from Isolated storage if it is there
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
            {
                var converted = (IsolatedStorageSettings.ApplicationSettings["SessionData"] as IEnumerable <SessionItemModel>);

                SessionList = converted.ToObservableCollection(SessionList);
                var loadedEventArgs = new LoadEventArgs {
                    IsLoaded = true, Message = string.Empty
                };
                OnDataLoaded(loadedEventArgs);
            }
            // Get the data from Isolated storage if it is there
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SpeakerData"))
            {
                var converted = (IsolatedStorageSettings.ApplicationSettings["SpeakerData"] as IEnumerable <SpeakerItemModel>);

                SpeakerList = converted.ToObservableCollection(SpeakerList);
                var loadedEventArgs = new LoadEventArgs {
                    IsLoaded = true, Message = string.Empty
                };
                OnDataLoaded(loadedEventArgs);
            }


            // Get the last time the data was downloaded.
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionLastDownload"))
            {
                sessionLastDownload = (DateTime)IsolatedStorageSettings.ApplicationSettings["SessionLastDownload"];
            }

            // Check if we need to download the latest data, or if we can just use the isolated storage data
            // Cache the data for 2 hours
            if ((sessionLastDownload.AddHours(2) < DateTime.Now) || !IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
            {
                // Download the session data
                var sessionWebClient = new SharpGIS.GZipWebClient();
                sessionWebClient.DownloadStringCompleted += sessionWebClient_DownloadStringCompleted;
                sessionWebClient.DownloadStringAsync(new Uri(Settings.SessionServiceUri));

                // Download speaker data
                var speakerWebClient = new SharpGIS.GZipWebClient();
                speakerWebClient.DownloadStringCompleted += speakerWebClient_DownloadStringCompleted;
                speakerWebClient.DownloadStringAsync(new Uri(Settings.SpeakerServiceUri));
            }
        }
        public void GetData()
        {
            SessionList = new ObservableCollection<SessionItemModel>();
            SpeakerList = new ObservableCollection<SpeakerItemModel>();
            DateTime sessionLastDownload = DateTime.MinValue;

            // Get the data from Isolated storage if it is there
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
            {
                var converted = (IsolatedStorageSettings.ApplicationSettings["SessionData"] as IEnumerable<SessionItemModel>);

                SessionList = converted.ToObservableCollection(SessionList);
                var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                OnDataLoaded(loadedEventArgs);
            }
            // Get the data from Isolated storage if it is there
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SpeakerData"))
            {
                var converted = (IsolatedStorageSettings.ApplicationSettings["SpeakerData"] as IEnumerable<SpeakerItemModel>);

                SpeakerList = converted.ToObservableCollection(SpeakerList);
                var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                OnDataLoaded(loadedEventArgs);
            }

            // Get the last time the data was downloaded.
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionLastDownload"))
            {
                sessionLastDownload = (DateTime)IsolatedStorageSettings.ApplicationSettings["SessionLastDownload"];
            }

            // Check if we need to download the latest data, or if we can just use the isolated storage data
            // Cache the data for 2 hours
            if ((sessionLastDownload.AddHours(2) < DateTime.Now) || !IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
            {
                // Download the session data
                var sessionWebClient = new SharpGIS.GZipWebClient();
                sessionWebClient.DownloadStringCompleted += sessionWebClient_DownloadStringCompleted;
                sessionWebClient.DownloadStringAsync(new Uri(Settings.SessionServiceUri));

                // Download speaker data
                var speakerWebClient = new SharpGIS.GZipWebClient();
                speakerWebClient.DownloadStringCompleted += speakerWebClient_DownloadStringCompleted;
                speakerWebClient.DownloadStringAsync(new Uri(Settings.SpeakerServiceUri));
            }
        }
        void speakerWebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                var deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SpeakerResponse>>(e.Result);
                {
                    var converted = (from s in deserialized
                                     orderby s.Last
                                     select new SpeakerItemModel
                                     {
                                         Id = s.Id,
                                         Bio = StripHtmlTags(s.Bio ?? ""),
                                         FirstName = s.First,
                                         LastName = s.Last,
                                         PictureUrl = s.Photo,

                                         //Build specific
                                         SessionIds = (s.SessionIds != null ? s.SessionIds.ToObservableCollection() : null),

                                     }).ToList();

                    // Display the data on the screen ONLY if we didn't already load from the cache
                    // Don't bother about rebinding everything, just wait until the user launches the next time.
                    if (SpeakerList.Count < 1)
                        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            SpeakerList = converted.ToObservableCollection(SpeakerList);
                            var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                            OnDataLoaded(loadedEventArgs);
                        });

                    // Make sure the sessions are online before caching
                    if (converted.Count > 1)
                    {
                        // Save the results into the cache.
                        // First save the data
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SpeakerData"))
                            IsolatedStorageSettings.ApplicationSettings.Remove("SpeakerData");
                        IsolatedStorageSettings.ApplicationSettings.Add("SpeakerData", converted);

                        // then update the last updated key
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SpeakerLastDownload"))
                            IsolatedStorageSettings.ApplicationSettings.Remove("SpeakerLastDownload");
                        IsolatedStorageSettings.ApplicationSettings.Add("SpeakerLastDownload", DateTime.Now);
                        IsolatedStorageSettings.ApplicationSettings.Save(); // trigger a save
                    }
                }
            }
            catch (WebException)
            {
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    var loadedEventArgs = new LoadEventArgs { IsLoaded = false, Message = "There was a network error. Close the app and try again." };
                    OnDataLoaded(loadedEventArgs);
                    System.Windows.MessageBox.Show("There was a network error. Close the app and try again.");
                });
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        void sessionWebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                var deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SessionsResponse>>(e.Result);
                {
                    DateTime tempTime;
                    var converted = (from s in deserialized
                                     orderby s.Code
                                     select new SessionItemModel
                                                {
                                                    Id = s.Id,
                                                    Code = s.Code,
                                                    Title = s.Title,
                                                    Description = StripHtmlTags(s.Description),
                                                    Location = s.Room,
                                                    Date = (DateTime.TryParse(s.Starts, out tempTime) ? DateTime.Parse(s.Starts) : DateTime.MinValue),
                                                    //Speakers = s.Speakers.Select(p => new SpeakerItemModel { Id = p.SpeakerId, FirstName = p.First, LastName = p.Last, PictureUrl = p.SmallImage }).ToObservableCollection()

                                                    //Build specific
                                                    SpeakerIds = (s.SpeakerIds != null ? s.SpeakerIds.ToObservableCollection() : null),
                                                    Link = s.Link,
                                                    SlidesUri = s.Slides,
                                                    Thumbnail = s.ThumbnailImage,
                                                    WmvUri = s.Wmv,
                                                }).ToList();

                    // Display the data on the screen ONLY if we didn't already load from the cache
                    // Don't bother about rebinding everything, just wait until the user launches the next time.
                    if (SessionList.Count < 1)
                        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            SessionList = converted.ToObservableCollection(SessionList);
                            //SpeakerList = SessionList.SelectMany(p => p.Speakers).Distinct().OrderBy(p => p.SurnameFirstname).ToObservableCollection(SpeakerList);
                            var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                            OnDataLoaded(loadedEventArgs);
                        });

                    // Make sure the sessions are online before caching
                    if (converted.Count > 1)
                    {
                        // Save the results into the cache.
                        // First save the data
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
                            IsolatedStorageSettings.ApplicationSettings.Remove("SessionData");
                        IsolatedStorageSettings.ApplicationSettings.Add("SessionData", converted);

                        // then update the last updated key
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionLastDownload"))
                            IsolatedStorageSettings.ApplicationSettings.Remove("SessionLastDownload");
                        IsolatedStorageSettings.ApplicationSettings.Add("SessionLastDownload", DateTime.Now);
                        IsolatedStorageSettings.ApplicationSettings.Save(); // trigger a save
                    }
                    else
                        SessionsAreNotOnlineYet = true;
                }
            }
            catch (WebException ex)
            {
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    var loadedEventArgs = new LoadEventArgs { IsLoaded = false, Message = "There was a network error. Close the app and try again." };
                    OnDataLoaded(loadedEventArgs);
                    System.Windows.MessageBox.Show("There was a network error. Close the app and try again.");
                });
            }
            catch (Exception ex)
            {
                throw;
            }
        }
 protected virtual void OnDataLoaded(LoadEventArgs e)
 {
     if (DataLoaded != null)
     {
         DataLoaded(this, e);
     }
 }
Пример #7
0
 void Service_DataLoaded(object sender, LoadEventArgs e)
 {
     this.IsDataLoaded = e.IsLoaded;
     IsLoading = false;
 }
Пример #8
0
        void speakerWebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                var deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SpeakerResponse> >(e.Result);
                {
                    var converted = (from s in deserialized
                                     orderby s.Last
                                     select new SpeakerItemModel
                    {
                        Id = s.Id,
                        Bio = StripHtmlTags(s.Bio ?? ""),
                        FirstName = s.First,
                        LastName = s.Last,
                        PictureUrl = s.Photo,

                        //Build specific
                        SessionIds = (s.SessionIds != null ? s.SessionIds.ToObservableCollection() : null),
                    }).ToList();

                    // Display the data on the screen ONLY if we didn't already load from the cache
                    // Don't bother about rebinding everything, just wait until the user launches the next time.
                    if (SpeakerList.Count < 1)
                    {
                        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            SpeakerList         = converted.ToObservableCollection(SpeakerList);
                            var loadedEventArgs = new LoadEventArgs {
                                IsLoaded = true, Message = string.Empty
                            };
                            OnDataLoaded(loadedEventArgs);
                        });
                    }

                    // Make sure the sessions are online before caching
                    if (converted.Count > 1)
                    {
                        // Save the results into the cache.
                        // First save the data
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SpeakerData"))
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove("SpeakerData");
                        }
                        IsolatedStorageSettings.ApplicationSettings.Add("SpeakerData", converted);

                        // then update the last updated key
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SpeakerLastDownload"))
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove("SpeakerLastDownload");
                        }
                        IsolatedStorageSettings.ApplicationSettings.Add("SpeakerLastDownload", DateTime.Now);
                        IsolatedStorageSettings.ApplicationSettings.Save(); // trigger a save
                    }
                }
            }
            catch (WebException)
            {
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    var loadedEventArgs = new LoadEventArgs {
                        IsLoaded = false, Message = "There was a network error. Close the app and try again."
                    };
                    OnDataLoaded(loadedEventArgs);
                    System.Windows.MessageBox.Show("There was a network error. Close the app and try again.");
                });
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #9
0
        void sessionWebClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                var deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SessionsResponse> >(e.Result);
                {
                    DateTime tempTime;
                    var      converted = (from s in deserialized
                                          orderby s.Code
                                          select new SessionItemModel
                    {
                        Id = s.Id,
                        Code = s.Code,
                        Title = s.Title,
                        Description = StripHtmlTags(s.Description),
                        Location = s.Room,
                        Date = (DateTime.TryParse(s.Starts, out tempTime) ? DateTime.Parse(s.Starts) : DateTime.MinValue),
                        //Speakers = s.Speakers.Select(p => new SpeakerItemModel { Id = p.SpeakerId, FirstName = p.First, LastName = p.Last, PictureUrl = p.SmallImage }).ToObservableCollection()

                        //Build specific
                        SpeakerIds = (s.SpeakerIds != null ? s.SpeakerIds.ToObservableCollection() : null),
                        Link = s.Link,
                        SlidesUri = s.Slides,
                        Thumbnail = s.ThumbnailImage,
                        WmvUri = s.Wmv,
                    }).ToList();

                    // Display the data on the screen ONLY if we didn't already load from the cache
                    // Don't bother about rebinding everything, just wait until the user launches the next time.
                    if (SessionList.Count < 1)
                    {
                        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            SessionList = converted.ToObservableCollection(SessionList);
                            //SpeakerList = SessionList.SelectMany(p => p.Speakers).Distinct().OrderBy(p => p.SurnameFirstname).ToObservableCollection(SpeakerList);
                            var loadedEventArgs = new LoadEventArgs {
                                IsLoaded = true, Message = string.Empty
                            };
                            OnDataLoaded(loadedEventArgs);
                        });
                    }

                    // Make sure the sessions are online before caching
                    if (converted.Count > 1)
                    {
                        // Save the results into the cache.
                        // First save the data
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove("SessionData");
                        }
                        IsolatedStorageSettings.ApplicationSettings.Add("SessionData", converted);

                        // then update the last updated key
                        if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionLastDownload"))
                        {
                            IsolatedStorageSettings.ApplicationSettings.Remove("SessionLastDownload");
                        }
                        IsolatedStorageSettings.ApplicationSettings.Add("SessionLastDownload", DateTime.Now);
                        IsolatedStorageSettings.ApplicationSettings.Save(); // trigger a save
                    }
                    else
                    {
                        SessionsAreNotOnlineYet = true;
                    }
                }
            }
            catch (WebException ex)
            {
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    var loadedEventArgs = new LoadEventArgs {
                        IsLoaded = false, Message = "There was a network error. Close the app and try again."
                    };
                    OnDataLoaded(loadedEventArgs);
                    System.Windows.MessageBox.Show("There was a network error. Close the app and try again.");
                });
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async void GetData()
        {
            SessionList = new ObservableCollection<SessionItemModel>();
            SpeakerList = new ObservableCollection<SpeakerItemModel>();
            DateTime sessionLastDownload = DateTime.MinValue;


            // Get the data from Isolated storage if it is there
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
            {
                var converted = (IsolatedStorageSettings.ApplicationSettings["SessionData"] as IEnumerable<SessionItemModel>);

                SessionList.Clear();
                converted.ToList().ForEach(p => SessionList.Add(p));
                var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                OnDataLoaded(loadedEventArgs);
            }
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SpeakerData"))
            {
                var converted = (IsolatedStorageSettings.ApplicationSettings["SpeakerData"] as IEnumerable<SpeakerItemModel>);

                SpeakerList.Clear();
                converted.OrderBy(p => p.SurnameFirstname).ToList().ForEach(p => SpeakerList.Add(p));
                var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                OnDataLoaded(loadedEventArgs);
            }


            // Get the last time the data was downloaded.
            if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionLastDownload"))
            {
                sessionLastDownload = (DateTime)IsolatedStorageSettings.ApplicationSettings["SessionLastDownload"];
            }

            // Check if we need to download the latest data, or if we can just use the isolated storage data
            // Cache the data for 2 hours
            if ((sessionLastDownload.AddHours(2) < DateTime.Now) || !IsolatedStorageSettings.ApplicationSettings.Contains("SessionData"))
            {
                var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                // Download the data
                try
                {
                    var feedString = await TechEd2013ConferenceFeed.GetFeed();
                    ParseSessions(feedString);
                    ParseSpeakers(feedString);
                }
                catch (WebException)
                {
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        loadedEventArgs = new LoadEventArgs { IsLoaded = false, Message = "There was a network error. Close the app and try again." };
                        OnDataLoaded(loadedEventArgs);
                        System.Windows.MessageBox.Show("There was a network error. Close the app and try again.");
                    });
                }
                catch (Exception ex)
                {
                    System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        loadedEventArgs = new LoadEventArgs { IsLoaded = false, Message = ex.Message };
                        OnDataLoaded(loadedEventArgs);
                        System.Windows.MessageBox.Show(ex.Message);
                    });
                }
                finally
                {
                    OnDataLoaded(loadedEventArgs);
                }
            }
        }
        private void ParseSessions(string conferenceFeed)
        {
            var sessions = TechEd2013ConferenceFeed.ExtractSessions(conferenceFeed);

            // Display the data on the screen ONLY if we didn't already load from the cache
            // Don't bother about rebinding everything, just wait until the user launches the next time.
            if (SessionList.Count < 1)
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    SessionList.Clear();
                    sessions.ToList().ForEach(p => SessionList.Add(p));
                    var loadedEventArgs = new LoadEventArgs { IsLoaded = true, Message = string.Empty };
                    OnDataLoaded(loadedEventArgs);
                });


            // Save the results into the cache.
            SaveListToIsolatedStorage("SessionData", sessions);
        }