コード例 #1
0
        // Returns a populated DataTable or null if query throws an exception.
        // Can throw COMException on SQL syntax error
        public static DataTable runQuery(string q, object context, Func <int, bool> updateCallback = null)
        {
            var dt    = new DataTable();
            var lp    = new LogQueryClassClass();
            int count = 0;
            var run   = true;

            try
            {
                var ilr = lp.Execute(q, context);

                for (int i = 0; i < ilr.getColumnCount(); i++)
                {
                    dt.Columns.Add(new DataColumn(ilr.getColumnName(i)));
                }

                while (!ilr.atEnd() && run)
                {
                    var      rec = ilr.getRecord();
                    string[] row = new string[ilr.getColumnCount()];

                    for (int i = 0; i < ilr.getColumnCount(); i++)
                    {
                        row[i] = rec.getValue(i).ToString();
                    }

                    dt.Rows.Add(row);

                    // Only update every ~50 times to keep from lagging up the process too much.
                    if (updateCallback != null && (count++ % 53 == 0))
                    {
                        run = updateCallback(count);
                    }

                    ilr.moveNext();
                }

                if (updateCallback != null)
                {
                    updateCallback(count);
                }

                ilr.close();
            }
            catch
            {
                // LogParser doesn't call CloseInput on some sql syntax exceptions.
                // This can cause files to remain locked. So, we cleanup and rethrow.
                dynamic obj = (dynamic)context;

                if (obj.GetType().GetMethod("CloseInput") != null)
                {
                    obj.CloseInput(true);
                }

                throw;
            }

            return(dt);
        }
コード例 #2
0
        protected override int RunQuery(string query)
        {
            // Instantiate the LogQuery object
            var logQuery = new LogQueryClassClass();

            // cache the input context, only ask for it once
            if (myInputContext == null)
            {
                myInputContext = GetInputContext();
            }

            // Execute the query
            var rowcount   = 0;
            var oRecordSet = logQuery.Execute(query, myInputContext);

            // Browse the recordset
            for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
            {
                rowcount = Convert.ToInt32(oRecordSet.getRecord().toNativeString(""));
            }
            // Close the recordset
            oRecordSet.close();

            return(rowcount);
        }
コード例 #3
0
ファイル: IISLogReader.cs プロジェクト: oogg/IISLogToWcat
        public IEnumerable<WebTestRequest> GetRequests()
        {
            LogQueryClassClass logQuery = new LogQueryClassClass();
            COMIISW3CInputContextClassClass iisInputFormat = new COMIISW3CInputContextClassClass();

            string query = @"SELECT s-port, cs-method, cs-uri-stem, cs-uri-query FROM " + m_iisLogPath;

            ILogRecordset recordSet = logQuery.Execute(query, iisInputFormat);
            while (!recordSet.atEnd())
            {
                ILogRecord record = recordSet.getRecord();
                if (record.getValueEx("cs-method").ToString() == "GET")
                {
                    string path = record.getValueEx("cs-uri-stem").ToString();
                    string querystring = record.getValueEx("cs-uri-query").ToString();

                    var urlBuilder = new StringBuilder();
                    urlBuilder.Append(path);
                    if (!String.IsNullOrEmpty(querystring))
                    {
                        urlBuilder.Append("?");
                        urlBuilder.Append(querystring);
                    }

                    var request = new WebTestRequest(urlBuilder.ToString());
                    yield return request;
                }

                recordSet.moveNext();
            }

            recordSet.close();
        }
コード例 #4
0
        //TODO: add methods for other types
        // W3C - COMW3CInputContextClassClass
        // NCSA - COMIISNCSAInputContextClassClass


        private static DataTable Execute <T>(string query) where T : new()
        {
            LogQueryClassClass log       = new LogQueryClassClass();
            ILogRecordset      recordset = log.Execute(query, new T());
            ILogRecord         record    = null;

            DataTable dt          = new DataTable();
            Int32     columnCount = recordset.getColumnCount();

            for (int i = 0; i < columnCount; i++)
            {
                dt.Columns.Add(recordset.getColumnName(i), types[recordset.getColumnType(i) - 1]);
            }

            for (; !recordset.atEnd(); recordset.moveNext())
            {
                DataRow dr = dt.NewRow();

                record = recordset.getRecord();

                for (int i = 0; i < columnCount; i++)
                {
                    dr[i] = record.getValue(i);
                }
                dt.Rows.Add(dr);
            }
            return(dt);
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: modulexcite/LogParserPlusApp
        /// <summary>
        /// Returns a set of records from a Log Parser query.
        /// </summary>
        /// <param name="query">The full query to perform.</param>
        /// <param name="input">Input file format.</param>
        /// <returns>Record set from Log Parser.</returns>
        private ILogRecordset GetRecordSet(string query, Object input)
        {
            LogQueryClassClass logParser = new LogQueryClassClass();

            ILogRecordset rs;

            try {
                rs = logParser.Execute(query, input);
            } catch (FileNotFoundException) {
                MessageBox.Show("The FROM field is invalid. Please verify that the file(s) you wish to parse is entered correctly.");
                rs = logParser.Execute("SELECT TOP 0 '' FROM *.*", input);
            } catch (Exception ex) {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.GetType().ToString());
                rs = logParser.Execute("SELECT TOP 0 '' FROM *.*", input);
            }

            if (logParser != null)
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(logParser);
                logParser = null;
            }

            return(rs);
        }
コード例 #6
0
ファイル: IISLogParser.cs プロジェクト: dziedrius/EILA
 public void ParseLog(string query)
 {
     var logParser = new LogQueryClassClass();
     var logContext = new COMW3CInputContextClassClass();
     var outputContext = new COMCSVOutputContextClassClass { oDQuotes = @"AUTO" };
     logParser.ExecuteBatch(query, logContext, outputContext);
 }
コード例 #7
0
        public GatherResult GatherLogs()
        {
            var dynamicResults = new List<dynamic>();
            DateTime? lastLogEntryTime = null;
            var logQuery = new LogQueryClassClass();
            var inputFormat = new COMW3CInputContextClassClass();
            const string query = "SELECT TO_TIMESTAMP(date, time) AS [EventTime], * FROM '{0}' WHERE EventTime > TIMESTAMP('{1}','yyyy-MM-dd HH:mm:ss')";

            var results =
                logQuery.Execute(string.Format(query, logLocation, LastLogEntrySent.ToString("yyyy-MM-dd HH:mm:ss")), inputFormat);
            var columnNames = new List<string>();
            var columnCount = results.getColumnCount();
            for (var i = 0; i < columnCount; ++i)
            {
                columnNames.Add(results.getColumnName(i));
            }

            while (!results.atEnd())
            {
                var obj = new ExpandoObject();
                IDictionary<string, object> underObject = obj;
                underObject.Add("Source", "IisLog");
                underObject.Add("Devicename", Environment.MachineName);
                var record = results.getRecord();
                var filtered = false;
                for (var i = 0; i < columnCount; ++i)
                {
                    if (columnNames[i] == "cs(User-Agent)")
                    {
                        var userAgent = (string)record.getValue(i);
                        if (filters.Any(f => userAgent.IndexOf(f) != -1))
                        {
                            filtered = true;
                            break;
                        };
                    }

                    if (columnNames[i] == "EventTime")
                    {
                        var eventDate = DateTime.Parse(((DateTime)record.getValue(i)).ToString("o") + "Z").ToUniversalTime();
                        if (eventDate > LastLogEntrySent) lastLogEntryTime = eventDate;
                        underObject.Add(columnNames[i], eventDate.ToString("o"));
                    }
                    else
                    {
                        underObject.Add(columnNames[i], record.getValue(i));
                    }
                }
                if(!filtered)
                    dynamicResults.Add(underObject);
                results.moveNext();
            }
            return new GatherResult
                {
                    Logs = dynamicResults,
                    LastLogEntryTime = lastLogEntryTime
                };
        }
コード例 #8
0
        public ILogRecordset extractRawJson(String fileName)
        {
            LogQueryClass logQuery = new LogQueryClassClass();
            MSUtil.COMCSVInputContextClassClass inputFormat = new COMCSVInputContextClassClass();
            //C:\\Users\\jthomas\\Desktop\\SendGrid\\11_27-12_3\\11_15-11_18Output_30.csv' ";

            String strQuery = @"SELECT _raw FROM '" + fileName + "'";
            ILogRecordset results = logQuery.Execute(strQuery, inputFormat);
            return results;
        }
コード例 #9
0
        public ILogRecordset extractRawJson(String fileName)
        {
            LogQueryClass logQuery = new LogQueryClassClass();

            MSUtil.COMCSVInputContextClassClass inputFormat = new COMCSVInputContextClassClass();
            //C:\\Users\\jthomas\\Desktop\\SendGrid\\11_27-12_3\\11_15-11_18Output_30.csv' ";


            String        strQuery = @"SELECT _raw FROM '" + fileName + "'";
            ILogRecordset results  = logQuery.Execute(strQuery, inputFormat);

            return(results);
        }
コード例 #10
0
        public override IList<IResult> Get()
        {
            var rtn = new List<IResult>();
            const string CheckpointFile = @"checkpoint.lpc";

            var logParser = new LogQueryClassClass();
            var w3Clog = new COMIISW3CInputContextClass
            {
                iCheckpoint = CheckpointFile
            };

            var records = logParser.Execute(this.Sql, w3Clog);
            while (!records.atEnd())
            {
                var record = records.getRecord();
                rtn.Add(this.Map(record));
                records.moveNext();
            }
            return rtn;
        }
コード例 #11
0
        public static IReadOnlyList <int> QueryLogs(string fromClause, string whereClause)
        {
            var query = $"SELECT time-taken AS TimeTaken FROM {fromClause} WHERE {whereClause} ORDER BY TimeTaken";

            var timesTaken = new List <int>();

            var logParser = new LogQueryClassClass();
            var iisLog    = new COMIISW3CInputContextClassClass();

            var recordSet = logParser.Execute(query, iisLog);

            while (!recordSet.atEnd())
            {
                var recordRow = recordSet.getRecord();
                timesTaken.Add(Convert.ToInt32(recordRow.getValue(0)));

                recordSet.moveNext();
            }

            return(timesTaken);
        }
コード例 #12
0
        public ILogRecordset executeCommand()
        {
            // prepare LogParser Recordset & Record objects
            ILogRecordset rsLP  = null;
            ILogRecord    rowLP = null;

            LogQueryClassClass      LogParser = null;
            COMCSVInputContextClass W3Clog    = null;


            LogParser = new LogQueryClassClass();

            W3Clog = new COMCSVInputContextClass();

            try
            {
                //W3C Logparsing SQL. Replace this SQL query with whatever
                //you want to retrieve. The example below
                //will sum up all the bandwidth
                //Usage of a specific folder with name
                //"userID". Download Log Parser 2.2
                //from Microsoft and see sample queries.

                foreach (string s in logList)
                {
                    cmd = Utils.ReplaceFirst(cmd, s, "'" + currentDir + "\\Logs\\" + s + "'");
                }

                Debug.WriteLine(cmd);

                // run the query against W3C log
                rsLP = LogParser.Execute(cmd, W3Clog);
            }
            catch
            {
                throw;
            }
            return(rsLP);
        }
コード例 #13
0
        public GatherResult GatherLogs()
        {
            var          dynamicResults   = new List <dynamic>();
            DateTime?    lastLogEntryTime = null;
            var          logQuery         = new LogQueryClassClass();
            var          inputFormat      = new COMW3CInputContextClassClass();
            const string query            = "SELECT TO_TIMESTAMP(date, time) AS [EventTime], * FROM '{0}' WHERE EventTime > TIMESTAMP('{1}','yyyy-MM-dd HH:mm:ss')";

            var results =
                logQuery.Execute(string.Format(query, logLocation, LastLogEntrySent.ToString("yyyy-MM-dd HH:mm:ss")), inputFormat);
            var columnNames = new List <string>();
            var columnCount = results.getColumnCount();

            for (var i = 0; i < columnCount; ++i)
            {
                columnNames.Add(results.getColumnName(i));
            }

            while (!results.atEnd())
            {
                var obj = new ExpandoObject();
                IDictionary <string, object> underObject = obj;
                underObject.Add("Source", "IisLog");
                underObject.Add("Devicename", Environment.MachineName);
                var record   = results.getRecord();
                var filtered = false;
                for (var i = 0; i < columnCount; ++i)
                {
                    if (columnNames[i] == "cs(User-Agent)")
                    {
                        var userAgent = (string)record.getValue(i);
                        if (filters.Any(f => userAgent.IndexOf(f) != -1))
                        {
                            filtered = true;
                            break;
                        }
                        ;
                    }

                    if (columnNames[i] == "EventTime")
                    {
                        var eventDate = DateTime.Parse(((DateTime)record.getValue(i)).ToString("o") + "Z").ToUniversalTime();
                        if (eventDate > LastLogEntrySent)
                        {
                            lastLogEntryTime = eventDate;
                        }
                        underObject.Add(columnNames[i], eventDate.ToString("o"));
                    }
                    else
                    {
                        underObject.Add(columnNames[i], record.getValue(i));
                    }
                }
                if (!filtered)
                {
                    dynamicResults.Add(underObject);
                }
                results.moveNext();
            }
            return(new GatherResult
            {
                Logs = dynamicResults,
                LastLogEntryTime = lastLogEntryTime
            });
        }
コード例 #14
0
 private static void Parse(string checkpointFile, string strSQL)
 {
     var logParser = new LogQueryClassClass();
     var w3Clog = new COMIISW3CInputContextClass
         {
             iCheckpoint = checkpointFile
         };
     var logRecordset = logParser.Execute(strSQL, w3Clog);
     while (!logRecordset.atEnd())
     {
         var logRecord = logRecordset.getRecord();
         //Console.WriteLine(logRecord.getValue(0).GetType());
         //Console.WriteLine(logRecord.getValue(1).GetType());
         //Console.WriteLine(string.Format("{0} {1}", logRecord.getValue(0), logRecord.getValue(1)));
         logRecordset.moveNext();
     }
 }
コード例 #15
0
ファイル: Form1.cs プロジェクト: jnribelles/LogParserPlusApp
		/// <summary>
		/// Returns a set of records from a Log Parser query.
		/// </summary>
		/// <param name="query">The full query to perform.</param>
		/// <param name="input">Input file format.</param>
		/// <returns>Record set from Log Parser.</returns>
		private ILogRecordset GetRecordSet(string query, Object input) {
			LogQueryClassClass logParser = new LogQueryClassClass();

			ILogRecordset rs;
			try {
				rs = logParser.Execute(query, input);
			} catch (FileNotFoundException) {
				MessageBox.Show("The FROM field is invalid. Please verify that the file(s) you wish to parse is entered correctly.");
				rs = logParser.Execute("SELECT TOP 0 '' FROM *.*", input);
			} catch (Exception ex) {
				MessageBox.Show(ex.Message);
				MessageBox.Show(ex.GetType().ToString());
				rs = logParser.Execute("SELECT TOP 0 '' FROM *.*", input);
			}

			if (logParser != null) {
				System.Runtime.InteropServices.Marshal.ReleaseComObject(logParser);
				logParser = null;
			}

			return rs;
		}
コード例 #16
0
        private static void ExecuteBatch(string query, object Input, object Output)
        {
            LogQueryClassClass log = new LogQueryClassClass();

            log.ExecuteBatch(query, Input, Output);
        }
コード例 #17
0
        // todo: check for parse errors
        private static void ExectuteBatch <T>(string query) where T : new()
        {
            LogQueryClassClass log = new LogQueryClassClass();

            log.ExecuteBatch(query, new T());
        }