Ejemplo n.º 1
0
        public static void LoadConfig()
        {
            if (File.Exists("IRCStatistician.conf"))
            {
                AppLog.WriteLine(1, "STATUS", "Loading configuration from IRCStatistician.conf");
                string       CurLine;
                StreamReader ConfigFile = new StreamReader("IRCStatistician.conf");
                while ((CurLine = ConfigFile.ReadLine()) != null)
                {
                    if (CurLine.Substring(0, 1) != "#")
                    {
                        string[] CurLineSplit = CurLine.Split(new char[1] {
                            '='
                        }, 2);
                        AppLog.WriteLine(4, "CONFIG", "Configuration Option: " + CurLineSplit[0] + " = " + CurLineSplit[1]);
                        switch (CurLineSplit[0].ToLower())
                        {
                        case "sqlserverhost":
                            m_SQLServerHost = CurLineSplit[1];
                            break;

                        case "sqlserverport":
                            m_SQLServerPort = Convert.ToInt32(CurLineSplit[1]);
                            break;

                        case "sqlusername":
                            m_SQLUsername = CurLineSplit[1];
                            break;

                        case "sqlpassword":
                            m_SQLPassword = CurLineSplit[1];
                            break;

                        case "sqldatabase":
                            m_SQLDatabase = CurLineSplit[1];
                            break;

                        case "sqltableprefix":
                            m_SQLTablePrefix = CurLineSplit[1];
                            break;

                        case "resolution":
                            m_Resolution = Convert.ToInt32(CurLineSplit[1]);
                            break;

                        default:
                            AppLog.WriteLine(1, "ERROR", "Unknown Configuration Option: " + CurLineSplit[0] + " = " + CurLineSplit[1]);
                            break;
                        }
                    }
                }
            }
            else
            {
                AppLog.WriteLine(1, "ERROR", "No Configuration File Found. Did you copy IRCStatistician.sample.conf and change the settings?");
            }
        }
Ejemplo n.º 2
0
        public void ProcessLog(string Data)
        {
            TextReader LogTextReader = new StringReader(Data);
            string     CurLine;
            int        i          = 0;
            DateTime   StartOfDay = DateTime.MinValue;
            DateTime   Timestamp  = DateTime.MinValue;

            while ((CurLine = LogTextReader.ReadLine()) != null)
            {
                if (CurLine.Substring(0, 1) == "#")
                {
                    if (CurLine.Substring(0, 15) == "# Opened (UTC):")
                    {
                        string DayStr = CurLine.Substring(16);
                        StartOfDay = Convert.ToDateTime(DayStr.Substring(0, DayStr.IndexOf(' ')));
                    }
                    // Is a comment
                }
                else
                {
                    string TimeNum = CurLine.Substring(0, CurLine.IndexOf(' '));
                    Timestamp = StartOfDay.AddMilliseconds(Convert.ToDouble(TimeNum));
                    // The will return the number of whole Config.Resolution chunks that have passed since Jan 1 2014.
                    uint TimeframeID = (uint)(((Timestamp - new DateTime(2014, 1, 1)).TotalSeconds) / Config.Resolution);
                    CurLine = CurLine.Substring(TimeNum.Length + 1);
                    if (CurLine.Substring(0, 1) == ":")
                    {
                        CurLine = CurLine.Substring(1);
                        string[] ParameterSplit = CurLine.Split(" ".ToCharArray(), 3, StringSplitOptions.RemoveEmptyEntries);
                        Sender   Sender         = IRCFunctions.ParseSender(ParameterSplit[0]);
                        string   Command        = ParameterSplit[1];
                        string   Parameters     = ParameterSplit[2];
                        Network.Parse(Timestamp, TimeframeID, Sender, Command, Parameters);
                    }
                    else if (CurLine.Substring(0, 4) == "PING")
                    {
                        // Do anything here?
                    }
                    else
                    {
                        AppLog.WriteLine(5, "DEBUG", "Unknown Line Format: " + CurLine);
                    }
                }
                i++;
            }
        }