AdvancedLogParser.InfoGather.GetDMTime C# (CSharp) Method

GetDMTime() public static method

public static GetDMTime ( ) : void
return void
        public static void GetDMTime()
        {
            currentLoader.status.Text = "Querying DM Time...";
            Application.DoEvents();
            DateTime checkFrom = DateTime.UtcNow.Subtract(TimeSpan.FromDays(30));
            try
            {
                using (MySqlDataReader reader = MySqlHelper.ExecuteReader(ConnectionString, String.Format("SELECT * FROM alandsyu_live.logs WHERE Date > '{0}/{1}/{2}' AND (Event = \"XP Gain, DM RP\" OR Event = \"XP Gain, DM Quest\")", checkFrom.Year, checkFrom.Month, checkFrom.Day)))
                {
                    currentLoader.status.Text = "Parsing DM Time...";
                    Application.DoEvents();
                    while (reader.Read())
                    {
                        try
                        {
                            uint id = (uint)reader.GetValue(0);
                            ushort serverId = (ushort)reader.GetValue(1);
                            uint characterId = (uint)reader.GetValue(2);
                            string eventName = (string)reader.GetValue(3);
                            string eventDescription = (string)reader.GetValue(4);
                            string timeDMed;
                            if (eventName == "XP Gain, DM RP")
                            {
                                timeDMed = eventDescription.Split(' ')[7];
                            }
                            else
                            {
                                timeDMed = eventDescription.Split(' ')[11];
                            }
                            float addingTime = 0.0f;
                            float.TryParse(timeDMed, out addingTime);
                            Character charDMed = Characters.List[characterId];
                            charDMed.DMTime += addingTime;
                            Player playerDMed = Players.ListByPlayerId[charDMed.PlayerId];
                            playerDMed.DMTime += addingTime;
                        }
                        catch(Exception e)
                        {
                            MessageBox.Show(e.Message);
                            continue;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                Application.Exit();
            }
        }

Usage Example

Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            InfoGather.DatabasePassword = ConfigurationSettings.AppSettings["DatabasePassword"];
            InfoGather.DatabaseSchema   = ConfigurationSettings.AppSettings["DatabaseSchema"];
            InfoGather.DatabaseServer   = ConfigurationSettings.AppSettings["DatabaseServer"];
            InfoGather.DatabasePort     = ConfigurationSettings.AppSettings["DatabasePort"];
            InfoGather.DatabaseUser     = ConfigurationSettings.AppSettings["DatabaseUser"];
            InfoGather.BuildConnectionString();
            Players.ListByPlayerId = new Dictionary <uint, Player>();
            Players.ListByKey      = new Dictionary <string, Player>();
            Characters.List        = new Dictionary <uint, Character>();
            Logs.AdvancementAlerts = new Dictionary <uint, Log>();
            Logs.DeathAlerts       = new Dictionary <uint, Log>();
            Logs.EnforcementAlerts = new Dictionary <uint, Log>();
            Logs.RecentLogins      = new Dictionary <uint, Log>();
            Servers.List           = new Dictionary <uint, Server>();
            if (InfoGather.GetPlayers())
            {
                InfoGather.GetCharacters();
                InfoGather.CountBankValue();
                InfoGather.CountpChestValue();
                InfoGather.GetAlerts();
                InfoGather.GetLogins();
                InfoGather.IdentifyLogins();
                InfoGather.GetDMTime();
                InfoGather.currentLoader.Close();
                InfoGather.currentLoader.Dispose();
                if (ServerFocus >= 0)
                {
                    foreach (Server srv in Servers.List.Values)
                    {
                        if (srv.ServerId == Math.Abs(ServerFocus))
                        {
                            Application.Run(new ServerView(srv));
                        }
                    }
                }
                else
                {
                    foreach (Server srv in Servers.List.Values)
                    {
                        new ServerView(srv).Show();
                    }
                    new ServerView(null).Show();
                    Application.Run(new PrimaryDisplay());
                }
            }
        }