Example #1
0
        private void DumpData()
        {
            List <Indihiang.DomainObject.DumpData> listDump;
            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)");

            while (!_finish)
            {
                try
                {
                    if (_dumpLogQueue.TryDequeue(out listDump))
                    {
                        for (int j = 0; j < listDump.Count; j++)
                        {
                            if (!string.IsNullOrEmpty(listDump[j].Client_IP))
                            {
                                if (!cacheIpCountry.ContainsKey(listDump[j].Client_IP))
                                {
                                    double ip = IndihiangHelper.IPAddressToNumber(listDump[j].Client_IP);
                                    for (int k = 0; k < listIpCountry.Count; k++)
                                    {
                                        if (ip >= listIpCountry[k].IpStart && ip <= listIpCountry[k].IpEnd)
                                        {
                                            Indihiang.DomainObject.DumpData obj = listDump[j];
                                            obj.IPClientCountry = listIpCountry[k].CoutryName;
                                            listDump[j]         = obj;

                                            cacheIpCountry.Add(listDump[j].Client_IP, listIpCountry[k].CoutryName);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    Indihiang.DomainObject.DumpData obj = listDump[j];
                                    obj.IPClientCountry = cacheIpCountry[listDump[j].Client_IP];
                                    listDump[j]         = obj;
                                }
                            }
                        }
                        PerformDump(listDump);
                        listDump.Clear();
                    }
                    else
                    {
                        Thread.Sleep(10);
                    }
                }
                catch (Exception err)
                {
                    Logger.Write(err.Message);
                    Logger.Write(err.StackTrace);

                    Debug.WriteLine(err.Message);
                }
            }
            if (!_dumpLogQueue.IsEmpty)
            {
                Debug.WriteLine(string.Format("Total remain data: {0}", _dumpLogQueue.Count));
                List <Indihiang.DomainObject.DumpData>[] list = _dumpLogQueue.ToArray();
                for (int i = 0; i < list.Length; i++)
                {
                    Debug.WriteLine(string.Format("Dump data: {0}:{1}", i + 1, _dumpLogQueue.Count));

                    for (int j = 0; j < list[i].Count; j++)
                    {
                        if (!string.IsNullOrEmpty(list[i][j].Client_IP))
                        {
                            if (!cacheIpCountry.ContainsKey(list[i][j].Client_IP))
                            {
                                double ip = IndihiangHelper.IPAddressToNumber(list[i][j].Client_IP);
                                for (int k = 0; k < listIpCountry.Count; k++)
                                {
                                    if (ip >= listIpCountry[k].IpStart && ip <= listIpCountry[k].IpEnd)
                                    {
                                        Indihiang.DomainObject.DumpData obj = list[i][j];
                                        obj.IPClientCountry = listIpCountry[k].CoutryName;
                                        list[i][j]          = obj;

                                        cacheIpCountry.Add(list[i][j].Client_IP, listIpCountry[k].CoutryName);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                Indihiang.DomainObject.DumpData obj = list[i][j];
                                obj.IPClientCountry = cacheIpCountry[list[i][j].Client_IP];
                                list[i][j]          = obj;
                            }
                        }
                    }
                    PerformDump(list[i]);
                    list[i].Clear();
                }
            }
            cacheIpCountry.Clear();
            listIpCountry.Clear();
            _exitDump.Set();
        }
Example #2
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);
        }