コード例 #1
0
 private void WriteLog()
 {
     if (_logging)
     {
         try
         {
             if (LogFile.Length > Conf.LogFileSizeKB * 1024)
             {
                 LogFile.Append(
                     "<tr><td style=\"color:red\" valign=\"top\">Logging Exiting</td><td valign=\"top\">" +
                     DateTime.Now.ToLongTimeString() +
                     "</td><td valign=\"top\">Logging is being disabled as it has reached the maximum size (" +
                     Conf.LogFileSizeKB + "kb).</td></tr>");
                 _logging = false;
             }
             if (_lastlog.Length != LogFile.Length)
             {
                 string fc = LogTemplate.Replace("<!--CONTENT-->", LogFile.ToString()).Replace("<!--VERSION-->",
                                                                                               Application.
                                                                                               ProductVersion);
                 File.WriteAllText(Program.AppDataPath + @"log_" + NextLog + ".htm", fc);
                 _lastlog = LogFile.ToString();
             }
         }
         catch (Exception)
         {
             _logging = false;
         }
     }
 }
コード例 #2
0
        private bool TryMergeLogData(Log log, out LogTemplate result)
        {
            result = null;
            if (this.UnmatchedLogPool.ContainsKey(log.Words.Length))
            {
                var pool = this.UnmatchedLogPool[log.Words.Length];
                foreach (var unmatchedLog in pool)
                {
                    if (TemplateCorrection.TryMerge(log.Words, unmatchedLog.Words, this.LcsThreshold, this.LcsTokensOnly, out result))
                    {
                        pool.Remove(unmatchedLog);
                        result.LogIds = new List <int> {
                            log.LogId, unmatchedLog.LogId
                        };

                        return(true);
                    }
                }
            }
            else
            {
                this.UnmatchedLogPool.Add(log.Words.Length, new List <Log>());
            }

            this.UnmatchedLogPool[log.Words.Length].Add(log);
            return(false);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: nowonbun/nowonbunstore
 static void Main()
 {
     LoggerBuilder.Init(LogTemplate.GetLogTemp(ConfigSystem.ReadConfig("Config", "Log", "Path"))).Set("Server").Info("Server Program Start");
     FactoryDao.CreateInstance(ConfigSystem.ReadConfig("Config", "DB", "Connection"), ConfigSystem.ReadConfig("Config", "Log", "Path"));
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new MainForm());
 }
コード例 #4
0
ファイル: TokenTree.cs プロジェクト: jmty0083/Venus
        internal void RemoveTemplate(LogTemplate template)
        {
            var node = _root;

            foreach (var item in template.Tokens)
            {
                node = node.Children[item];
            }
            node.TemplateIds.Remove(template.TemplateId);

            if (node.IsEmpty())
            {
                node.Parent.Children.Remove(node.Token);
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Logger logger = null;

            try
            {
                if (Debug.IsDebug())
                {
                    args = new String[] { Debug.GetDebugKey(), Debug.GetDebugParam() };
                }
                if (args.Length != 2)
                {
                    throw new ScraperException("Parameter Length Error " + args.Length);
                }
                logger = LoggerBuilder.Init(LogTemplate.GetLogTemp(ConfigSystem.ReadConfig("Config", "Log", "WritePath") + "\\" + args[0] + ".log")).Set("Server").Info("Client Program Start");
                logger.Debug("arg[0] : " + args[0]);
                logger.Debug("arg[1] : " + args[1]);
                FactoryDao.CreateInstance(ConfigSystem.ReadConfig("Config", "DB", "Connection"), ConfigSystem.ReadConfig("Config", "Temp", "Path"));
                IScrapingStatusDao dao = FactoryDao.GetInstance().GetDao <IScrapingStatusDao>();
                if (!Debug.IsDebug())
                {
                    ScrapingStatus entity = dao.GetEntity(args[0]);

                    if (entity == null)
                    {
                        throw new ScraperException("Nothing entity " + args[0]);
                    }

                    if (entity.Status != "0")
                    {
                        throw new ScraperException("entity status" + args[0]);
                    }
                    entity.Status = "1";
                    dao.Update(entity);
                }
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ScraperContext(args[0], args[1]));
            }
            catch (Exception e)
            {
                if (logger != null)
                {
                    logger.Error(e.ToString());
                }
                Exit();
            }
        }
コード例 #6
0
ファイル: TemplateCorrection.cs プロジェクト: jmty0083/Venus
        internal static bool TryAbsorb(LogTemplate t1, LogTemplate t2, out LogTemplate tout)
        {
            tout = null !;
            if (t1.Length == t2.Length)
            {
                return(false);
            }

            int  p1 = 0, p2 = 0;
            bool t1l = false, t2l = false;

            while (p1 < t1.Length || p2 < t2.Length)
            {
                if (p1 < t1.Length && p2 < t2.Length && t1[p1] == t2[p2])
                {
                    p1++;
                    p2++;
                }
                else if (p1 < t1.Length && t1[p1] == Constants.VariablePlaceholder)
                {
                    p1++;
                    if (t2l)
                    {
                        return(false);
                    }
                    t1l = true;
                }
                else if (p2 < t2.Length && t2[p2] == Constants.VariablePlaceholder)
                {
                    p2++;
                    if (t1l)
                    {
                        return(false);
                    }
                    t2l = true;
                }
                else
                {
                    return(false);
                }
            }

            tout = t1.Length > t2.Length ? t1 : t2;

            return(true);
        }
コード例 #7
0
        static void Main()
        {
            string   mtxName = "WebScraping";
            Mutex    mtx     = new Mutex(true, mtxName);
            TimeSpan tsWait  = new TimeSpan(0, 0, 1);
            bool     success = mtx.WaitOne(tsWait);

            if (!success)
            {
                MessageBox.Show("이미실행중입니다.");
                return;
            }
            LoggerBuilder.Init(LogTemplate.GetLogTemp(ConfigSystem.ReadConfig("Config", "Log", "WritePath") + "\\Broker.log"));
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main());
        }
コード例 #8
0
        public void FormatProcessIdTest()
        {
            string    categoryName = "test";
            LogLevel  logLevel     = LogLevel.Warning;
            EventId   eventId      = new EventId(5, "five");
            Exception?ex           = null;
            string    message      = "fnord";

            object[]? scopes = null;
            string template = "{ProcessId}";

            var logTemplate = new LogTemplate(template);
            var actual      = logTemplate.Bind(categoryName, logLevel, eventId, message, ex, scopes);

            string expected = Process.GetCurrentProcess().Id.ToString();

            Assert.AreEqual(expected, actual);
        }
コード例 #9
0
        public void FormatMessagePrefixControlCharacter()
        {
            string    categoryName = "test";
            LogLevel  logLevel     = LogLevel.Warning;
            EventId   eventId      = new EventId(5, "five");
            Exception?ex           = null;
            string    message      = "Something to\tsay";

            object[]? scopes = null;
            string template = "<{MessagePrefix}>";

            var logTemplate = new LogTemplate(template);
            var actual      = logTemplate.Bind(categoryName, logLevel, eventId, message, ex, scopes);

            string expected = "<Something tosay>";

            Assert.AreEqual(expected, actual);
        }
コード例 #10
0
        public void FormatIdAndMessageTest()
        {
            string    categoryName = "test";
            LogLevel  logLevel     = LogLevel.Warning;
            EventId   eventId      = new EventId(5, "five");
            Exception?ex           = null;
            string    message      = "fnord";

            object[]? scopes = null;
            string template = "{Id}.{Message}";

            var logTemplate = new LogTemplate(template);
            var actual      = logTemplate.Bind(categoryName, logLevel, eventId, message, ex, scopes);

            string expected = "5.fnord";

            Assert.AreEqual(expected, actual);
        }
コード例 #11
0
    protected override void OnCellRenderer(int groupIndex, int cellIndex, object cellData, RectTransform cellView, bool selected)
    {
        Animator m_Animator = cellView.GetComponent <Animator>();

        if (m_Animator)
        {
            m_Animator.SetBool("IsOn", selected);
        }
        if (OwnerView.State.GetPageIndex() == 0)
        {
            MailDataVO m_MailVo = (MailDataVO)cellData;
            if (selected)
            {
                if (m_LastMailSelectVo != m_MailVo)
                {
                    m_LastMailSelectVo = m_MailVo;

                    NetworkManager.Instance.GetMailController().C_to_S_GetMailContent(m_LastMailSelectVo.Id);
                    if (m_LastMailSelectVo.IsNew == 1)
                    {
                        RecordNewMail(m_LastMailSelectVo.Id);
                        m_MailProxy.ClearMailNew(m_LastMailSelectVo.Id);
                    }
                }
                object data = OwnerView.State.GetTipData();
                OwnerView.State.SetTipData(null);
                OwnerView.State.SetTipData(data);
                SetMailState();
            }
            MailTemplate m_MailTemplate = cellView.GetOrAddComponent <MailTemplate>();
            m_MailTemplate.Init(m_MailVo, RecordNewMail);
        }
        else
        {
            LogDataVO   m_LogVo       = (LogDataVO)cellData;
            LogTemplate m_LogTemplate = cellView.GetOrAddComponent <LogTemplate>();
            m_LogTemplate.Init(m_LogVo);
            if (selected)
            {
                m_LastLogSelectVo = m_LogVo;
                SetLogState();
            }
        }
    }
コード例 #12
0
        public void FormatMessagePrefixLength()
        {
            string    categoryName = "test";
            LogLevel  logLevel     = LogLevel.Warning;
            EventId   eventId      = new EventId(5, "five");
            Exception?ex           = null;
            //                1234567890123456789012345678901234567890
            string message = "Something to say Something to say Something to say. the rest of the trace.";

            object[]? scopes = null;
            string template = "<{MessagePrefix}>";

            var logTemplate = new LogTemplate(template);
            var actual      = logTemplate.Bind(categoryName, logLevel, eventId, message, ex, scopes);

            string expect = "<Something to say Something to say Som...>";

            Assert.AreEqual(expect, actual);
        }
コード例 #13
0
        static void Main(string[] args)
        {
            Logger logger = null;

            try
            {
                String arg = null;
                if (Debug.IsDebug())
                {
                    arg = Debug.GetDebugParam();
                }
                else
                {
                    if (args.Length != 1)
                    {
                        throw new ScraperException("Parameter Length Error " + args.Length);
                    }
                    byte[] buffer = Convert.FromBase64String(args[0]);
                    arg = Encoding.UTF8.GetString(buffer);
                }
                Parameter param = JsonConvert.DeserializeObject <Parameter>(arg);
                logger = LoggerBuilder.Init(LogTemplate.GetLogTemp(ConfigSystem.ReadConfig("Config", "Log", "WritePath") + "\\" + param.Key + ".log")).Set("Server").Info("Client Program Start");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                if (Debug.IsDebug())
                {
                    Application.Run(new ScraperForm(param));
                }
                else
                {
                    Application.Run(new ScraperContext(param));
                }
            }
            catch (Exception e)
            {
                if (logger != null)
                {
                    logger.Error(e.ToString());
                }
                Exit();
            }
        }
コード例 #14
0
        public void Logs_Contains_Correct_Message_Templates()
        {
            IEnumerable <LogTemplate> templates = _logViewer.GetMessageTemplates(_logTimePeriod);

            // Count no of templates
            Assert.AreEqual(25, templates.Count());

            // Verify all templates & counts are unique
            CollectionAssert.AllItemsAreUnique(templates);

            // Ensure the collection contains LogTemplate objects
            CollectionAssert.AllItemsAreInstancesOfType(templates, typeof(LogTemplate));

            // Get first item & verify its template & count are what we expect
            LogTemplate popularTemplate = templates.FirstOrDefault();

            Assert.IsNotNull(popularTemplate);
            Assert.AreEqual("{EndMessage} ({Duration}ms) [Timing {TimingId}]", popularTemplate.MessageTemplate);
            Assert.AreEqual(26, popularTemplate.Count);
        }
コード例 #15
0
        private void BuildIndex(LogTemplate template)
        {
            this.Templates.Add(template.TemplateId, template);

            if (this.LengthIndexer.ContainsKey(template.Length))
            {
                this.LengthIndexer[template.Length].Add(template.TemplateId);
            }
            else
            {
                this.LengthIndexer.Add(template.Length, new HashSet <int> {
                    template.TemplateId
                });
            }

            if (this.TokenIndexer.ContainsKey(template.TokensHash))
            {
                this.TokenIndexer[template.TokensHash].Add(template.TemplateId);
            }
            else
            {
                this.TokenIndexer.Add(template.TokensHash, new HashSet <int> {
                    template.TemplateId
                });
            }

            foreach (var logId in template.LogIds)
            {
                if (this.LogTemplateLookupTable.ContainsKey(logId))
                {
                    this.LogTemplateLookupTable[logId] = template.TemplateId;
                }
                else
                {
                    this.LogTemplateLookupTable.Add(logId, template.TemplateId);
                }
            }

            this.PrefixTree.InsertTemplate(template);
        }
コード例 #16
0
        private bool TryAbsorbTemplate(LogTemplate template, out LogTemplate result)
        {
            result = null;
            if (this.TokenIndexer.ContainsKey(template.TokensHash))
            {
                var list = this.TokenIndexer[template.TokensHash];
                foreach (var tryTemplateId in list)
                {
                    if (TemplateCorrection.TryAbsorb(template, this.Templates[tryTemplateId], out result))
                    {
                        result.LogIds = template.LogIds
                                        .Concat(this.Templates[tryTemplateId].LogIds)
                                        .ToList();

                        this.RemoveTemplate(tryTemplateId);
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #17
0
        private bool TryMergeTemplate(LogTemplate template, out LogTemplate result)
        {
            result = null;
            if (this.LengthIndexer.ContainsKey(template.Length))
            {
                var list = this.LengthIndexer[template.Length];
                foreach (var tryTemplateId in list)
                {
                    if (TemplateCorrection.TryMerge(template.Sequence, this.Templates[tryTemplateId].Sequence, this.LcsThreshold, this.LcsTokensOnly, out result))
                    {
                        result.LogIds = template.LogIds
                                        .Concat(this.Templates[tryTemplateId].LogIds)
                                        .ToList();

                        //this.Templates[templateId].EmergedId = result.TemplateId;
                        this.RemoveTemplate(tryTemplateId);

                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #18
0
        public void FormatPrincipalNameTest()
        {
            string    categoryName = "test";
            LogLevel  logLevel     = LogLevel.Warning;
            EventId   eventId      = new EventId(5, "five");
            Exception?ex           = null;
            string    message      = "fnord";

            object[]? scopes = null;
            string template = "{Id}.{PrincipalName}";

            var    logTemplate = new LogTemplate(template);
            string actual;

            using (var scope = new UserResetScope("testuser"))
            {
                actual = logTemplate.Bind(categoryName, logLevel, eventId, message, ex, scopes);
            }

            string expected = "5.testuser";

            Assert.AreEqual(expected, actual);
        }
コード例 #19
0
ファイル: TemplateCorrection.cs プロジェクト: jmty0083/Venus
        internal static bool TryMerge(string[] t1, string[] t2, double lcsThreshold, bool lcsTokenOnly, out LogTemplate tout)
        {
            tout = null !;
            if (t1.Length != t2.Length)
            {
                return(false);
            }

            //var t1t = t1.Where(x => x != Constants.VariablePlaceholder).ToArray();
            //var t2t = t2.Where(x => x != Constants.VariablePlaceholder).ToArray();

            //var lcs = QuickAlgorithms.LongestCommonSequence(t1t, t2t);


            var matrix = new int[t1.Length + 1, t2.Length + 1];

            for (int i = 0; i < t1.Length; i++)
            {
                for (int j = 0; j < t2.Length; j++)
                {
                    if (t1[i] == t2[j])
                    {
                        matrix[i + 1, j + 1] = matrix[i, j] + 1;
                    }
                    else
                    {
                        matrix[i + 1, j + 1] = Math.Max(matrix[i + 1, j], matrix[i, j + 1]);
                    }
                }
            }

            var lcs = LongestCommonSequenceWithVaPInReverse(t1, t2, matrix);

            if (lcsTokenOnly)
            {
                if (2d * lcs.Count / (t1.Count(x => x != Constants.VariablePlaceholder) + t2.Count(x => x != Constants.VariablePlaceholder)) < lcsThreshold)
                {
                    return(false);
                }
            }
            else
            {
                if ((double)matrix[t1.Length, t2.Length] / t1.Length < lcsThreshold)
                {
                    return(false);
                }
            }

            //lcs.Reverse();

            var result = new List <string>();
            int p1 = t1.Length, p2 = t2.Length;

            while (p1 > 0 && p2 > 0)
            {
                if (t1[p1 - 1] == t2[p2 - 1])
                {
                    if (t1[p1 - 1] == lcs.FirstOrDefault())
                    {
                        lcs.RemoveAt(0);
                    }

                    result.Add(t1[p1 - 1]);
                    p1--;
                    p2--;
                }
                else if (t1[p1 - 1] == lcs.FirstOrDefault())
                {
                    result.Add(Constants.VariablePlaceholder);
                    p2--;
                }
                else if (t2[p2 - 1] == lcs.FirstOrDefault())
                {
                    result.Add(Constants.VariablePlaceholder);
                    p1--;
                }
                else
                {
                    result.Add(Constants.VariablePlaceholder);
                    if ((matrix[p1 - 1, p2] == matrix[p1, p2]) && (matrix[p1, p2 - 1] == matrix[p1, p2]))
                    {
                        p1--;
                        p2--;
                    }
                    else if (matrix[p1 - 1, p2] == matrix[p1, p2])
                    {
                        p1--;
                    }
                    else
                    {
                        p2--;
                    }
                }
            }

            for (int i = 0; i < p1 + p2; i++)
            {
                result.Add(Constants.VariablePlaceholder);
            }

            result.Reverse();
            tout = new LogTemplate(result);
            return(true);
        }
コード例 #20
0
ファイル: TokenTree.cs プロジェクト: jmty0083/Venus
        internal void InsertTemplate(LogTemplate template)
        {
            var tokens = template.Tokens.ToArray();

            InsertTemplate(_root, tokens, 0, template.TemplateId, template.Length);
        }