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; }
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 string getOldGrade(byte oldGradeId, int what) { // var context = new _8a_oldContext(); if (oldGrades == null) { using (var db = new _8a_oldContext()) { oldGrades = db.Set <ScoreGrades>().ToDictionary(g => g.Id, g => new string[] { g.FraGrade.ToLower(), g.FraBoulder.ToLower() }); } } return(oldGrades[oldGradeId][what]); }
public string Generate(int maxRows, string staticFileName = "") { var context = new _8a_oldContext(); IQueryable <_8anu.Data.Migration.Model.Country> oldCountries = context.Set <_8anu.Data.Migration.Model.Country>(); // for countries we always take all // if (maxRows > 0) // { // oldNews = oldNews.Take(maxRows); // } var newCountries = new Dictionary <string, Country>(); var maxCountryId = 0; foreach (var old in oldCountries) { var item = new Country { Id = old.Id, Name = old.Whole, Slug = old.Slug, ISO2 = old.Iso, ISO3 = old.Short }; if (item.Id > maxCountryId) { maxCountryId = item.Id.Value; } newCountries.Add(item.ISO3, item); } var unknown = new Country { Id = ++maxCountryId, Name = "Unknown", Slug = "unknown", ISO2 = "--", ISO3 = "---" }; newCountries.Add(unknown.ISO3, unknown); SeedStore.UnknownCountry = unknown; SeedStore.Countries = newCountries; var json = JsonConvert.SerializeObject(newCountries.Values); return(json); }
public string Generate(int maxRows, string staticFileName = "") { Console.Write(Environment.NewLine); var context = new _8a_oldContext(); newThreads = new Dictionary <int, ForumThread>(); var threadComments = new Dictionary <int, ForumComment>(); // add forum general var oldThreads = context.Set <Model.ForumThreads>().Where(f => f.CountryCode == "GLOBAL" && f.ObjectClass == "CLS_ForumGeneral").ToList(); AddThreads(context, oldThreads, newThreads, threadComments, 1); // add forum dr8a oldThreads = context.Set <Model.ForumThreads>().Where(f => f.ObjectClass == "CLS_ForumDr8a").ToList(); AddThreads(context, oldThreads, newThreads, threadComments, 2); // add country specific forums var countryCategories = SeedStore.ForumCategories.Values.Where(c => c.ParentId == 3).ToList(); foreach (var countryCategory in countryCategories) { var iso3 = SeedStore.Countries.Values.Where(c => c.Slug == countryCategory.Slug).FirstOrDefault().ISO3; oldThreads = context.Set <Model.ForumThreads>().Where(f => f.ObjectClass == "CLS_ForumGeneral" && f.CountryCode == iso3).ToList(); AddThreads(context, oldThreads, newThreads, threadComments, countryCategory.Id.Value); } var newComments = SeedStore.ThreadComments.Concat(threadComments).ToDictionary(x => x.Key, x => x.Value); SeedStore.ThreadComments = newComments; var json = JsonConvert.SerializeObject(newThreads.Values); return(json); }
public string Generate(int maxRows, string staticFileName = "") { var context = new _8a_oldContext(); IQueryable <NewsAll> oldNews = context.Set <NewsAll>() .Where(n => n.Video == 0 && n.Country == "GLOBAL") .OrderByDescending(n => n.Datum); if (maxRows > 0) { oldNews = oldNews.Take(maxRows); } /* * var myNews = new List<NewsAll>(); * if (maxRows > 0) { * myNews = oldNews.Take(maxRows).ToList(); * } * else { * myNews = oldNews.ToList(); * } */ newNews = new List <NewsItem>(); foreach (var old in oldNews) { var item = new NewsItem { Id = (int)old.Id, DateCreated = old.Datum, DateModified = old.Datum, DatePublished = old.Datum, Title = old.Rubrik, Description = old.Text, Slug = old.Slug, LegacyId = (int)old.Id }; newNews.Add(item); } var json = JsonConvert.SerializeObject(newNews); return(json); }
private int GetCountryId(string countryCode) { var retval = -1; if (_oldCountries == null) { var context = new _8a_oldContext(); _oldCountries = context.Set <Model.Country>().ToList(); } var country = _oldCountries.Where(c => c.Short.Equals(countryCode)).FirstOrDefault(); if (country != null) { retval = country.Id; } return(retval); }
private int GetCountryId(string countryCode) { var retval = -1; countryCode = Regex.Replace(countryCode.Trim(), @"\r\n?|\n", ""); if (_oldCountries == null) { var context = new _8a_oldContext(); _oldCountries = context.Set <Model.Country>().ToList(); } var country = _oldCountries.FirstOrDefault(c => c.Short.Equals(countryCode)); if (country != null) { retval = country.Id; } return(retval); }
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(""); }
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 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 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); }