Exemple #1
0
 public HomeController()
 {
     db              = new RankContext();
     matchManager    = new MatchManager(db);
     rankArchManager = new RankArchManager(db);
     cache           = new CacheManager();
 }
Exemple #2
0
        private static int UpdateGuildWeeklyRanking(RankContext context, DateTime?rankingDate = null)
        {
            rankingDate = GetRankingUpdatedDate(rankingDate);

            foreach (var guild in context.Characters.Include(C => C.Guild)
                     .Include(C => C.Ranks)
                     .Where(C => C.IsActivated && C.GuildId != null)
                     .GroupBy(C => C.GuildId))
            {
                var currentWeekRanks = guild.Select(C => new { C.Id, C.Name, Rank = C.Ranks?.FirstOrDefault(R => R.Date.GetValueOrDefault() == rankingDate) })
                                       .Where(CWR => CWR.Rank != null)
                                       .OrderBy(CWR => CWR.Rank.Ranking)
                                       .ToList();

                for (int i = 1; i <= currentWeekRanks.Count; i++)
                {
                    var rank = currentWeekRanks[i - 1];
                    if (context.WeeklyRanks.Any(WR => WR.CharacterId == rank.Id && WR.Date == rankingDate))
                    {
                        continue;
                    }

                    var weeklyRank = new WeeklyRank {
                        CharacterId = rank.Id, GuildId = guild.Key, Ranking = i, Date = rankingDate
                    };
                    context.WeeklyRanks.Add(weeklyRank);
                }
            }

            return(context.SaveChanges());
        }
Exemple #3
0
 public ManageController()
 {
     db             = new RankContext();
     sessionManager = new SessionManager();
     accountManager = new AccountManager(db, sessionManager);
     matchManager   = new MatchManager(db);
 }
Exemple #4
0
        private static Character CreateCharacter(RankContext context, string characterName, Guild guild, string guildPositionDisplay)
        {
            var character     = context.Characters.Include("Guild").Include("Ranks").FirstOrDefault(C => C.Name == characterName);
            var guildPosition = EnumHelper.ParseDisplayToEnum <GuildPositions>(guildPositionDisplay);

            if (character == null)
            {
                character = new Character {
                    Name = characterName, GuildId = guild.Id, GuildPosition = guildPosition
                };
                context.Characters.Add(character);
            }

            if (character.GuildId != guild.Id)
            {
                character.GuildId = guild.Id;
            }

            if (character.GuildPosition != guildPosition)
            {
                character.GuildPosition = guildPosition;
            }

            context.SaveChanges();

            return(character);
        }
Exemple #5
0
        private static Character GetOrCreateCharacter(RankContext context, string characterName, Guid?guildId, string guildPositionDisplay)
        {
            var            character     = context.Characters.FirstOrDefault(C => C.Name == characterName);
            GuildPositions?guildPosition = null;

            if (String.IsNullOrWhiteSpace(guildPositionDisplay) != true)
            {
                guildPosition = EnumHelper.ParseDisplayToEnum <GuildPositions>(guildPositionDisplay);
            }

            if (character == null)
            {
                character = new Character {
                    Name = characterName, GuildId = guildId, GuildPosition = guildPosition
                };
                context.Characters.Add(character);
            }
            else
            {
                if (character.GuildId != guildId)
                {
                    character.GuildId = guildId;
                }
                if (character.GuildPosition != guildPosition)
                {
                    character.GuildPosition = guildPosition;
                }
            }

            context.SaveChanges();

            return(character);
        }
Exemple #6
0
        private static void AddWeeklyRanking(RankContext context, Guild guild, DateTime?rankingDate = null)
        {
            rankingDate = GetRankingUpdatedDate(rankingDate);

            List <Rank> currentWeekRanks = new List <Rank>();

            foreach (var characterId in guild.Characters.Where(C => C.IsActivated).Select(C => C.Id))
            {
                var character = context.Characters.Include("Guild").Include("Ranks")
                                .FirstOrDefault(C => C.Id == characterId);

                var currentWeekRank = character.Ranks.FirstOrDefault(R => R.Date.GetValueOrDefault() == rankingDate);
                if (currentWeekRank != null)
                {
                    currentWeekRanks.Add(currentWeekRank);
                }
            }

            currentWeekRanks = currentWeekRanks.OrderBy(R => R.Ranking).ToList();

            for (int i = 1; i <= currentWeekRanks.Count; i++)
            {
                var rank       = currentWeekRanks[i - 1];
                var weeklyRank = new WeeklyRank {
                    CharacterId = rank.CharacterId, GuildId = guild.Id, Ranking = i, Date = rankingDate
                };
                context.WeeklyRanks.Add(weeklyRank);
                context.SaveChanges();
            }
        }
Exemple #7
0
 public BoardController()
 {
     db             = new RankContext();
     sessionManager = new SessionManager();
     accountManager = new AccountManager(db, sessionManager);
     matchManager   = new MatchManager(db);
     boardManager   = new BoardManager(db);
     cache          = new CacheManager();
 }
        public MemberRankController(RankContext context, IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment,
                                    IConfiguration configuration)
        {
            _context            = context;
            _memoryCache        = memoryCache;
            _hostingEnvironment = hostingEnvironment;

            _defaultSubDomain = configuration.GetValue <string>("DefaultSubDomain");
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static bool IsAnyMatch()
        {
            RankContext db      = new RankContext();
            var         matches = db.Match.ToList();

            if (matches.Count == 0)
            {
                return(false);
            }
            return(true);
        }
Exemple #10
0
        public RankController(RankContext context)
        {
            _context = context;

            if (_context.Ranks.Count() == 0)
            {
                _context.Ranks.Add(new Rank {
                    Name = "White"
                });
                _context.SaveChanges();
            }
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static int MatchNotification()
        {
            RankContext db      = new RankContext();
            string      name    = UserName();
            var         matches = db.Match.Where(m => m.Team1 == name || m.Team2 == name).Where(m => m.IsFinished == false && m.NotAddedBy == name).ToList();

            if (matches == null || matches.Count == 0)
            {
                return(0);
            }
            return(matches.Count);
        }
Exemple #12
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static string KingOfShooters()
        {
            RankContext db   = new RankContext();
            var         king = db.Member.OrderByDescending(k => k.Goals).Take(1).SingleOrDefault();

            if (king != null)
            {
                return(king.MName + "(" + king.Goals + ")");
            }
            else
            {
                return(" ");
            }
        }
Exemple #13
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static bool IsAllAccepted()
        {
            RankContext db      = new RankContext();
            string      name    = UserName();
            var         matches = db.Match.Where(m => m.IsFinished == false && (m.Team1 == name || m.Team2 == name)).ToList();

            foreach (var m in matches)
            {
                if (m.NotAddedBy == name)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #14
0
        private static Guild CreateGuild(RankContext context, string guildName)
        {
            var guild = context.Guilds.Include("Characters").FirstOrDefault(G => G.Name == guildName);

            if (guild == null)
            {
                guild = new Guild {
                    Name = guildName
                };
                context.Guilds.Add(guild);
                context.SaveChanges();
            }

            return(guild);
        }
Exemple #15
0
        private static Rank UpdateRanking(RankContext context, Character member, string ranking, DateTime rankingDate)
        {
            var rank = member.Ranks?.FirstOrDefault(R => R.Date.Value == rankingDate);

            if (rank == null)
            {
                rank = new Rank {
                    CharacterId = member.Id, Ranking = Int32.Parse(ranking), Date = rankingDate
                };
                context.Ranks.Add(rank);
                context.SaveChanges();

                Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Updated the Ranking. Name={member.Name}, Rank={ranking}");
            }

            return(rank);
        }
Exemple #16
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static string[] Leaders()
        {
            RankContext db = new RankContext();

            if (IsAnyMatch())
            {
                var leaders = db.Rank.OrderBy(p => p.Position).Take(3).ToList();

                if (leaders != null && leaders.Count >= 3)
                {
                    string[] ls = new string[3];
                    ls[0] = leaders[0].Uname;
                    ls[1] = leaders[1].Uname;
                    ls[2] = leaders[2].Uname;
                    return(ls);
                }
            }
            return(null);
        }
Exemple #17
0
        private static Guild GetOrCreateGuild(RankContext context, string guildName)
        {
            if (String.IsNullOrWhiteSpace(guildName))
            {
                throw new ArgumentException("The guild name is invalid.", nameof(guildName));
            }

            var guild = context.Guilds.FirstOrDefault(G => G.Name == guildName);

            if (guild == null)
            {
                guild = new Guild {
                    Name = guildName
                };
                context.Guilds.Add(guild);
                context.SaveChanges();
            }

            return(guild);
        }
Exemple #18
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static bool FinishLeagueCheck()
        {
            RankContext db    = new RankContext();
            var         users = db.Users.Where(u => u.IsAdmin == false && u.stat == Status.Registration && u.IsAccept == true).ToList();
            var         date  = db.RoundDate.SingleOrDefault();
            var         rank  = db.Rank.ToList();

            if (DateTime.Now >= date.RoundEndDatetime)
            {
                return(true);
            }
            foreach (var r in rank)
            {
                if (r.Played < users.Count - 1)
                {
                    return(false);
                }
            }
            return(false);
        }
Exemple #19
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static bool IsArchAdded()
        {
            RankContext db    = new RankContext();
            var         archs = db.RankArch.ToList();

            if (db.Match.ToList().Count == 0)
            {
                return(false);
            }

            var matches = db.Match.Min(m => m.Date);

            foreach (var a in archs)
            {
                if (matches == a.From)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #20
0
 private static void UpdateWeeklyRanking(RankContext context, Guild guild, DateTime rankingDate)
 {
     AddWeeklyRanking(context, guild, rankingDate);
 }
Exemple #21
0
 public ProfileController()
 {
     db             = new RankContext();
     sessionManager = new SessionManager();
     accountManager = new AccountManager(db, sessionManager);
 }
 public CharactersController(RankContext context)
 {
     _context = context;
 }
Exemple #23
0
 public BoardManager(RankContext db)
 {
     this.db = db;
 }
Exemple #24
0
 public MatchesController(RankContext context)
 {
     _context = context;
 }
Exemple #25
0
 public RankArchManager(RankContext db)
 {
     this.db = db;
 }
Exemple #26
0
 public MatchController()
 {
     db           = new RankContext();
     matchManager = new MatchManager(db);
 }
Exemple #27
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Need a Guild Member file that type is csv.");
                Console.Read();
                return;
            }

            // Validate a Guild Member file
            var guildMemberFilePath = args[0];
            var guildMemberFileInfo = new FileInfo(guildMemberFilePath);

            if (!guildMemberFileInfo.Exists || !guildMemberFileInfo.Extension.Equals(".csv", StringComparison.CurrentCultureIgnoreCase))
            {
                Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Invalid a Guild Member file");
                Console.Read();
                return;
            }

            // Initialize a DB
            var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            var options          = SqlServerDbContextOptionsExtensions.UseSqlServer(new DbContextOptionsBuilder <RankContext>(), connectionString).Options;

            using (var context = new RankContext(options))
            {
                DbInitializer.Initialize(context);
                var guildName = guildMemberFileInfo.Name.Replace(guildMemberFileInfo.Extension, "");
                var guild     = CreateGuild(context, guildName);

#if UPDATE_WEEKLY_RANKING
                UpdateWeeklyRanking(context, guild, new DateTime(2018, 8, 10));
#else
                // Read a Guild Member file
                using (var sr = guildMemberFileInfo.OpenText())
                {
                    var membersInfo = sr.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var memberInfo in membersInfo)
                    {
                        var splitedMemberInfo = memberInfo.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        if (splitedMemberInfo.Length != 2)
                        {
                            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Invalid a Member Info");
                            continue;
                        }

                        // Gets or Create the Guild and Member to Database
                        var guildPosition = splitedMemberInfo[0];
                        var characterName = splitedMemberInfo[1];
                        var member        = CreateCharacter(context, characterName, guild, guildPosition);

                        // Get a Ranking of Character vis web parsing
                        var ranking = GetCharacterRanking(member.Name, UsedEncoding);
                        if (String.IsNullOrWhiteSpace(ranking))
                        {
                            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Cannot found a ranking of Member '{member.Name}'");
                            continue;
                        }

                        var rankingDate = GetRankingUpdatedDate();

                        // Update
                        UpdateRanking(context, member, ranking, rankingDate);
                    }
                }

                // Add Weekly Ranking
                AddWeeklyRanking(context, guild);
#endif
            }

            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Finish a getting the ranking of memeber!");
            Console.ReadLine();
        }
Exemple #28
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Need a Character list file that type is csv.");
                Console.Read();
                return;
            }

            // Validate a Character List file
            var characterListFilePath = args[0];
            var characterListFileInfo = new FileInfo(characterListFilePath);

            if (!characterListFileInfo.Exists || !characterListFileInfo.Extension.Equals(".csv", StringComparison.CurrentCultureIgnoreCase))
            {
                Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Invalid a Character List file");
                Console.Read();
                return;
            }

            var             rankingDate    = GetRankingUpdatedDate();
            IRankingCrawler rankingCrawler = new RankingCrawlerV2();

            // Initialize a DB
            var connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            var options          = SqlServerDbContextOptionsExtensions.UseSqlServer(new DbContextOptionsBuilder <RankContext>(), connectionString).Options;

            using (var context = new RankContext(options))
            {
                DbInitializer.Initialize(context);

                // Read a Character List file
                using (var sr = characterListFileInfo.OpenText())
                {
                    var characterInfos = sr.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var characterInfo in characterInfos)
                    {
                        var splitedCharacterInfos = characterInfo.Split(',');
                        if (splitedCharacterInfos.Length < 3)
                        {
                            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Invalid a Character Info. Input = [{splitedCharacterInfos}]");
                            continue;
                        }

                        var guildName     = splitedCharacterInfos[0];
                        var guildPosition = splitedCharacterInfos[1];
                        var characterName = splitedCharacterInfos[2];

                        // Gets or Create a Guild to Database
                        Guild guild = null;
                        if (String.IsNullOrWhiteSpace(guildName) != true)
                        {
                            guild = GetOrCreateGuild(context, guildName);
                        }

                        // Gets or Create a Character to Database
                        var character = GetOrCreateCharacter(context, characterName, guild?.Id, guildPosition);

                        // Get a Ranking of Character vis web parsing
                        var ranking = rankingCrawler.GetCharacterRanking(character.Name);
                        if (String.IsNullOrWhiteSpace(ranking))
                        {
                            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Cannot found a ranking of Member '{character.Name}'");
                            continue;
                        }



                        // Update Character Ranking
                        UpdateCharacterRanking(context, character, ranking, rankingDate);
                    }

                    // Update Guild Weekly Ranking
                    UpdateGuildWeeklyRanking(context, rankingDate);
                }
            }

            Console.WriteLine($"[{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")}] Finish a getting the ranking of character list!");
            Console.ReadLine();
        }
Exemple #29
0
 public RanksController(RankContext context, IMemoryCache memoryCache)
 {
     _context        = context;
     _memoryCache    = memoryCache;
     _rankingCrawler = new RankingCrawlerV2();
 }
Exemple #30
0
 public MatchManager(RankContext db)
 {
     this.db      = db;
     boardManager = new BoardManager(db);
 }