From 0a6f171f83ed211106acf421b88562d4baed44ea Mon Sep 17 00:00:00 2001 From: John Date: Thu, 12 Aug 2010 16:01:34 +0000 Subject: [PATCH] --- .../Properties/AssemblyInfo.cs | 35 ++++ PROMS/Volian.Base.Library/VlnSettings.cs | 54 +++++ .../Volian.Base.Library.csproj | 70 +++++++ .../Volian.Base.Library.csproj.vspscc | 10 + PROMS/Volian.Base.Library/vlnStackTrace.cs | 195 ++++++++++++++++++ 5 files changed, 364 insertions(+) create mode 100644 PROMS/Volian.Base.Library/Properties/AssemblyInfo.cs create mode 100644 PROMS/Volian.Base.Library/VlnSettings.cs create mode 100644 PROMS/Volian.Base.Library/Volian.Base.Library.csproj create mode 100644 PROMS/Volian.Base.Library/Volian.Base.Library.csproj.vspscc create mode 100644 PROMS/Volian.Base.Library/vlnStackTrace.cs diff --git a/PROMS/Volian.Base.Library/Properties/AssemblyInfo.cs b/PROMS/Volian.Base.Library/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..c7bb2ad3 --- /dev/null +++ b/PROMS/Volian.Base.Library/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Volian.Base.Library")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Volian.Base.Library")] +[assembly: AssemblyCopyright("Copyright © 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6de1141c-643a-40dd-b296-06eeff462603")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PROMS/Volian.Base.Library/VlnSettings.cs b/PROMS/Volian.Base.Library/VlnSettings.cs new file mode 100644 index 00000000..7dfdf6a0 --- /dev/null +++ b/PROMS/Volian.Base.Library/VlnSettings.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace Volian.Base.Library +{ + public static class VlnSettings + { + // This is used to toggle the colored text during the Data Conversion + // and will set the font and background in PROMS 2010 for Demo/Release mode (white background black text) + // or for Debug mode (shaded background, and color text on PDF output + // For PROMS 2010, this is set via the App.config setting: + // + // + // For DataLoader, this is set via the Debug checkbox on the form. + + private static bool _DebugMode = true; + + public static bool DebugMode + { + get { return _DebugMode; } + set { _DebugMode = value; } + } + private static string _TemporaryFolder = null; + public static string TemporaryFolder + { + get + { + if (_TemporaryFolder == null) + { + // This will create a Temp\VE-PROMS folder in the LocalSettings Folder. + //XP - C:\Documents and Settings\{user}\Local Settings\Application Data\Temp\VE-PROMS + //Vista - C:\Users\{user}\AppData\Local\Temp\VE-PROMS + _TemporaryFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Temp"; + if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); + _TemporaryFolder += @"\VE-PROMS"; + if (!Directory.Exists(TemporaryFolder)) Directory.CreateDirectory(TemporaryFolder); + } + return _TemporaryFolder; + } + } + // used for Debug mode (at least for now) + // this is where the PDF 16-bit VE-PROMS output is placed and merge (via layers) into the PROMS 2010 PDF Output + private static string _OldPDFFolder = @"C:\Temp\16bit"; + + public static string OldPDFFolder + { + get { return VlnSettings._OldPDFFolder; } + set { VlnSettings._OldPDFFolder = value; } + } + + } +} diff --git a/PROMS/Volian.Base.Library/Volian.Base.Library.csproj b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj new file mode 100644 index 00000000..30e1c073 --- /dev/null +++ b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj @@ -0,0 +1,70 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {AEEE9FD1-6892-45E2-A67E-418C06D46FF9} + Library + Properties + Volian.Base.Library + Volian.Base.Library + SAK + SAK + SAK + SAK + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\Debug\ + DEBUG;TRACE + full + x86 + prompt + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PROMS/Volian.Base.Library/Volian.Base.Library.csproj.vspscc b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj.vspscc new file mode 100644 index 00000000..b6d32892 --- /dev/null +++ b/PROMS/Volian.Base.Library/Volian.Base.Library.csproj.vspscc @@ -0,0 +1,10 @@ +"" +{ +"FILE_VERSION" = "9237" +"ENLISTMENT_CHOICE" = "NEVER" +"PROJECT_FILE_RELATIVE_PATH" = "" +"NUMBER_OF_EXCLUDED_FILES" = "0" +"ORIGINAL_PROJECT_FILE_PATH" = "" +"NUMBER_OF_NESTED_PROJECTS" = "0" +"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER" +} diff --git a/PROMS/Volian.Base.Library/vlnStackTrace.cs b/PROMS/Volian.Base.Library/vlnStackTrace.cs new file mode 100644 index 00000000..093d264c --- /dev/null +++ b/PROMS/Volian.Base.Library/vlnStackTrace.cs @@ -0,0 +1,195 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Diagnostics; + +namespace Volian.Base.Library +{ + // This provides a more robust stack trace than what visual studio offers + public static class vlnStackTrace + { + public static string GetStack(string str, params object[] objects) + { + return string.Format(str, objects) + StackToString(); + } + public static void ShowStack(string str, params object[] objects) + { + Console.WriteLine(string.Format(str, objects) + StackToString()); + } + public static string GetStack() + { + return StackToString(); + } + public static void ShowStack() + { + Console.WriteLine(StackToString()); + } + private static string StackToString() + { + StringBuilder sb = new StringBuilder(); + StackTrace st = new StackTrace(true); + StackFrame[] sfs = st.GetFrames(); + int ii = 0; + string sLast = ""; + string sThis = ""; + int imax = MatchingStackFrame(sfs); + foreach (StackFrame sf in sfs) + { + if (imax == 0) + sb.Append(string.Format("\r\n{0}---------", "".PadLeft(ii++ * 2))); + imax--; + if (ii < 2) ii++; + else + { + string sMethod = sf.GetMethod().Name; + string sNamespace = sf.GetMethod().ReflectedType.Namespace; + string sType = sf.GetMethod().ReflectedType.Name; + if (sf.GetFileLineNumber() != 0) + { + sMethod += string.Format(" {0}[{1}]", sf.GetFileName(), sf.GetFileLineNumber()); + sThis = ""; + } + else + { + sThis = sNamespace; + } + if (sLast == sThis && sThis != "") + sb.Append(string.Format("\t*.{0}.{1}", sType, sMethod)); + else + sb.Append(string.Format("\r\n{0}{1}.{2}.{3}", "".PadLeft(ii++ * 2), sNamespace, sType, sMethod)); + } + sLast = sThis; + } + return sb.ToString(); + } + public static void ShowStackFirstLocal(string str) + { + Console.WriteLine(str + " " + StackToStringLocal(3,0)); + } + public static void ShowStackLocal(string str,int start) + { + Console.WriteLine(str + " " + StackToStringLocal(start,1)); + } + public static void ShowStackLocal(string str,int start, int limit) + { + Console.WriteLine(str + " " + StackToStringLocal(start, limit)); + } + private static string StackToStringLocal(int start, int limit) + { + StringBuilder sb = new StringBuilder(); + string sep = "Local Method - "; + StackTrace st = new StackTrace(true); + StackFrame[] sfs = st.GetFrames(); + int count = 0; + int localCount = 0; + foreach (StackFrame sf in sfs) + { + count++; + if (count > start) + { + if (sf.GetFileLineNumber() != 0) + { + string sMethod = sf.GetMethod().Name; + string sNamespace = sf.GetMethod().ReflectedType.Namespace; + string sType = sf.GetMethod().ReflectedType.Name; + sMethod += string.Format(" {0}[{1}]", sf.GetFileName(), sf.GetFileLineNumber()); + sb.Append(sep + string.Format("{0}.{1}.{2}", sNamespace, sType, sMethod)); + localCount ++; + if (localCount >= limit) + return sb.ToString(); + sep = "\r\n" + "".PadRight(localCount *2); + } + } + } + if (localCount > 0) + return sb.ToString(); + return "No Local Method"; + } + public static string CalledFrom + { + get + { + StackTrace st = new StackTrace(true); + StackFrame[] sfs = st.GetFrames(); + int count = 0; + foreach (StackFrame sf in sfs) + { + if (sf.GetFileLineNumber() != 0) + { + count++; + { + string sMethod = sf.GetMethod().Name; + string sNamespace = sf.GetMethod().ReflectedType.Namespace; + string sType = sf.GetMethod().ReflectedType.Name; + sMethod += string.Format(" {0}[{1}]", sf.GetFileName(), sf.GetFileLineNumber()); + if (count > 3) + return string.Format("{0}.{1}.{2}", sNamespace, sType, sMethod); + } + } + } + return "No Local Method"; + } + } + private static StackFrame[] _LastSFS; + private static int MatchingStackFrame(StackFrame[] sfs) + { + int iFound = -1; + if (_LastSFS != null) + { + // start at the far end and work backward + for (int i = 1; iFound < 0 && i <= sfs.Length && i <= _LastSFS.Length; i++) + { + if (!Match(sfs[sfs.Length - i],_LastSFS[_LastSFS.Length - i])) + iFound = 1+ sfs.Length - i; + } + } + if (iFound < 0) iFound = sfs.Length; + _LastSFS = (StackFrame[])sfs.Clone(); + return iFound; + } + + private static bool Match(StackFrame stackFrame1, StackFrame stackFrame2) + { + if (stackFrame1.GetMethod().Name != stackFrame2.GetMethod().Name) return false; + if (stackFrame1.GetMethod().DeclaringType.FullName != stackFrame2.GetMethod().DeclaringType.FullName) return false; + if (stackFrame1.GetILOffset() != stackFrame2.GetILOffset()) return false; + return true; + } + public static bool ScrollInStack() + { + StackTrace st = new StackTrace(true); + StackFrame[] sfs = st.GetFrames(); + bool retval = false; + foreach (StackFrame sf in sfs) + { + string sMethod = sf.GetMethod().Name; + string sNamespace = sf.GetMethod().ReflectedType.Namespace; + string sType = sf.GetMethod().ReflectedType.Name; + if (sMethod.ToUpper().Contains("SCROLL") || sType.ToUpper().Contains("SCROLL")) + { + retval = true; + Console.WriteLine("{0}.{1}.{2}", sNamespace, sType, sMethod); + } + } + return retval; + } + /// + /// This will clear the Output window when run in the Development Environment + /// Add EnvDTE and EnvDTE80 to references from .NET + /// + public static void ClearOutputWindow() + { +#if (DEBUG) + try + { + EnvDTE80.DTE2 dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0"); + dte2.ToolWindows.OutputWindow.ActivePane.Clear(); + } + catch (Exception ex) + { + Console.WriteLine("ClearOutputWindow {0} - {1}\r\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace); + } +#endif + } + } +}