private void Do(string json) { if (json.Contains("\"Publications\": [")) { this.publikationen.Items.Clear(); if (json.Contains("\"PublisherUrl\":")) { var publicationData = JsonConvert.DeserializeObject <OldPublicationData>(json); MediaRepo.Media.Clear(); PublisherRepo.Publisher.Clear(); this.publikationen.Items.Clear(); foreach (var publication in publicationData.Publications) { Publisher publ = new Publisher(); publ.Id = PublisherRepo.Publisher.Count + 1; publ.Name = publication.Publisher; publ.Link = publication.PublisherUrl; PublisherRepo.Publisher.Add(publ); Medium med = new Medium(); med.Id = MediaRepo.Media.Count + 1; med.Name = publication.Medium; med.PublisherId = publ.Id; MediaRepo.Media.Add(med); Publication pub = new Publication(); pub.Id = publication.Id; pub.Name = publication.Name; pub.Description = publication.Description; pub.Date = publication.Date; pub.Link = publication.Link; pub.Reviewed = false; pub.Type = publication.Type; pub.MediumId = med.Id; this.publikationen.Items.Add(pub); PublisherRepo.OnPublisherCollectionImport(); MediaRepo.OnMediaCollectionImport(); } } else { //TODO Check if table exist, drop and create new var publicationData = JsonConvert.DeserializeObject <PublicationData>(json); foreach (var publication in publicationData.Publications) { this.publikationen.Items.Add(publication); } } } else if (json.Contains("\"Publisher\": [")) { PublisherRepo.Publisher.Clear(); var publicationData = JsonConvert.DeserializeObject <PublisherRepoInstance>(json); PublisherRepo.Publisher = publicationData.Publisher; PublisherRepo.OnPublisherCollectionImport(); } else if (json.Contains("\"Media\": [")) { MediaRepo.Media.Clear(); var publicationData = JsonConvert.DeserializeObject <MediaRepoInstance>(json); MediaRepo.Media = publicationData.Media; MediaRepo.OnMediaCollectionImport(); } else if (json.Contains("\"Projects\": [")) { var publicationData = JsonConvert.DeserializeObject <ProjectRepoInstance>(json); ProjectRepo.Projects = publicationData.Projects; ProjectRepo.OnProjectCollectionImport(); } }
private void ImportDB2() { // Read DB using (var db = new DataContext()) { // Drop DB // db.Database.Delete(); // Init Database for EF if (!db.Publications.Any() && !db.Media.Any() && !db.Publishers.Any() && !db.Projects.Any()) { InitEFDb(); } // Import Publication // Display all Publications from the database var query = from b in db.Publications orderby b.Id select b; Console.WriteLine("Read all Publications in the database..."); this.publikationen.Items.Clear(); foreach (var item in query) { this.publikationen.Items.Add(item); } // Import Media // Display all Media from the database var query2 = from b in db.Media orderby b.Id select b; Console.WriteLine("Read all Media in the database..."); MediaRepo.Media.Clear(); foreach (var item in query2) { MediaRepo.Media.Add(item); } MediaRepo.OnMediaCollectionImport(); // Import Publishers // Display all Publishers from the database var query3 = from b in db.Publishers orderby b.Id select b; Console.WriteLine("Read all Publishers in the database..."); PublisherRepo.Publisher.Clear(); foreach (var item in query3) { PublisherRepo.Publisher.Add(item); } PublisherRepo.OnPublisherCollectionImport(); // Import Projects // Display all Projects from the database var query4 = from b in db.Projects orderby b.Id select b; Console.WriteLine("Read all Projects in the database..."); ProjectRepo.Projects.Clear(); foreach (var item in query4) { ProjectRepo.Projects.Add(item); } ProjectRepo.OnProjectCollectionImport(); } Console.WriteLine("Import Database with EF completed!"); }