mirror of
https://github.com/cyberark/RPCMon
synced 2026-06-06 15:34:28 +00:00
Adding import (from JSON) and export(from JSON) option.
This commit is contained in:
Generated
+58
-13
@@ -33,6 +33,10 @@
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.importToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.importAllDataToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.importAsIsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.importToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.dBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.loadDBToolStripMenuItemLoadDB = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.buildDBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
@@ -47,8 +51,8 @@
|
||||
this.toolStripButtonFind = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButtonHighlight = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButtonGrid = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButtonAutoScroll = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButtonRemoveDuplicate = new System.Windows.Forms.ToolStripButton();
|
||||
this.toolStripButtonAutoScroll = new System.Windows.Forms.ToolStripButton();
|
||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
||||
this.ColumnPID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnTID = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
@@ -97,7 +101,9 @@
|
||||
// fileToolStripMenuItem
|
||||
//
|
||||
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.saveToolStripMenuItem});
|
||||
this.saveToolStripMenuItem,
|
||||
this.importToolStripMenuItem,
|
||||
this.importToolStripMenuItem1});
|
||||
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
|
||||
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
|
||||
this.fileToolStripMenuItem.Text = "File";
|
||||
@@ -105,10 +111,40 @@
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(107, 22);
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
|
||||
this.saveToolStripMenuItem.Text = "Save...";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||
//
|
||||
// importToolStripMenuItem
|
||||
//
|
||||
this.importToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.importAllDataToolStripMenuItem,
|
||||
this.importAsIsToolStripMenuItem});
|
||||
this.importToolStripMenuItem.Name = "importToolStripMenuItem";
|
||||
this.importToolStripMenuItem.Size = new System.Drawing.Size(119, 22);
|
||||
this.importToolStripMenuItem.Text = "Export";
|
||||
//
|
||||
// importAllDataToolStripMenuItem
|
||||
//
|
||||
this.importAllDataToolStripMenuItem.Name = "importAllDataToolStripMenuItem";
|
||||
this.importAllDataToolStripMenuItem.Size = new System.Drawing.Size(161, 22);
|
||||
this.importAllDataToolStripMenuItem.Text = "Export All Data...";
|
||||
this.importAllDataToolStripMenuItem.Click += new System.EventHandler(this.exportAllDataToolStripMenuItem_Click);
|
||||
//
|
||||
// importAsIsToolStripMenuItem
|
||||
//
|
||||
this.importAsIsToolStripMenuItem.Name = "importAsIsToolStripMenuItem";
|
||||
this.importAsIsToolStripMenuItem.Size = new System.Drawing.Size(161, 22);
|
||||
this.importAsIsToolStripMenuItem.Text = "Export As Is...";
|
||||
this.importAsIsToolStripMenuItem.Click += new System.EventHandler(this.exportAsIsToolStripMenuItem_Click);
|
||||
//
|
||||
// importToolStripMenuItem1
|
||||
//
|
||||
this.importToolStripMenuItem1.Name = "importToolStripMenuItem1";
|
||||
this.importToolStripMenuItem1.Size = new System.Drawing.Size(119, 22);
|
||||
this.importToolStripMenuItem1.Text = "Import...";
|
||||
this.importToolStripMenuItem1.Click += new System.EventHandler(this.importToolStripMenuItem1_Click);
|
||||
//
|
||||
// dBToolStripMenuItem
|
||||
//
|
||||
this.dBToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
@@ -242,6 +278,16 @@
|
||||
this.toolStripButtonGrid.Text = "Show Grid";
|
||||
this.toolStripButtonGrid.Click += new System.EventHandler(this.toolStripButtonGrid_Click);
|
||||
//
|
||||
// toolStripButtonRemoveDuplicate
|
||||
//
|
||||
this.toolStripButtonRemoveDuplicate.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.toolStripButtonRemoveDuplicate.Image = global::RPCMon.Properties.Resources.duplicate_disable;
|
||||
this.toolStripButtonRemoveDuplicate.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.toolStripButtonRemoveDuplicate.Name = "toolStripButtonRemoveDuplicate";
|
||||
this.toolStripButtonRemoveDuplicate.Size = new System.Drawing.Size(24, 24);
|
||||
this.toolStripButtonRemoveDuplicate.Text = "Remove Duplicate Rows";
|
||||
this.toolStripButtonRemoveDuplicate.Click += new System.EventHandler(this.toolStripButtonRemoveDuplicate_Click);
|
||||
//
|
||||
// toolStripButtonAutoScroll
|
||||
//
|
||||
this.toolStripButtonAutoScroll.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
@@ -253,18 +299,9 @@
|
||||
this.toolStripButtonAutoScroll.ToolTipText = "Auto Scroll";
|
||||
this.toolStripButtonAutoScroll.Click += new System.EventHandler(this.toolStripButtonAutoScroll_Click);
|
||||
//
|
||||
// toolStripButtonRemoveDuplicate
|
||||
//
|
||||
this.toolStripButtonRemoveDuplicate.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
this.toolStripButtonRemoveDuplicate.Image = global::RPCMon.Properties.Resources.duplicate_disable;
|
||||
this.toolStripButtonRemoveDuplicate.ImageTransparentColor = System.Drawing.Color.Magenta;
|
||||
this.toolStripButtonRemoveDuplicate.Name = "toolStripButtonRemoveDuplicate";
|
||||
this.toolStripButtonRemoveDuplicate.Size = new System.Drawing.Size(24, 24);
|
||||
this.toolStripButtonRemoveDuplicate.Text = "Remove Duplicate Rows";
|
||||
this.toolStripButtonRemoveDuplicate.Click += new System.EventHandler(this.toolStripButtonRemoveDuplicate_Click);
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
this.dataGridView1.AllowDrop = true;
|
||||
this.dataGridView1.AllowUserToAddRows = false;
|
||||
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
@@ -295,6 +332,8 @@
|
||||
this.dataGridView1.TabIndex = 3;
|
||||
this.dataGridView1.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseClick);
|
||||
this.dataGridView1.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_ColumnHeaderMouseClick);
|
||||
this.dataGridView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.dataGridView1_DragDrop);
|
||||
this.dataGridView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.dataGridView1_DragEnter);
|
||||
//
|
||||
// ColumnPID
|
||||
//
|
||||
@@ -400,6 +439,7 @@
|
||||
//
|
||||
// statusStrip1
|
||||
//
|
||||
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelTotalEvents,
|
||||
this.toolStripStatusLabelDBPath});
|
||||
@@ -426,6 +466,7 @@
|
||||
//
|
||||
// contextMenuStripRightClickGridView
|
||||
//
|
||||
this.contextMenuStripRightClickGridView.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.contextMenuStripRightClickGridView.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.copyRowToolStripMenuItem,
|
||||
this.copyCellToolStripMenuItem});
|
||||
@@ -518,6 +559,10 @@
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn ColumnImpersonationLevel;
|
||||
private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem setDbgHelpFilePathToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem importAllDataToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem importAsIsToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem importToolStripMenuItem1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+127
-2
@@ -17,6 +17,7 @@ using Microsoft.Diagnostics.Tracing.Parsers.MicrosoftWindowsRPC;
|
||||
using RPCMon.Control;
|
||||
using System.Reflection;
|
||||
using System.Security.Principal;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace RPCMon
|
||||
{
|
||||
@@ -1123,9 +1124,133 @@ namespace RPCMon
|
||||
checkIdDBGHelpExist();
|
||||
}
|
||||
|
||||
|
||||
private void exportAllDataToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath = saveFilePath();
|
||||
if (filePath == "") return;
|
||||
JArray data = new JArray();
|
||||
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||||
{
|
||||
JObject rowData = new JObject();
|
||||
foreach (DataGridViewColumn col in dataGridView1.Columns)
|
||||
{
|
||||
rowData[col.HeaderText] = (string)row.Cells[col.Index].Value;
|
||||
}
|
||||
data.Add(rowData);
|
||||
}
|
||||
string json = data.ToString();
|
||||
File.WriteAllText(filePath, json);
|
||||
MessageBox.Show("Export Completed!");
|
||||
}
|
||||
|
||||
private void exportAsIsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath = saveFilePath();
|
||||
if(filePath == "") return;
|
||||
JArray data = new JArray();
|
||||
foreach (DataGridViewRow row in dataGridView1.Rows)
|
||||
{
|
||||
if (row.Visible)
|
||||
{
|
||||
JObject rowData = new JObject();
|
||||
rowData["Highlighted"] = row.DefaultCellStyle.BackColor != Color.White;
|
||||
rowData["Bold"] = row.DefaultCellStyle.Font.Bold;
|
||||
foreach (DataGridViewColumn col in dataGridView1.Columns)
|
||||
{
|
||||
rowData[col.HeaderText] = (string)row.Cells[col.Index].Value;
|
||||
|
||||
}
|
||||
data.Add(rowData);
|
||||
}
|
||||
|
||||
}
|
||||
string json = data.ToString();
|
||||
File.WriteAllText(filePath, json);
|
||||
MessageBox.Show("Export Completed!");
|
||||
}
|
||||
private string saveFilePath()
|
||||
{
|
||||
string filePath = "";
|
||||
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
|
||||
saveFileDialog1.Filter = "JSON files|*.json";
|
||||
saveFileDialog1.Title = "Save as JSON File";
|
||||
|
||||
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
filePath = saveFileDialog1.FileName;
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
private void importToolStripMenuItem1_Click(object sender, EventArgs e)
|
||||
{
|
||||
string fileName = "";
|
||||
OpenFileDialog openFileDialog1 = new OpenFileDialog();
|
||||
openFileDialog1.Title = "Select a JSON file";
|
||||
openFileDialog1.Filter = "JSON files|*.json";
|
||||
|
||||
if (openFileDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
fileName = openFileDialog1.FileName;
|
||||
}
|
||||
if(fileName == "") return;
|
||||
importFile(fileName);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void dataGridView1_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effect = DragDropEffects.All;
|
||||
}
|
||||
|
||||
private void dataGridView1_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
|
||||
importFile(fileList[0]);
|
||||
|
||||
}
|
||||
|
||||
private void importFile(string fileName)
|
||||
{
|
||||
string json = File.ReadAllText(fileName);
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> data = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(json);
|
||||
foreach (Dictionary<string, object> item in data)
|
||||
{
|
||||
DataGridViewRow row = new DataGridViewRow();
|
||||
foreach (KeyValuePair<string, object> pair in item)
|
||||
{
|
||||
if (pair.Key.Equals("Highlighted"))
|
||||
{
|
||||
row.DefaultCellStyle.BackColor = pair.Value.Equals(false) ? Color.White : Color.Cyan;
|
||||
continue;
|
||||
}
|
||||
else if (pair.Key.Equals("Bold"))
|
||||
{
|
||||
row.DefaultCellStyle.Font = pair.Value.Equals(true) ? new System.Drawing.Font(this.Font, FontStyle.Bold) : new System.Drawing.Font(this.Font, FontStyle.Regular);
|
||||
continue;
|
||||
}
|
||||
DataGridViewCell cell = new DataGridViewTextBoxCell();
|
||||
cell.Value = pair.Value;
|
||||
row.Cells.Add(cell);
|
||||
}
|
||||
|
||||
dataGridView1.Rows.Add(row);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Invalid File!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
MessageBox.Show("Import Completed!", "Import Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
private void updateToolStripStatusLabelDBPath(string i_DBPath)
|
||||
{
|
||||
{
|
||||
this.toolStripStatusLabelDBPath.Text = "DB File: " + Path.GetFileName(this.m_RPCDBPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user