public static async Task<IEnumerable<Speaker>> GetSpeakers()
        {
            if (_speakers != null)
                return _speakers.Values;

            _speakers = new Dictionary<string, Speaker>();
            _sessions = new Dictionary<string, Session>();

            List<Speaker> speakers = new List<Speaker>();

            HttpClient http = new HttpClient();
            JObject speakersJson = JObject.Parse(await http.GetStringAsync(SPEAKERS_URL));
            foreach (var item in speakersJson)
            {
                dynamic value = item.Value;
                Speaker speaker = new Speaker
                {
                    Name = item.Key,
                    Bio = value.bio,
                    Blog = value.blog,
                    Twitter = value.twitter,
                    PhotoURL = CDN_BASE_URL + value.photo
                };
                speakers.Add(speaker);
                _speakers.Add(speaker.Name, speaker);
            }

            JObject sessionsJson = JObject.Parse(await http.GetStringAsync(SESSIONS_URL));
            foreach (var day in sessionsJson)
            {
                Dictionary<int, string> trackTitles = new Dictionary<int, string>();
                dynamic value = day.Value;
                dynamic tracks = value.tracks;
                for (int i = 0; i < tracks.Count; ++i)
                {
                    dynamic track = tracks[i];
                    trackTitles.Add((int)track.index.Value, (string)track.title);
                }
                dynamic slots = value.slots;
                foreach (var slot in slots)
                {
                    dynamic sessions = slot.Value.sessions;
                    for (int i = 0; i < sessions.Count; ++i)
                    {
                        dynamic session = sessions[i];
                        string speakerName = session.speaker;
                        Session newSession = new Session
                        {
                            Title = session.title,
                            Description = session.@abstract,
                            Track = trackTitles[(int)session.track.Value],
                            Time = session.time,
                            Id = Guid.NewGuid().ToString()
                        };
                        _speakers[speakerName].Sessions.Add(newSession);
                        _sessions.Add(newSession.Id, newSession);
                    }
                }
            }

            return speakers;
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <Speaker> > GetSpeakers()
        {
            if (_speakers != null)
            {
                return(_speakers.Values);
            }

            _speakers = new Dictionary <string, Speaker>();
            _sessions = new Dictionary <string, Session>();

            List <Speaker> speakers = new List <Speaker>();

            JObject speakersJson = JObject.Parse(await ReadAllTextAsync("speakers.json"));

            foreach (var item in speakersJson)
            {
                dynamic value   = item.Value;
                Speaker speaker = new Speaker
                {
                    Name     = item.Key,
                    Bio      = value.bio,
                    Blog     = value.blog,
                    Twitter  = value.twitter,
                    PhotoURL = CDN_BASE_URL + value.photo
                };
                speakers.Add(speaker);
                _speakers.Add(speaker.Name, speaker);
            }

            JObject sessionsJson = JObject.Parse(await ReadAllTextAsync("sessions.json"));

            foreach (var day in sessionsJson)
            {
                Dictionary <int, string> trackTitles = new Dictionary <int, string>();
                dynamic value  = day.Value;
                dynamic tracks = value.tracks;
                for (int i = 0; i < tracks.Count; ++i)
                {
                    dynamic track = tracks[i];
                    trackTitles.Add((int)track.index.Value, (string)track.title);
                }
                dynamic slots = value.slots;
                foreach (var slot in slots)
                {
                    dynamic sessions = slot.Value.sessions;
                    for (int i = 0; i < sessions.Count; ++i)
                    {
                        dynamic session     = sessions[i];
                        string  speakerName = session.speaker;
                        if (!_speakers.ContainsKey(speakerName))
                        {
                            continue;
                        }
                        Session newSession = new Session
                        {
                            Title       = session.title,
                            Description = session.@abstract,
                            Track       = trackTitles[(int)session.track.Value],
                            Time        = session.time,
                            Id          = Guid.NewGuid().ToString()
                        };
                        _speakers[speakerName].Sessions.Add(newSession);
                        _sessions.Add(newSession.Id, newSession);
                    }
                }
            }

            return(speakers);
        }