コード例 #1
0
ファイル: LogParser.cs プロジェクト: wsharba/edocs
        private void ParseChunk(RawEvent ev)
        {
            if (XPerCents > 0 && ++ParseChunkCounter % XPerCents == 0)
            {
                RaiseProgress(ParserProgressStage.ParsingChunks, ParseChunkCounter * ProgressReportStep / XPerCents);
            }

            int processedBodyLines;

            for (int i = ev.Header.Index + 1; i < ev.Footer.Index - 1; i++)
            {
                string line = GetLine(i);
                foreach (var rule in bodyRules)
                {
                    var result = rule.Apply(line); //RuleApplyCached(rule, i, line);
                    if (ProcessAsChunkBody(i, result, ev, out processedBodyLines))
                    {
                        i += processedBodyLines;
                        break;
                    }
                }
            }
            lock (_lockRawEvents)
                RawEvents.Add(ev);  //TODO rewrite with ReaderWriterLockSlim
        }
コード例 #2
0
 private static string GetEventUniqueName(RawEvent ev)
 {
     if(ev.Type == EventType.Sql) {
         return ev.Key;
     }
     return null;
 }
コード例 #3
0
ファイル: LogParser.cs プロジェクト: wsharba/edocs
        private bool ProcessAsChunkHeader(int index, RuleResult result)
        {
            if (result.LineType != LineType.Header)
            {
                return(false);
            }

            string key = result.Key;

            if (IncompleteChunks.ContainsKey(key))
            {
                //IncompleteChunks.Remove(key);
                //I've modified regexps. Let's give edocs another try...
                RawEvent inc = IncompleteChunks[key];

                LogMessage("{5}: Found a new event header with the same key {0} before the footer of the previous event\n" +
                           "\tPrevious header at line {1}: {2}\n" +
                           "\tNew header at line {3}: {4}",
                           key, inc.Header.Index, GetLine(inc.Header.Index), index, GetLine(index), System.IO.Path.GetFileName(Log.FileName));
            }

            IncompleteChunks[key] = new RawEvent(key)
            {
                Header = new LogLine(index, result), Type = result.EventType
            };
            return(true);
        }
コード例 #4
0
ファイル: LogParser.cs プロジェクト: wsharba/edocs
        private bool ProcessAsChunkFooter(int index, RuleResult result)
        {
            if (result.LineType != LineType.Footer)
            {
                return(false);
            }

            string key = result.Key;

            if (!IncompleteChunks.ContainsKey(key))
            {
                LogMessage("{2}: Footer without header at {0}: {1}", index, GetLine(index), System.IO.Path.GetFileName(Log.FileName));
                return(false);  // footer without header - strange, but we don't need it
            }

            RawEvent inc = IncompleteChunks[key];

            IncompleteChunks.Remove(key);
            if (inc.Header.Index >= index)
            {
                LogMessage("{4}: Footer above header at {0}: {1}\n\tHeader at {2}: {3}", index, GetLine(index), inc.Header.Index, GetLine(inc.Header.Index), System.IO.Path.GetFileName(Log.FileName));
                return(false);
            }

            inc.Footer = new LogLine(index, result);
            Chunks.Add(inc);
            return(true);
        }
コード例 #5
0
ファイル: LogParser.cs プロジェクト: wsharba/edocs
 private void FormatEvent(RawEvent raw)
 {
     switch (raw.Type)
     {
     case EventType.Sql:
         lock (_lockEvents)
             Events.Add(SqlEventFactory.GetEvent(raw));
         break;
     }
 }
コード例 #6
0
        private static void SaveSqlBodyToFile(RawEvent ev)
        {
            if(ev.Type == EventType.Sql) {
                string fileName = GetEventUniqueName(ev);
                string fullFileName = fileName; // TODO
                using(var writer = File.CreateText(fullFileName)) {

                }
            }
        }
コード例 #7
0
        public static BaseEvent GetEvent(RawEvent raw)
        {
            if (raw.Type != EventType.Sql)
            {
                throw new ArgumentException("Sql event expected");
            }

            var ev = new SqlEvent(raw);

            string pool = raw.Header.Values[ValueKeys.Index];

            ev.ConnectionIndex = string.IsNullOrEmpty(pool) ? -1 : Convert.ToInt32(pool);
            ev.IsNew           = raw.Header.Values[ValueKeys.IsNew];

            // TODO: f*****g edocs... Body is sometimes missing...
            SqlQueryEvent query = new SqlQueryEvent();

            foreach (var bodyLine in raw.Body)
            {
                if (bodyLine.RuleType == typeof(SqlBodyRule) || bodyLine.RuleType == typeof(SqlBodyNotifyRule))
                {
                    query      = new SqlQueryEvent();
                    query.Time = bodyLine.Values[ValueKeys.Time];
                    ev.Queries.Add(query);
                    //TODO: line index
                }

                /*else if(bodyLine.RuleType == typeof(SqlStatementRequiredRule.AutoCommitLineRule) {
                 *  query.AutoCommit = bodyLine.Content; // TODO: On or Off only
                 * }*/
                else if (bodyLine.RuleType == typeof(SqlStatementRequiredRule.StatementLineRule))
                {
                    query.Command = bodyLine.Content;
                }
                else if (bodyLine.RuleType == typeof(SqlBodyTimerReadItemRule))
                {
                    query.DurationReadItem = bodyLine.Values[ValueKeys.Duration];
                }
                else if (bodyLine.RuleType == typeof(SqlBodyTimerIssueCommandRule))
                {
                    query.DurationIssueCommand = bodyLine.Values[ValueKeys.Duration];
                }
            }
            return(ev);
        }
コード例 #8
0
ファイル: LogParser.cs プロジェクト: wsharba/edocs
        private bool ProcessAsChunkBody(int index, RuleResult result, RawEvent raw, out int processedBodyLines)
        {
            processedBodyLines = 0;
            if (result.LineType != LineType.Body)
            {
                return(false);
            }

            if (result.Key != raw.Key)
            {
                return(false);
            }

            string key = result.Key;

            raw.Body.Add(new LogLine(index, result));

            //TODO require the RequiredRule
            if (result.RequiredBlockRule != null)
            {
                var blockResult = ProcessRequiredBodyBlock(index, result);
                if (blockResult != null)
                {
                    foreach (var pair in blockResult.LineRuleResults)
                    {
                        int idx = pair.Key + index + 1;
                        raw.Body.Add(new LogLine(idx, pair.Value)
                        {
                            Content = GetLine(idx)
                        });
                    }
                    processedBodyLines = blockResult.ProcessedCount;
                }
            }
            return(true);
        }
コード例 #9
0
ファイル: LogParser.cs プロジェクト: rexwhitten/edocs
        private void ParseChunk(RawEvent ev)
        {
            if(XPerCents > 0 && ++ParseChunkCounter % XPerCents == 0)
                RaiseProgress(ParserProgressStage.ParsingChunks, ParseChunkCounter * ProgressReportStep / XPerCents);

            int processedBodyLines;
            for(int i = ev.Header.Index + 1; i < ev.Footer.Index - 1; i++) {
                string line = GetLine(i);
                foreach(var rule in bodyRules) {
                    var result = rule.Apply(line); //RuleApplyCached(rule, i, line);
                    if(ProcessAsChunkBody(i, result, ev, out processedBodyLines)) {
                        i += processedBodyLines;
                        break;
                    }
                }
            }
            lock(_lockRawEvents)
                RawEvents.Add(ev);  //TODO rewrite with ReaderWriterLockSlim
        }
コード例 #10
0
ファイル: LogParser.cs プロジェクト: rexwhitten/edocs
 private void FormatEvent(RawEvent raw)
 {
     switch(raw.Type) {
         case EventType.Sql:
             lock(_lockEvents)
                 Events.Add(SqlEventFactory.GetEvent(raw));
             break;
     }
 }
コード例 #11
0
ファイル: Event.cs プロジェクト: rexwhitten/edocs
 public BaseEvent(RawEvent raw)
 {
     Raw = raw;
 }
コード例 #12
0
        private SqlEvent() : this(null) { } // for serializer

        public SqlEvent(RawEvent raw) : base(raw)
        {
        }
コード例 #13
0
ファイル: Sql.cs プロジェクト: rexwhitten/edocs
        public static BaseEvent GetEvent(RawEvent raw)
        {
            if(raw.Type != EventType.Sql)
                throw new ArgumentException("Sql event expected");

            var ev = new SqlEvent(raw);

            string pool = raw.Header.Values[ValueKeys.Index];
            ev.ConnectionIndex = string.IsNullOrEmpty(pool) ? -1 : Convert.ToInt32(pool);
            ev.IsNew = raw.Header.Values[ValueKeys.IsNew];

            // TODO: f*****g edocs... Body is sometimes missing...
            SqlQueryEvent query = new SqlQueryEvent();
            foreach(var bodyLine in raw.Body) {
                if(bodyLine.RuleType == typeof(SqlBodyRule) || bodyLine.RuleType == typeof(SqlBodyNotifyRule)) {
                    query = new SqlQueryEvent();
                    query.Time = bodyLine.Values[ValueKeys.Time];
                    ev.Queries.Add(query);
                    //TODO: line index
                }
                /*else if(bodyLine.RuleType == typeof(SqlStatementRequiredRule.AutoCommitLineRule) {
                    query.AutoCommit = bodyLine.Content; // TODO: On or Off only
                }*/
                else if(bodyLine.RuleType == typeof(SqlStatementRequiredRule.StatementLineRule))
                    query.Command = bodyLine.Content;
                else if(bodyLine.RuleType == typeof(SqlBodyTimerReadItemRule))
                    query.DurationReadItem = bodyLine.Values[ValueKeys.Duration];
                else if(bodyLine.RuleType == typeof(SqlBodyTimerIssueCommandRule))
                    query.DurationIssueCommand = bodyLine.Values[ValueKeys.Duration];
            }
            return ev;
        }
コード例 #14
0
ファイル: Sql.cs プロジェクト: rexwhitten/edocs
 public SqlEvent(RawEvent raw)
     : base(raw)
 {
 }
コード例 #15
0
ファイル: LogParser.cs プロジェクト: rexwhitten/edocs
        private bool ProcessAsChunkBody(int index, RuleResult result, RawEvent raw, out int processedBodyLines)
        {
            processedBodyLines = 0;
            if(result.LineType != LineType.Body)
                return false;

            if(result.Key != raw.Key)
                return false;

            string key = result.Key;
            raw.Body.Add(new LogLine(index, result));

            //TODO require the RequiredRule
            if(result.RequiredBlockRule != null) {
                var blockResult = ProcessRequiredBodyBlock(index, result);
                if(blockResult != null) {
                    foreach(var pair in blockResult.LineRuleResults) {
                        int idx = pair.Key + index + 1;
                        raw.Body.Add(new LogLine(idx, pair.Value) { Content = GetLine(idx) });
                    }
                    processedBodyLines = blockResult.ProcessedCount;
                }
            }
            return true;
        }
コード例 #16
0
ファイル: LogParser.cs プロジェクト: rexwhitten/edocs
        private bool ProcessAsChunkHeader(int index, RuleResult result)
        {
            if(result.LineType != LineType.Header)
                return false;

            string key = result.Key;
            if(IncompleteChunks.ContainsKey(key)) {
                //IncompleteChunks.Remove(key);
                //I've modified regexps. Let's give edocs another try...
                RawEvent inc = IncompleteChunks[key];

                LogMessage("{5}: Found a new event header with the same key {0} before the footer of the previous event\n" +
                    "\tPrevious header at line {1}: {2}\n" +
                    "\tNew header at line {3}: {4}",
                    key, inc.Header.Index, GetLine(inc.Header.Index), index, GetLine(index), System.IO.Path.GetFileName(Log.FileName));
            }

            IncompleteChunks[key] = new RawEvent(key) { Header = new LogLine(index, result), Type = result.EventType };
            return true;
        }
コード例 #17
0
ファイル: Event.cs プロジェクト: wsharba/edocs
 public BaseEvent(RawEvent raw)
 {
     Raw = raw;
 }