Example #1
0
        public void UpdateFavorite(MonkeySpace.Core.Session session, bool isFavorite)
        {
            var isAlreadyFavorite = UserData.IsFavorite(session.Code);

            if (isAlreadyFavorite && isFavorite)
            {
                return;                                              // no change
            }
            if (!isAlreadyFavorite && !isFavorite)
            {
                return;                                                // no change
            }
            if (isFavorite)
            {
                UserData.AddFavoriteSession(session.Code);
            }
            else             // not Favorite
            {
                UserData.RemoveFavoriteSession(session.Code);
            }

            favoriteSessions = null;             // so it gets reloaded next use

            // This updates the 'whats on next' with favourites (if required)
            LoadWhatsOn(CurrentConferenceCode);
        }
Example #2
0
        public void UpdateFavorite(MonkeySpace.Core.Session session, bool isFavorite)
        {
            var fs = (from s in App.ViewModel.FavoriteSessions
                      where s.Code == session.Code
                      select s).ToList();

            if (fs.Count > 0)
            {
                // remove, as it might be old data persisted anyway (from previous conf.xml file)
                App.ViewModel.FavoriteSessions.Remove(fs[0]);
            }
            if (isFavorite)
            {   // add it again
                App.ViewModel.FavoriteSessions.Add(session);
            }

            var temp = favoriteSessions.OrderBy(s => s.Start.Ticks);

            favoriteSessions = new ObservableCollection <MonkeySpace.Core.Session>();
            foreach (var t in temp)
            {
                favoriteSessions.Add(t);
            }
            NotifyPropertyChanged("FavoriteSessions");
            string currentConf = (string)IsolatedStorageSettings.ApplicationSettings["LastConferenceCode"];

            App.ViewModel.LoadWhatsOn(currentConf);
        }
        public static void LoadFromString(string jsonString)
        {
            #if WINDOWS_PHONE
            jsonString = jsonString.Replace("0000-04:00", ""); // HACK: excuse this timezone hack
            var sessions = JsonConvert.DeserializeObject<List<Session>>(jsonString);
            Sessions = new Dictionary<int, Session>();
            Speakers = new Dictionary<int, Speaker>();
            foreach (var session in sessions) {
                Sessions.Add(session.Id, session);
                Console.WriteLine("Session: " + session.Title);
                foreach (var speaker in session.Speakers) {
                    speaker.Sessions.Add(session);
                    if (!Speakers.ContainsKey(speaker.Id)) {
                        Speakers.Add(speaker.Id, speaker);
                    }
                    Console.WriteLine("Speaker: " + speaker.Name);
                }
            }
            #else
            var jsonObject = JsonValue.Parse (jsonString);

            if (jsonObject != null)
            {
                for (var j = 0;j < jsonObject.Count; j++) {
                    var jsonSession = jsonObject[j];// as JsonValue;
                    var session = new Session(jsonSession);

                    Sessions.Add(session.Id, session);
                    Console.WriteLine ("Session: " + session.Title);

                    if (jsonSession.ContainsKey("speakers"))
                    {

                        var jsonSpeakers = jsonSession["speakers"]; // as JsonValue;

                        for (var k = 0; k < jsonSpeakers.Count; k++)
                        {
                            var jsonSpeaker = jsonSpeakers[k]; // as JsonValue;
                            var speaker = new Speaker(jsonSpeaker);

                            if (!Speakers.ContainsKey(speaker.Id))
                            {
                                Speakers.Add(speaker.Id, speaker);
                            }
                            else
                            {
                                speaker = Speakers[speaker.Id];
                            }
                            speaker.Sessions.Add(session);
                            session.Speakers.Add(speaker);

                            Console.WriteLine("Speaker: " + speaker.Name);
                        }
                    }
                }
            }
            #endif
            Console.WriteLine ("done");
        }
        /// <summary>
        /// Parses the json passed in and ONLY if the parsing succeeded does it populate the ref params
        /// </summary>
        static bool ParseJson(string jsonString, ref Dictionary<int, Session> sessions, ref Dictionary<int, Speaker> speakers)
        {
            Dictionary<int, Session> localSessions = new Dictionary<int, Session>();
            Dictionary<int, Speaker> localSpeakers = new Dictionary<int, Speaker>();

            try {
                var jsonObject = JsonValue.Parse (jsonString);

                if (jsonObject != null) {
                    for (var j = 0; j < jsonObject.Count; j++) {
                        var jsonSession = jsonObject [j];// as JsonValue;
                        var session = new Session (jsonSession);

                        localSessions.Add (session.Id, session);
                        Console.WriteLine ("Session: " + session.Title);

                        var jsonSpeakers = jsonSession ["speakers"];// as JsonValue;

                        for (var k = 0; k < jsonSpeakers.Count; k++) {
                            var jsonSpeaker = jsonSpeakers [k]; // as JsonValue;
                            var speaker = new Speaker (jsonSpeaker);

                            if (!localSpeakers.ContainsKey (speaker.Id)) {
                                localSpeakers.Add (speaker.Id, speaker);
                            } else {
                                speaker = localSpeakers [speaker.Id];
                            }
                            speaker.Sessions.Add (session);
                            session.Speakers.Add (speaker);

                            Console.WriteLine ("Speaker: " + speaker.Name);
                        }
                    }
                }
            } catch (Exception ex) {
                // something in the parsing failed
                Console.WriteLine ("Parsing failed " + ex);
                return false;
            }
            speakers = localSpeakers;
            sessions = localSessions;
            return true;
        }