Exemple #1
0
 void dataAddThread()
 {
     try
     {
         while (true)
         {
             waitHandle.WaitOne();
             if (dataQueue.Count > 10)
             {
                 while (dataQueue.Count > 0)
                 {
                     System.Process.ProcessStatistics.process_statistics procStats = dataQueue.Dequeue();
                     addSqlData(procStats);
                 }
             }
             Thread.Sleep(10);
         }
     }
     catch (ThreadAbortException ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
     }
 }
Exemple #2
0
        public bool addData(System.Process.ProcessStatistics.process_statistics procStats)
        {
            bool bRet = false;

            try
            {
                //string txtSQLQuery = "insert into  processes (desc) values ('" + txtDesc.Text + "')";
                //ExecuteQuery(txtSQLQuery);
                object[] o = new object[] {
                    procStats.remoteIP,
                    procStats.processID,
                    procStats.sName,
                    procStats.procUsage.user,
                    procStats.procUsage.kernel,
                    new DateTime(procStats.dateTime),
                    procStats.duration,
                    0,
                };

                //some data for the live view
                lastUserValue  += procStats.procUsage.user;
                lastUserMeasure = new DateTime(procStats.dateTime);

                DataRow dr;
                //check if data already exists
                dr = dsProcesses.Tables[0].Rows.Find(procStats.processID.ToString());
                if (dr == null)
                {   //add a new row
                    dr           = dtProcesses.NewRow();
                    dr.ItemArray = o;
                    dtProcesses.Rows.Add(dr);
                }
                else
                {
                    dr.ItemArray = o;
                }

                dr.AcceptChanges();
                dtProcesses.AcceptChanges();
                dsProcesses.AcceptChanges();
                bRet = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("addData Exception: " + ex.Message);
            }
            return(bRet);
        }
Exemple #3
0
        //see also http://www.techcoil.com/blog/my-experience-with-system-data-sqlite-in-c/
        public void addSqlData(System.Process.ProcessStatistics.process_statistics procStats)
        {
            //System.Diagnostics.Debug.WriteLine(procStats.dumpStatistics());

            long rowID = 0; //last inserted row

            #region Process_data
            //build a list of field names of process table
            if (FieldsProcessTable.Length == 0)
            {
                //StringBuilder
                //FieldsProcessTable = new StringBuilder();
                for (int ix = 0; ix < _fieldsProcess.Length; ix++)
                {
                    FieldsProcessTable.Append(_fieldsProcess[ix].FieldName);
                    if (ix < _fieldsProcess.Length - 1)
                    {
                        FieldsProcessTable.Append(", ");
                    }
                }
            }

            StringBuilder FieldsProcessValues = new StringBuilder();
            FieldsProcessValues.Append("'" + procStats.remoteIP + "', ");
            FieldsProcessValues.Append(procStats.processID.ToString() + ", ");
            FieldsProcessValues.Append("'" + procStats.sName + "', ");
            FieldsProcessValues.Append(procStats.procUsage.user.ToString() + ", ");
            FieldsProcessValues.Append(procStats.procUsage.kernel.ToString() + ", ");
            FieldsProcessValues.Append(procStats.dateTime.ToString() + ", ");
            FieldsProcessValues.Append(procStats.duration.ToString() + ", ");
            FieldsProcessValues.Append("NULL");    //add an idx although it is autoincrement

            string sqlStatement = "INSERT INTO processes " +
                                  "(" +
                                  FieldsProcessTable +
                                  ")" +
                                  " VALUES(" +
                                  FieldsProcessValues.ToString() +
                                  ")";

            rowID = executeNonQuery(sqlStatement);
            #endregion

            #region Threads_data
            if (FieldsThreadsTable.Length == 0)
            {
                for (int ix = 0; ix < _fieldsThread.Length; ix++)
                {
                    FieldsThreadsTable.Append(_fieldsThread[ix].FieldName);
                    if (ix < _fieldsThread.Length - 1)
                    {
                        FieldsThreadsTable.Append(", ");
                    }
                }
            }

            StringBuilder FieldsThreadValues            = new StringBuilder();
            System.Process.threadStatistic[] threadList = procStats.ThreadStatList.ToArray();
            for (int it = 0; it < threadList.Length; it++)
            {
                FieldsThreadValues = new StringBuilder();
                FieldsThreadValues.Append(threadList[it].dwThreadID.ToString() + ", ");
                FieldsThreadValues.Append(threadList[it].dwOwnerProcID.ToString() + ", ");
                FieldsThreadValues.Append(threadList[it].thread_times.user.ToString() + ", ");
                FieldsThreadValues.Append(threadList[it].thread_times.kernel.ToString() + ", ");

                FieldsThreadValues.Append(threadList[it].duration.ToString() + ", ");
                FieldsThreadValues.Append(threadList[it].timestamp.ToString() + ", ");
                FieldsThreadValues.Append(rowID.ToString());

                sqlStatement = "INSERT INTO Threads " +
                               "(" +
                               FieldsThreadsTable +
                               ")" +
                               " VALUES(" +
                               FieldsThreadValues.ToString() +
                               ")";
                executeNonQuery(sqlStatement);
            }
            #endregion
        }