From 2c14e4113bf57302cc9651e55154d13f411e29e3 Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 21 Apr 2010 20:55:28 +0000 Subject: [PATCH] Added Error Handling code Added a new parameter to SaveSectionDocument and Error Handling Changed error handling for InvokeMember to throw an exception Added code to change the view to PrintMode when determining length --- PROMS/DataLoader/Procedures.cs | 47 ++++++++++++++++++------ PROMS/DataLoader/Sections.cs | 4 +- PROMS/LBWordLibrary/LBComObject.cs | 10 +---- PROMS/LBWordLibrary/LBObjectExtension.cs | 4 +- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/PROMS/DataLoader/Procedures.cs b/PROMS/DataLoader/Procedures.cs index 4ca09ae3..d0294f1b 100644 --- a/PROMS/DataLoader/Procedures.cs +++ b/PROMS/DataLoader/Procedures.cs @@ -79,16 +79,7 @@ namespace DataLoader // 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); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - //Application.Exit(); - throw ex; // Exit from Data Loader - } + TryToLoadDataSet(ds, fname, dapsi); int handleAfter = HandleCount; if (!RunWithDB2K && handleAfter - handleBefore > 10) { @@ -268,6 +259,40 @@ namespace DataLoader ds.Dispose(); return itm; } + + private static void TryToLoadDataSet(DataSet ds, string fname, OleDbDataAdapter dapsi) + { + try + { + dapsi.Fill(ds); + } + catch (Exception ex) + { + FileInfo fi; + switch (ex.Message) + { + case "Index file not found.":// then delete inf file + fi = new FileInfo(fname.ToLower().Replace(".dbf",".inf")); + fi.Delete(); + TryToLoadDataSet(ds, fname, dapsi); // Try again + break; + case "External table is not in the expected format.": // then pad dbt file with 128 zeros. + fi = new FileInfo(fname.ToLower().Replace(".dbf", ".dbt")); + FileStream fs = fi.OpenWrite(); + fs.Position = fs.Length; + byte[] buf = new byte[128]; + for (int i = 0; i < 128; i++) buf[i] = 0; + fs.Write(buf, 0, 128); + fs.Close(); + TryToLoadDataSet(ds, fname, dapsi); // Try again + break; + default: // Unrecognized error + Console.WriteLine(ex.Message); + //Application.Exit(); + throw new Exception("Error in MigrateProcedure: " + fname, ex); + } + } + } private bool dB2KInstalled() { Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"software\dBase\dB2K"); @@ -316,7 +341,7 @@ namespace DataLoader catch (Exception ex) { _MyLog.ErrorFormat("MigrateProcedures - {0} - {1}\r\n\r\n{2}", pth,ex.Message, ex.InnerException); - throw ex; + throw new Exception("Error in MigrateProcedures: " + pth, ex); } return FirstItm; } diff --git a/PROMS/DataLoader/Sections.cs b/PROMS/DataLoader/Sections.cs index cfef8d25..da145e34 100644 --- a/PROMS/DataLoader/Sections.cs +++ b/PROMS/DataLoader/Sections.cs @@ -71,7 +71,7 @@ namespace DataLoader string thenum = num.ToString("d2"); fname = string.Format("{0}\\rtffiles\\{1}.A{2}", pth, ProcFileName, thenum); Application.DoEvents(); - SaveSectionDocument(fname, stpseq, SecType, ref Documentid); + SaveSectionDocument(fname, stpseq, SecType, ref Documentid, procitem.DisplayNumber + ":" + (Number == string.Empty ? Title : Number)); if (Documentid == 0) { if (MissingDocument==null) MissingDocument = Document.MakeDocument("MISSING FILE IN CONVERSION", null, null, null); @@ -453,6 +453,8 @@ namespace DataLoader } } Item secitem = AddSection(procitem, num, title, stype, dts, init, ci, step + sequence, fmt, libDocid, pth, FromItem, sectFormat); + if (secitem == null) + throw (new Exception("Null parameter in AddSection")); thesectid = secitem.ItemID; // if the editsectid hasn't been set yet, set it to this section id, i.e. the first diff --git a/PROMS/LBWordLibrary/LBComObject.cs b/PROMS/LBWordLibrary/LBComObject.cs index bef0b734..7b29c048 100644 --- a/PROMS/LBWordLibrary/LBComObject.cs +++ b/PROMS/LBWordLibrary/LBComObject.cs @@ -42,15 +42,7 @@ namespace LBWordLibrary } catch (Exception ex) { - StringBuilder sb = new StringBuilder(); - sb.Append(string.Format("{0}.{1} {2} - {3}", _MyType.Name, name, bf.ToString(), ex.GetType().Name)); - string prefix = "\r\n "; - do - { - sb.Append(prefix + ex.Message); - ex = ex.InnerException; - } while (ex != null); - Console.WriteLine(sb.ToString()); + throw new Exception(string.Format("LBComObject.DoInvokeMember {0}.{1}", _MyType.Name, name), ex); } return null; } diff --git a/PROMS/LBWordLibrary/LBObjectExtension.cs b/PROMS/LBWordLibrary/LBObjectExtension.cs index 449385a0..0718c1f3 100644 --- a/PROMS/LBWordLibrary/LBObjectExtension.cs +++ b/PROMS/LBWordLibrary/LBObjectExtension.cs @@ -263,6 +263,8 @@ namespace LBWordLibrary { get { + ActiveWindow.ActivePane.View.Type = LBWdViewType.wdPrintView; + ActiveWindow.View.Type = LBWdViewType.wdPrintView; LBPages myPages = ActiveWindow.ActivePane.Pages;// Start with pages float retval = (float)myPages.Count - 1; LBRange myRange = Range(); @@ -485,7 +487,7 @@ namespace LBWordLibrary string previous = LBDocumentClass.GetRangeText(myRange); if (Regex.IsMatch(previous, "[A-Z]")) return true; if (Regex.IsMatch(previous, "[a-z]")) return false; - start = start - 1; + start = start - 1; } return false; }