示例#1
0
        internal static bool FindPlayer(string playername)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var    queryData = string.Concat("&q={\"Name\":\"", playername, "\"}");
                    string url       = SWGoH.MongoDBRepo.BuildApiUrl("Queue", queryData, "", "", "");

                    string response = client.GetStringAsync(url).Result;
                    if (response != "" && response != "[  ]")
                    {
                        List <BsonDocument> document = BsonSerializer.Deserialize <List <BsonDocument> >(response);
                        QueueDto            result1  = BsonSerializer.Deserialize <QueueDto>(document.FirstOrDefault());
                        if (result1 != null)
                        {
                            return(true);
                        }
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                SWGoH.Log.ConsoleMessage("Error getting from Queu!!" + e.Message);
                return(false);
            }
            return(false);
        }
示例#2
0
        public static void RemoveFromQueu(QueueDto q)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    var        deleteurl = SWGoH.MongoDBRepo.BuildApiUrlFromId("Queue", q.Id.ToString());
                    WebRequest request   = WebRequest.Create(deleteurl);
                    request.Method = "DELETE";

                    HttpWebResponse response1 = (HttpWebResponse)request.GetResponse();
                    if (response1.StatusCode == HttpStatusCode.OK)
                    {
                        SWGoH.Log.ConsoleMessage("Removed From Queu!");
                    }
                    else
                    {
                        SWGoH.Log.ConsoleMessage("Could not remove from Queu!");
                    }
                }
            }
            catch (Exception e)
            {
                SWGoH.Log.ConsoleMessage("Error Deleting From Queu:" + e.Message);
            }
        }
示例#3
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);
            }
        }
示例#4
0
        public static void AddPlayer(string PlayerName, Command cmd, PriorityEnum priority, SWGoH.Enums.QueueEnum.QueueType type, DateTime nextrundate)
        {
            try
            {
                MongoDBRepo    mongo = new MongoDBRepo();
                IMongoDatabase db    = mongo.Connect();
                if (db != null)
                {
                    IMongoCollection <QueueDto> collection = db.GetCollection <QueueDto>("Queue");
                    if (collection != null)
                    {
                        FilterDefinition <QueueDto> filter = Builders <QueueDto> .Filter.Eq("Name", PlayerName);

                        UpdateDefinition <QueueDto> update = Builders <QueueDto> .Update.Set("Name", PlayerName)
                                                             .Set("InsertedDate", DateTime.UtcNow.ToString("o"))
                                                             .Set("ProcessingStartDate", "")
                                                             .Set("NextRunDate", nextrundate.ToString("o"))
                                                             .Set("Status", SWGoH.Enums.QueueEnum.QueueStatus.PendingProcess)
                                                             .Set("Priority", priority)
                                                             .Set("Type", type)
                                                             .Set("Command", cmd)
                                                             .Set("ComputerName", "");

                        var opts = new FindOneAndUpdateOptions <QueueDto>()
                        {
                            IsUpsert       = true,
                            ReturnDocument = ReturnDocument.After,
                            Sort           = Builders <QueueDto> .Sort.Descending(r => r.Priority).Ascending(r => r.NextRunDate)
                        };
                        QueueDto found = collection.FindOneAndUpdate <QueueDto>(filter, update, opts);
                        if (found != null)
                        {
                            SWGoH.Log.ConsoleMessage("Added Player To Queu:" + PlayerName);
                        }
                    }
                }
                else
                {
                    using (HttpClient client = new HttpClient())
                    {
                        JObject data = new JObject(
                            new JProperty("Name", PlayerName),
                            new JProperty("InsertedDate", DateTime.UtcNow.ToString("o")),
                            new JProperty("ProcessingStartDate", ""),
                            new JProperty("NextRunDate", nextrundate.ToString("o")),
                            new JProperty("Status", SWGoH.Enums.QueueEnum.QueueStatus.PendingProcess),
                            new JProperty("Priority", priority),
                            new JProperty("Type", type),
                            new JProperty("Command", cmd),
                            new JProperty("ComputerName", ""));

                        var httpContent = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
                        var requestUri  = string.Format(SWGoH.MongoDBRepo.BuildApiUrl("Queue", "", "", "", ""));
                        HttpResponseMessage response = client.PostAsync(requestUri, httpContent).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            SWGoH.Log.ConsoleMessage("Added Player To Queu:" + PlayerName);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SWGoH.Log.ConsoleMessage("Error Adding Player To Queu:" + e.Message);
            }
        }
示例#5
0
        public static QueueDto GetQueu()
        {
            bool onlymanual = SWGoH.Settings.appSettings.UpdateOnlyManual;

            try
            {
                MongoDBRepo    mongo = new MongoDBRepo();
                IMongoDatabase db    = mongo.Connect();
                if (db != null)
                {
                    SWGoH.Log.ConsoleMessageNotInFile("Getting from Queu!! (mongo)");
                    IMongoCollection <QueueDto> collection = db.GetCollection <QueueDto>("Queue");
                    if (collection != null)
                    {
                        //FilterDefinition<QueueDto> filter2 = Builders<QueueDto>.Filter.Eq("Priority", 2);
                        //UpdateDefinition<QueueDto> update2 = Builders<QueueDto>.Update.Set("Priority", 1);
                        //UpdateOptions opts2 = new UpdateOptions();
                        //opts2.IsUpsert = false;
                        //DeleteResult res2 = collection.DeleteMany(filter2);

                        FilterDefinition <QueueDto> filter = Builders <QueueDto> .Filter.Eq("Status", 0);

                        UpdateDefinition <QueueDto> update = Builders <QueueDto> .Update.Set("Status", 1).Set("ProcessingStartDate", DateTime.UtcNow.ToString("o")).Set("ComputerName", SWGoH.Settings.appSettings.ComputerName);

                        var opts = new FindOneAndUpdateOptions <QueueDto>()
                        {
                            IsUpsert       = false,
                            ReturnDocument = ReturnDocument.After,
                            Sort           = Builders <QueueDto> .Sort.Descending(r => r.Priority).Ascending(r => r.NextRunDate)
                        };
                        QueueDto found = collection.FindOneAndUpdate <QueueDto>(filter, update, opts);
                        if (found != null)
                        {
                            DateTime nextrun = DateTime.Parse(found.NextRunDate).ToUniversalTime();
                            if (DateTime.UtcNow < nextrun || (onlymanual && found.Priority != PriorityEnum.ManualLoad))
                            {
                                found.Status = QueueStatus.PendingProcess;

                                FilterDefinition <QueueDto> filter1 = Builders <QueueDto> .Filter.Eq("_id", found.Id);

                                UpdateDefinition <QueueDto> update1 = Builders <QueueDto> .Update.Set("Status", 0).Set("ComputerName", "");

                                UpdateOptions opts1 = new UpdateOptions();
                                opts1.IsUpsert = false;

                                UpdateResult res = collection.UpdateOne(filter1, update1, opts1);
                                return(null);
                            }
                        }
                        return(found);
                    }
                }
                else
                {
                    SWGoH.Log.ConsoleMessageNotInFile("Getting from Queu!!");
                    using (HttpClient client = new HttpClient())
                    {
                        string url = SWGoH.MongoDBRepo.BuildApiUrl("Queue", "&q={\"Status\":0}", "&s={\"Priority\":-1,\"NextRunDate\":1}", "&l=1", "");

                        string response = client.GetStringAsync(url).Result;
                        if (response != "" && response != "[  ]")
                        {
                            List <BsonDocument> document = BsonSerializer.Deserialize <List <BsonDocument> >(response);
                            QueueDto            result1  = BsonSerializer.Deserialize <QueueDto>(document.FirstOrDefault());
                            if (result1 != null)
                            {
                                //check nextrundate
                                DateTime nextrun = DateTime.Parse(result1.NextRunDate).ToUniversalTime();
                                if (DateTime.UtcNow > nextrun)
                                {
                                    //UPDATE with Status = 1
                                    JObject data = new JObject(
                                        new JProperty("Name", result1.Name),
                                        new JProperty("InsertedDate", result1.InsertedDate),
                                        new JProperty("ProcessingStartDate", DateTime.UtcNow.ToString("o")),
                                        new JProperty("NextRunDate", result1.NextRunDate),
                                        new JProperty("Status", SWGoH.Enums.QueueEnum.QueueStatus.Processing),
                                        new JProperty("Priority", result1.Priority),
                                        new JProperty("Type", result1.Type),
                                        new JProperty("Command", result1.Command),
                                        new JProperty("ComputerName", SWGoH.Settings.appSettings.ComputerName));

                                    var httpContent = new StringContent(data.ToString(), Encoding.UTF8, "application/json");
                                    var requestUri  = SWGoH.MongoDBRepo.BuildApiUrlFromId("Queue", result1.Id.ToString());
                                    using (HttpClient client1 = new HttpClient())
                                    {
                                        HttpResponseMessage updateresult = client1.PutAsync(requestUri, httpContent).Result;
                                    }
                                    SWGoH.Log.ConsoleMessage("Got from Queu Player " + result1.Name);
                                    return(result1);
                                }
                                else
                                {
                                    return(null);
                                }
                            }
                            return(result1);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SWGoH.Log.ConsoleMessage("Error getting from Queu!!" + e.Message);
                return(null);
            }
            return(null);
        }
示例#6
0
        private static void TimerProc(Object o)
        {
            if (isWorking)
            {
                return;
            }
            isWorking = true;
            Timer t = o as Timer;

            t.Change(Timeout.Infinite, Timeout.Infinite);

            //SWGoH.QueueMethods.AddPlayer("newholborn", Command.UpdatePlayer, 1, Enums.QueueEnum.QueueType.Player, DateTime.UtcNow);
            //SWGoH.QueueMethods.AddPlayer("tsitas_66", Command.UpdatePlayer, 4, Enums.QueueEnum.QueueType.Player, DateTime.UtcNow.AddHours (15.0));
            //SWGoH.QueueMethods.AddPlayer("tsitas", Command.UpdatePlayer, 1, Enums.QueueEnum.QueueType.Player, DateTime.UtcNow);
            //SWGoH.QueueMethods.AddPlayer("Roukoun", Command.UpdatePlayer, 5, Enums.QueueEnum.QueueType.Player, DateTime.UtcNow);
            //SWGoH.QueueMethods.AddPlayer("aramil", Command.GetNewCharacters,  PriorityEnum.ManualLoad , Enums.QueueEnum.QueueType.Player, DateTime.UtcNow);

            //SWGoH.QueueMethods.AddPlayer("newholborn", Command.UpdatePlayer, 3, Enums.QueueEnum.QueueType.Player, DateTime.UtcNow);

            //SWGoH.QueueMethods.AddPlayer("41st", Command.UpdateGuildWithNoChars , PriorityEnum.DailyUpdate, Enums.QueueEnum.QueueType.Guild, DateTime.UtcNow);
            //ExecuteCommand(Command.GetNewCharacters, "aramil", null); return;
            //ExecuteCommand(Command.TestZetas, "aramil", null); return;
            //ExecuteCommand(Command.UpdatePlayer, "newholborn", null);
            //ExecuteCommand(Command.Test, "newholborn", null);
            //ExecuteCommand(Command.UpdateGuildWithNoChars, "41st", null);return;
            //ExecuteCommand(Command.UpdateGuild , "501st", null); return;
            ExecuteCommand(Command.UpdateUnknownGuild, "Order 66 501st Division#@#32#@#order-66-501st-division", null); return;

            int    now     = DateTime.UtcNow.Minute;
            double minutes = 0.0;

            minutes = DateTime.UtcNow.Subtract(mLastProcess).TotalMinutes;
            bool check = minutes > Settings.appSettings.MinutesUntilNextProcess;

            if (check)
            {
                workingQ = QueueMethods.GetQueu();
                if (workingQ != null)
                {
                    int ret = ExecuteCommand(workingQ.Command, workingQ.Name, workingQ);
                    if (ret == 1 || ret == 5)
                    {
                        mLastProcess = DateTime.UtcNow;
                    }
                    workingQ = null;
                }
                else
                {
                    //int now = DateTime.UtcNow.Minute;
                    //double minutes = 0.0;
                    //minutes = DateTime.UtcNow.Subtract(mLastProcess).TotalMinutes;
                    //bool check = minutes > Settings.appSettings.MinutesUntilNextProcess;
                    //if (check)
                    //{
                    //    PlayerDto player = QueueMethods.GetLastUpdatedPlayer("41st");
                    //    if (player != null)
                    //    {
                    //        QueueMethods.AddPlayer(player.PlayerName, Command.UpdatePlayer, 1 , Enums.QueueEnum.QueueType.Player , DateTime.UtcNow);
                    //    }
                    //}
                    Console.WriteLine("Nothing to process");
                }
            }
            else
            {
                Console.WriteLine("Waiting...  " + ((int)(Settings.appSettings.MinutesUntilNextProcess - minutes)).ToString() + " minutes");
            }
            isWorking = false;
            t.Change(Settings.appSettings.GlobalConsoleTimerInterval, Settings.appSettings.GlobalConsoleTimerInterval);
            GC.Collect();
        }
示例#7
0
        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());
        }