Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        private void cleanSectors()
        {
            Console.WriteLine("***************************");
            Console.WriteLine("*** clean sectors table ***");
            Console.WriteLine("***************************");
            var changedList = new List <CragSectors>();

            using (var context = new _8a_oldContext())
            {
                foreach (CragSectors sector in context.CragSectors)
                {
                    var changed = false;
                    sector.Name = unidecode(sector.Name, out changed);

                    if (changed)
                    {
                        changedList.Add(sector);
                    }
                }

                if (changedList.Any())
                {
                    context.CragSectors.UpdateRange(changedList);
                    context.SaveChanges();
                    Console.WriteLine("we saved now " + changedList.Count().ToString() + " sectors...");
                }
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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]);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public void DoSomething()
        {
            Console.WriteLine("****************************************");
            Console.WriteLine("*** analyze wrongly inserted ascents ***");
            Console.WriteLine("****************************************");

            var wrongList = new List <Score>();

            using (var context = new _8a_oldContext())
            {
                // first we take all crags and scores to a hashtable
                var crags = context.Crag.ToDictionary(k => k.Name + "_" + k.CountryId + "_" + k.Type.ToString(), v => v);
                // var sectors = context.CragSectors.ToDictionary(k => k.Id, v => v);

                var totalNotFoundWithRightType = 0;
                var totalFoundWithOtherKey     = 0;
                var totalNotFoundAtAll         = 0;
                foreach (Score score in context.Score)
                {
                    var cragKey = score.Crag + "_" + score.Country + "_" + score.What.ToString();

                    // find our crag
                    if (!crags.ContainsKey(cragKey))
                    {
                        Console.WriteLine("no crag found with matching ascent type:" + cragKey);
                        totalNotFoundWithRightType++;

                        cragKey = score.Crag + "_" + score.Country + "_" + (score.What == 0 ? 1 : 0).ToString();

                        if (!crags.ContainsKey(cragKey))
                        {
                            Console.WriteLine("no crag found with OPPOSITE ascent type: " + cragKey);
                            totalNotFoundAtAll++;
                        }
                        else
                        {
                            totalFoundWithOtherKey++;
                        }
                    }

                    // if found let's get the crag
                    // var crag = crags.ContainsKey(cragKey);
                }

                Console.WriteLine("not found with right type: " + totalNotFoundWithRightType);
                Console.WriteLine("FOUND with WRONG type: " + totalFoundWithOtherKey);
                Console.WriteLine("not found at all: " + totalNotFoundAtAll);
            }
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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("");
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 public Sectors()
 {
     context = new _8a_oldContext();
 }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        private void cleanScores()
        {
            Console.WriteLine("*************************");
            Console.WriteLine("*** clean score table ***");
            Console.WriteLine("*************************");

            var countries = new string[]
            {
                "Canada", "Portugal", "España", "Italy", "France", "United Kingdom", "Russia", "Australia",
                "Spain", "Brazil", "United States", "Slovenia", "Ukraine", "Switzerland", "Malaysia",
                "Australia", "Serbia [(]Yugoslavia[)]", "South Africa", "Germany", "Mexico", "Macedonia [(]Republic of[)]",
                "Greece", "Austria", "Croatia", "Argentina", "Poland", "Laos", "Turkey", "India", "Japan",
                "Bulgaria", "China", "Hungary", "Thailand", "Malta", "United kingdom,", "New Zealand",
                "Czech Republic", "Philippines", "Cuba", "Colombia", "Norway", "Montenegro", "Romania",
                "Macedonia", "Sweden", "Luxembourg"
            };

            var   ptrn            = string.Format(" ({0}) (Rout?e?s?|Bould?e?r?s?)( [(].*)?$", string.Join("|", countries));
            Regex countryBugRegex = new Regex(ptrn, RegexOptions.Compiled);

            var changedList = new List <Score>();

            using (var context = new _8a_oldContext())
            {
                foreach (Score score in context.Score)
                {
                    var changed = false;
                    score.Name       = unidecode(score.Name, out changed);
                    score.Crag       = unidecode(score.Crag, out changed);
                    score.CragSector = unidecode(score.CragSector, out changed);
                    score.Comment    = unidecode(score.Comment, out changed);

                    var old = score.Crag;
                    score.Crag = countryBugRegex.Replace(score.Crag, "");
                    if (!old.Equals(score.Crag))
                    {
                        changed = true;
                        Console.WriteLine(old + " ---> " + score.Crag);
                    }

                    if (changed)
                    {
                        changedList.Add(score);
                    }
                }

                if (changedList.Any())
                {
                    context.Score.UpdateRange(changedList);
                    context.SaveChanges();
                    Console.WriteLine("we saved now " + changedList.Count().ToString() + " scores...");
                }
            }

            /*
             * using (var context = new _8a_oldContext())
             * {
             *  var scores = context.Score.Where(s => reg.IsMatch(s.Crag)).ToList();
             *
             *  foreach (var score in scores)
             *  {
             *      var old = score.Crag;
             *      score.Crag = reg.Replace(score.Crag, "");
             *      Console.WriteLine(old + " ---> " + score.Crag);
             *  }
             *  context.Score.UpdateRange(scores);
             *  context.SaveChanges();
             *  Console.WriteLine(scores.Count().ToString() + " scores done");
             * }
             */
        }
Exemplo n.º 16
0
        private void cleanCrags()
        {
            Console.WriteLine("*************************");
            Console.WriteLine("*** clean crags table ***");
            Console.WriteLine("*************************");
            var changedList = new List <Crag>();

            using (var context = new _8a_oldContext())
            {
                var firstZimny = false;
                foreach (Crag crag in context.Crag)
                {
                    var changed   = false;
                    var firstRzed = false;
                    crag.Name = unidecode(crag.Name, out changed);
                    if (changed)
                    {
                        if (crag.Name == "Ciężkowice"

                            || crag.Name == "Kamień Leski" ||
                            crag.Name == "Borzęta" ||
                            crag.Name == "Skarżyce" ||
                            crag.Name == "Čreta" ||
                            crag.Name == "La Guairita" ||
                            crag.Name == "Kusięta" ||
                            crag.Name == "Żurowa" ||
                            crag.Name == "Szklarska poręba" ||
                            crag.Name == "Rożnów" ||
                            crag.Name == "Wąwóz Ostryszni" ||
                            crag.Name == "Céüse" ||
                            crag.Name == "Rzêdkowice" ||
                            crag.Name == "Wieżyca" ||
                            crag.Name == "Smoleń" ||
                            crag.Name == "Dolina Będkowska" ||
                            crag.Name == "Csókakő"

                            )
                        {
                            crag.Name = crag.Name + " - copy";
                        }
                        else if (crag.Name == "Zimny Dół")
                        {
                            //crag.Name = crag.Name + " - 3";
                            var zimnyid = firstZimny ? 2 : 3;
                            crag.Name  = crag.Name + " - " + zimnyid.ToString() + "copy";
                            firstZimny = true;
                        }
                        else if (crag.Name == "Rzędkowice")
                        {
                            //crag.Name = crag.Name + " - 3";
                            var id = firstRzed ? 2 : 3;
                            crag.Name = crag.Name + " - " + id.ToString() + "copy";
                            firstRzed = true;
                        }
                    }

                    crag.City = unidecode(crag.City, out changed);

                    if (changed)
                    {
                        changedList.Add(crag);
                    }
                }

                if (changedList.Any())
                {
                    context.Crag.UpdateRange(changedList);
                    context.SaveChanges();
                    Console.WriteLine("we saved now " + changedList.Count().ToString() + " crags...");
                }
            }
        }