Added Error Handling and Reporting

This commit is contained in:
Rich
2009-11-04 17:15:29 +00:00
parent cd04644e2f
commit f26cc50c3c
13 changed files with 265 additions and 86 deletions

View File

@@ -29,12 +29,18 @@ namespace DataLoader
public static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//public static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
public static int HandleCount
{
get { return System.Diagnostics.Process.GetCurrentProcess().HandleCount; }
}
private bool RunWithDB2K = false;
private Item MigrateProcedure(OleDbConnection cn, DataRow dr, Item FromItem, string pth, DocVersion docver, bool convertProcedures)
{
dicOldStepSequence = new Dictionary<object, string>();
Stack<int> SubSectLevels = new Stack<int>(); // levels of subsections
ProcFileName = dr["Entry"].ToString();
ProcNumber = dr["Number"].ToString();
frmMain.Status = "Processing Procedure " + ProcNumber + " - " + ProcFileName;
DateTime dts = GetDTS(dr["Date"].ToString(), dr["Time"].ToString());
string userid = dr["initials"].ToString().Trim();
if (userid == null || userid == "") userid = "Migration";
@@ -72,6 +78,7 @@ namespace DataLoader
DbtOk(dr["entry"].ToString(),pth);
// See if there is PSI and if so, add it to the xml.
OleDbDataAdapter dapsi = new OleDbDataAdapter("select * from [" + dr["entry"] + "] where [STEP] is null", cn);
int handleBefore = HandleCount;
try
{
dapsi.Fill(ds);
@@ -79,7 +86,26 @@ namespace DataLoader
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Application.Exit();
//Application.Exit();
throw ex; // Exit from Data Loader
}
int handleAfter = HandleCount;
if (!RunWithDB2K && handleAfter - handleBefore > 10)
{
string msg = "It appears that handles are being created and not cleared.";
if (dB2KInstalled())
{
msg += "\r\n\r\nThis is most likely because dB2K is installed." +
"\r\n\r\nUninstall dB2K and run again.";
if (MessageBox.Show(msg + "\r\n\r\nDo you want to continue?", "Run with dB2K",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
RunWithDB2K = true;
}
else
{
msg += "\r\n\r\nCall Volian for support.";
}
if (!RunWithDB2K)throw new Exception(msg);
}
dt = ds.Tables[0];
@@ -140,7 +166,7 @@ namespace DataLoader
foreach(ItemInfo ii in dvi.Procedures){
if (ii.MyContent.Number == number)
{
Console.WriteLine(number);
//Console.WriteLine(number);
itm = ii.Get();
cont = ii.MyContent.Get();
}
@@ -173,6 +199,7 @@ namespace DataLoader
{
log.ErrorFormat("{0}\r\n\r\n{1}", ex.Message, ex.InnerException);
log.Error(ex.StackTrace);
frmMain.AddError(ex, "MigrateProcedure - {0}", ProcFileName);
}
da.Dispose();
@@ -237,6 +264,13 @@ namespace DataLoader
ds.Dispose();
return itm;
}
private bool dB2KInstalled()
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"software\dBase\dB2K");
bool retval = key != null;
key.Close();
return retval;
}
private Item MigrateProcedures(OleDbConnection cn, string pth, DocVersion docver, bool convertProcedures)
{
Item FirstItm = null;
@@ -260,6 +294,7 @@ namespace DataLoader
catch (Exception ex)
{
_MyLog.ErrorFormat("MigrateProcedures - {0} - {1}\r\n\r\n{2}", pth,ex.Message, ex.InnerException);
throw ex;
}
return FirstItm;
}