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

@@ -36,9 +36,17 @@ namespace DataLoader
string path = "c:\\development\\fmtall\\" + format + "all.xml";
if (File.Exists(path))
{
xd = new XmlDocument();
xd.Load(path);
fmtdata = xd.OuterXml;
try
{
xd = new XmlDocument();
xd.Load(path);
fmtdata = xd.OuterXml;
}
catch(Exception ex)
{
frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path);
return null;
}
}
// Do we need genmac - only if non-subformat
@@ -47,9 +55,17 @@ namespace DataLoader
path = "c:\\development\\genmacall\\" + format + ".svg";
if (File.Exists(path))
{
XmlDocument xdg = new XmlDocument();
xdg.Load(path);
genmacdata = xdg.OuterXml;
try
{
XmlDocument xdg = new XmlDocument();
xdg.Load(path);
genmacdata = xdg.OuterXml;
}
catch (Exception ex)
{
frmMain.AddError(ex, "AddFormatToDB('{0}','{1}')", parent.Name, path);
return null;
}
}
}
// Get the name & then create the record.
@@ -79,7 +95,7 @@ namespace DataLoader
// Load base format.
basefmt = AddFormatToDB(null, "base", false, DateTime.Now, "Migration");
if (basefmt == null) return;
// now loop through all files... If there is an _ in the name, it's a subformat
// (for example, AEP_00.xml) skip it in main loop, it's handled for each format.
DirectoryInfo di = new DirectoryInfo(@"c:\development\fmtall");
@@ -95,28 +111,33 @@ namespace DataLoader
try
{
parent = AddFormatToDB(basefmt, fmtname, issub, DateTime.Now, "Migration");
// now see if there are any subformats associated with this, if so
// add them here...
DirectoryInfo sdi = new DirectoryInfo("c:\\development\\fmtall");
FileInfo[] sfis = di.GetFiles(fmtname + "_*.xml");
foreach (FileInfo sfi in sfis)
if (parent != null)
{
string nm = sfi.Name.Substring(0, sfi.Name.Length - 7);
Console.WriteLine("Processing {0}", sfi.Name);
try
// now see if there are any subformats associated with this, if so
// add them here...
DirectoryInfo sdi = new DirectoryInfo("c:\\development\\fmtall");
FileInfo[] sfis = di.GetFiles(fmtname + "_*.xml");
foreach (FileInfo sfi in sfis)
{
Format subfmt = AddFormatToDB(parent, nm, true, DateTime.Now, "Migration");
}
catch (Exception ex)
{
Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
string nm = sfi.Name.Substring(0, sfi.Name.Length - 7);
//Console.WriteLine("Processing {0}", sfi.Name);
frmMain.Status = string.Format("Processing Format {0}", sfi.Name);
try
{
AddFormatToDB(parent, nm, true, DateTime.Now, "Migration");
}
catch (Exception ex)
{
frmMain.AddError(ex, "LoadAllFormats() '{0}'", sfi.Name);
//Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
frmMain.AddError(ex, "LoadAllFormats() '{0}'", fi.Name);
//Console.WriteLine("{0} - {1}", ex.GetType().Name, ex.Message);
}
}
}
@@ -152,7 +173,8 @@ namespace DataLoader
catch (Exception ex)
{
log.ErrorFormat("Error getting xml version of format {0}", ex.Message);
}
frmMain.AddError(ex, "GetFormat('{0}')", format);
}
FormatInfo recInfo = FormatInfo.Get(rec.FormatID);
return recInfo;
}