public bool addData(VMusage.procVMinfo vmInfo) { bool bRet = false; try { //string txtSQLQuery = "insert into processes (desc) values ('" + txtDesc.Text + "')"; //ExecuteQuery(txtSQLQuery); object[] o = new object[]{ vmInfo.remoteIP, vmInfo.name, vmInfo.memusage, vmInfo.slot, vmInfo.procID, new DateTime(vmInfo.Time), 0, }; DataRow dr; //check if data already exists dr = dsVMUsage.Tables[0].Rows.Find(vmInfo.name); if (dr == null) { //add a new row dr = dtVMUsage.NewRow(); dr.ItemArray = o; dtVMUsage.Rows.Add(dr); } else dr.ItemArray = o; dr.AcceptChanges(); dtVMUsage.AcceptChanges(); dsVMUsage.AcceptChanges(); bRet = true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("addData Exception: " + ex.Message); } return bRet; }
//see also http://www.techcoil.com/blog/my-experience-with-system-data-sqlite-in-c/ public void addSqlData(VMusage.procVMinfo procVMStats) { //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("'" + procVMStats.remoteIP + "', "); FieldsProcessValues.Append("'" + procVMStats.name.ToString()+"', "); FieldsProcessValues.Append("'" + procVMStats.memusage.ToString() + "', "); FieldsProcessValues.Append("'" + procVMStats.slot.ToString() + "', "); FieldsProcessValues.Append(procVMStats.procID.ToString() + ", "); FieldsProcessValues.Append(procVMStats.Time.ToString() + ", "); FieldsProcessValues.Append("NULL"); //add an idx although it is autoincrement string sqlStatement = "INSERT INTO VMUsage " + "(" + FieldsProcessTable + ")" + " VALUES(" + FieldsProcessValues.ToString() + ")"; rowID = executeNonQuery(sqlStatement); #endregion }
void recvr_onUpdateMem(object sender, VMusage.MemoryInfoHelper data) { addLog(data.ToString()); }
void recvr_onUpdate(object sender, VMusage.procVMinfo data) { System.Diagnostics.Debug.WriteLine("recvr_onUpdate() called"); //string s = data.processID.ToString() + ", " + // data.sName + ", " + // data.procUsage.user.ToString() + ", " + // data.duration.ToString(); ////addLog(s); //System.Diagnostics.Debug.WriteLine( data.dumpStatistics() ); addData(data); }
void addData(VMusage.procVMinfo vmdata) { if (this.dataGridView1.InvokeRequired) { addDataCallback d = new addDataCallback(addData); this.Invoke(d, new object[] { vmdata }); } else { System.Diagnostics.Debug.WriteLine("addData() called"); dataGridView1.SuspendLayout(); //enqueue data to be saved to sqlite dataQueue.Enqueue(vmdata); if (bAllowGUIupdate) { //dataAccess.addSqlData(procStats); //dtProcesses.Rows.Clear(); dataAccess.addData(vmdata); //release queue data dataAccess.waitHandle.Set(); //object[] o = new object[7]{ procUsage.procStatistics. .procStatistics. [i].sApp, eventEntries[i].sArg, eventEntries[i].sEvent, // eventEntries[i].sStartTime, eventEntries[i].sEndTime, eventEntries[i].sType, eventEntries[i].sHandle }; } dataGridView1.Refresh(); dataGridView1.ResumeLayout(); } }
private void updateStatus(VMusage.procVMinfo data) { //System.Diagnostics.Debug.WriteLine("updateStatus: " + data.dumpStatistics()); if (this.onUpdate != null) this.onUpdate(this, data); }
void listener_onUpdate(object sender, VMusage.procVMinfo data) { updateStatus(data); }