Beispiel #1
0
        protected virtual void OnAnalyzeLog(LogInfoEventArgs e)
        {
            if (AnalyzeLogHandler != null)
            {
                AnalyzeLogHandler(this, e);
            }

            Debug.WriteLine(String.Format("Indihiang:: {0}", e.Message));
        }
Beispiel #2
0
        public void Analyze()
        {
            QueryPerformanceCounter(ref _startTime);

            LogInfoEventArgs logInfo = new LogInfoEventArgs(
                LogParserId.ToString(),
                EnumLogFile.UNKNOWN,
                LogProcessStatus.SUCCESS,
                "Process()",
                "Starting..");

            _synContext.Post(OnAnalyzeLog, logInfo);

            if (_iisInfo == null)
            {
                if (!useExistData)
                {
                    if (!Verify())
                    {
                        return;
                    }
                }
                else
                {
                    _parser = LogParserFactory.CreateParserByType(EnumLogFile.W3CEXT);
                }
            }
            else
            {
                _parser = LogParserFactory.CreateParserByType(EnumLogFile.W3CEXT);
            }
            _parser.ParserID         = LogParserId.ToString();
            _parser.ParseLogHandler += ParseLogHandler;
            _parser.UseParallel      = _useParallel;

            if (useExistData)
            {
                _logFilePath = Path.GetDirectoryName(_fileName);
            }
            else
            {
                string path = string.Format("{0}\\Indihiang\\", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
                _logFilePath = String.Format("{0}\\Data\\{1}\\", path, LogParserId.ToString());
            }

            //_finish = false;
            //if (_dataQueue == null)
            //    _dataQueue = new Thread(DumpData);
            if (_thread == null)
            {
                _thread = new Thread(Process); // original
            }
            //_thread = new Thread(ParseLog);

            _thread.IsBackground = true;
            _thread.Start();
        }
Beispiel #3
0
        protected virtual void OnParseLog(LogInfoEventArgs e)
        {
            if (ParseLogHandler != null)
            {
                ParseLogHandler(this, e);
            }

            Debug.WriteLine(String.Format("OnParseLog:: {0}", e.Message));
        }
Beispiel #4
0
        protected virtual void OnEndAnalyze(LogInfoEventArgs logInfo)
        {
            Thread.Sleep(100);
            if (EndAnalyzeHandler != null)
            {
                EndAnalyzeHandler(this, logInfo);
            }

            Debug.WriteLine(String.Format("Indihiang:: {0}", logInfo.Message));
        }
Beispiel #5
0
        private bool CheckFile()
        {
            if (_fileName.StartsWith("--"))
            {
                List <string> files = IndihiangHelper.ParseFile(_fileName);

                LogInfoEventArgs logInfo = null;
                for (int i = 0; i < files.Count; i++)
                {
                    if (!string.IsNullOrEmpty(files[i]))
                    {
                        if (!File.Exists(files[i]))
                        {
                            logInfo = new LogInfoEventArgs(
                                LogParserId.ToString(),
                                EnumLogFile.UNKNOWN,
                                LogProcessStatus.FAILED,
                                "LogParser.CheckFile()",
                                String.Format("{0} isn't found", files[i]));
                            _synContext.Post(OnAnalyzeLog, logInfo);

                            return(false);
                        }
                    }
                }

                logInfo = new LogInfoEventArgs(
                    LogParserId.ToString(),
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Process()",
                    string.Format("Total log files are {0} files", files.Count.ToString()));
                _synContext.Post(OnAnalyzeLog, logInfo);
            }
            else
            if (!File.Exists(_fileName))
            {
                LogInfoEventArgs logInfo = new LogInfoEventArgs(
                    LogParserId.ToString(),
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.FAILED,
                    "LogParser.CheckFile()",
                    String.Format("{0} isn't found", _fileName));
                _synContext.Post(OnAnalyzeLog, logInfo);

                return(false);
            }

            return(true);
        }
Beispiel #6
0
        private bool CheckParser()
        {
            _parser          = LogParserFactory.CreateParser(_fileName);
            _parser.LogFile  = _fileName;
            _parser.ParserID = LogParserId.ToString();
            if (_parser == null)
            {
                LogInfoEventArgs logInfo = new LogInfoEventArgs(
                    LogParserId.ToString(),
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.FAILED,
                    "LogParser.Verify()",
                    "Application cannot verify log file format or there are more than log file format");
                _synContext.Post(OnAnalyzeLog, logInfo);

                return(false);
            }

            return(true);
        }
Beispiel #7
0
        private void Process()
        {
            Thread.Sleep(100);
            LogInfoEventArgs logInfo = null;

            if (_iisInfo != null)
            {
                LogFileProcessing();
            }

            logInfo = new LogInfoEventArgs(
                LogParserId.ToString(),
                EnumLogFile.UNKNOWN,
                LogProcessStatus.SUCCESS,
                "Process()",
                "Running log parser...");

            _synContext.Post(OnAnalyzeLog, logInfo);

            if (!useExistData)
            {
                if (_fileName.StartsWith("--"))
                {
                    _parser.LogFile = _fileName;
                }
                _parser.Parse();
            }

            logInfo = new LogInfoEventArgs(
                LogParserId.ToString(),
                EnumLogFile.UNKNOWN,
                LogProcessStatus.SUCCESS,
                "Process()",
                "Done");
            Thread.Sleep(100);
            _synContext.Post(OnEndAnalyze, logInfo);
        }
Beispiel #8
0
        private void LogFileProcessing()
        {
            LogInfoEventArgs logInfo;
            string           message = string.Empty;

            if (_iisInfo.LocalComputer)
            {
                message = "Checking log files...";
            }
            else
            {
                message = "Copy remote web server log file into local...";
            }

            #region Logging
            logInfo = new LogInfoEventArgs(
                LogParserId.ToString(),
                EnumLogFile.UNKNOWN,
                LogProcessStatus.SUCCESS,
                "Process()",
                message);

            _synContext.Post(OnAnalyzeLog, logInfo);
            #endregion

            string sourceFiles = string.Empty;

            if (!_iisInfo.LocalComputer)
            {
                RemoteFileCopyHelper.CopyRemoteFiles(_iisInfo);
                string path = string.Format("{0}\\Indihiang\\", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
                sourceFiles = String.Format("{0}\\Temp\\{1}{2}\\", path, _iisInfo.RemoteServer, _iisInfo.Id);
            }
            else
            {
                sourceFiles = String.Format("{0}\\W3SVC{1}\\", _iisInfo.LogPath, _iisInfo.Id);
            }

            int      total = 0;
            string[] files = Directory.GetFiles(sourceFiles);

            if (files != null)
            {
                total = files.Length;
                string file = "--";
                for (int i = 0; i < files.Length; i++)
                {
                    file = String.Format("{0}{1};", file, files[i]);
                }

                _parser.LogFile = file;
            }


            if (_iisInfo.LocalComputer)
            {
                message = "Check log files was done";
            }
            else
            {
                message = "Copy remote web server log files into local was done";
            }

            #region logging
            logInfo = new LogInfoEventArgs(
                LogParserId.ToString(),
                EnumLogFile.UNKNOWN,
                LogProcessStatus.SUCCESS,
                "Process()",
                message);
            _synContext.Post(OnAnalyzeLog, logInfo);
            logInfo = new LogInfoEventArgs(
                LogParserId.ToString(),
                EnumLogFile.UNKNOWN,
                LogProcessStatus.SUCCESS,
                "Process()",
                string.Format("Total remote log files are {0} files", total.ToString()));
            _synContext.Post(OnAnalyzeLog, logInfo);
            #endregion


            if (total == 0)
            {
                logInfo = new LogInfoEventArgs(
                    LogParserId.ToString(),
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Process()",
                    "No log file will be analyzed.");
                _synContext.Post(OnEndAnalyze, logInfo);
                Thread.Sleep(100);

                return;
            }
        }
Beispiel #9
0
 private void ParseLogHandler(object sender, LogInfoEventArgs e)
 {
     _synContext.Post(OnAnalyzeLog, e);
 }
Beispiel #10
0
        private bool ParallelParse(bool success, List <string> listFiles)
        {
            try
            {
                List <ManualResetEventSlim> resets = new List <ManualResetEventSlim>();
                _exitDump = new ManualResetEventSlim(false);

                int i = 0;
                Parallel.ForEach <string>(listFiles, file =>
                {
                    LogInfoEventArgs logInfo = new LogInfoEventArgs(
                        ParserID,
                        EnumLogFile.UNKNOWN,
                        LogProcessStatus.SUCCESS,
                        "Parse()",
                        String.Format("Run Parse on file {0}", file));
                    _synContext.Post(OnParseLog, logInfo);


                    ManualResetEventSlim obj = new ManualResetEventSlim(false);
                    resets.Add(obj);
                    try
                    {
                        RunParse(file);

                        logInfo = new LogInfoEventArgs(
                            ParserID,
                            EnumLogFile.UNKNOWN,
                            LogProcessStatus.SUCCESS,
                            "Parse()",
                            String.Format("Run Parse : {0} was done", file));
                        _synContext.Post(OnParseLog, logInfo);
                    }
                    catch (Exception err)
                    {
                        logInfo = new LogInfoEventArgs(
                            ParserID,
                            EnumLogFile.UNKNOWN,
                            LogProcessStatus.SUCCESS,
                            "Parse()",
                            String.Format("Error occurred on file {0}==>{1}\r\n{2}", file, err.Message, err.StackTrace));
                        _synContext.Post(OnParseLog, logInfo);
                    }
                    obj.Set();
                });


                try
                {
                    for (i = 0; i < resets.Count; i++)
                    {
                        if (!resets[i].IsSet)
                        {
                            resets[i].Wait();
                        }
                    }
                }
                catch { }
                _finish = true;

                LogInfoEventArgs logInfo2 = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    "Consolidating log files...");
                _synContext.Post(OnParseLog, logInfo2);

                try
                {
                    if (!_exitDump.IsSet)
                    {
                        _exitDump.Wait();
                    }
                }
                catch { }

                logInfo2 = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    "Consolidated log file was done");
                _synContext.Post(OnParseLog, logInfo2);

                Thread.Sleep(100);
                success = true;
            }
            catch (AggregateException err)
            {
                Logger.Write(err.Message);
                Logger.Write(err.StackTrace);

                #region Handle Exception
                LogInfoEventArgs logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Internal Error: {0}", err.Message));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Source Internal Error: {0}", err.Source));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Detail Internal Error: {0}", err.StackTrace));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Internal Exception Error: {0}", err.InnerException.Message));
                _synContext.Post(OnParseLog, logInfo);

                #endregion
            }
            catch (Exception err)
            {
                Logger.Write(err.Message);
                Logger.Write(err.StackTrace);

                #region Handle Exception
                LogInfoEventArgs logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Internal Error: {0}", err.Message));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Source Internal Error: {0}", err.Source));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Detail Internal Error: {0}", err.StackTrace));
                _synContext.Post(OnParseLog, logInfo);

                #endregion
            }
            return(success);
        }
Beispiel #11
0
        private bool SequentialParse(bool success, List <string> listFiles)
        {
            try
            {
                //List<ManualResetEventSlim> resets = new List<ManualResetEventSlim>();
                //_exitDump = new ManualResetEventSlim(false);

                DataHelper helper = new DataHelper(IndihiangHelper.GetIPCountryDb());
                List <Indihiang.DomainObject.IPCountry> listIpCountry = helper.GetAllIpCountry();

                Dictionary <string, string> cacheIpCountry = new Dictionary <string, string>();
                cacheIpCountry.Add("127.0.0.1", "(Local)");

                for (int i = 0; i < listFiles.Count; i++)
                {
                    LogInfoEventArgs logInfo = new LogInfoEventArgs(
                        ParserID,
                        EnumLogFile.UNKNOWN,
                        LogProcessStatus.SUCCESS,
                        "Parse()",
                        String.Format("Run Parse on file {0}", listFiles[i]));
                    _synContext.Post(OnParseLog, logInfo);

                    try
                    {
                        RunParse(listFiles[i]);
                        DumpPartial(listIpCountry, cacheIpCountry);

                        logInfo = new LogInfoEventArgs(
                            ParserID,
                            EnumLogFile.UNKNOWN,
                            LogProcessStatus.SUCCESS,
                            "Parse()",
                            String.Format("Run Parse : {0} was done", listFiles[i]));
                        _synContext.Post(OnParseLog, logInfo);
                    }
                    catch (Exception err)
                    {
                        logInfo = new LogInfoEventArgs(
                            ParserID,
                            EnumLogFile.UNKNOWN,
                            LogProcessStatus.SUCCESS,
                            "Parse()",
                            String.Format("Error occurred on file {0}==>{1}\r\n{2}", listFiles[i], err.Message, err.StackTrace));
                        _synContext.Post(OnParseLog, logInfo);
                    }
                }


                _finish = true;

                //LogInfoEventArgs logInfo2 = new LogInfoEventArgs(
                //                   ParserID,
                //                   EnumLogFile.UNKNOWN,
                //                   LogProcessStatus.SUCCESS,
                //                   "Parse()",
                //                   "Consolidating log files...");
                //_synContext.Post(OnParseLog, logInfo2);
                //try
                //{
                //    //DumpData();

                //    //if (!_exitDump.IsSet)
                //    //    _exitDump.Wait();
                //}
                //catch { }

                LogInfoEventArgs logInfo2 = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    "Consolidated log file was done");
                _synContext.Post(OnParseLog, logInfo2);

                Thread.Sleep(100);
                success = true;
            }
            catch (AggregateException err)
            {
                Logger.Write(err.Message);
                Logger.Write(err.StackTrace);

                #region Handle Exception
                LogInfoEventArgs logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Internal Error: {0}", err.Message));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Source Internal Error: {0}", err.Source));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Detail Internal Error: {0}", err.StackTrace));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Internal Exception Error: {0}", err.InnerException.Message));
                _synContext.Post(OnParseLog, logInfo);

                #endregion
            }
            catch (Exception err)
            {
                Logger.Write(err.Message);
                Logger.Write(err.StackTrace);

                #region Handle Exception
                LogInfoEventArgs logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Internal Error: {0}", err.Message));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Source Internal Error: {0}", err.Source));
                _synContext.Post(OnParseLog, logInfo);
                logInfo = new LogInfoEventArgs(
                    ParserID,
                    EnumLogFile.UNKNOWN,
                    LogProcessStatus.SUCCESS,
                    "Parse()",
                    String.Format("Detail Internal Error: {0}", err.StackTrace));
                _synContext.Post(OnParseLog, logInfo);

                #endregion
            }
            return(success);
        }