private bool CheckLastUpdateWithCurrent(ExportMethodEnum ExportMethod) { using (HttpClient client = new HttpClient()) { string url = SWGoH.MongoDBRepo.BuildApiUrl("Guild", "&q={\"Name\":\"" + Name + "\"}", "&s={\"LastSwGohUpdated\":-1}", "&l=1", "&f={\"LastSwGohUpdated\": 1}"); string response = client.GetStringAsync(url).Result; if (response != "" && response != "[ ]") { List <GuildDto> result = JsonConvert.DeserializeObject <List <GuildDto> >(response); if (result.Count == 1) { GuildDto Found = result[0]; if (LastSwGohUpdated.CompareTo(Found.LastSwGohUpdated) == 0) { SWGoH.Log.ConsoleMessage("No need to update!!!!"); return(false); } return(true); } else { return(true); } } } return(true); }
private bool CheckLastUpdateWithCurrent(ExportMethodEnum ExportMethod) { using (HttpClient client = new HttpClient()) { var queryData = string.Concat("q={\"Name\":\"", Name, "\"}"); var orderby = "s={\"LastSwGohUpdated\":-1}"; var limit = "l=1"; string apikey = "JmQkm6eGcaYwn_EqePgpNm57-0LcgA0O"; string url = string.Format("https://api.mlab.com/api/1/databases/triplezero/collections/Guild/?{0}&{1}&{2}&apiKey={3}", queryData, orderby, limit, apikey); string response = client.GetStringAsync(url).Result; if (response != "") { List <GuildDto> result = JsonConvert.DeserializeObject <List <GuildDto> >(response); if (result.Count == 1) { GuildDto Found = result[0]; if (LastSwGohUpdated.CompareTo(Found.LastSwGohUpdated) == 0) { ConsoleMessage("No need to update!!!!"); return(false); } return(true); } else { return(true); } } } return(true); }
public void UpdateOnlyGuildWithNoChars(ExportMethodEnum ExportMethod) { int count = 0; if (CheckLastUpdateWithCurrent(ExportMethodEnum.Database)) { for (int i = 0; i < PlayerNames.Count; i++) { count++; SWGoH.PlayerDto player = new PlayerDto(PlayerNames[i]); int ret = player.ParseSwGoh(ExportMethod, false, false); if (ret == 1) { if (Players == null) { Players = new List <PlayerDto>(); } player.LastClassUpdated = null; Players.Add(player); SWGoH.Log.ConsoleMessage("Added Player : " + player.PlayerName + " aka " + player.PlayerNameInGame); } else if (ret == 0) { Thread.Sleep(Settings.appSettings.DelayErrorPerPlayerAtGuildSearch); i--; } else { if (Players == null) { Players = new List <PlayerDto>(); } Players.Add(player); } } Export(ExportMethod, false); } }
public void UpdateAllPlayers(ExportMethodEnum ExportMethod, bool AddCharacters) { int count = 0; for (int i = 0; i < PlayerNames.Count; i++) { count++; SWGoH.PlayerDto player = new PlayerDto(PlayerNames[i]); int ret = player.ParseSwGoh(ExportMethod, AddCharacters, false); if (ret == 1) { player.LastClassUpdated = DateTime.UtcNow; player.Export(ExportMethod); if (Players == null) { Players = new List <PlayerDto>(); } Players.Add(player); Thread.Sleep(Settings.appSettings.DelayPerPlayerAtGuildSearch); } else if (ret == 0) { Thread.Sleep(Settings.appSettings.DelayErrorPerPlayerAtGuildSearch); i--; } else { if (Players == null) { Players = new List <PlayerDto>(); } Players.Add(player); } } Export(ExportMethod, false); }
static void Main(string[] args) { //string pname = "41st"; //Command command = Command.UpdateGuild; SwGoh.CharactersConfig.ExportCharacterFilesToDB(); ExportMethodEnum mExportMethod = ExportMethodEnum.Database; string pname = "newholborn"; Command command = Command.UpdatePlayer; if (args.Length > 0) { string commandstr = args[0]; if (args.Length > 2 && commandstr == "ups") { command = Command.UpdatePlayers; } else if (commandstr == "up") { command = Command.UpdatePlayer; } else if (commandstr == "ug") { command = Command.UpdateGuild; } else if (commandstr == "ugnochars") { command = Command.UpdateGuildWithNoChars; } else if (commandstr == "help") { command = Command.Help; } else if (commandstr == "test") { command = Command.Test; } else { command = Command.UnKnown; } if (args.Length > 1) { pname = args[1]; } } switch (command) { case Command.UpdatePlayer: { SwGoh.PlayerDto player = new PlayerDto(pname); int ret = player.ParseSwGoh(mExportMethod, true); if (ret == 1) { player.Export(mExportMethod); } break; } case Command.UpdateGuild: { SwGoh.GuildDto guild = new GuildDto(); guild.Name = guild.GetGuildNameFromAlias(pname); guild.ParseSwGoh(); if (guild.PlayerNames != null && guild.PlayerNames.Count > 0) { guild.UpdateAllPlayers(mExportMethod, true); } break; } case Command.UpdatePlayers: { for (int i = 1; i < args.Length; i++) { SwGoh.PlayerDto player = new PlayerDto(args[i]); int ret = player.ParseSwGoh(mExportMethod, true); if (ret == 1) { player.Export(mExportMethod); } } break; } case Command.UpdateGuildWithNoChars: { SwGoh.GuildDto guild = new GuildDto(); guild.Name = guild.GetGuildNameFromAlias(pname); guild.ParseSwGoh(); if (guild.PlayerNames != null && guild.PlayerNames.Count > 0) { guild.UpdateOnlyGuildWithNoChars(mExportMethod); } 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(); break; } default: { Console.WriteLine("Unknown command , please try again.!!!!"); break; } } Console.WriteLine(""); Console.WriteLine("Press Enter to close!!!!"); Console.Read(); }
public void Export(ExportMethodEnum ExportMethod, bool FullUpdateClass) { if (ExportMethod == ExportMethodEnum.File) { try { LastClassUpdated = DateTime.UtcNow; string directory = AppDomain.CurrentDomain.BaseDirectory + "PlayerJsons"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Ignore; serializer.Formatting = Formatting.Indented; string fname = directory + "\\" + Name + @".json"; using (StreamWriter sw = new StreamWriter(fname)) using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, this); } } catch { //Error Occured , Contact Developer } } else if (ExportMethod == ExportMethodEnum.Database) { using (HttpClient client = new HttpClient()) { SWGoH.Log.ConsoleMessage("Exporting To Database guild : " + this.Name); LastClassUpdated = DateTime.UtcNow; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; if (!FullUpdateClass) { foreach (PlayerDto item in Players) { item.Characters = null; } } string json = JsonConvert.SerializeObject(this, settings); if (!FullUpdateClass) { client.BaseAddress = new Uri(SWGoH.MongoDBRepo.BuildApiUrl("Guild", "", "", "", "")); HttpResponseMessage response = client.PostAsync("", new StringContent(json.ToString(), Encoding.UTF8, "application/json")).Result; if (response.IsSuccessStatusCode) { SWGoH.Log.ConsoleMessage("Exported To Database guild : " + this.Name); } else { SWGoH.Log.ConsoleMessage("Error Exporting to Database guild : " + this.Name); } } else { // NOT IMPLMEMENTED } } } }
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()); }
public void Export(ExportMethodEnum ExportMethod, bool FullUpdateClass) { if (ExportMethod == ExportMethodEnum.File) { try { LastClassUpdated = DateTime.UtcNow; string directory = AppDomain.CurrentDomain.BaseDirectory + "PlayerJsons"; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } JsonSerializer serializer = new JsonSerializer(); serializer.NullValueHandling = NullValueHandling.Ignore; serializer.Formatting = Formatting.Indented; string fname = directory + "\\" + Name + @".json"; using (StreamWriter sw = new StreamWriter(fname)) using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, this); } } catch { //Error Occured , Contact Developer } } else if (ExportMethod == ExportMethodEnum.Database) { using (HttpClient client = new HttpClient()) { ConsoleMessage("Exporting To Database guild : " + this.Name); LastClassUpdated = DateTime.UtcNow; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; if (!FullUpdateClass) { this.PlayerNames = null; foreach (PlayerDto item in Players) { item.Characters = null; } } string json = JsonConvert.SerializeObject(this, settings); if (!FullUpdateClass) { client.BaseAddress = new Uri("https://api.mlab.com/api/1/databases/triplezero/collections/Guild?apiKey=JmQkm6eGcaYwn_EqePgpNm57-0LcgA0O"); } else { // NOT IMPLMEMENTED client.BaseAddress = new Uri("https://api.mlab.com/api/1/databases/triplezero/collections/GuildWithCharacters?apiKey=JmQkm6eGcaYwn_EqePgpNm57-0LcgA0O"); } HttpResponseMessage response = client.PostAsync("", new StringContent(json.ToString(), Encoding.UTF8, "application/json")).Result; if (response.IsSuccessStatusCode) { ConsoleMessage("Exported To Database guild : " + this.Name); } else { ConsoleMessage("Error Exporting to Database guild : " + this.Name); } } } }