コード例 #1
0
 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);
 }
コード例 #2
0
        public static void UpdateQueueAndProcessLater(QueueDto q, object whotoupdate, double hours, bool fromnow)
        {
            PlayerDto player = whotoupdate as PlayerDto;

            SWGoH.GuildDto guild = whotoupdate as GuildDto;
            try
            {
                string nextrun = "";
                if (player != null)
                {
                    nextrun = player.LastSwGohUpdated.AddHours(hours).ToString("o");
                }
                else if (guild != null)
                {
                    nextrun = guild.LastSwGohUpdated.AddHours(hours).ToString("o");
                }
                else
                {
                    nextrun = DateTime.UtcNow.AddHours(hours).ToString("o");
                }

                if (fromnow)
                {
                    nextrun = DateTime.UtcNow.AddHours(hours).ToString("o");
                }

                JObject data = new JObject(
                    new JProperty("Name", q.Name),
                    new JProperty("InsertedDate", DateTime.UtcNow.ToString("o")),
                    new JProperty("ProcessingStartDate", ""),
                    new JProperty("NextRunDate", nextrun),
                    new JProperty("Status", SWGoH.Enums.QueueEnum.QueueStatus.PendingProcess),
                    new JProperty("Priority", q.Priority),
                    new JProperty("Type", q.Type),
                    new JProperty("Command", q.Command),
                    new JProperty("ComputerName", ""));

                var httpContent = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
                var requestUri  = SWGoH.MongoDBRepo.BuildApiUrlFromId("Queue", q.Id.ToString());
                using (HttpClient client1 = new HttpClient())
                {
                    HttpResponseMessage updateresult = client1.PutAsync(requestUri, httpContent).Result;
                }
                SWGoH.Log.ConsoleMessage(q.Name + " Added To Queu to be processed later :");
            }
            catch (Exception e)
            {
                SWGoH.Log.ConsoleMessage("Error updating Queu to be processed later :" + e.Message);
            }
        }
コード例 #3
0
        public static PlayerDto GetLastUpdatedPlayer(string guildname)
        {
            SWGoH.Log.ConsoleMessageNotInFile("Getting LastUpdated From Queu!!");
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var    queryData = string.Concat("&q={\"GuildName\" : \"" + GuildDto.GetGuildNameFromAlias(guildname) + "\" }");
                    var    field     = "f={\"PlayerName\": 1,\"LastSwGohUpdated\": 1, \"LastClassUpdated\" : 1 }";
                    string url       = SWGoH.MongoDBRepo.BuildApiUrl("Player", queryData, "&s={\"LastSwGohUpdated\":1}", "", field);

                    string response = client.GetStringAsync(url).Result;
                    if (response != "" && response != "[  ]")
                    {
                        List <PlayerDto> result = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PlayerDto> >(response);
                        if (result.Count > 0)
                        {
                            foreach (PlayerDto item in result)
                            {
                                DateTime lastc = item.LastClassUpdated.Value;
                                if (DateTime.UtcNow.Subtract(lastc).TotalHours < Settings.appSettings.HoursForNextCheckLastswGohUpdate)
                                {
                                    continue;
                                }
                                bool check = CheckStatusForPlayer(item.PlayerName);
                                if (check)
                                {
                                    continue;
                                }
                                return(item);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SWGoH.Log.ConsoleMessage("Error getting LastUpdatedPlayerToQueu!! : " + e.Message);
                return(null);
            }
            return(null);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: gittsi/TripleZeroOLD
        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());
        }