my DebugHelper and TraceHelper classes

I’ve posted a few code snippets and some people noticed that there are references to unresolved methods. I am using a few helper classes. This post describes my DebugHelper and TraceHelper classes. 

namespace FSHelperLib

{

    using Microsoft.VisualBasic;

    using Microsoft.VisualBasic.CompilerServices;

    using System;

    using System.Collections;

    using System.Data;

    using System.Data.SqlClient;

    using System.Diagnostics;

      using System.Collections.Specialized ;

      using System.IO;

    using System.Net;

    using System.Runtime.CompilerServices;

    using System.Runtime.InteropServices;

    using System.Web.SessionState;

    using System.Web.UI;

    using System.Windows.Forms;

 

      public class DebugHelper : TraceHelper

      {

            // Methods

            public DebugHelper()

            {

            }

 

            public static void LogToFile(Exception exc, string path, bool append)

            {

                  // string text1;

                  StreamWriter writer1 = new StreamWriter(path, append);

                  writer1.AutoFlush = true;

                  Debug.WriteLine(exc.ToString());

                  writer1.WriteLine(TraceHelper.LineWithTrace(DateTime.Now.ToString()));

                  writer1.WriteLine(TraceHelper.LineWithTrace(exc.ToString()));

                  writer1.Close();

                  //return text1;

            }

 

            [Conditional(“DEBUG”)]

            public static void Print(BindingMemberInfo bInfo, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine(TraceString(bInfo, sComment));

            }

 

            [Conditional(“DEBUG”)]

            public static void Print(ControlBindingsCollection bindings, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine(TraceString(bindings, sComment));

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintBindingMemberInfo(System.Windows.Forms.Control container, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine(BindingMemberInfoAsString(container, sComment));

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintChildren(System.Web.UI.Control container, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine(ChildrenAsString(container, sComment));

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintConstraints(DataTable tbl, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  Debug.WriteLine(“Table: “ + tbl.TableName);

                  foreach (Constraint constraint1 in tbl.Constraints )

                  {

                        Debug.WriteLine(constraint1.ToString());

                  }

            }

            [Conditional(“DEBUG”)]

            public static void PrintCookies(  string url, CookieContainer container)

            {

                  PrintCookies( new Uri(url),container );

            }

            [Conditional(“DEBUG”)]

            public static void PrintCookies(   Uri uri      ,CookieContainer container)

            {

                  if (container==null)

                  {

                        DebugHelper.TracedLine (“CookieContainer is null”);

                        return;

                  }

                  System.Net.CookieCollection cookies = container.GetCookies(uri);

                  PrintCookies(cookies,“PrintCookies for Uri “ + uri.ToString() );

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintCookies(CookieCollection cookies, string sComment)

            {

                  PrintCookies( cookies,  sComment,OutputLevel.Brief);

            }

            [Conditional(“DEBUG”)]

            public static void PrintCookies(CookieCollection cookies, string sComment,OutputLevel level)

            {

                  PrintIfNotEmpty(sComment);

                  Debug.WriteLine(“Cookies collection. Count=” + cookies.Count.ToString());

                       

                  // Print the properties of each cookie.

                  foreach (Cookie cookie1 in cookies )

                  {

                        if(level>OutputLevel.Brief )

                        {

                              Debug.WriteLine(string.Format(“{0} = {1}”, cookie1.Name, cookie1.Value));

                              Debug.WriteLine(“Domain: {0}”, cookie1.Domain);

                              Debug.WriteLine(“Path: {0}”, cookie1.Path);

                              Debug.WriteLine(“Port: {0}”, cookie1.Port);

                              Debug.WriteLine(string.Format(“Secure: {0}”, cookie1.Secure));

                              Debug.WriteLine(string.Format(“When issued: {0}”, cookie1.TimeStamp));

                              Debug.WriteLine(string.Format(“Expires: {0} (expired? {1})”, cookie1.Expires, cookie1.Expired));

                              Debug.WriteLine(string.Format(“Don’t save: {0}”, cookie1.Discard));

                              Debug.WriteLine(string.Format(“Comment: {0}”, cookie1.Comment));

                              Debug.WriteLine(string.Format(“Uri for comments: {0}”, cookie1.CommentUri));

                              DebugHelper.WriteLine(“Version: RFC {0}” , cookie1.Version == 1 ? “2109” : “2965”);

                        }

                        // Show the string representation of the cookie.

                        Debug.WriteLine(“String: {0}”, cookie1.ToString());

                  }

            }

            //          coll=Request.ServerVariables;

            [Conditional(“DEBUG”)]

            public static void PrintServerVariables(NameValueCollection coll, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine( NameValueCollectionAsString(coll,sComment));

                  //                if (!DataHelper.IsNullOrEmpty(sComment))

                  //                {

                  //                      Debug.WriteLine(sComment);

                  //                }

                  //                int loop1, loop2;

                  //

                  //                // Get names of all keys into a string array.

                  //                String[] arr1 = coll.AllKeys;

                  //                for (loop1 = 0; loop1 < arr1.Length; loop1++)

                  //                {

                  //                      Debug.WriteLine(“Key: ” + arr1[loop1] );

                  //                      String[] arr2=coll.GetValues(arr1[loop1]);

                  //                      for (loop2 = 0; loop2 < arr2.Length; loop2++)

                  //                      {

                  //                            Debug.WriteLine(“Value ” + loop2 + “: ” + arr2[loop2] );

                  //                      }

                  //                }

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintCurrentRow(BindingManagerBase bm, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  //        ‘ Check the type of the Current object. If it is not a

                  //        ‘ DataRowView, exit the method.

                  if (bm.Current.GetType() != typeof(DataRowView))

                  {

                        return;

                  }

                  DataRowView drv = (DataRowView) bm.Current;

            DebugHelper.PrintRow(drv.Row , “”);

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintDataAdapter(SqlDataAdapter da, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  Debug.WriteLine(“DataAdapter SelectCommand “ + da.SelectCommand.CommandText);

                  if (da.InsertCommand != null)

                  {

                        Debug.WriteLine(“DataAdapter InsertCommand “ + da.InsertCommand.CommandText);

                  }

                  if (da.UpdateCommand != null)

                  {

                        Debug.WriteLine(“DataAdapter UpdateCommand “ + da.UpdateCommand.CommandText);

                  }

                  if (da.DeleteCommand != null)

                  {

                        Debug.WriteLine(“DataAdapter DeleteCommand “ + da.DeleteCommand.CommandText);

                  }

            }

            [Conditional(“DEBUG”)]

            public static void PrintSqlCommandBuilder(SqlCommandBuilder commandBuilder, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  PrintDataAdapter(commandBuilder.DataAdapter,“”);                 

                  Debug.WriteLine(“SqlCommandBuilder InsertCommand “ + commandBuilder.GetInsertCommand().CommandText);

                  Debug.WriteLine(“SqlCommandBuilder UpdateCommand “ + commandBuilder.GetUpdateCommand().CommandText);

                  Debug.WriteLine(“SqlCommandBuilder DeleteCommand “ + commandBuilder.GetDeleteCommand().CommandText);

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintDataset(DataSet ds, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  Debug.WriteLine(“Tables Count: “ + StringType.FromInteger(ds.Tables.Count));

                  foreach (DataTable table1 in ds.Tables)

                  {

                        DebugHelper.PrintTable(table1, “”);

                  }

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintDictionary(IDictionary coll, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine(DictionaryAsString(coll,sComment));

            }

            //E.G Page.Request.Form includes __EVENTTARGET

            [Conditional(“DEBUG”)]

            public static void PrintNameObjectCollection(NameValueCollection coll, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine(NameValueCollectionAsString(coll,sComment));

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintPrimaryKeys(DataTable myTable, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  DataColumn[] columnArray1 = myTable.PrimaryKey; //        ‘ Create the array for the columns.

                  Debug.WriteLine(“Primary Keys Column Count: “ + columnArray1.Length.ToString());

                  int num2 = columnArray1.GetUpperBound(0);//        ‘ Get the number of elements in the array.

                  for (int num1 = 0; num1 <= num2; num1++)

                  {

                        Debug.WriteLine(columnArray1[num1].ColumnName + “: “ + columnArray1[num1].DataType.ToString());

                  }

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintRow(DataRow row, [Optional] string sComment /* = “” */)

            {

                  Debug.WriteLine( RowAsString(row, sComment));

            }

            //    ”TODO: see trace.axd- should be better

            [Conditional(“DEBUG”)]

            public static void PrintSessionCollection(HttpSessionState myCol, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  foreach (string text1 in myCol.Keys )

                  {

                        Debug.WriteLine(ObjectType.StrCatObj((“Session(“” + text1) + “”)=”, myCol[text1]));

                  }

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintTable(DataTable tbl, [Optional] string sComment /* = “” */)

            {

                  PrintIfNotEmpty(sComment);

                  if (tbl==null)

                  {

                        Debug.WriteLine(“Table is null”);

                        return;

                  }

                  Debug.WriteLine(String.Format(“Table: ‘{0}’ with {1} rows “ , tbl.TableName,tbl.Rows.Count) );

                  foreach (DataRow row1 in tbl.Rows)

                  {

                        DebugHelper.PrintRow(row1, “”);

                  }

            }

        [Conditional(“DEBUG”)]

        public static void PrintView(DataView view, string sComment )

        {

            PrintIfNotEmpty(sComment);

            if (view == null)

            {

                Debug.WriteLine(“view is null”);

                return;

            }

            Debug.WriteLine(String.Format(“view: ‘{0}’ with {1} rows “, view.Table.TableName, view.Count));

            for(int i=0;i<view.Count;i++)

            {

                DebugHelper.PrintRow(view[i].Row , “”);

            }

        }

        [Conditional(“DEBUG”)]

            public static void PrintAppDomain(string sComment )

            {

                  PrintIfNotEmpty(sComment);

                  AppDomain domain = AppDomain.CurrentDomain;

 

                  // Write out application domain information

                  Debug.WriteLine(“Host domain: “ + domain.FriendlyName);

                  Debug.WriteLine(“Configuration file is: “ + domain.SetupInformation.ConfigurationFile);

                  Debug.WriteLine(“Application Base Directory is: “ + domain.BaseDirectory);

                  Debug.WriteLine(“RelativeSearchPath is: “ + domain.RelativeSearchPath);

                   

            }

            private static void PrintIfNotEmpty(string sComment )

            {

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        Debug.WriteLine(sComment);

                  }

            }

            [Conditional(“DEBUG”)]

            public static void TracedLine(string sComment)

            {

                  string sRet = TraceHelper.LineWithTrace(sComment);

                  Debug.WriteLine(sRet);

            }

            [Conditional(“DEBUG”)]

            public static void WriteLine(string format,params object[] arg)

            {

                  Debug.WriteLine(string.Format(format, arg));

            }

            [Conditional(“DEBUG”)]

            public static void TracedLine(string format,params object[] arg)

            {

                  string sRet = TraceHelper.LineWithTrace(format,arg);

                  Debug.WriteLine(sRet);

            }

            [Conditional(“DEBUG”)]

            public static void VariableNotNullAssert(object argument, string argumentName)

            { //Idea from http://blogs.msdn.com/brada/archive/2004/07/11/180315.aspx

                  if (argument == null)

                  {                 //          throw new ArgumentNullException(argumentName);

                        Debug.Assert(false,argumentName+ ” cannot be null”) ;

                  }

            }

 

            [Conditional(“DEBUG”)]

            public static void PrintRowErrors(DataSet myDataSet)

            {

                  foreach(DataTable myTable in myDataSet.Tables)

                  {

                        foreach(DataRow myRow in myTable.Rows)

                        {

                              if(myRow.HasErrors)

                              {

                                    Debug.WriteLine(myRow.RowError);

                              }

                        }

                  }

            }

            //see ASP.NET Identity Matrix http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetAP05.asp

            [Conditional(“DEBUG”)]

            public static void PrintAspNetIdentities()

            {

                  bool bHttpContextAvailable=(System.Web.HttpContext.Current!=null);

                  if (bHttpContextAvailable)

                  { Debug.WriteLine(“HttpContext.Current.User=” + System.Web.HttpContext.Current.User.Identity.Name   );}

                  else

                  { Debug.WriteLine(“HttpContext.Current is not available”  );}

                  Debug.WriteLine(“WindowsIdentity.GetCurrent()=” + System.Security.Principal.WindowsIdentity.GetCurrent().Name  );

                  Debug.WriteLine(“Thread.CurrentPrincipal =” + System.Threading.Thread.CurrentPrincipal.Identity.Name   );

                  string AuthenticationType   = System.Security.Principal.WindowsIdentity.GetCurrent().AuthenticationType;

                  Debug.WriteLine(       AuthenticationType                  =” +       AuthenticationType                  );

                  if (bHttpContextAvailable)

                  {

                        NameValueCollection  serverVariables =       System.Web.HttpContext.Current.Request.ServerVariables; 

                        Debug.WriteLine(“serverVariables[LOGON_USER]=” + serverVariables[“LOGON_USER”] );

                        Debug.WriteLine(“serverVariables[AUTH_USER]=” + serverVariables[“AUTH_USER”] );

                        Debug.WriteLine(“serverVariables[REMOTE_USER]=” + serverVariables[“REMOTE_USER”] );

                  }

            }

            public static string DateTimeInFileName(DateTime time, bool IncludeSecs,bool IncludeMilliSecs)

            {

                  string format=“yyMMdd_HHmm”;

                  if (IncludeSecs==true) format+=“ss”;

                  if (IncludeSecs==true) format+=“fffffff”;

                  return  time.ToString(format);

            }

            [Conditional(“DEBUG”)]

            public static void PrintHttpWebRequest(HttpWebRequest reqHttp, string sComment )

            {

                  PrintIfNotEmpty(sComment);

//http://www.codeproject.com/csharp/ClientTicket_MSNP9.asp

                  Debug.Write(” AllowAutoRedirect: “ + reqHttp.AllowAutoRedirect);

                  Debug.Write(” Pipelined is: “ + reqHttp.Pipelined);

                  Debug.Write(” KeepAlive is: “ + reqHttp.KeepAlive);

                  Debug.WriteLine(” ProtocolVersion is: “ + reqHttp.ProtocolVersion);

            }

            [Conditional(“DEBUG”)]

            public static void PrintHttpWebResponse(HttpWebResponse  respHttp, string sComment )

            {

                  PrintIfNotEmpty(sComment);

                  //http://www.codeproject.com/csharp/ClientTicket_MSNP9.asp

                  Debug.WriteLine(” StatusCode: “ + respHttp.StatusCode);

                  Debug.WriteLine(” ResponseUri: “ + respHttp.ResponseUri);

                  Debug.WriteLine(” Headers are: “ + respHttp.Headers.ToString());

            }

            [Conditional(“DEBUG”)]

            public static void PrintDirectoryEntryProperties(System.DirectoryServices.DirectoryEntry entry, string sComment)

        { //similar to GetPropertyList function from http://www.c-sharpcorner.com/UploadFile/klaus_salchner@hotmail.com/LDAPIISWinNTDirectoryServices08242005032318AM/LDAPIISWinNTDirectoryServices.aspx?ArticleID=74360cb9-3d8e-49c2-9429-3d492857ac95

            PrintIfNotEmpty(sComment);

            // loop through all the properties and get the key for each

            foreach (string Key in entry.Properties.PropertyNames)

            {

                string sPropertyValues = String.Empty;

                // now loop through all the values in the property;

                // can be a multi-value property

                foreach (object Value in entry.Properties[Key])

                    sPropertyValues += Convert.ToString(Value) + “;”;

                // cut off the separator at the end of the value list

                sPropertyValues = sPropertyValues.Substring(0, sPropertyValues.Length – 1);

                // now add the property info to the property list

                Debug.WriteLine(Key + “=” + sPropertyValues);

            }

        }

 

 

      }//public class DebugHelper

}//namespace FSHelperLib

 

 

//TRACEHELPER.CS

 

namespace FSHelperLib

{

    using Microsoft.VisualBasic.CompilerServices;

    using System;

    using System.Data;

      using System.IO;

      using System.Diagnostics;

    using System.Reflection;

    using System.Runtime.CompilerServices;

      using System.Runtime.InteropServices;//for Optional

      using System.Collections.Specialized;

      using System.Collections;

      using System.Windows.Forms;

 

    public class TraceHelper

    {

        // Methods

        public TraceHelper()

        {

        }

 

//          ‘Returns false if can’t be coverted to string

//          ‘sValue is returned as string  if can be converted to string or Null if DBNull

            public static bool ColumnValueToString(DataRow row, DataColumn myColumn, ref string sValue)

        {

                  return ColumnValueToString(  myColumn, row[myColumn], ref  sValue);

        }

            //          ‘Returns false if can’t be coverted to string

            //          ‘sValue is returned as string  if can be converted to string or Null if DBNull

            public static bool ColumnValueToString(DataRowView row, DataColumn myColumn, ref string sValue)

            {

                  return ColumnValueToString(  myColumn, row[myColumn.Ordinal], ref  sValue);

            }

 

            private static bool ColumnValueToString( DataColumn myColumn,Object oColumnValue, ref string sValue)

            {

                  bool bRet = false;

                  if (TraceHelper.IsPrintableType(myColumn.DataType))

                  {

                        bRet = true;

                  }

                  else if ((myColumn.DataType == Type.GetType(“System.Object”)) && TraceHelper.IsPrintableType(oColumnValue.GetType()))

                  {

                        sValue = StringType.FromObject(oColumnValue);

                        bRet = true;

                  }

                  if (bRet)

                  {

                        sValue = StringType.FromObject(DataHelper.Nz(RuntimeHelpers.GetObjectValue(oColumnValue), “Null”));

                  }

                  return bRet;

            }

 

            public static string FindCallerFunction()

            {

                  return FindCallerFunction(1);//exclude itself

            }

        public static string FindCallerFunction(int nSkip)

        {

//        ‘Navigate through stack skipping system functions , ErrorReport  and TracedLine methods

//        ‘Smarter than System.Reflection.MethodInfo.GetCurrentMethod()

            string sRet=“”;

            StackTrace trace1 = new StackTrace();

            int num2 = trace1.FrameCount;

            for (int num1 = 1; num1 <= num2; num1++)

            {

                MethodBase base1 = trace1.GetFrame(num1).GetMethod();

                bool bSkip = false;

                string sReflectedType = base1.ReflectedType.ToString();

                        switch(base1.Name)

                        {

                              case “TracedLine”: case  “LineWithTrace”: case “ShowException” : case “TraceWithTime”:

                                    bSkip = true;

                                    break;

                                    //                if (StringType.StrCmp(base1.Name, “TracedLine”, false) == 0)

                                    //                {

                                    //                    bSkip = true;

                                    //                }

                                    //                else if (StringType.StrCmp(base1.Name, “LineWithTrace”, false) == 0)

                                    //                {

                                    //                    bSkip = true;

                                    //                }

//                else if (StringType.StrCmp(base1.Name, “ShowException”, false) == 0)

//                {

//                    bSkip = true;

//                }

//                else if (StringType.StrCmp(base1.Name, “TraceWithTime”, false) == 0)

//                {

//                    bSkip = true;

//                }

                       

                              default:

                                    if (sReflectedType.StartsWith(“System.Windows.Forms”))

                                    {

                                          bSkip = true;

                                    }

                                    else if (sReflectedType.StartsWith(“ControlNativeWindow”))

                                    {

                                          bSkip = true;

                                    }

                                    else if (sReflectedType.StartsWith(“ThreadContext”))

                                    {

                                          bSkip = true;

                                    }

                                    else if (sReflectedType.EndsWith(“ErrorReportForm”))

                                    {

                                          bSkip = true;

                                    }

                                    else if (sReflectedType.EndsWith(“ErrorForm”))

                                    {

                                          bSkip = true;

                                    }

                                    else if (sReflectedType.EndsWith(“ActivityLogCls”))

                                    {

                                          bSkip = true;

                                    }

                                    else if (sReflectedType.EndsWith(“ActivityLogCmpnt”))

                                    {

                                          bSkip = true;

                                    }

                                    break;

                              }

                              if (!bSkip)

                              {

                                    if(nSkip<=0)

                                    {

                                          sRet = sReflectedType + “.” + base1.Name;

                                          break;//FOR                                     return sRet;

                                    }

                                    else

                                    {

                                          nSkip–;

                                    }

                              }

            }//for

            return sRet;

        }

 

        public static bool IsPrintableType(Type DataType)

        {

//        ‘Todo add other types

            if ((DataType == Type.GetType(“System.String”)) || (DataType == Type.GetType(“System.Decimal”)) ||

                        (DataType == Type.GetType(“System.Int32”)) || (DataType == Type.GetType(“System.Int64”)) ||

                        (DataType == Type.GetType(“System.Double”)) || (DataType == Type.GetType(“System.DateTime”))

                        || (DataType == Type.GetType(“System.Boolean”))

                        )

            {

                return true;

            }

            return false;

        }

 

        public static string LineWithTrace(string sComment)

        {

            return (TraceHelper.FindCallerFunction() + “:” + sComment);

        }

            public static string LineWithTrace(string format,params object[] arg)

            {  

                  return (TraceHelper.FindCallerFunction() + “:” + string.Format(format, arg));

            }

 

        public static string TraceWithTime(string sComment)

        {

            return (DateTime.Now.ToString() + ” :” + TraceHelper.LineWithTrace(sComment));

        }

            public static string TraceString(BindingMemberInfo bInfo, [Optional] string sComment /* = “” */)

            {

                  string text2 = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        text2 = text2 + sComment;

                  }

                  text2 = text2 + ” BindingPath: “ + bInfo.BindingPath + “rn”;

                  text2 = text2 + ” BindingField: “ + bInfo.BindingField + “rn”;

                  text2 = text2 + ” BindingMember: “ + bInfo.BindingMember + “rn”;

                  //Debug.WriteLine(text2);

                  return text2;

            }

 

            //[Conditional(“DEBUG”)]

            public static string TraceString(ControlBindingsCollection bindings, [Optional] string sComment /* = “” */)

            {

                  string text2 = “”;

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        text2=sComment;

                  }

                  foreach(Binding binding1 in bindings)

                  {

                              sRet = “”;

                              sRet = sRet + ” DataSource: “ + binding1.DataSource.ToString();

                              sRet = sRet + ” PropertyName: “ + binding1.PropertyName;

                              Debug.WriteLine(sRet);

                              text2 = text2 + sRet;

                              text2 = text2 + TraceString(binding1.BindingMemberInfo, “”);

                  }

                  return text2;

            }

 

            //[Conditional(“DEBUG”)]

            public static string BindingMemberInfoAsString(System.Windows.Forms.Control container, [Optional] string sComment /* = “” */)

            {

                  string text2 = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        text2=sComment;

                  }

                        foreach (System.Windows.Forms.Control control1 in container.Controls )

                        {

                              text2+=TraceString(control1.DataBindings, “”);

                        }

                  return text2;

            }

 

            //[Conditional(“DEBUG”)]

            public static string ChildrenAsString(System.Web.UI.Control container, [Optional] string sComment /* = “” */)

            {

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        sRet = sRet + sComment+“rn”;

                  }

                        foreach (System.Web.UI.Control control1 in container.Controls)

                        {

                              sRet = sRet + (“ID= “ + control1.ID + “(“ + control1.GetType().ToString()) + “)rn”;

                        }

            //    Debug.WriteLine(sRet);

                  return sRet;

            }

            public static string RowAsString(DataRow row, [Optional] string sComment /* = “” */)

            {

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        sRet = sRet + sComment;

                  }

                  if(row!=null && row.Table!=null &&  row.RowState!= DataRowState.Deleted)

                  {

                        foreach (DataColumn column1 in row.Table.Columns )

                        {

                              sRet = sRet + ColumnWithValueAsString( column1,row[column1]);//text3;

                        }

                  }

                  //Debug.WriteLine(sRet);

                  return sRet;

            }

            public static string RowAsString(DataRowView row, [Optional] string sComment /* = “” */)

            {

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        sRet = sRet + sComment;

                  }

                  if(row!=null)//3/8/2005

                  {

                        DataTable tbl=row.DataView.Table;

                        if( tbl!=null)//8/4/2005

                        {

                              foreach (DataColumn column1 in tbl.Columns )

                              {

                                    sRet = sRet + ColumnWithValueAsString( column1,row[column1.Ordinal]);

                              }

                        }

                        else Debug.Assert(false,“row.DataView.Table cannot be null”) ;

                  }

                  else Debug.Assert(false,“row cannot be null”) ;

                  Debug.WriteLine(sRet);

                  return sRet;

            }

            private  static string ColumnWithValueAsString(DataColumn column1,Object oColumnValue )

            {

                  string sRet = “”;

                  string[] textArray1 = new string[5] { sRet, column1.ColumnName, “(“, column1.DataType.ToString(), “)” } ;

                  sRet = string.Concat(textArray1);

                  string sValue = “”;

                  if (TraceHelper.ColumnValueToString(column1,oColumnValue, ref sValue))

                  {

                        sValue = String.Format(” Value={0}rn”, sValue );

                  }

                  else

                  {

                        sValue = ” Value not printable rn”;

                  }

                  return sRet + sValue;

            }

 

           

            public static string NameValueCollectionAsString(NameValueCollection coll, [Optional] string sComment /* = “” */)

            {

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        sRet +=  sComment+Environment.NewLine ;

                  }

                  int loop1, loop2;

 

                  // Get names of all keys into a string array.

                  String[] arr1 = coll.AllKeys;

                  sRet += “Length= “ + arr1.Length.ToString()+Environment.NewLine ;

                  for (loop1 = 0; loop1 < arr1.Length; loop1++)

                  {

                        sRet +=(“Key: “ + arr1[loop1] );//+Environment.NewLine;

                        String[] arr2=coll.GetValues(arr1[loop1]);

                        for (loop2 = 0; loop2 < arr2.Length; loop2++)

                        {

                              sRet +=(” Value “ + loop2 + “: “ + arr2[loop2] ) +Environment.NewLine;

                        }

                  }

                  return sRet;

            }

            public static string DictionaryAsString(IDictionary dict, [Optional] string sComment /* = “” */)

            {

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        sRet +=  sComment+Environment.NewLine ;

                  }

                  if (dict == null)

                  {

                        sRet +=(“Dictionary is null: “)+Environment.NewLine ;

                  }

                  else

                  {

                        string sEntry=“”;

                        sRet +=(“Dictionary Count: “ + StringType.FromInteger(dict.Count));

                        foreach (DictionaryEntry entry1 in dict)

                        {

                             // sEntry += String.Format(“{0} ({1}): {2} rn”,entry1.Key, entry1.Key.GetType().ToString(), entry1.Value.ToString());

                   if(entry1.Key!=null)
                    {
                       sEntry += String.Format(“{0} ({1}): “, entry1.Key, entry1.Key.GetType().ToString());
                    }
                    if (entry1.Value != null)
                    {
                        sEntry +=  entry1.Value.ToString();
                    }
                    sEntry += ” rn”;

                        }

                        sRet +=(sEntry);

                  }

                  return sRet;

            }

            public static string StringArrayAsString(string[] asStrings,  string sComment)

            {

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        sRet +=  sComment+Environment.NewLine ;

                  }

                  if ((asStrings==null) ||(asStrings.Length  == 0))

                  {

                        sRet +=(“Array is empty.”)+Environment.NewLine ;

                  }

                  else

                  {

                        sRet +=(“Array Count: “ + StringType.FromInteger(asStrings.Length ))+Environment.NewLine ;

                        foreach (string  sEntry in asStrings)

                        {

                              sRet +=(sEntry)+Environment.NewLine ;

                        }

                  }

                  return sRet;

            }

            public static string TracedTimeSpanAsString(DateTime timeStart,  string sComment)

            {

                  return TimeSpanAsString(timeStart, TraceHelper.FindCallerFunction(1) + “:” +sComment);

            }

            public static string TimeSpanAsString(DateTime timeStart,  string sComment)

            {

                  string sRet = “”;

                  if (!DataHelper.IsNullOrEmpty(sComment))

                  {

                        sRet +=  sComment+” “;

                  }

                  TimeSpan span1 = DateTime.Now.Subtract(timeStart);

                  sRet+= span1.ToString();

                  return sRet;

            }

            public string CurrentDomainPaths()

            {

                  return Environment.Version.ToString() + “rn” + Assembly.GetExecutingAssembly().CodeBase + “rn” +

                        “ApplicationBase: “ + AppDomain.CurrentDomain.SetupInformation.ApplicationBase + “rn” +

                        “PrivateBinPath: “ + AppDomain.CurrentDomain.SetupInformation.PrivateBinPath + “rn” +

                        “PrivateBinProbe: “ + AppDomain.CurrentDomain.SetupInformation.PrivateBinPathProbe  + “rn” +

                        Directory.GetCurrentDirectory() + “rn” + AppDomain.CurrentDomain.FriendlyName + “rn”;

            }

            /// <summary>

            /// Enumeration of trace entry severities.

            /// </summary>

            public enum OutputLevel

            {

                  Brief=1,

                  Detailed=2,

                  Verbose=4

            }

 

            //Attempt to create 28/3/2005

            //issue base class doesn’t have public indexer, and have to pass NameValueCollection

            // so see NameValueCollectionAsString

//          public static string NameObjectCollectionAsString(NameValueCollection coll, [Optional] string sComment /* = “” */)

//          {

//                string sRet = “”;

//                if (!DataHelper.IsNullOrEmpty(sComment))

//                {

//                      sRet +=  sComment+Environment.NewLine ;

//                }

//                if (coll == null)

//                {

//                      sRet +=(“Collection is null: “)+Environment.NewLine ;

//                }

//                else

//                {

//                      string sEntry=””;

//                      sRet +=(“NameObjectCollection Count: ” + StringType.FromInteger(coll.Count));

//                      //ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsspecializednameobjectcollectionbaseclasstopic.htm

//                      foreach ( String sKey in coll.Keys ) 

//                      {

//                            sEntry =String.Format( “{0}, {1}”, sKey, coll[sKey] );

//                            sRet +=(sEntry);

//                      }

//                }

//                return sRet;

//          }

 

    }

}

 

 

 

Advertisements