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();
            }
        }
        void _speakerClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                string stringArray = e.Result.Substring(12, e.Result.Length - 13);

                ReportSpeakerProgress("Reading data...", 70);
                List<SpeakerDto> speakers;
                try
                {
                    speakers = JsonConvert.DeserializeObject<List<SpeakerDto>>(stringArray);
                }
                catch (JsonReaderException ex)
                {
                    NetworkWentBoom();
                    return;
                }

                ReportSpeakerProgress("Preparing to save...", 75);

                ConferenceDataContext localDc = new ConferenceDataContext("isostore:/conference.sdf");

                // make a db if it ain't there
                if (!localDc.DatabaseExists())
                    localDc.CreateDatabase();

                ReportSpeakerProgress("Clearing existing data...", 80);
                int c = localDc.Speakers.Count();

                localDc.SessionTags.DeleteAllOnSubmit(localDc.SessionTags);
                localDc.Tags.DeleteAllOnSubmit(localDc.Tags);
                localDc.SessionSpeakers.DeleteAllOnSubmit(localDc.SessionSpeakers);
                localDc.Speakers.DeleteAllOnSubmit(localDc.Speakers);
                localDc.SubmitChanges();

                ReportSpeakerProgress("Saving to device...", 85);
                var speakerlist = speakers.Select(s => new Speaker
                {
                    Bio = s.bio,
                    Blog = s.blog,
                    CreatedAt = s.created_at,
                    Email = s.email,
                    FirstName = s.first_name,
                    LastName = s.last_name,
                    Location = s.location,
                    Picture = s.picture,
                    SpeakerId = s.id,
                    Twitter = s.twitter,
                    Website = s.website,
                    UpdatedAt = s.updated_at,
                    SessionSpeakers = new EntitySet<SessionSpeakers>()
                }).ToList();

                speakerlist.Add(new Speaker { FirstName = "TBD", SessionSpeakers = new EntitySet<SessionSpeakers>(), CreatedAt=DateTime.Now, UpdatedAt=DateTime.Now });

                foreach (var spkr in speakerlist)
                {
                    localDc.Speakers.InsertOnSubmit(spkr);
                    localDc.SubmitChanges();
                }

                ReportSpeakerProgress("Speakers downloaded and saved.", 100);

                _client = new WebClient();
                UpdateCachedSessions();
            }
            else
            {
                NetworkWentBoom();
            }
        }
        public void RefreshSavedSessions(ConferenceDataContext dc)
        {
            if (dc == null)
                dc = new ConferenceDataContext("isostore:/conference.sdf");

            // get the saved sessions for the phone
            List<int> savedSessions = new List<int>();
            if (IsolatedStorageSettings.ApplicationSettings.Contains("FavouriteSessions"))
                savedSessions = (List<int>)IsolatedStorageSettings.ApplicationSettings["FavouriteSessions"];

            if (dc.DatabaseExists())
                SavedSessions = dc.Sessions.Where(s => savedSessions.Contains(s.SessionId)).ToList();
        }
        public void RefreshData()
        {
            Sessions = null;
            ConferenceDataContext dc = new ConferenceDataContext("isostore:/conference.sdf");

            if (dc.DatabaseExists())
            {
                Sessions = dc.Sessions.OrderBy(r => r.Title).ToList();
                Tags =  dc.Tags.ToList().OrderBy(t => t.Title).ToList();
            }

            RefreshSavedSessions(dc);
        }
 public void RefreshData()
 {
     Speakers = null;
     ConferenceDataContext dc = new ConferenceDataContext("isostore:/conference.sdf");
     if (dc.DatabaseExists())
         Speakers = dc.Speakers.OrderBy(s => s.FirstName).ToList();
 }
        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();
            }
        }
        void _speakerClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                string stringArray = e.Result.Substring(12, e.Result.Length - 13);

                ReportSpeakerProgress("Reading data...", 70);
                List <SpeakerDto> speakers;
                try
                {
                    speakers = JsonConvert.DeserializeObject <List <SpeakerDto> >(stringArray);
                }
                catch (JsonReaderException ex)
                {
                    NetworkWentBoom();
                    return;
                }

                ReportSpeakerProgress("Preparing to save...", 75);

                ConferenceDataContext localDc = new ConferenceDataContext("isostore:/conference.sdf");

                // make a db if it ain't there
                if (!localDc.DatabaseExists())
                {
                    localDc.CreateDatabase();
                }

                ReportSpeakerProgress("Clearing existing data...", 80);
                int c = localDc.Speakers.Count();

                localDc.SessionTags.DeleteAllOnSubmit(localDc.SessionTags);
                localDc.Tags.DeleteAllOnSubmit(localDc.Tags);
                localDc.SessionSpeakers.DeleteAllOnSubmit(localDc.SessionSpeakers);
                localDc.Speakers.DeleteAllOnSubmit(localDc.Speakers);
                localDc.SubmitChanges();

                ReportSpeakerProgress("Saving to device...", 85);
                var speakerlist = speakers.Select(s => new Speaker
                {
                    Bio             = s.bio,
                    Blog            = s.blog,
                    CreatedAt       = s.created_at,
                    Email           = s.email,
                    FirstName       = s.first_name,
                    LastName        = s.last_name,
                    Location        = s.location,
                    Picture         = s.picture,
                    SpeakerId       = s.id,
                    Twitter         = s.twitter,
                    Website         = s.website,
                    UpdatedAt       = s.updated_at,
                    SessionSpeakers = new EntitySet <SessionSpeakers>()
                }).ToList();

                speakerlist.Add(new Speaker {
                    FirstName = "TBD", SessionSpeakers = new EntitySet <SessionSpeakers>(), CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now
                });

                foreach (var spkr in speakerlist)
                {
                    localDc.Speakers.InsertOnSubmit(spkr);
                    localDc.SubmitChanges();
                }

                ReportSpeakerProgress("Speakers downloaded and saved.", 100);

                _client = new WebClient();
                UpdateCachedSessions();
            }
            else
            {
                NetworkWentBoom();
            }
        }