Beispiel #1
0
        public override async Task LoadDataAsync(Stream fileStream, BackEndContext db)
        {
            // var blah = new RootObject().rooms[0].sessions[0].speakers[0].name;

            var addedSpeakers = new Dictionary <string, Speaker>();
            var addedTracks   = new Dictionary <string, Track>();

            var array = await JToken.LoadAsync(new JsonTextReader(new StreamReader(fileStream)));

            var root = array.ToObject <List <RootObject> >();

            foreach (var date in root)
            {
                foreach (var room in date.rooms)
                {
                    if (!addedTracks.ContainsKey(room.name))
                    {
                        var thisTrack = new Track {
                            Name = room.name
                        };
                        db.Tracks.Add(thisTrack);
                        addedTracks.Add(thisTrack.Name, thisTrack);
                    }

                    foreach (var thisSession in room.sessions)
                    {
                        foreach (var speaker in thisSession.speakers)
                        {
                            if (!addedSpeakers.ContainsKey(speaker.name))
                            {
                                var thisSpeaker = new Speaker {
                                    Name = speaker.name
                                };
                                db.Speakers.Add(thisSpeaker);
                                addedSpeakers.Add(thisSpeaker.Name, thisSpeaker);
                            }
                        }

                        var session = new Session
                        {
                            Title     = thisSession.title,
                            StartTime = thisSession.startsAt,
                            EndTime   = thisSession.endsAt,
                            Track     = addedTracks[room.name],
                            Abstract  = thisSession.description
                        };

                        session.SessionSpeakers = new List <SessionSpeaker>();
                        foreach (var sp in thisSession.speakers)
                        {
                            session.SessionSpeakers.Add(new SessionSpeaker
                            {
                                Session = session,
                                Speaker = addedSpeakers[sp.name]
                            });
                        }

                        db.Sessions.Add(session);
                    }
                }
            }
        }
        public override async Task LoadDataAsync(Stream fileStream, BackEndContext db)
        {
            var reader = new JsonTextReader(new StreamReader(fileStream));

            var speakerNames = new Dictionary <string, Speaker>();
            var tracks       = new Dictionary <string, Track>();

            JArray doc = await JArray.LoadAsync(reader);

            foreach (JObject item in doc)
            {
                var theseSpeakers = new List <Speaker>();
                foreach (var thisSpeakerName in item["speakerNames"])
                {
                    if (!speakerNames.ContainsKey(thisSpeakerName.Value <string>()))
                    {
                        var thisSpeaker = new Speaker {
                            Name = thisSpeakerName.Value <string>()
                        };
                        db.Speakers.Add(thisSpeaker);
                        speakerNames.Add(thisSpeakerName.Value <string>(), thisSpeaker);
                        Console.WriteLine(thisSpeakerName.Value <string>());
                    }
                    theseSpeakers.Add(speakerNames[thisSpeakerName.Value <string>()]);
                }

                var theseTracks = new List <Track>();
                foreach (var thisTrackName in item["trackNames"])
                {
                    if (!tracks.ContainsKey(thisTrackName.Value <string>()))
                    {
                        var thisTrack = new Track {
                            Name = thisTrackName.Value <string>()
                        };
                        db.Tracks.Add(thisTrack);
                        tracks.Add(thisTrackName.Value <string>(), thisTrack);
                    }
                    theseTracks.Add(tracks[thisTrackName.Value <string>()]);
                }

                var session = new Session
                {
                    Title     = item["title"].Value <string>(),
                    StartTime = item["startTime"].Value <DateTime>(),
                    EndTime   = item["endTime"].Value <DateTime>(),
                    Track     = theseTracks[0],
                    Abstract  = item["abstract"].Value <string>()
                };

                session.SessionSpeakers = new List <SessionSpeaker>();
                foreach (var sp in theseSpeakers)
                {
                    session.SessionSpeakers.Add(new SessionSpeaker
                    {
                        Session = session,
                        Speaker = sp
                    });
                }

                db.Sessions.Add(session);
            }
        }
 public abstract Task LoadDataAsync(Stream fileStream, BackEndContext db);