public string Generate(int maxRows, string staticFileName = "") { var context = new _8a_oldContext(); IQueryable <_8anu.Data.Migration.Model.CragArea> oldAreas = context.Set <_8anu.Data.Migration.Model.CragArea>(); if (maxRows > 0) { oldAreas = oldAreas.Take(maxRows); } newAreas = new List <Area>(); foreach (var old in oldAreas) { var item = new Area { Id = old.Id, Slug = "", Name = old.Name, Published = true, DateCreated = old.Date, DateModified = old.Date, CountryId = SeedStore.GetCountryByCountryISO3(old.CountryId).Id.Value, LegacyId = old.Id }; newAreas.Add(item); } var json = JsonConvert.SerializeObject(newAreas); return(json); }
private void CreateCountryGroups(int parentCategory, Dictionary <int, ForumCategory> items) { //var items = new List<ForumCategory>(); var curId = parentCategory; var context = new _8a_oldContext(); var countries = context.Set <Model.ForumThreads>().Where(f => f.CountryCode != "GLOBAL" && f.ObjectClass == "CLS_ForumGeneral").Select(f => f.CountryCode).Distinct().ToList(); foreach (var countryISO3 in countries) { var country = SeedStore.GetCountryByCountryISO3(countryISO3); if (country == null) { Console.Write(Environment.NewLine); Console.WriteLine("countrycode: '" + countryISO3 + "' not found. Skipped creating this country"); continue; } var now = DateTime.Now; var newGroup = new ForumCategory { Id = ++curId, Slug = country.Slug, Name = country.Name, UserId = SeedStore.GetZeroUserId(), DateCreated = now, DateModified = now, ParentId = parentCategory }; items.Add(newGroup.Id.Value, newGroup); } //return items; }
private void GenerateAscents() { var timer = Stopwatch.StartNew(); // what we basically do here is get ascents from the score table // and if there is sector & crag for the ascent, we create new route // for it. if not, then we create new sectore / crag for the ascent IQueryable <Score> oldScores = context.Set <_8anu.Data.Migration.Model.Score>() .OrderBy(s => s.Id); if (SeedStore.MaxRowsPerTable > 0) { oldScores = oldScores .Take(SeedStore.MaxRowsPerTable); } // initialize our ascents .. might be slightly faster SeedStore.InitializeAscentsArray(SeedStore.MaxRowsPerTable); var di = Directory.GetParent(AppContext.BaseDirectory); var root = di.FullName; var outputPath = root + Path.DirectorySeparatorChar + "output"; var path = outputPath + Path.DirectorySeparatorChar + "ascents.json"; File.Delete(path); var filestream = new FileStream(path, FileMode.Create); using (var sq = new StreamWriter(filestream)) using (var json = new JsonTextWriter(sq)) { json.WriteStartArray(); var first = true; foreach (var score in oldScores) { var ascent = HandleScore(score); if (ascent != null) { // save to hashtable so we got something to save our sql from SeedStore.AddAscent(ascent); if (!first) { json.WriteRaw(","); } json.WriteRaw(JsonConvert.SerializeObject(ascent, Formatting.Indented)); } first = false; } json.WriteEndArray(); } timer.Stop(); TimeSpan timespan = timer.Elapsed; Console.WriteLine("scores Completed! took " + String.Format("{0:00}:{1:00}:{2:00}", timespan.Minutes, timespan.Seconds, timespan.Milliseconds / 10)); Console.WriteLine("crags: {0}, sectors: {1}, b: {2}, r: {3}, a: {4}", new object[] { SeedStore.CragCount, SeedStore.SectorCount, SeedStore.BoulderCount, SeedStore.RouteCount, SeedStore.AscentCount }); }
private void GenerateFiles(string namespce, string baseUrl, IDisk disk) { var aspNetCoreGenerator = new AspNetCoreGenerator(disk); aspNetCoreGenerator.NameSpace = namespce; aspNetCoreGenerator.TemplateRoot = TemplateRoot; var pivotResources = ResourceCollection.NestedResources.Where(r => r.Pivot != null).ToList(); var pivotClasses = pivotResources.Select(r => r.Pivot).Distinct().ToList(); var oasGenerator = new OASGenerator(disk); oasGenerator.TemplateRoot = TemplateRoot; oasGenerator.Render("", "restapi.yml", "oas3template.sbn", new Dictionary <string, object> { { "resources", ResourceCollection.RootResources }, { "classes", DataModel.CommonClasses }, { "project_title", namespce }, { "base_url", baseUrl } }); aspNetCoreGenerator.RenderResources(ControllerFolder, r => $"{FullName(r)}Controller.cs", "server/resourceController.sbn", ResourceCollection.RootResources.ToList()); aspNetCoreGenerator.RenderResources(ControllerFolder, r => $"{FullName(r)}Controller.cs", "server/nestedResourceController.sbn", ResourceCollection.NestedResources.Where(r => r.Pivot == null).ToList()); aspNetCoreGenerator.RenderResources($"{ServiceFolder}/Interfaces", r => $"I{FullName(r)}Service.cs", "server/resourceServiceInterface.sbn", ResourceCollection.RootResources.ToList()); aspNetCoreGenerator.RenderResources(ServiceFolder, r => $"{FullName(r)}Service.cs", "server/resourceService.sbn", ResourceCollection.RootResources.ToList()); aspNetCoreGenerator.RenderResources(ControllerFolder, r => $"{FullName(r)}Controller.cs", "server/pivotController.sbn", pivotResources); aspNetCoreGenerator.RenderClasses(EntityFolder, s => $"{s.Name}.cs", "server/entity.sbn", DataModel.Classes.Where(c => !c.IsPivot)); aspNetCoreGenerator.Render("", "ApplicationDbContext.cs", "server/applicationDbContext.sbn", new Dictionary <string, object> { { "classes", DataModel.Classes }, { "seedList", SeedStore.All() }, { "name_space", namespce } }); aspNetCoreGenerator.Render("", "Startup.cs", "server/startup.sbn", new Dictionary <string, object> { { "resources", ResourceCollection.RootResources } }); var typeScriptGenerator = new TypeScriptGenerator(disk); typeScriptGenerator.TemplateRoot = TemplateRoot; typeScriptGenerator.RenderClasses($"{ClientFolder}/models", s => $"{s.Name}.{ClientExtension}", "client/model.sbn", DataModel.CommonClasses); typeScriptGenerator.RenderClasses($"{ClientFolder}/views", s => $"{s.Name}List.{ClientComponentExtension}", "client/model_list.sbn", DataModel.CommonClasses); typeScriptGenerator.RenderClasses($"{ClientFolder}/components", s => $"{s.Name}View.{ClientComponentExtension}", "client/model_view.sbn", DataModel.CommonClasses); typeScriptGenerator.RenderClasses($"{ClientFolder}/components", s => $"{s.Name}Edit.{ClientComponentExtension}", "client/model_edit.sbn", DataModel.CommonClasses); typeScriptGenerator.RenderResources($"{ClientFolder}/store", s => $"{s.Name}Module.{ClientExtension}", "client/store_module.sbn", ResourceCollection.RootResources); typeScriptGenerator.Render($"{ClientFolder}/router", $"index.{ClientExtension}", "client/router.sbn", new Dictionary <string, object> { { "classes", DataModel.CommonClasses } }); typeScriptGenerator.Render(ClientFolder, $"App.{ClientComponentExtension}", "client/app.sbn", new Dictionary <string, object> { { "classes", DataModel.CommonClasses } }); typeScriptGenerator.Render($"{ClientFolder}/api", $"index.{ClientExtension}", "client/api_client.sbn", new Dictionary <string, object> { { "resources", ResourceCollection.RootResources }, { "classes", DataModel.CommonClasses } }); typeScriptGenerator.Render($"{ClientFolder}/store", $"index.{ClientExtension}", "client/store.sbn", new Dictionary <string, object> { { "classes", DataModel.CommonClasses }, { "base_url", baseUrl } }); }
public string Generate(int maxRows, string staticFileName = "") { var now = DateTime.Now; var items = new Dictionary <int, ForumCategory>(); var zeroUserId = SeedStore.GetZeroUserId(); var general = new ForumCategory { Id = 1, Slug = "general", Name = "Open forum", UserId = zeroUserId, DateCreated = now, DateModified = now }; items.Add(general.Id.Value, general); var dr8a = new ForumCategory { Id = 2, Slug = "dr8a", Name = "Dr 8a", UserId = zeroUserId, DateCreated = now, DateModified = now }; items.Add(dr8a.Id.Value, dr8a); var countryGroup = new ForumCategory { Id = 3, Slug = "country", Name = "Country specific forums", UserId = zeroUserId, DateCreated = now, DateModified = now }; items.Add(countryGroup.Id.Value, countryGroup); CreateCountryGroups(3, items); //items.AddRange(CreateCountryGroups(3)); SeedStore.ForumCategories = items; var json = JsonConvert.SerializeObject(items.Values); return(json); }
public string Generate(int maxRows, string staticFileName = "") { foreach (var boulder in SeedStore.GetBoulders()) { SeedStore.UpdateGrade(boulder); } var json = JsonConvert.SerializeObject(SeedStore.GetBoulders()); return(json); }
public void GenerateSqlFile(string path) { var tablename = "boulders"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `date_created`, `date_modified`, `difficulty`, `grade`, `grading_system`, `name`, `notes`, `path`, `reference_width`, `sector_id`, `sit_down_start`, `topo_num`, `traverse`, `slug`, `legacy_id`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var boulders = SeedStore.GetBoulders(); var rowCount = boulders.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var thingie in boulders) { var item = thingie as _8anu.Api.Common.DataEntities.Boulder; rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { item.Id, item.DateCreated.ToSqlInsertString(), item.DateModified.ToSqlInsertString(), item.Difficulty.ToSqlInsertString(), item.Grade.ToSqlInsertString(), item.GradingSystem.ToSqlInsertString(), item.Name.ToSqlInsertStringEscape(true), item.Notes.ToSqlInsertStringEscape(true), item.Path.ToSqlInsertStringEscape(true), item.ReferenceWidth.HasValue ? item.ReferenceWidth.Value.ToString() : "NULL", item.SectorId, item.SitDownStart ? 1 : 0, item.TopoNum.ToSqlInsertStringEscape(true), item.Traverse.HasValue ? (item.Traverse.Value ? "1" : "0") : "NULL", SeedStore.GetNewSlug().ToSqlInsertString(), item.LegacyId.HasValue ? item.LegacyId.ToString() : "NULL" })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
public void GenerateSqlFile(string path) { var tablename = "countries"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `iso2`, `iso3`, `name`, `slug`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var rowCount = SeedStore.Countries.Values.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var country in SeedStore.Countries.Values) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { country.Id, country.ISO2.ToSqlInsertString(), country.ISO3.ToSqlInsertString(), country.Name.ToSqlInsertStringEscape(), country.Slug.ToSqlInsertString() })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
public void GenerateSqlFile(string path) { var tablename = "ascents"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `user_id`, `date`, `difficulty`, `zlaggable_id`, `zlaggable_type`, `comment`, `score`, `type`, `rating`, `repeat`, `project`, `chipped`, `exclude_from_ranking`, `note`, `date_created`, `date_modified`, `recommended`, `legacy_id`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var ascents = SeedStore.Ascents; var rowCount = ascents.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var item in ascents) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { item.Id, item.UserId, item.Date.UtcDateTime.ToSqlInsertString(), item.Difficulty.ToSqlInsertString(true), item.ZlaggableId.Value, item.ZlaggableType.ToSqlInsertString(true), item.Comment.ToSqlInsertStringEscape(true), item.Score.HasValue ? item.Score.Value.ToString() : "NULL", item.Type.ToSqlInsertString(true), item.Rating.HasValue ? item.Rating.Value.ToString() : "NULL", item.Repeat.HasValue ? (item.Repeat.Value ? 1 : 0).ToString() : "NULL", item.Project.HasValue ? (item.Project.Value ? 1 : 0).ToString() : "NULL", item.Chipped.HasValue ? (item.Chipped.Value ? 1 : 0).ToString() : "NULL", item.ExcludeFromRanking.HasValue ? (item.ExcludeFromRanking.Value ? 1 : 0).ToString() : "NULL", item.Note.HasValue ? item.Note.Value.ToString() : "NULL", item.DateCreated.ToSqlInsertString(), item.DateModified.ToSqlInsertString(), (item.Recommended ? 1 : 0).ToString(), item.LegacyId.HasValue ? item.LegacyId.ToString() : "NULL" })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
private void AddThreads(_8a_oldContext context, List <Model.ForumThreads> oldThreads, Dictionary <int, ForumThread> newThreads, Dictionary <int, ForumComment> newThreadComments, int ForumCategoryId) { var skippedThreadsCount = 0; var skippedCommentsCount = 0; foreach (var oldthread in oldThreads) { // jump over if this thread don't have any comments var oldComments = context.Set <Model.ObjectComments>() .Where(c => c.ObjectId == oldthread.ObjectId && c.ObjectClass == oldthread.ObjectClass) .OrderByDescending(c => c.Date).ToList(); if (!oldComments.Any()) { continue; } var userId = oldthread.UserId == 0 ? SeedStore.GetZeroUserId() : (int)oldthread.UserId; // jump over if this thread is created by user that is not moved to new system for some reason if (!SeedStore.AddedUserIds.Contains(userId)) { Console.WriteLine("no user found from added users, skipped thread id: " + oldthread.Id); skippedThreadsCount++; continue; } var newThread = new ForumThread { Id = ++currentThreadId, Slug = oldthread.Slug, Title = oldthread.Head, ForumCategoryId = ForumCategoryId, UserId = userId }; var isFirstComment = true; // create all comments foreach (var oldComment in oldComments) { var commentUserId = oldComment.UserId == 0 ? SeedStore.GetZeroUserId() : (int)oldComment.UserId; // jump over if this thread is created by user that is not moved to new system for some reason if (!SeedStore.AddedUserIds.Contains(commentUserId)) { skippedCommentsCount++; Console.WriteLine("no user found from added users, skipped thread id: " + oldComment.Id); continue; } // set date to thread if this is the first comment if (isFirstComment) { isFirstComment = false; newThread.DateCreated = oldComment.Date; newThread.DateModified = oldComment.Date; } var newComment = new ForumComment { Id = currentNewThreadCommentId++, ForumThreadId = currentThreadId, UserId = commentUserId, Content = oldComment.Text, DateCreated = oldComment.Date, DateModified = oldComment.Date, LegacyId = (int)oldComment.Id }; newThreadComments.Add(newComment.Id.Value, newComment); } newThreads.Add(newThread.Id.Value, newThread); } Console.WriteLine("skipped threads: " + skippedThreadsCount + ", skipped comments: " + skippedCommentsCount); }
public void GenerateSqlFile(string path) { var tablename = "crags"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `slug`, `category`, `name`, `town`, `country_id`, `latitude`, `longitude`,`date_created`,`date_modified`,`published`,`access`, `area_id`, `legacy_id`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var crags = SeedStore.GetCrags(); var rowCount = crags.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var crag in crags) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { crag.Id, crag.Slug.ToSqlInsertString(), crag.Category.ToSqlInsertString(), crag.Name.ToSqlInsertStringEscape(false), crag.Town.ToSqlInsertStringEscape(true), crag.CountryId, crag.Latitude.HasValue ? crag.Latitude.ToString() : "NULL", crag.Longitude.HasValue ? crag.Longitude.ToString() : "NULL", crag.DateCreated.ToSqlInsertString(), crag.DateModified.ToSqlInsertString(), crag.Published ? 1 : 0, crag.Access.ToSqlInsertStringEscape(false), crag.AreaId.HasValue ? crag.AreaId.ToString() : "NULL", crag.LegacyId.HasValue ? crag.LegacyId.ToString() : "NULL" })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
static void MainRun() { // Create service collection ServiceCollection serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); // Create service provider IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); // Get backup sources for client // List<String> sources = configuration.GetSection("Backup:Sources").GetChildren().Select(x => x.Value).ToList(); // var sqlConnectionString = configuration.GetConnectionString("AWSConnection"); // Console.WriteLine("connectionstring: " + sqlConnectionString); // get and create folder for output if not exists var di = Directory.GetParent(AppContext.BaseDirectory); var root = di.FullName; var outputPath = root + Path.DirectorySeparatorChar + "output"; var sqlOutputpath = root + Path.DirectorySeparatorChar + "sql"; var inputPath = root + Path.DirectorySeparatorChar + "input"; if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } if (!Directory.Exists(sqlOutputpath)) { Directory.CreateDirectory(sqlOutputpath); } // get settings var msettings = configuration.GetSection("MigrationSettings"); var maxRowsPerTable = msettings.GetValue <int>("MaxRowsPerTable"); if (_overWriteMax > -1) { maxRowsPerTable = _overWriteMax; } SeedStore.MaxRowsPerTable = maxRowsPerTable; Console.WriteLine("max rows: " + maxRowsPerTable.ToString()); // add constants to seedsettings var myConstants = new Dictionary <string, string>(); var constants = msettings.GetSection("Constants"); if (constants != null && constants.GetChildren().Any()) { foreach (var item in constants.GetChildren()) { var key = item.GetValue <string>("name"); var value = item.GetValue <string>("value"); SeedStore.Settings.Add(key, value); } } // text to add to all files so dev's know these files will be overwritten var infoText = @"// // THIS FILE IS GENERATED BY // 8anu.Data.Migration command line tool // //" + Environment.NewLine; // get path where to copy the files var copyPath = di.Parent.Parent.Parent.Parent.FullName; copyPath = copyPath + Path.DirectorySeparatorChar + "8anu.Api" + Path.DirectorySeparatorChar + "Seed" + Path.DirectorySeparatorChar + "input"; Console.WriteLine("path to copy files to = " + copyPath); // delete all files from the output folder Array.ForEach(Directory.GetFiles(outputPath), filePath => File.Delete(filePath)); // delete all files from the destination folder if (_copyToOutputLocation) { Array.ForEach(Directory.GetFiles(copyPath), filePath => File.Delete(filePath)); } // copy configuration file contents to output location var sourcePathAndFile = root + Path.DirectorySeparatorChar + "migrationsettings.json"; var configContent = File.ReadAllText(sourcePathAndFile); configContent = infoText + configContent; var destinationPathAndFile = copyPath + Path.DirectorySeparatorChar + "migrationsettings.json"; if (_copyToOutputLocation) { File.WriteAllText(destinationPathAndFile, configContent); Console.WriteLine("copied migrationsettings.json to destination"); } var models = msettings.GetSection("Models").GetChildren(); // hard coded to be able to save crags again after the loop var cragsFileName = ""; IGenerator cragsGenerator = null; foreach (var model in models) { var maxRows = maxRowsPerTable; try { maxRows = model.GetValue <int>("MaxRowsPerTable"); } catch {} var name = model.GetValue <string>("Name"); var cls = model.GetValue <string>("GeneratorClass"); var inputFile = model.GetValue <string>("InputFile"); Console.Write("generate (" + (maxRows > 0 ? maxRows.ToString() : "all") + ")items for: " + name + " (" + (cls.Length > 0 ? cls : ("static: " + inputFile)) + ") .... "); // get model properties if (model.GetValue <bool>("Skip", false)) { Console.Write("SKIP" + Environment.NewLine); continue; } var streamOut = model.GetValue <bool>("StreamOut", false); // get type & generate content var json = ""; var inputFileName = ""; if (!string.IsNullOrEmpty(inputFile)) { inputFileName = inputPath + Path.DirectorySeparatorChar + inputFile; } // generator takes care of streaming the output if (streamOut) { inputFileName = outputPath + Path.DirectorySeparatorChar + name + ".json"; } if (cls.Length > 0) { var myType = Type.GetType(cls); IGenerator generator = (IGenerator)Activator.CreateInstance(myType); json = generator.Generate(maxRows, inputFileName); if (SeedStore.GenerateSQLFiles) { var sqlFile = sqlOutputpath + Path.DirectorySeparatorChar + name + ".sql"; generator.GenerateSqlFile(sqlFile); } if (name == "crags") { cragsGenerator = generator; } } // write file and copy file var filename = name + ".json"; var pathAndName = outputPath + Path.DirectorySeparatorChar + filename; if (!streamOut) { json = infoText + json; File.WriteAllText(pathAndName, json); } if (name == "crags") { cragsFileName = pathAndName; } // copy file to api project // don't copy files since we zip them later on and copy all at once // var copyPathAndName = copyPath + Path.DirectorySeparatorChar + filename; // File.Copy(pathAndName, copyPathAndName, true); Console.Write("done!" + Environment.NewLine); } // if crags have to be generated again... if (cragsFileName != "") { var json = JsonConvert.SerializeObject(SeedStore.GetCrags()); json = infoText + json; File.WriteAllText(cragsFileName, json); if (SeedStore.GenerateSQLFiles) { var sqlFile = sqlOutputpath + Path.DirectorySeparatorChar + "crags" + ".sql"; cragsGenerator.GenerateSqlFile(sqlFile); } } // create all.sql var allSqlFile = sqlOutputpath + Path.DirectorySeparatorChar + "all.sql"; File.WriteAllText(allSqlFile, SeedStore.AllSql); var sqlpath = root + Path.DirectorySeparatorChar + "sql"; var sqlzipfile = "seed_data_sql.zip"; sqlzipfile = root + Path.DirectorySeparatorChar + sqlzipfile; File.Delete(sqlzipfile); ZipFile.CreateFromDirectory(sqlpath, sqlzipfile); // zip seed data files and copy to api project var zipFileName = "seed_data_json.zip"; var zipPathAndFileName = root + Path.DirectorySeparatorChar + zipFileName; File.Delete(zipPathAndFileName); ZipFile.CreateFromDirectory(outputPath, zipPathAndFileName); if (_copyToOutputLocation) { var dest = copyPath + Path.DirectorySeparatorChar + zipFileName; File.Copy(zipPathAndFileName, dest, true); } }
public void GenerateSqlFile(string path) { var tablename = "grading_systems"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `category`, `grade`, `type`, `vl_grade`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var rowCount = SeedStore.GradingSystems.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var grade in SeedStore.GradingSystems) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { grade.Id, grade.Category.ToSqlInsertString(), grade.Grade.ToSqlInsertString(), grade.Type.ToSqlInsertString(), grade.VLGrade.ToSqlInsertString() })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
public void GenerateSqlFile(string path) { var tablename = "forum_categories"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `date_created`, `date_modified`, `description`, `name`, `parent_id`, `slug`, `user_id`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var rowCount = SeedStore.ForumCategories.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var cat in SeedStore.ForumCategories.Values) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { cat.Id, cat.DateCreated.ToSqlInsertString(), cat.DateModified.ToSqlInsertString(), cat.Description.ToSqlInsertStringEscape(true), cat.Name.ToSqlInsertStringEscape(false), cat.ParentId.HasValue ? cat.ParentId.Value.ToString() : "NULL", cat.Slug.ToSqlInsertString(), cat.UserId })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
public void GenerateSqlFile(string path) { var tablename = "users"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `country_id`, `date_created`, `date_modified`, `first_name`, `gender`, `last_name`, `slug`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var rowCount = SeedStore.Users.Values.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var user in SeedStore.Users.Values) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { user.Id, user.CountryId, user.DateCreated.ToSqlInsertString(), user.DateModified.ToSqlInsertString(), user.FirstName.ToSqlInsertStringEscape(false), user.Gender == Api.Common.Enums.GenderEnum.Male ? 0 : 1, user.LastName.ToSqlInsertStringEscape(false), user.Slug.ToSqlInsertString() })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
public void GenerateSqlFile(string path) { var tablename = "areas"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `country_id`, `date_created`, `date_modified`, `description`, `name`, `published`, `slug`, `legacy_id`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var rowCount = newAreas.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var area in newAreas) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { area.Id, area.CountryId, area.DateCreated.ToSqlInsertString(), area.DateModified.ToSqlInsertString(), area.Description.ToSqlInsertStringEscape(), area.Name.ToSqlInsertStringEscape(), area.Published ? 1 : 0, SeedStore.GetNewSlug().ToSqlInsertString(), area.LegacyId.HasValue ? area.LegacyId.ToString() : "NULL" })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
public string Generate(int maxRows, string staticFileName = "") { var context = new _8a_oldContext(); IQueryable <_8anu.Data.Migration.Model.Userinfo> oldItems = context.Set <_8anu.Data.Migration.Model.Userinfo>(); if (maxRows > 0) { oldItems = oldItems.Take(maxRows); } var newItems = new Dictionary <int, User>(); var skippedCount = 0; var doneCount = 0; var skippedUserIds = new HashSet <int>(); var addedUserIds = new HashSet <int>(); foreach (var old in oldItems) { // todo: remove items with name and lastname "?" // todo: look for duplicate names with same firstname and lastname (plus id at the end) these should be preferably be converted to slug-hashtext // todo: look for people who don't have country in the country table. // todo: check for names in the DB that have &; in their names or cities and change these to unicode // todo: check for users in DB with linebreak in their country code var newCountryId = GetCountryId(old.Country); if (newCountryId == -1) { newCountryId = SeedStore.UnknownCountry.Id.Value; var s = String.Format("id: {0:-6} - {1:-30} - country: '{2:-5}' - will be using undefined country id: " + newCountryId, old.Id.ToString(), old.FName + " " + old.LName, old.Country); Console.WriteLine(s); } if (newCountryId == -1) { skippedUserIds.Add((int)old.Id); var s = String.Format("id: {0:-6} - {1:-30} - country: '{2:-5}' - and that's not OK - SKIP", old.Id.ToString(), old.FName + " " + old.LName, old.Country); Console.WriteLine(s); skippedCount++; continue; } addedUserIds.Add((int)old.Id); var zeroId = SeedStore.GetZeroUserId(); // here we need to fix the ID for the 0 - user int newId = old.Id > 0 ? (int)old.Id : zeroId; var now = DateTime.Now; var item = new User { Id = newId, Slug = old.Slug, FirstName = old.FName, LastName = old.LName, Gender = (Api.Common.Enums.GenderEnum)old.Sex, CountryId = newCountryId, DateCreated = now, DateModified = now }; newItems.Add(item.Id.Value, item); doneCount++; } SeedStore.SkippedUserIds = skippedUserIds; SeedStore.AddedUserIds = addedUserIds; SeedStore.Users = newItems; Console.WriteLine("done: " + doneCount.ToString() + " - skipped: " + skippedCount.ToString()); var json = JsonConvert.SerializeObject(newItems.Values); return(json); }
private Api.Common.DataEntities.Ascent HandleScore(Score score) { currentScoreId = Convert.ToInt32(score.Id); ind++; if (ind % 10000 == 0) { Console.Write(". " + (++logTimes * 10000).ToString("#,##0")); Console.WriteLine("crags: {0}, sectors: {1}, b: {2}, r: {3}, a: {4}", new object[] { SeedStore.CragCount, SeedStore.SectorCount, SeedStore.BoulderCount, SeedStore.RouteCount, SeedStore.AscentCount }); } else if (ind % 10000 == 0) { Console.Write("."); } // todo: unicode crag name, look for &234 without ; and remove spaces // todo: only do the unicode check if we create a new one // todo: find out does old 8a get routes difficulty from the first ascent in score DB? Crag crag = null; Sector sector = null; Zlaggable thingie = null; var scoreHasCountry = false; var scoreHasRouteOrBoulderName = false; var scoreHasCragName = false; var scoreHasSectorName = false; var cragName = getValue(score.Crag, "Unknown Crag", out scoreHasCragName); var sectorName = getValue(score.CragSector, "Unknown Sector", out scoreHasSectorName); var routeName = getValue(score.Name, "Unknown ", out scoreHasRouteOrBoulderName); if (!scoreHasRouteOrBoulderName) { var ending = score.What == 0 ? "route" : "boulder"; routeName += ending; } var verticalCategory = score.What == 0 ? SeedStore.CATEGORY_SPORTSCLIMBING : SeedStore.CATEGORY_BOULDERING; var verticalAscentCategory = score.What == 0 ? SeedStore.ASCENT_CATEGORY_ROUTE : SeedStore.ASCENT_CATEGORY_BOULDER; var scoreHasCrag = false; var scoreHasSector = false; var scoreHasRouteOrBoulder = false; var countryId = -1; // get user var user = SeedStore.GetUser(Convert.ToInt32(score.UserId)); if (user == null) { Console.WriteLine("score id: " + score.Id.ToString() + " USER DatabaseId: " + score.UserId.ToString() + " NOT FOUND!"); return(null); } // // get country - default to users country // var countryISO3 = score.Country; try { if (!string.IsNullOrEmpty(countryISO3)) { countryId = SeedStore.GetCountryId(score.Country); scoreHasCountry = true; } else { // if scores country is null, get users country // this will be used if we create new crag countryId = user.CountryId; } } catch { Console.WriteLine("trouble getting country for score id: " + score.Id + " - countryISO3: " + countryISO3); countryId = user.CountryId; } if (scoreHasCragName) { // get crag by name only crag = SeedStore.GetCragOnlyByName(score.Crag, verticalCategory); } else { crag = SeedStore.GetCrag(cragName, verticalCategory, countryId); } /* * // get existing crag * if (scoreHasCountry && scoreHasCragName) * { * // look for crag first by country * crag = SeedStore.GetCrag(score.Crag, verticalCategory, countryId); * * scoreHasCrag |= crag != null; * * // todo: * // optional: get existing crag with different category * } * else if (scoreHasCragName) * { * // score has no country defined .. so we just look for the crag name * crag = SeedStore.GetCragOnlyByName(score.Crag, verticalCategory); * } */ // im here with my performance tests: // return null; // create crag if we still don't have one if (crag == null) { var cragId = ++SeedStore.MaxCragId; var now = DateTime.Now; crag = new Crag { Id = cragId, Slug = cragName.ToSlug(postString: cragId.ToString()), Category = verticalCategory, Name = cragName, CountryId = countryId, DateCreated = now, DateModified = now, Published = true }; SeedStore.AddCrag(crag); } // get existing sector if score happens to have a crag //if (scoreHasCrag) //{ sector = SeedStore.GetSector(crag.Id.Value, sectorName); scoreHasSector |= sector != null; //} // create sector if nothing found if (sector == null) { var now = DateTime.Now; // create new sector var sectorId = ++SeedStore.MaxSectorId; sector = new Sector { Id = sectorId, Slug = "", CragId = crag.Id.Value, Name = sectorName, Category = verticalCategory, DateCreated = now, DateModified = now }; SeedStore.AddSector(sector); } // only try to get existing "climbablethingie" if there is already a sector //if (scoreHasSector) //{ thingie = SeedStore.GetThingie(sector.Id.Value, routeName, score.What); scoreHasRouteOrBoulder |= thingie != null; //} // get grading system to be used for using with route/boulder and ascent var gradingSystem = getGradingSystem(score.Grade, score.What); // no thingie (route or boulder) so we make new one if (thingie == null) { var now = DateTime.Now; if (score.What == 0) // could check for category but let's speed things up { //if (!scoreHasRouteOrBoulderName) //{ // routeName += "route"; //} var routeId = ++SeedStore.MaxRouteId; thingie = new Route { Id = routeId, Name = routeName, Slug = "", SectorId = sector.Id.Value }; SeedStore.AddRoute(thingie); } else { //if (!scoreHasRouteOrBoulderName) //{ // routeName += "boulder"; //} var boulderId = ++SeedStore.MaxBoulderId; thingie = new Boulder { Id = boulderId, Name = routeName, Slug = "", SectorId = sector.Id.Value }; SeedStore.AddBoulder(thingie); } thingie.DateCreated = now; thingie.DateModified = now; thingie.Difficulty = gradingSystem.Grade; // 6a+ thingie.Grade = gradingSystem.VLGrade; // vl-1-39 thingie.GradingSystem = gradingSystem.Type; // french } SeedStore.AddGrade(thingie.Id.Value, gradingSystem, score.What == 0 ? ZlaggableCategoryEnum.Sportclimbing : ZlaggableCategoryEnum.Bouldering); var objectClassLength = score.ObjectClass.Length; // comparing lenghts so it's a bit faster // lengths // 14 = CLS_UserAscent // 22 = CLS_UserAscent_Project // 18 = CLS_UserAscent_Try var type = ""; if (objectClassLength != 18) { type = getVerticalAscentType(score.How); } else { type = "go"; } var isProject = objectClassLength == 22; // create ascent var ascent = new Ascent { Id = ++SeedStore.MaxAscentId, UserId = user.Id.Value, Date = ParseScoreDate(score.Date), // climbed that shit date Difficulty = gradingSystem.Grade, // eg. 8a+ ZlaggableId = thingie.Id, // ID of route or boulder ZlaggableType = verticalAscentCategory, // route / boulder Comment = score.Comment, // user comment Score = score.TotalScore, Type = type, // f, os, tr, rp, go Rating = score.Rate, Repeat = score.Repeat == 1 ? true : false, Project = isProject, Chipped = score.Chipped == 1, ExcludeFromRanking = score.ExcludeFromRanking == 1, Note = Convert.ToInt32(score.Fa), DateCreated = score.RecDate, DateModified = score.RecDate, Recommended = score.UserRecommended == 1, LegacyId = (int)score.Id // todo: userRecommended to Route "likes" // todo: what to do with projectAscentDate? // todo: what to do with YellowId // variations -> not used // steepness -> not used // altgrade -> not used }; //SeedStore.Ascents.Add(ascent); return(ascent); }
public string Generate(int maxRows, string staticFileName = "") { //IQueryable<_8anu.Data.Migration.Model.CragSectors> oldSectors = IQueryable <_8anu.Data.Migration.Model.CragSectors> oldSectors = context.Set <_8anu.Data.Migration.Model.CragSectors>(); if (maxRows > 0) { oldSectors = oldSectors.Take(maxRows); } foreach (var old in oldSectors) { // let's see if our crag exists var myCrag = SeedStore.GetCrag(old.CragId); if (myCrag == null) { Console.WriteLine("crag id: " + old.CragId + " does not exist for sector id: " + old.Id + ", name: " + old.Name); continue; } double?lat = null; double?lng = null; if (!(string.IsNullOrEmpty(old.GoggleMapX.Trim()) && string.IsNullOrEmpty(old.GoggleMapY.Trim()))) { try { lat = double.Parse(old.GoggleMapX.Trim(), CultureInfo.InvariantCulture.NumberFormat); lng = double.Parse(old.GoggleMapY.Trim(), CultureInfo.InvariantCulture.NumberFormat); } catch { lat = null; lng = null; Console.WriteLine(Environment.NewLine); Console.WriteLine("sector: " + old.Name + " - id: " + old.Id.ToString() + "exception converting lat & longitude"); } } var now = DateTime.Now; var item = new Sector { Id = (int)old.Id, CragId = old.CragId, Name = old.Name, Latitude = lat, Longitude = lng, Category = myCrag.Category, DateCreated = now, DateModified = now }; if (item.Id.Value > SeedStore.MaxSectorId) { SeedStore.MaxSectorId = item.Id.Value; } try { SeedStore.AddSector(item); } catch { // this is propably just duplicate.. so we'll forget it } } GenerateAscents(); var json = JsonConvert.SerializeObject(SeedStore.GetSectors()); return(json); }
public static void Seed(this EFContext context) { SeedStore.InsertData(context); SeedSaleTransaction.InsertData(context); }
public void GenerateSqlFile(string path) { var tablename = "sectors"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `category`, `crag_id`, `date_created`, `date_modified`, `latitude`, `longitude`, `name`, `notes`, `ordering`, `slug`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var sectors = SeedStore.GetSectors(); var rowCount = sectors.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var sector in sectors) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { sector.Id, sector.Category.ToSqlInsertString(), sector.CragId, sector.DateCreated.ToSqlInsertString(), sector.DateModified.ToSqlInsertString(), sector.Latitude.HasValue ? sector.Latitude.ToString() : "NULL", sector.Longitude.HasValue ? sector.Longitude.ToString() : "NULL", sector.Name.ToSqlInsertStringEscape(false), sector.Notes.ToSqlInsertStringEscape(true), sector.Ordering.HasValue ? sector.Ordering.ToString() : "NULL", SeedStore.GetNewSlug().ToSqlInsertString() })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }
public string Generate(int maxRows, string staticFileName = "") { var context = new _8a_oldContext(); IQueryable <_8anu.Data.Migration.Model.Crag> oldCrags = context.Set <_8anu.Data.Migration.Model.Crag>(); if (maxRows > 0) { oldCrags = oldCrags.Take(maxRows); } var newCrags = new Dictionary <int, Crag>(); foreach (var old in oldCrags) { double?lat = null; double?lng = null; if (!(string.IsNullOrEmpty(old.GoggleMapX.Trim()) && string.IsNullOrEmpty(old.GoggleMapY.Trim()))) { try { lat = double.Parse(old.GoggleMapX.Trim(), CultureInfo.InvariantCulture.NumberFormat); lng = double.Parse(old.GoggleMapY.Trim(), CultureInfo.InvariantCulture.NumberFormat); } catch { lat = null; lng = null; Console.WriteLine(Environment.NewLine); Console.WriteLine("crag: " + old.Name + " - id: " + old.Id.ToString() + "exception converting lat & longitude"); // Console.WriteLine("exception with original lat: " + old.GoggleMapX); // Console.WriteLine("exception with original lng: " + old.GoggleMapY); } } var category = old.Type == 0 ? SeedStore.CATEGORY_SPORTSCLIMBING : SeedStore.CATEGORY_BOULDERING; var item = new Crag { Id = (int)old.Id, Slug = old.Slug, Category = category, Name = old.Name, Town = old.City, CountryId = GetCountryId(old.CountryId), Latitude = lat, Longitude = lng, DateCreated = old.EditDate, DateModified = old.EditDate, Published = old.Active == 1 ? true : false, Access = old.AccessInfo, LegacyId = (int)old.Id }; // increase maxID so we can autoincrement new crags later (sector generator) if (item.Id.Value > SeedStore.MaxCragId) { SeedStore.MaxCragId = item.Id.Value; } if (old.CragAreaId > 0) { item.AreaId = old.CragAreaId; } //newCrags.Add(item.DatabaseId.Value, item); SeedStore.AddCrag(item); } // SeedStore.AddCragsRange(newCrags); //var json = JsonConvert.SerializeObject(newCrags.Values); //return json; return(""); }
public void GenerateSqlFile(string path) { var tablename = "test_models"; SeedStore.AddAllSqlString(tablename); var head = $@"TRUNCATE TABLE `{tablename}`; ALTER TABLE `{tablename}` DISABLE KEYS;"; var tail = $"ALTER TABLE `{tablename}` ENABLE KEYS;"; var insertHead = @"INSERT INTO `" + tablename + @"` (`id`, `date_created`, `date_modified`, `message`) VALUES"; var currentPageRow = 1; var rowNumber = 0; var maxRowCountPerInsert = SeedStore.MAX_ROW_COUNT_PER_INSERT; var rowCount = items.Count; using (var filestream = new FileStream(path, FileMode.Create)) using (var sq = new StreamWriter(filestream)) { sq.WriteLine(SeedStore.SQL_HEAD); sq.WriteLine(head); sq.WriteLine(); sq.WriteLine(insertHead); foreach (var test in items) { rowNumber++; if (currentPageRow > maxRowCountPerInsert) { sq.WriteLine(); sq.WriteLine(insertHead); currentPageRow = 1; } var line = new StringBuilder("("); line.Append(string.Join(",", new object[] { test.Id, test.DateCreated.ToSqlInsertString(), test.DateModified.ToSqlInsertString(), test.Message.ToSqlInsertStringEscape() })); line.Append(")"); currentPageRow++; if (currentPageRow <= maxRowCountPerInsert && rowNumber < rowCount) { line.Append(","); } else { line.Append(";"); } sq.WriteLine(line); } sq.WriteLine(); sq.WriteLine(tail); sq.WriteLine(); sq.WriteLine(SeedStore.SQL_TAIL); } }