private static bool Handler(CtrlType sig) { switch (sig) { case CtrlType.CTRL_C_EVENT: case CtrlType.CTRL_LOGOFF_EVENT: case CtrlType.CTRL_SHUTDOWN_EVENT: case CtrlType.CTRL_CLOSE_EVENT: { PlayerDto.isOnExit = true; isWorking = true; SWGoH.MongoDBRepo.SetWorking(false); if (workingQ != null) { QueueMethods.UpdateQueueAndProcessLater(workingQ, null, 0.5, true); } Thread.Sleep(5000); return(false); } default: return(false); } }
private static int ExecuteCommand(Command commandstr, string pname, QueueDto q) { ExportMethodEnum mExportMethod = ExportMethodEnum.Database; switch (commandstr) { case Command.UpdatePlayer: { SWGoH.PlayerDto player = new PlayerDto(pname); int ret = player.ParseSwGoh(mExportMethod, true, false); if (SWGoH.PlayerDto.isOnExit) { return(-1); } if (ret == 0 || (q != null && q.Priority == PriorityEnum.ManualLoad)) { player.LastClassUpdated = DateTime.UtcNow; player.Export(mExportMethod); player.DeletePlayerFromDBAsync(); if (q != null) { QueueMethods.RemoveFromQueu(q); } } else if (ret == 1 || ret == 2) { player.LastClassUpdated = DateTime.UtcNow; if (ret == 1) { player.Export(mExportMethod); player.DeletePlayerFromDBAsync(); if (q != null) { QueueMethods.UpdateQueueAndProcessLater(q, player, 24.2, false); } } else if (ret == 2) { if (q != null) { QueueMethods.UpdateQueueAndProcessLater(q, player, 0.5, true); } } } return(ret); } case Command.UpdateUnknownGuild: { string command = pname; string[] opponent = command.Split("#@#"); if (opponent.Length > 0) { try { string guildRealName = opponent[0]; string IDstr = opponent[1]; string guildname = opponent[2]; int guildID = int.Parse(IDstr); string guildURL = "/" + IDstr + "/" + guildname + "/"; bool ret = SWGoH.GuildConfigDto.AddGuildToConfig(guildname, guildID, guildURL, guildRealName); if (ret) { ExecuteCommand(Command.UpdateGuild, guildRealName, null); } } catch (Exception e) { SWGoH.Log.ConsoleMessage(pname + " ERROR : " + e.Message); } } break; } case Command.UpdateGuild: { SWGoH.GuildDto guild = new GuildDto(); guild.Name = GuildDto.GetGuildNameFromAlias(pname); guild.ParseSwGoh(); if (guild.PlayerNames != null && guild.PlayerNames.Count > 0) { QueueMethods.AddPlayer(pname, Command.UpdateGuildWithNoChars, PriorityEnum.ManualLoad, QueueType.Guild, DateTime.UtcNow); } for (int i = 0; i < guild.PlayerNames.Count; i++) { QueueMethods.AddPlayer(guild.PlayerNames[i], Command.UpdatePlayer, PriorityEnum.ManualLoad, QueueType.Player, DateTime.UtcNow.AddSeconds((double)i)); } if (q != null) { QueueMethods.RemoveFromQueu(q); } break; } case Command.UpdatePlayers: { string[] arg = pname.Split(','); for (int i = 0; i < arg.Length; i++) { ExecuteCommand(Command.UpdatePlayer, arg[i], null); } break; } case Command.UpdateGuildWithNoChars: { SWGoH.GuildDto guild = new GuildDto { Name = GuildDto.GetGuildNameFromAlias(pname) }; guild.ParseSwGoh(); if (guild.PlayerNames != null && guild.PlayerNames.Count > 0) { guild.UpdateOnlyGuildWithNoChars(mExportMethod); guild.CheckForNewPlayers(); if (q != null && q.Priority == PriorityEnum.ManualLoad) { QueueMethods.RemoveFromQueu(q); } else { if (q != null) { QueueMethods.UpdateQueueAndProcessLater(q, guild, 24.1, false); } } } break; } case Command.GetNewCharacters: { SWGoH.PlayerDto player = new PlayerDto(pname); int ret = player.ParseSwGoh(mExportMethod, true, true); if (q != null) { QueueMethods.RemoveFromQueu(q); } break; } case Command.Help: { Console.WriteLine("Command Update Player"); Console.WriteLine("Usage : <app> up <playername>"); Console.WriteLine("Update only one player with his characters."); Console.WriteLine(""); Console.WriteLine("Command Update Players"); Console.WriteLine("Usage : <app> ups <playername1> <playername2> <playername3>"); Console.WriteLine("Update provided players with their characters."); Console.WriteLine(""); Console.WriteLine("Command Update Guild"); Console.WriteLine("Usage : <app> ug <guildname>"); Console.WriteLine("Update all players with their characters and at the end update the guild file."); Console.WriteLine(""); Console.WriteLine("Command Update Guild without the characters of the players"); Console.WriteLine("Usage : <app> ugnochars <guildname>"); Console.WriteLine("Update the guild file."); Console.WriteLine(""); Console.WriteLine("Command Help"); Console.WriteLine("Usage : <app> help"); Console.WriteLine("You already know this command!!!!!"); break; } case Command.Test: { //SwGoh.CharactersConfig.ExportCharacterFilesToDB(); //SWGoH.GuildDto guild = new GuildDto(); //guild.Name = GuildDto.GetGuildNameFromAlias("41st"); //guild.ParseSwGoh(); //for (int i = 0; i < guild.PlayerNames.Count; i++) //{ // QueueMethods.AddPlayer(guild.PlayerNames[i], Command.UpdatePlayer, PriorityEnum.DailyUpdate, QueueType.Player,DateTime.UtcNow ); //} //QueueMethods.AddPlayer("41st", Command.UpdateGuildWithNoChars, PriorityEnum.DailyUpdate, QueueType.Guild, DateTime.UtcNow); //QueueMethods.AddPlayer("newholborn", "up",3); //QueueMethods.AddPlayer("oaraug", "up", 3); //QueueMethods.AddPlayer("tsitas_66", "up",1); //QueueMethods.AddPlayer("tsitas_66", "up", 3); //QueueMethods.AddPlayer("41st", "ugnochars", 3); //for (int i = 0; i < 10; i++) //{ // QueueMethods.AddPlayer("tsitas_66", "up"); //} break; } case Command.TestZetas: { SWGoH.PlayerDto.TestZetas(); break; } default: { SWGoH.Log.ConsoleMessage("Unknown command , please try again.!!!!"); break; } } return(commandstr.GetHashCode()); }