Added a debug tool to view and manage log files. Slight tweaks to the main form as well as the thread exception methods.
This commit is contained in:
@@ -125,6 +125,12 @@
|
||||
<Compile Include="DebugDatabaseConverter.Designer.cs">
|
||||
<DependentUpon>DebugDatabaseConverter.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmLogFileViewer.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmLogFileViewer.Designer.cs">
|
||||
<DependentUpon>FrmLogFileViewer.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="FrmLoginForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -196,6 +202,9 @@
|
||||
<EmbeddedResource Include="FrmAddRecord.resx">
|
||||
<DependentUpon>FrmAddRecord.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmLogFileViewer.resx">
|
||||
<DependentUpon>FrmLogFileViewer.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="FrmLoginForm.resx">
|
||||
<DependentUpon>FrmLoginForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
partial class FrmLogFileViewer
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmLogFileViewer));
|
||||
this.mainLayoutPane = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.fileListTreeView = new System.Windows.Forms.TreeView();
|
||||
this.tabControl1 = new System.Windows.Forms.TabControl();
|
||||
this.friendlyViewTabPage = new System.Windows.Forms.TabPage();
|
||||
this.friendlyViewTextBox = new System.Windows.Forms.TextBox();
|
||||
this.rawViewTabPage = new System.Windows.Forms.TabPage();
|
||||
this.rawViewTextBox = new System.Windows.Forms.TextBox();
|
||||
this.selectedFileNameLabel = new System.Windows.Forms.Label();
|
||||
this.mainLayoutPane.SuspendLayout();
|
||||
this.tabControl1.SuspendLayout();
|
||||
this.friendlyViewTabPage.SuspendLayout();
|
||||
this.rawViewTabPage.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// mainLayoutPane
|
||||
//
|
||||
this.mainLayoutPane.ColumnCount = 2;
|
||||
this.mainLayoutPane.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
|
||||
this.mainLayoutPane.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 75F));
|
||||
this.mainLayoutPane.Controls.Add(this.tabControl1, 1, 1);
|
||||
this.mainLayoutPane.Controls.Add(this.fileListTreeView, 0, 1);
|
||||
this.mainLayoutPane.Controls.Add(this.selectedFileNameLabel, 0, 0);
|
||||
this.mainLayoutPane.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.mainLayoutPane.Location = new System.Drawing.Point(0, 0);
|
||||
this.mainLayoutPane.Name = "mainLayoutPane";
|
||||
this.mainLayoutPane.RowCount = 2;
|
||||
this.mainLayoutPane.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 40F));
|
||||
this.mainLayoutPane.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
|
||||
this.mainLayoutPane.Size = new System.Drawing.Size(1083, 756);
|
||||
this.mainLayoutPane.TabIndex = 0;
|
||||
//
|
||||
// fileListTreeView
|
||||
//
|
||||
this.fileListTreeView.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.fileListTreeView.Location = new System.Drawing.Point(3, 43);
|
||||
this.fileListTreeView.Name = "fileListTreeView";
|
||||
this.fileListTreeView.Size = new System.Drawing.Size(264, 710);
|
||||
this.fileListTreeView.TabIndex = 3;
|
||||
//
|
||||
// tabControl1
|
||||
//
|
||||
this.tabControl1.Controls.Add(this.friendlyViewTabPage);
|
||||
this.tabControl1.Controls.Add(this.rawViewTabPage);
|
||||
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tabControl1.Location = new System.Drawing.Point(273, 43);
|
||||
this.tabControl1.Name = "tabControl1";
|
||||
this.tabControl1.SelectedIndex = 0;
|
||||
this.tabControl1.Size = new System.Drawing.Size(807, 710);
|
||||
this.tabControl1.TabIndex = 2;
|
||||
//
|
||||
// friendlyViewTabPage
|
||||
//
|
||||
this.friendlyViewTabPage.Controls.Add(this.friendlyViewTextBox);
|
||||
this.friendlyViewTabPage.Location = new System.Drawing.Point(4, 33);
|
||||
this.friendlyViewTabPage.Name = "friendlyViewTabPage";
|
||||
this.friendlyViewTabPage.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.friendlyViewTabPage.Size = new System.Drawing.Size(799, 673);
|
||||
this.friendlyViewTabPage.TabIndex = 0;
|
||||
this.friendlyViewTabPage.Text = "Friendly View";
|
||||
this.friendlyViewTabPage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// friendlyViewTextBox
|
||||
//
|
||||
this.friendlyViewTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.friendlyViewTextBox.Location = new System.Drawing.Point(3, 3);
|
||||
this.friendlyViewTextBox.Multiline = true;
|
||||
this.friendlyViewTextBox.Name = "friendlyViewTextBox";
|
||||
this.friendlyViewTextBox.ReadOnly = true;
|
||||
this.friendlyViewTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.friendlyViewTextBox.Size = new System.Drawing.Size(793, 667);
|
||||
this.friendlyViewTextBox.TabIndex = 0;
|
||||
//
|
||||
// rawViewTabPage
|
||||
//
|
||||
this.rawViewTabPage.Controls.Add(this.rawViewTextBox);
|
||||
this.rawViewTabPage.Location = new System.Drawing.Point(4, 33);
|
||||
this.rawViewTabPage.Name = "rawViewTabPage";
|
||||
this.rawViewTabPage.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.rawViewTabPage.Size = new System.Drawing.Size(799, 673);
|
||||
this.rawViewTabPage.TabIndex = 1;
|
||||
this.rawViewTabPage.Text = "Raw View";
|
||||
this.rawViewTabPage.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// rawViewTextBox
|
||||
//
|
||||
this.rawViewTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.rawViewTextBox.Location = new System.Drawing.Point(3, 3);
|
||||
this.rawViewTextBox.Multiline = true;
|
||||
this.rawViewTextBox.Name = "rawViewTextBox";
|
||||
this.rawViewTextBox.ReadOnly = true;
|
||||
this.rawViewTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.rawViewTextBox.Size = new System.Drawing.Size(793, 667);
|
||||
this.rawViewTextBox.TabIndex = 0;
|
||||
//
|
||||
// selectedFileNameLabel
|
||||
//
|
||||
this.selectedFileNameLabel.AutoSize = true;
|
||||
this.selectedFileNameLabel.Location = new System.Drawing.Point(3, 0);
|
||||
this.selectedFileNameLabel.Name = "selectedFileNameLabel";
|
||||
this.selectedFileNameLabel.Size = new System.Drawing.Size(0, 25);
|
||||
this.selectedFileNameLabel.TabIndex = 4;
|
||||
//
|
||||
// FrmLogFileViewer
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(11F, 24F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1083, 756);
|
||||
this.Controls.Add(this.mainLayoutPane);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "FrmLogFileViewer";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Log File Viewer";
|
||||
this.mainLayoutPane.ResumeLayout(false);
|
||||
this.mainLayoutPane.PerformLayout();
|
||||
this.tabControl1.ResumeLayout(false);
|
||||
this.friendlyViewTabPage.ResumeLayout(false);
|
||||
this.friendlyViewTabPage.PerformLayout();
|
||||
this.rawViewTabPage.ResumeLayout(false);
|
||||
this.rawViewTabPage.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TableLayoutPanel mainLayoutPane;
|
||||
private System.Windows.Forms.TabControl tabControl1;
|
||||
private System.Windows.Forms.TabPage friendlyViewTabPage;
|
||||
private System.Windows.Forms.TextBox friendlyViewTextBox;
|
||||
private System.Windows.Forms.TabPage rawViewTabPage;
|
||||
private System.Windows.Forms.TextBox rawViewTextBox;
|
||||
private System.Windows.Forms.TreeView fileListTreeView;
|
||||
private System.Windows.Forms.Label selectedFileNameLabel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
public partial class FrmLogFileViewer : Form
|
||||
{
|
||||
private string _clickedNode;
|
||||
//Create the right-click context menu.
|
||||
private readonly ContextMenu _menu = new ContextMenu();
|
||||
private readonly MenuItem _item = new MenuItem("Delete File");
|
||||
public FrmLogFileViewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
RefreshLogFileListing();
|
||||
fileListTreeView.NodeMouseClick += NodeSelectionChangedOnMouseClick;
|
||||
_menu.MenuItems.Add(_item);
|
||||
_item.Click += DeleteFile;
|
||||
}
|
||||
|
||||
private void DeleteFile(object sender, EventArgs e)
|
||||
{
|
||||
if (_clickedNode == string.Empty) return;
|
||||
if (!File.Exists(_clickedNode)) return;
|
||||
if (_clickedNode != null) File.Delete(_clickedNode);
|
||||
RefreshLogFileListing();
|
||||
}
|
||||
|
||||
private void NodeSelectionChangedOnMouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
//Refresh the text boxes.
|
||||
ReadSelectedFile(e.Node.Index);
|
||||
}
|
||||
else if(e.Button == MouseButtons.Right)
|
||||
{
|
||||
_clickedNode = e.Node.Name;
|
||||
_menu.Show(fileListTreeView, e.Location);
|
||||
fileListTreeView.SelectedNode = e.Node;
|
||||
ReadSelectedFile(e.Node.Index);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshLogFileListing()
|
||||
{
|
||||
var fileNames = Directory.GetFiles(GlobalClasses.LogFilePath);
|
||||
fileListTreeView.Nodes.Clear();
|
||||
foreach (var fileName in fileNames)
|
||||
{
|
||||
var file = new FileInfo(fileName);
|
||||
var node = new TreeNode(file.Name) { Name = file.FullName };
|
||||
fileListTreeView.Nodes.Add(node);
|
||||
}
|
||||
|
||||
if (fileListTreeView.Nodes.Count <= 0) return;
|
||||
ReadSelectedFile();
|
||||
}
|
||||
|
||||
private void ReadSelectedFile(int selectedIndex = -1)
|
||||
{
|
||||
var lines = File.ReadAllLines(selectedIndex == -1 ? fileListTreeView.Nodes[0].Name : fileListTreeView.Nodes[selectedIndex].Name);
|
||||
selectedFileNameLabel.Text = selectedIndex == -1
|
||||
? fileListTreeView.Nodes[0].Text
|
||||
: fileListTreeView.Nodes[selectedIndex].Text;
|
||||
friendlyViewTextBox.Text = string.Empty;
|
||||
rawViewTextBox.Text = string.Empty;
|
||||
var lastCharWasWhiteSpace = false;
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (line == string.Empty)
|
||||
{
|
||||
rawViewTextBox.Text += Environment.NewLine;
|
||||
if (!lastCharWasWhiteSpace)
|
||||
{
|
||||
friendlyViewTextBox.Text += Environment.NewLine;
|
||||
}
|
||||
lastCharWasWhiteSpace = true;
|
||||
continue;
|
||||
}
|
||||
if (!line.Trim().StartsWith("at"))
|
||||
{
|
||||
friendlyViewTextBox.Text += line + Environment.NewLine;
|
||||
}
|
||||
rawViewTextBox.Text += line + Environment.NewLine;
|
||||
lastCharWasWhiteSpace = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+16
-6
@@ -108,6 +108,7 @@
|
||||
this.grossProfitEstimatedWeeklyDeptmartmentExpenseLabel = new System.Windows.Forms.Label();
|
||||
this.perfectGrossProfitLabel = new System.Windows.Forms.Label();
|
||||
this.grossProfitDollarGrossProfitLabel = new System.Windows.Forms.Label();
|
||||
this.viewLogsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.mainMenu.SuspendLayout();
|
||||
this.mainTableLayoutPanel.SuspendLayout();
|
||||
this.commentMainTableLayoutPanel.SuspendLayout();
|
||||
@@ -172,7 +173,7 @@
|
||||
// exitFileMainMenu
|
||||
//
|
||||
this.exitFileMainMenu.Name = "exitFileMainMenu";
|
||||
this.exitFileMainMenu.Size = new System.Drawing.Size(240, 34);
|
||||
this.exitFileMainMenu.Size = new System.Drawing.Size(138, 34);
|
||||
this.exitFileMainMenu.Text = "E&xit";
|
||||
this.exitFileMainMenu.Click += new System.EventHandler(this.ExitProgram);
|
||||
//
|
||||
@@ -280,13 +281,14 @@
|
||||
// dbVersionHelpMainMenu
|
||||
//
|
||||
this.dbVersionHelpMainMenu.Name = "dbVersionHelpMainMenu";
|
||||
this.dbVersionHelpMainMenu.Size = new System.Drawing.Size(304, 34);
|
||||
this.dbVersionHelpMainMenu.Text = "Get &Database Version";
|
||||
this.dbVersionHelpMainMenu.Size = new System.Drawing.Size(288, 34);
|
||||
this.dbVersionHelpMainMenu.Text = "&Verison Information";
|
||||
this.dbVersionHelpMainMenu.Click += new System.EventHandler(this.DisplayDatabaseVersionNumber);
|
||||
//
|
||||
// debugMainMenu
|
||||
//
|
||||
this.debugMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.viewLogsToolStripMenuItem,
|
||||
this.rawViewDebugMainMenu,
|
||||
this.migrateDatabaseDebugMainMenu,
|
||||
this.addRecordToolStripMenuItem});
|
||||
@@ -299,21 +301,21 @@
|
||||
//
|
||||
this.rawViewDebugMainMenu.Name = "rawViewDebugMainMenu";
|
||||
this.rawViewDebugMainMenu.Size = new System.Drawing.Size(270, 34);
|
||||
this.rawViewDebugMainMenu.Text = "Raw View";
|
||||
this.rawViewDebugMainMenu.Text = "Ra&w View";
|
||||
this.rawViewDebugMainMenu.Click += new System.EventHandler(this.DisplayRawDatabaseView);
|
||||
//
|
||||
// migrateDatabaseDebugMainMenu
|
||||
//
|
||||
this.migrateDatabaseDebugMainMenu.Name = "migrateDatabaseDebugMainMenu";
|
||||
this.migrateDatabaseDebugMainMenu.Size = new System.Drawing.Size(270, 34);
|
||||
this.migrateDatabaseDebugMainMenu.Text = "Migrate Database";
|
||||
this.migrateDatabaseDebugMainMenu.Text = "&Migrate Database";
|
||||
this.migrateDatabaseDebugMainMenu.Click += new System.EventHandler(this.DisplayDebugTool);
|
||||
//
|
||||
// addRecordToolStripMenuItem
|
||||
//
|
||||
this.addRecordToolStripMenuItem.Name = "addRecordToolStripMenuItem";
|
||||
this.addRecordToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.addRecordToolStripMenuItem.Text = "Add Record";
|
||||
this.addRecordToolStripMenuItem.Text = "Add Re&cord";
|
||||
this.addRecordToolStripMenuItem.Click += new System.EventHandler(this.DisplayLegacyAddRecord);
|
||||
//
|
||||
// mainTableLayoutPanel
|
||||
@@ -980,6 +982,13 @@
|
||||
this.grossProfitDollarGrossProfitLabel.TabIndex = 2;
|
||||
this.grossProfitDollarGrossProfitLabel.Text = "Dollar Gross Profit: ";
|
||||
//
|
||||
// viewLogsToolStripMenuItem
|
||||
//
|
||||
this.viewLogsToolStripMenuItem.Name = "viewLogsToolStripMenuItem";
|
||||
this.viewLogsToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
|
||||
this.viewLogsToolStripMenuItem.Text = "View &Logs";
|
||||
this.viewLogsToolStripMenuItem.Click += new System.EventHandler(this.DebugViewLogFiles);
|
||||
//
|
||||
// FrmMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F);
|
||||
@@ -1107,6 +1116,7 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem manageSuppliersToolsMainMenu;
|
||||
private System.Windows.Forms.ToolStripMenuItem clearCurrentRecordSelectedDateToolsMainMenu;
|
||||
private System.Windows.Forms.ToolStripMenuItem clearCurrentActiveYearTools;
|
||||
private System.Windows.Forms.ToolStripMenuItem viewLogsToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1099,5 +1099,11 @@ namespace AdvertsingProfitControl
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void DebugViewLogFiles(object sender, EventArgs e)
|
||||
{
|
||||
var form = new FrmLogFileViewer();
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AdvertsingProfitControl
|
||||
{
|
||||
class GlobalClasses
|
||||
internal class GlobalClasses
|
||||
{
|
||||
public static string LogFilePath = @"C:\Users\" + Environment.UserName + @"\AppData\Local\APC\";
|
||||
|
||||
public static void LogError(object sender, System.Threading.ThreadExceptionEventArgs e)
|
||||
{
|
||||
using (
|
||||
StreamWriter file =
|
||||
var file =
|
||||
new StreamWriter(@"C:\Users\" + Environment.UserName + @"\AppData\Local\APC\" + DateTime.Now.ToString("MM-dd-yyyy") + ".log", true))
|
||||
{
|
||||
file.WriteLine(DateTime.Now + ": Unhandled Thread Exception:\n" + e.Exception.Message + "\n" + e.Exception.StackTrace);
|
||||
MessageBox.Show("An unhandled thread exception has occurred. Advertising Profit Control will be forced to exit.",
|
||||
"Fatal Error");
|
||||
file.WriteLine(DateTime.Now + ": Unhandled Thread Exception:\n" + e.Exception.Message + Environment.NewLine);
|
||||
MessageBox.Show(@"An unhandled thread exception has occurred. Advertising Profit Control will be forced to exit.",
|
||||
@"Fatal Error");
|
||||
Application.Exit();
|
||||
}
|
||||
}
|
||||
@@ -27,12 +24,12 @@ namespace AdvertsingProfitControl
|
||||
public static void LogError(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
using (
|
||||
StreamWriter file =
|
||||
var file =
|
||||
new StreamWriter(@"C:\Users\" + Environment.UserName + @"\AppData\Local\APC\" + DateTime.Now.ToString("MM-dd-yyyy") + ".log", true))
|
||||
{
|
||||
file.WriteLine(DateTime.Now + ": An unhandled exception occurred. \nException Object: " + e.ExceptionObject);
|
||||
MessageBox.Show("And unknown error has occurred. Advertising Profit Control will be forced to exit.",
|
||||
"Fatal Error");
|
||||
file.WriteLine(DateTime.Now + ": An unhandled exception occurred. \nException Object: " + e.ExceptionObject + Environment.NewLine);
|
||||
MessageBox.Show(@"And unknown error has occurred. Advertising Profit Control will be forced to exit.",
|
||||
@"Fatal Error");
|
||||
Application.Exit();
|
||||
}
|
||||
}
|
||||
@@ -40,7 +37,7 @@ namespace AdvertsingProfitControl
|
||||
public static void WriteToLog(string message)
|
||||
{
|
||||
using (
|
||||
StreamWriter file =
|
||||
var file =
|
||||
new StreamWriter(@"C:\Users\" + Environment.UserName + @"\AppData\Local\APC\Information.log", true))
|
||||
{
|
||||
file.WriteLine(message);
|
||||
|
||||
Reference in New Issue
Block a user