Ejemplo n.º 1
0
        void DeserializeConferenceFile(string xmlPath)
        {
            long start = DateTime.Now.Ticks;

            using (TextReader reader = new StreamReader(xmlPath))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Conference2));
                ConferenceData2 = (Conference2)serializer.Deserialize(reader);

                Console.WriteLine("[AppDelegate] deserialize2:" + new TimeSpan(DateTime.Now.Ticks - start).TotalMilliseconds);
                //http://stackoverflow.com/questions/617283/select-a-dictionaryt1-t2-with-linq
                // Version 2 'flat' data structure
                var sessDic2 = (from s2 in ConferenceData2.Sessions
                                select s2).ToDictionary(item => item.Code);
                var speaDic2 = (from s3 in ConferenceData2.Speakers
                                select s3).ToDictionary(item => item.Name);
                var tagDic2 = (from s3 in ConferenceData2.Tags
                               select s3).ToDictionary(item => item.Value);

                // dictionaries to re-constitute version 1 data structure
                var speaDic1 = new Dictionary <string, ConfXml.Speaker>();
                var sessDic1 = new Dictionary <string, ConfXml.Session2>();
                var tagDic1  = new Dictionary <string, ConfXml.Tag>();

                // create version 1 speakers
                foreach (var sp2 in speaDic2)
                {
                    ConfXml.Speaker sp1 = sp2.Value as ConfXml.Speaker;
                    speaDic1.Add(sp1.Name, sp1);
                }
                // create version 1 sessions
                // add sessions to version 1 tags
                // add sessions to version 1 speakers
                foreach (var se2 in sessDic2.Values)
                {
                    ConfXml.Session2 se1 = se2 as ConfXml.Session2;
                    sessDic1.Add(se1.Code, se1);
                    foreach (var ta2 in se2.TagStrings)
                    {
                        if (!tagDic1.Keys.Contains(ta2))
                        {
                            tagDic1.Add(ta2, new Tag {
                                Value = ta2
                            });
                        }
                        //Console.WriteLine("[AppDelegate] TAG " + ta2 + " ses " + se1.Code);
                        tagDic1[ta2].Sessions.Add(se1);
                        se1.Tags.Add(tagDic1[ta2]);
                    }
                    // add speakers to version 1 sessions
                    foreach (var spn in se2.SpeakerNames)
                    {
                        //Console.WriteLine("[AppDelegate] SPKR " + se1.Code + " ses " + spn);
                        if (speaDic1.ContainsKey(spn))
                        {   //Aaron  Skonnard
                            se1.Speakers.Add(speaDic1[spn]);
                            speaDic1[spn].Sessions.Add(se1);
                        }
                    }
                }
                // push into version 1 data structure, which rest of the app uses
                ConferenceData          = new ConfXml.Conference(ConferenceData2);
                ConferenceData.Speakers = speaDic1.Values.ToList();
                ConferenceData.Sessions = sessDic1.Values.ToList();
                ConferenceData.Tags     = tagDic1.Values.ToList();

                ConfItem = ConferenceData2;

                //
                // ######   Load 'favorites'   ####
                //
                var favPath = Path.Combine(Constants.DocumentsFolder, this.CurrentConferenceCode);
                favPath = Path.Combine(favPath, "Favorites.xml");

                FavoriteSessions = new List <Session2>();

                LoadWhatsOn(this.CurrentConferenceCode);

                this.IsDataLoaded = true;
            }
            Console.WriteLine("[AppDelegate] deserialize2+unpack:" + new TimeSpan(DateTime.Now.Ticks - start).TotalMilliseconds);
        }
Ejemplo n.º 2
0
        void DeserializeConferenceFile(string xmlPath)
        {
            long start = DateTime.Now.Ticks;
            using (TextReader reader = new StreamReader(xmlPath))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Conference2));
                ConferenceData2 = (Conference2)serializer.Deserialize(reader);

                Console.WriteLine("[AppDelegate] deserialize2:" + new TimeSpan(DateTime.Now.Ticks - start).TotalMilliseconds);
                //http://stackoverflow.com/questions/617283/select-a-dictionaryt1-t2-with-linq
                // Version 2 'flat' data structure
                var sessDic2 = (from s2 in ConferenceData2.Sessions
                                select s2).ToDictionary(item => item.Code);
                var speaDic2 = (from s3 in ConferenceData2.Speakers
                                select s3).ToDictionary(item => item.Name);
                var tagDic2 = (from s3 in ConferenceData2.Tags
                               select s3).ToDictionary(item => item.Value);

                // dictionaries to re-constitute version 1 data structure
                var speaDic1 = new Dictionary<string, ConfXml.Speaker>();
                var sessDic1 = new Dictionary<string, ConfXml.Session2>();
                var tagDic1 = new Dictionary<string, ConfXml.Tag>();

                // create version 1 speakers
                foreach (var sp2 in speaDic2)
                {
                    ConfXml.Speaker sp1 = sp2.Value as ConfXml.Speaker;
                    speaDic1.Add(sp1.Name, sp1);
                }
                // create version 1 sessions
                // add sessions to version 1 tags
                // add sessions to version 1 speakers
                foreach (var se2 in sessDic2.Values)
                {
                    ConfXml.Session2 se1 = se2 as ConfXml.Session2;
                    sessDic1.Add(se1.Code, se1);
                    foreach (var ta2 in se2.TagStrings)
                    {
                        if (!tagDic1.Keys.Contains(ta2))
                        {
                            tagDic1.Add(ta2, new Tag { Value = ta2 });
                        }
                        //Console.WriteLine("[AppDelegate] TAG " + ta2 + " ses " + se1.Code);
                        tagDic1[ta2].Sessions.Add(se1);
                        se1.Tags.Add(tagDic1[ta2]);
                    }
                    // add speakers to version 1 sessions
                    foreach (var spn in se2.SpeakerNames)
                    {
                        //Console.WriteLine("[AppDelegate] SPKR " + se1.Code + " ses " + spn);
                        if (speaDic1.ContainsKey(spn))
                        {   //Aaron  Skonnard
                            se1.Speakers.Add(speaDic1[spn]);
                            speaDic1[spn].Sessions.Add(se1);
                        }
                    }
                }
                // push into version 1 data structure, which rest of the app uses
                ConferenceData = new ConfXml.Conference(ConferenceData2);
                ConferenceData.Speakers = speaDic1.Values.ToList();
                ConferenceData.Sessions = sessDic1.Values.ToList();
                ConferenceData.Tags = tagDic1.Values.ToList();

                ConfItem = ConferenceData2;

                //
                // ######   Load 'favorites'   ####
                //
                var favPath = Path.Combine(Constants.DocumentsFolder, this.CurrentConferenceCode);
                favPath = Path.Combine(favPath, "Favorites.xml");

                FavoriteSessions = new List<Session2>();

                LoadWhatsOn(this.CurrentConferenceCode);

                this.IsDataLoaded = true;
            }
            Console.WriteLine("[AppDelegate] deserialize2+unpack:" + new TimeSpan(DateTime.Now.Ticks - start).TotalMilliseconds);
        }