protected override void Seed(DatabaseContext context) { // Here you can seed your core data if you have any. var baseTariff = new TariffDTO() { Name = "base Tariff", Price = 4.0 }; var dayTariff = new TariffDTO() { Name = "Day Tariff", Price = 4.2 }; var nightTariff = new TariffDTO() { Name = "Night Tariff", Price = 4.2 }; context.TariffDTOs.Add(baseTariff); context.TariffDTOs.Add(dayTariff); context.TariffDTOs.Add(nightTariff); var meterType = new MeterTypeDTO() { ManufacturerName = "Meteor", ModelName = "Signal 01", CalibrationIntervals = 10 }; var fistAgreement = new AgreementDTO() { Name = "First", Number = "01-01-2018", BegDate = new DateTime(2018, 3, 1), EndDate = new DateTime(2020, 3, 1), Deleted = false }; var secondAgr = new AgreementDTO() { Name = "Second (deleted)", Number = "01-01-2018", BegDate = new DateTime(2018, 3, 1), EndDate = new DateTime(2020, 3, 1), Deleted = true }; context.AgreementDTOs.Add(fistAgreement); context.AgreementDTOs.Add(secondAgr); var unitHouse = new UnitDTO() { Name = "House", Adress = "Moscow 1" }; var unitStore = new UnitDTO() { Name = "Store", Adress = "Novgorod 1" }; context.UnitDTOs.Add(unitHouse); context.UnitDTOs.Add(unitStore); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = fistAgreement, Childen = unitHouse, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 1.0, }); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = fistAgreement, Childen = unitStore, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 0.5 }); var tariffGroupHouse = new TariffGroupDTO() { Name = "Base Tariff House", Tariff = baseTariff }; var tariffGroupStore = new TariffGroupDTO() { Name = "Base Tariff Store", Tariff = baseTariff }; context.TariffGroupDTOs.Add(tariffGroupHouse); context.TariffGroupDTOs.Add(tariffGroupStore); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = unitHouse, Childen = tariffGroupHouse, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 1.0 }); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = unitStore, Childen = tariffGroupStore, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 1.0 }); var channelHouse = new ChannelDTO() { Name = "Base Channel", VoltageLevelId = 0 }; context.ChannelDTOs.Add(channelHouse); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = tariffGroupHouse, Childen = channelHouse, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 1.0 }); var consFlowStore = new ConstantFlowDTO() { Name = "Signal system", VoltageLevelId = 0, Сonsumption = 10.0 }; context.ConstantFlowDTOs.Add(consFlowStore); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = tariffGroupStore, Childen = consFlowStore, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 1.0 }); var meterHouse = new MeterDTO() { Name = "ground flow", CountScale = 6, PublicNumber = "34785", SerialNumber = "2016-04-23-02-2349" }; context.MeterDTOs.Add(meterHouse); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = channelHouse, Childen = meterHouse, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 1.0 }); var scaleHouse = new MeterScaleDTO() { Name = "All day", Dimension = 6, ZoneOfDayId = 0 }; context.MeterScaleDTOs.Add(scaleHouse); context.LinkObjectsDTOs.Add(new LinkObjectsDTO() { Owner = meterHouse, Childen = scaleHouse, BeginDate = new DateTime(2018, 1, 1), EndDate = new DateTime(2079, 1, 1), Factore = 1.0 }); context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO() { CreateDate = new DateTime(2018, 1, 1), ReceiptDate = new DateTime(2018, 1, 1), Meter = meterHouse, Scale = scaleHouse, Indication = 1012 }); context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO() { CreateDate = new DateTime(2018, 2, 1), ReceiptDate = new DateTime(2018, 2, 1), Meter = meterHouse, Scale = scaleHouse, Indication = 1057 }); context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO() { CreateDate = new DateTime(2018, 3, 1), ReceiptDate = new DateTime(2018, 3, 1), Meter = meterHouse, Scale = scaleHouse, Indication = 1135 }); context.IndicationDocumentDTOs.Add(new Models.Documents.IndicationDocumentDTO() { CreateDate = new DateTime(2018, 4, 1), ReceiptDate = new DateTime(2018, 4, 1), Meter = meterHouse, Scale = scaleHouse, Indication = 1208 }); }
static void Main(string[] args) { var songs = new List <SongDTO>(); var tunes = new List <TuneDTO>(); var meters = new List <MeterDTO>(); var parts = new List <BookPartDTO>(); var sections = new List <BookSectionDTO>(); var songSection = new List <SongSectionDTO>(); var songSectionLine = new List <SongSectionLineDTO>(); XmlSerializer serializer = new XmlSerializer(typeof(object), new XmlRootAttribute("html")); var nodes = (XmlNode[])serializer.Deserialize(new XmlTextReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "raw2.xml"))); var lastSectionId = ""; var lastPartId = ""; var lastSong = new SongDTO { Number = 0 }; for (int i = 0; i < nodes.Length; i++) { if (nodes[i].Name == "h1") { //we're at a header var bookPart = new BookPartDTO { Id = nodes[i].InnerText.Underscore(), Name = nodes[i].InnerText.Humanize(LetterCasing.Title) }; parts.Add(bookPart); lastPartId = bookPart.Id; } else if (nodes[i].Name == "h2" && nodes[i].NextSibling.Name == "h2") { var children = nodes[i].ChildNodes; //were at a section title var bookSection = new BookSectionDTO { Id = nodes[i].InnerText.Underscore(), BookPartId = lastPartId, Name = nodes[i].InnerText.Humanize(LetterCasing.Title) }; sections.Add(bookSection); lastSectionId = bookSection.Id; } else if (nodes[i].Name == "h2" && nodes[i].NextSibling.Name == "p") { var rawMeterName = nodes[i].ChildNodes[1].InnerText; var meter = meters.FirstOrDefault(m => m.Name == rawMeterName); if (meter == null) { var newMeter = new MeterDTO { Id = rawMeterName, Name = rawMeterName }; meters.Add(newMeter); meter = newMeter; } var rawTuneName = nodes[i].ChildNodes[1].InnerText.Replace("[", "").Replace(".", ""); var tune = tunes.FirstOrDefault(t => t.Name == rawTuneName); if (tune == null) { var newTune = new TuneDTO { Id = rawTuneName, Name = rawTuneName }; tunes.Add(newTune); tune = newTune; } var song = new SongDTO { Number = lastSong.Number + 1, Id = (lastSong.Number + 1).ToString(), BookSectionId = lastSectionId, MeterId = meter.Id, TuneId = tune.Id }; songs.Add(song); lastSong = song; } else if (nodes[i].Name == "p") { //song body var body = nodes[i].InnerText.Replace("<span>", "").Replace("</span>", ""); var songSections = body.Split("\r\n \r\n", StringSplitOptions.None).ToList(); for (int ii = 0; ii < songSections.Count; ii++) { if (songSections[ii].Count() <= 1) { break; } var section = new SongSectionDTO { Id = lastSong.Id + "." + ii, SongId = lastSong.Id, Order = ii }; songSection.Add(section); var currentSongLines = songSections[ii].Split("\n").ToList(); //remove spacing currentSongLines.RemoveAll(r => r == "\r"); for (int b = 0; b < currentSongLines.Count; b++) { currentSongLines[b] = currentSongLines[b].Replace(" ", "").Replace("\r", ""); } for (int iii = 0; iii < currentSongLines.Count; iii++) { var line = currentSongLines[iii]; if (line.Trim() == "") { continue; } songSectionLine.Add(new SongSectionLineDTO { Id = lastSong.Id + "." + section.Order + "." + iii.ToString(), Order = iii, SongSectionId = section.Id, Line = line }); } } } } using (var writer = new ChoCSVWriter <SongDTO>(@"C:\output\songs.csv")) { writer.Write(songs); } using (var writer = new ChoCSVWriter <TuneDTO>(@"C:\output\tunes.csv")) { writer.Write(tunes); } using (var writer = new ChoCSVWriter <MeterDTO>(@"C:\output\meters.csv")) { writer.Write(meters); } using (var writer = new ChoCSVWriter <BookPartDTO>(@"C:\output\book_parts.csv")) { writer.Write(parts); } using (var writer = new ChoCSVWriter <BookSectionDTO>(@"C:\output\book_sections.csv")) { writer.Write(sections); } using (var writer = new ChoCSVWriter <SongSectionDTO>(@"C:\output\song_sections.csv")) { writer.Write(songSection); } using (var writer = new ChoCSVWriter <SongSectionLineDTO>(@"C:\output\song_section_lines.csv")) { writer.Write(songSectionLine); } }