Пример #1
0
        public static DataTable GetData(string queryST, ref string retErr)
        {
            DataTable EventDT = new DataTable("EventDT");

            try
            {
                // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the Event Log Input Format object
                EventLogInputFormat oEVTInputFormat = new EventLogInputFormat();

                // Set its "direction" parameter to "BW"
                oEVTInputFormat.direction = "BW";

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(queryST, oEVTInputFormat);

                int i = 0;

                for (; i < oRecordSet.getColumnCount(); i++)
                {
                    string colnm;
                    colnm = oRecordSet.getColumnName(i);

                    EventDT.Columns.Add(new DataColumn(colnm, typeof(string)));
                }

                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    MSUtil.ILogRecord rowLP = null;
                    rowLP = oRecordSet.getRecord();

                    // populate holding table with site name & summary bytes for the period
                    DataRow dr = EventDT.NewRow();
                    for (int ct = 0; ct < i; ct++)
                    {
                        dr[ct] = rowLP.getValue(ct);
                    }
                    EventDT.Rows.Add(dr);
                }


                // Close the recordset
                oRecordSet.close();
            }
            catch (Exception exc)
            {
                retErr = "Unexpected error: " + exc.Message;
            }

            return(EventDT);
        }
Пример #2
0
        public static DataTable FSquery(string queryST, ref string retErr)
        {
            DataTable resultsDT = new DataTable("resultsDT");

            try
            {
                // Instantiate the LogQuery object
                LogQuery oLogQuery = new LogQuery();

                // Instantiate the File System Input Format object
                FileSystemInputFormat oFSInputFormat = new MSUtil.COMFileSystemInputContextClassClass();

                // Execute the query
                LogRecordSet oRecordSet = oLogQuery.Execute(queryST, oFSInputFormat);
                int          i          = 0;
                for (; i < oRecordSet.getColumnCount(); i++)
                {
                    string colnm;
                    colnm = oRecordSet.getColumnName(i);

                    resultsDT.Columns.Add(new DataColumn(colnm, typeof(string)));
                }

                for (; !oRecordSet.atEnd(); oRecordSet.moveNext())
                {
                    MSUtil.ILogRecord rowLP = null;
                    rowLP = oRecordSet.getRecord();

                    DataRow dr = resultsDT.NewRow();
                    for (int ct = 0; ct < i; ct++)
                    {
                        dr[ct] = rowLP.getValue(ct);
                    }
                    resultsDT.Rows.Add(dr);
                }

                // Close the recordset
                oRecordSet.close();
            }
            catch (Exception exc)
            {
                retErr = "Unexpected error: " + exc.Message;
            }

            return(resultsDT);
        }
Пример #3
0
        public QueryResult Execute()
        {
            lock (syncRoot)
            {
                this.isRunning = true;
            }
            Stopwatch watch = Stopwatch.StartNew();

            //if (this.logQuery != null)
            //{
            //    System.Runtime.InteropServices.Marshal.ReleaseComObject(this.logQuery);
            //    GC.SuppressFinalize(this.logQuery);
            //    this.logQuery = null;
            //}

            //this.logQuery = new MSUtil.LogQueryClassClass();

            this.results = null;
            QueryResult queryResult = new QueryResult();


            //MSUtil.COMChartOutputContextClassClass outPutFormat = new MSUtil.COMChartOutputContextClassClass();
            //outPutFormat.chartType = "PieExploded3D";
            //outPutFormat.view = true;

//			MSUtil.COMXMLOutputContextClassClass outPutFormat = new MSUtil.COMChartOutputContextClassClass();
//			this.logQuery.ExecuteBatch(Text, this.inputFormat, outPutFormat);
//			return null;


            MSUtil.ILogRecordset recordset = this.logQuery.Execute(Text, this.inputFormat);


            // TODO throw event on query finished

            bool columnsExtracted = false;
            long unitProcessed    = 0;

            // Browse the recordset
            for (; !recordset.atEnd() && unitProcessed < this.maxUnitsInResults /* && !cancelComputing.WaitOne(0,false) */; recordset.moveNext())
            {
                MSUtil.ILogRecord record = recordset.getRecord();

                // Remplissage des colonnes
                if (!columnsExtracted)
                {
                    for (int c = 0; c < recordset.getColumnCount(); c++)
                    {
                        DataColumn col = new DataColumn(recordset.getColumnName(c));
                        //object logRecord = record.getValueEx(c);
                        switch (recordset.getColumnType(c))
                        {
                        case 1:                                  // int32
                            col.DataType = typeof(int);
                            break;

                        case 2:                                  // double
                            col.DataType = typeof(double);
                            break;

                        case 4:                                  // datetime
                            col.DataType = typeof(DateTime);
                            break;

                        default:
                            col.DataType = typeof(string);
                            break;
                        }

                        queryResult.DataTable.Columns.Add(col);
                    }
                    columnsExtracted = true;
                }

                // on insert les datas
                DataRow dr = queryResult.DataTable.NewRow();
                dr[0] = record.getValue(0).ToString();

                //dataTableResults.ExtendedProperties.Add("source", record.getValue(0).ToString());

                for (int c = 1; c < recordset.getColumnCount(); c++)
                {
                    if (record.getValue(c) != DBNull.Value)
                    {
                        dr[c] = record.getValue(c).ToString();
                    }
                }
                //logQuery.inputUnitsProcessed;
                unitProcessed++;
                queryResult.DataTable.Rows.Add(dr);
                // MainForm.StatusBar.Text = string.Format("Computing in progress ... {0} line(s)",unitProcessed);
            }
            // MainForm.StatusBar.Text = string.Format("{0} input units processed",recordset.inputUnitsProcessed);
            recordset.close();


            queryResult.Duration = watch.Elapsed;

            lock (syncRoot)
            {
                this.isRunning = false;
            }
            this.results = queryResult;
            return(this.results);
        }
Пример #4
0
        public static QueryResult Execute(string query, string inputName, Dictionary <PropertyInfo, object> properties)
        {
            Stopwatch watch             = Stopwatch.StartNew();
            int       maxUnitsInResults = 5000;       // TODO add this to user settings

            MSUtil.LogQueryClassClass logQuery = new MSUtil.LogQueryClassClass();

            QueryResult queryResult = new QueryResult();

            object inputFormat = SqalpApplication.Inputs[inputName].CreateInstance();

            foreach (PropertyInfo propertyInfo in properties.Keys)
            {
                try
                {
                    propertyInfo.SetValue(inputFormat, properties[propertyInfo], null);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }


            MSUtil.ILogRecordset recordset = logQuery.Execute(query, inputFormat);

            bool columnsExtracted = false;
            long unitProcessed    = 0;

            // Browse the recordset
            for (; !recordset.atEnd() && unitProcessed < maxUnitsInResults /* && !cancelComputing.WaitOne(0,false) */; recordset.moveNext())
            {
                MSUtil.ILogRecord record = recordset.getRecord();

                // Remplissage des colonnes
                if (!columnsExtracted)
                {
                    for (int c = 0; c < recordset.getColumnCount(); c++)
                    {
                        DataColumn col = new DataColumn(recordset.getColumnName(c));
                        //object logRecord = record.getValueEx(c);
                        switch (recordset.getColumnType(c))
                        {
                        case 1:                                 // int32
                            col.DataType = typeof(int);
                            break;

                        case 2:                                 // double
                            col.DataType = typeof(double);
                            break;

                        case 4:                                 // datetime
                            col.DataType = typeof(DateTime);
                            break;

                        default:
                            col.DataType = typeof(string);
                            break;
                        }

                        queryResult.DataTable.Columns.Add(col);
                    }
                    columnsExtracted = true;
                }

                // on insert les datas
                DataRow dr = queryResult.DataTable.NewRow();
                dr[0] = record.getValue(0).ToString();

                //dataTableResults.ExtendedProperties.Add("source", record.getValue(0).ToString());

                for (int c = 1; c < recordset.getColumnCount(); c++)
                {
                    if (record.getValue(c) != DBNull.Value)
                    {
                        dr[c] = record.getValue(c).ToString();
                    }
                }
                //logQuery.inputUnitsProcessed;
                unitProcessed++;
                queryResult.DataTable.Rows.Add(dr);
                // MainForm.StatusBar.Text = string.Format("Computing in progress ... {0} line(s)",unitProcessed);
            }
            // MainForm.StatusBar.Text = string.Format("{0} input units processed",recordset.inputUnitsProcessed);
            recordset.close();


            queryResult.Duration = watch.Elapsed;

            if (logQuery != null)
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(logQuery);
                GC.SuppressFinalize(logQuery);
                logQuery = null;
            }

            return(queryResult);
        }