Added Error Handling and Reporting
This commit is contained in:
@@ -60,8 +60,45 @@ namespace DataLoader
|
||||
Application.DoEvents();
|
||||
}
|
||||
}
|
||||
private frmErrors _MyFrmErrors = null;
|
||||
|
||||
public string tbSourceText { get { return tbSource.Text; } set { tbSource.Text = value; } }
|
||||
public frmErrors MyFrmErrors
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_MyFrmErrors == null)
|
||||
{
|
||||
_MyFrmErrors = new frmErrors(this);
|
||||
_MyFrmErrors.FormClosing += new FormClosingEventHandler(_MyFrmErrors_FormClosing);
|
||||
}
|
||||
return _MyFrmErrors;
|
||||
}
|
||||
}
|
||||
void _MyFrmErrors_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
_MyFrmErrors = null;
|
||||
}
|
||||
public string MyError
|
||||
{
|
||||
get { return tsslError.Text; }
|
||||
set { MyFrmErrors.Add(value); tsslError.Text = string.Format("{0} Errors", MyFrmErrors.MyErrors.Count); }
|
||||
}
|
||||
public void AddError(string format, params object[] objs)
|
||||
{
|
||||
MyError = string.Format(format, objs);
|
||||
}
|
||||
public void AddError(Exception ex, string format, params object[] objs)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder( string.Format(format, objs));
|
||||
int indent = 0;
|
||||
while (ex != null)
|
||||
{
|
||||
sb.Append("\r\n" + "".PadRight((++indent)*2,' ') + string.Format("{0} - {1}",ex.GetType().Name,ex.Message));
|
||||
ex=ex.InnerException;
|
||||
}
|
||||
MyError = sb.ToString();
|
||||
}
|
||||
public string tbSourceText { get { return tbSource.Text; } set { tbSource.Text = value; } }
|
||||
|
||||
public frmLoader()
|
||||
{
|
||||
@@ -184,23 +221,51 @@ namespace DataLoader
|
||||
ldr.ClearData();
|
||||
bool suc = ldr.LoadFolders(tbVePromsPath.Text);
|
||||
}
|
||||
private System.Diagnostics.Process [] WordProcesses
|
||||
{
|
||||
get
|
||||
{
|
||||
return System.Diagnostics.Process.GetProcessesByName("WINWORD");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnConvert_Click(object sender, System.EventArgs e)
|
||||
{
|
||||
Database.LoggingInfo = false;
|
||||
bool success = true;
|
||||
// if purge data, purge it all & reload folders & security.
|
||||
if (cbPurgeData.Checked)
|
||||
{
|
||||
ldr.ClearData();
|
||||
success = ldr.LoadFolders(tbVePromsPath.Text);
|
||||
if (success) success = ldr.LoadSecurity(tbVesamPath.Text, tbVePromsPath.Text);
|
||||
if (cbFormatsOnly.Checked)
|
||||
{
|
||||
MessageBox.Show("Formats Loaded");
|
||||
return;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Process[] wordProcesses = WordProcesses;
|
||||
MyFrmErrors.Clear();
|
||||
if (wordProcesses.Length > 0)
|
||||
{
|
||||
AddError("{0} copies of MS Word are running", wordProcesses.Length);
|
||||
if (MessageBox.Show("MS Word is Running and must be stopped", "MS Word is Running", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
TerminateProcesses(wordProcesses);
|
||||
MyFrmErrors.Clear();
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
Database.LoggingInfo = false;
|
||||
bool success = true;
|
||||
// if purge data, purge it all & reload folders & security.
|
||||
if (cbPurgeData.Checked)
|
||||
{
|
||||
Status = "Purging Data";
|
||||
ldr.ClearData();
|
||||
Status = "Loading Folders";
|
||||
success = ldr.LoadFolders(tbVePromsPath.Text);
|
||||
if (success)
|
||||
{
|
||||
Status = "Loading Security";
|
||||
success = ldr.LoadSecurity(tbVesamPath.Text, tbVePromsPath.Text);
|
||||
}
|
||||
if (cbFormatsOnly.Checked)
|
||||
{
|
||||
MessageBox.Show("Formats Loaded");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (success)
|
||||
{
|
||||
TimeSpan ts = new TimeSpan();
|
||||
@@ -211,7 +276,8 @@ namespace DataLoader
|
||||
if (vi.Title.ToUpper() == tbSource.Text.ToUpper()) // is this the procedure set we want to convert?
|
||||
{
|
||||
v = DocVersion.Get(vi.VersionID);
|
||||
ts+=ldr.MigrateDocVersion(v, true);
|
||||
Status = "Load " + v.Title + " - " + v.Name;
|
||||
ts += ldr.MigrateDocVersion(v, true);
|
||||
}
|
||||
//v = DocVersion.Get(vi.VersionID);
|
||||
//bool convertProcedures = (vi.Title.ToUpper() == tbSource.Text.ToUpper());
|
||||
@@ -220,7 +286,20 @@ namespace DataLoader
|
||||
}
|
||||
MessageBox.Show(string.Format("{0} seconds", ts.TotalSeconds));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AddError("===================== Fatal Error ==========================\r\n{0} - {1}", ex.GetType().Name, ex.Message);
|
||||
MessageBox.Show(ex.Message, "Fatal Error During Loading", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_MyLog.Fatal(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void TerminateProcesses(System.Diagnostics.Process [] wordProcesses)
|
||||
{
|
||||
foreach (System.Diagnostics.Process proc in wordProcesses)
|
||||
proc.Kill();
|
||||
}
|
||||
public void UpdateLabels(int incPrc, int incSec, int incStp)
|
||||
{
|
||||
if (incPrc == 0 && incSec == 0 && incStp == 0)//Reset
|
||||
@@ -241,6 +320,7 @@ namespace DataLoader
|
||||
catch (Exception ex)
|
||||
{
|
||||
_MyLog.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
|
||||
AddError(ex, "UpdateLabels");
|
||||
}
|
||||
}
|
||||
//Database.LoggingInfo = (pbProc.Value > 153 && pbSect.Value > 11 && pbStep.Value > 61);
|
||||
|
Reference in New Issue
Block a user