Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the SessionViewModel class.
        /// </summary>
        public SessionViewModel()
        {
            Messenger.Default.Register<SessionSelectionChangedMessage>(this, delegate(SessionSelectionChangedMessage message) {
                this.Session = message.Session;
            });

            if (IsInDesignMode)
            {
                Session = new Session
                {
                    Title = "Some Really Big Long Title",
                    TagList = "FOO, ASP.NET, MICROSOFT",
                    Room = "Pootzy",
                    Abstract = @"<p>Some <b>great</b> stuff in this one!</p><p>Read all about the great stuff that is great and plus it's not bad too (so, it's really awesome!)</p>"
                    //SessionSpeakers = new System.Data.Linq.EntitySet<SessionSpeakers>() { new SessionSpeakers { Session = Session, Speaker = new Speaker { FirstName = "Jar Jar", LastName = "Binks" } } }
                };
            }
            else
            {
                // Code runs "for real": Connect to service, etc...
            }
        }
Ejemplo n.º 2
0
 internal void SendSessionNavigatingMessage(Session session)
 {
     Messenger.Default.Send<SessionSelectionChangedMessage>(new SessionSelectionChangedMessage { Session = session });
 }
Ejemplo n.º 3
0
        void SessionDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                string stringArray = e.Result.Substring(12, e.Result.Length - 13);

                ReportSessionProgress("Reading data...", 80);
                List<SessionDto> sessions = JsonConvert.DeserializeObject<List<SessionDto>>(stringArray);

                ReportSessionProgress("Preparing to save data...", 85);
                ConferenceDataContext dc = new ConferenceDataContext("isostore:/conference.sdf");

                dc.Sessions.DeleteAllOnSubmit(dc.Sessions);
                dc.SubmitChanges();

                ReportSessionProgress("Saving to device...", 90);
                List<Session> sessionList = new List<Session>();
                foreach (var ssn in sessions.OrderBy(r=>r.title))
                {
                    // check to see if the tags exist already, if not add them
                    foreach (var tag in ssn.tags)
                    {
                        if (dc.Tags.Where(t=>t.Title == tag).Count() == 0)
                        {
                            dc.Tags.InsertOnSubmit(new Tag { Title = tag, SessionTags = new EntitySet<SessionTags>() });
                            dc.SubmitChanges();
                        }
                    }

                    // create a db version of the record
                    Session s = new Session
                    {
                        Abstract = ssn.@abstract,
                        Finish = ssn.finish,
                        Room = ssn.room,
                        SessionId = ssn.id,
                        Start = ssn.start,
                        TagList = string.Join(", ", ssn.tags).ToUpper(),
                        Title = ssn.title,
                        SessionSpeakers = new EntitySet<SessionSpeakers>(),
                        SessionTags = new EntitySet<SessionTags>()
                    };

                    // update the db
                    dc.Sessions.InsertOnSubmit(s);
                    dc.SubmitChanges();

                    // build up the speaker list
                    foreach (int speakerId in ssn.speakers)
                    {
                        Speaker speaker = dc.Speakers.Where(sp => sp.SpeakerId == speakerId).First();
                        s.SessionSpeakers.Add(new SessionSpeakers { Speaker = speaker, Session = s });
                        dc.SubmitChanges();
                    }

                    // default is a speaker if none are present
                    if (s.SessionSpeakers.Count == 0)
                        s.SessionSpeakers.Add(new SessionSpeakers { Session = s, Speaker = dc.Speakers.Where(k => k.FirstName == "TBD").First() });

                    // build up the tag list
                    foreach (var item in ssn.tags)
                    {
                        Tag tag = dc.Tags.Where(t => t.Title == item).First();
                        s.SessionTags.Add(new SessionTags { Session = s, Tag = tag });
                        dc.SubmitChanges();
                    }
                }

                ReportSessionProgress("Sessions downloaded and saved.", 95);

                int sessionCount = dc.Sessions.Count();
                int speakersCount = dc.Speakers.Count();
                ReportCompletedRefresh(sessionCount, speakersCount);
                dc.Dispose();
                dc = null;
            }
            else
            {
                NetworkWentBoom();
            }
        }