Example #1
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public async Task LoadData()
        {
            var manager = new ConferenceManager();
            //bool networkAvailable = false;// App.NetworkMonitor.IsAvailable();

            int nextVersion = -1;


            if (NetworkInterface.GetIsNetworkAvailable())
            {
                nextVersion = await manager.GetLatestVersion();

                if (nextVersion != -1 && (App.CurrentSessionVersion < nextVersion && App.DefaultSessionVersion < nextVersion))
                {
                    var newData = await manager.GetLatestData();

                    var res = await manager.GetData(newData, true);

                    if (res && manager.GetSessions().Any() && manager.GetSpeakers().Any())
                    {
                        App.CurrentSessionData = newData;
                        AppStorageHelper.SaveCurrentSessionData(App.CurrentSessionData);
                        AppStorageHelper.SaveCurrentVersionNumber(nextVersion.ToString());

                        Insights.Track("New Session Data", new Dictionary <string, string> {
                            { "New Version", nextVersion.ToString() },
                            { "Old Version", App.CurrentSessionVersion.ToString() },
                            { "Sessions Count", manager.GetSessions().Count.ToString() },
                            { "Speakers Count", manager.GetSpeakers().Count.ToString() }
                        });
                        App.CurrentSessionVersion = nextVersion;
                    }
                }
            }


            //nextVersion = -1;


            if (String.IsNullOrEmpty(App.CurrentSessionData))
            {
                var sessionData = Utils.ReadFile(Wac2015.Helpers.Settings.StaticData);
                App.CurrentSessionData = sessionData;
                var res = await manager.GetData(sessionData, true);
            }
            else
            {
                await manager.GetData(App.CurrentSessionData, true);
            }
            //var res = await manager.GetData(Settings.ConferenceDataUri);
            //Service.GetData();

            Sessions = manager.GetSessions();

            Speakers = manager.GetSpeakers();
            Speakers = Speakers.OrderBy(s => s.Name).ToObservableCollection();
            if (!String.IsNullOrEmpty(App.SessionId))
            {
                App.CurrentSession =
                    (from s in Sessions
                     where s.Id.ToLower().Equals(App.SessionId.ToLower())
                     select s).FirstOrDefault();
            }

            if (!String.IsNullOrEmpty(App.SpeakerId))
            {
                App.CurrentSpeaker =
                    (from s in Speakers
                     where s.Id.ToLower().Equals(App.SpeakerId.ToLower())
                     select s).FirstOrDefault();
            }

            if (App.SavedSessionIds == null)
            {
                App.SavedSessionIds = new List <string>();
            }
            else if (App.SavedSessionIds != null && App.SavedSessionIds.Count > 0)
            {
                App.SavedSessions = new ObservableCollection <Session>();
                foreach (var sessionId in App.SavedSessionIds)
                {
                    string id      = sessionId;
                    var    session = Sessions.FirstOrDefault(s => s.Id == id);
                    if (session != null)
                    {
                        App.SavedSessions.Add(session);
                    }
                }
            }
            //if (Service.SessionsAreNotOnlineYet)
            //    DiscoveredThatSessionsAreNotOnlineYet = true;

            //needs to get it from iso if available...
            App.Sessions = Sessions;
            App.Speakers = Speakers;

            if (App.SavedSessions == null)
            {
                App.SavedSessions = new ObservableCollection <Session>();
            }

            //SavedSessions = App.SavedSessions;
            Sessions      = Sessions.OrderBy(s => s.Begins).ToObservableCollection();
            SavedSessions = (from s in Sessions
                             join sid in App.SavedSessionIds
                             on s.Id equals sid
                             select s).ToObservableCollection();

            var date = "2015-03-18T09:30:00.0000000+05:30";
            var dt   = DateTime.Parse(date);

            DayOneSessions = (from s in Sessions
                              where s.Begins.Date == dt.Date
                              select s).ToObservableCollection();


            DayOneCollection = SessionKeyGroup <Session> .CreateDateGroups(DayOneSessions, CultureInfo.CurrentCulture,
                                                                           (Session s) => s.Begins, true);

            dt             = dt.AddDays(1);
            DayTwoSessions = (from s in Sessions
                              where s.Begins.Date == dt.Date
                              select s).ToObservableCollection();

            DayTwoCollection = SessionKeyGroup <Session> .CreateDateGroups(DayTwoSessions, CultureInfo.CurrentCulture,
                                                                           (Session s) => s.Begins, true);

            TimeBasedCollection = SessionKeyGroup <Session> .CreateDateGroups(Sessions, CultureInfo.CurrentCulture,
                                                                              (Session s) => s.Begins, true);

            TrackBasedCollection = SessionKeyGroup <Session> .CreateTrackGroups(Sessions, CultureInfo.CurrentCulture,
                                                                                (Session s) => s.TrackName, false);

            TimeBasedMyAgendaCollection = SessionKeyGroup <Session> .CreateDateGroups(SavedSessions, CultureInfo.CurrentCulture,
                                                                                      (Session s) => s.Begins, true);

            this.IsDataLoaded = true;
            //await LoadTwitterFeeds();
            //if (result != null)
            //    TwitterFeeds = result;
            await Task.Factory.StartNew(async() => { await LoadNews(); });
        }