Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / MS / Internal / documents / DocumentsTrace.cs / 1 / DocumentsTrace.cs
//#define TRACE //---------------------------------------------------------------------------- //// Copyright (C) 2004 by Microsoft Corporation. All rights reserved. // // // Description: DocumentsTrace is a tracing utility for Fixed and Flow documents // // History: // 02/03/2004 - Zhenbin Xu (ZhenbinX) - Created based on System.Windows.Media.Utility.MediaTrace // //--------------------------------------------------------------------------- namespace MS.Internal.Documents { using System; using System.Diagnostics; using System.Reflection; using System.Security; using System.Security.Permissions; using MS.Internal.PresentationFramework; // SecurityHelper internal sealed class DocumentsTrace { internal static class FixedFormat { #if DEBUG public static DocumentsTrace FixedDocument = new DocumentsTrace("FixedFormat-FixedDocument"); public static DocumentsTrace PageContent= new DocumentsTrace("FixedFormat-PageContent"); public static DocumentsTrace IDF = new DocumentsTrace("FixedFormat-IDFAsync"); #else public static DocumentsTrace FixedDocument = null; public static DocumentsTrace PageContent = null; public static DocumentsTrace IDF = null; #endif #if DEBUG static FixedFormat() { // FixedFormat.IDF.Enable(); // FixedFormat.FixedDocument.Enable(); // FixedFormat.PageContent.Enable(); } #endif } internal static class FixedTextOM { #if DEBUG public static DocumentsTrace TextView = new DocumentsTrace("FixedTextOM-TextView"); public static DocumentsTrace TextContainer = new DocumentsTrace("FixedTextOM-TextContainer"); public static DocumentsTrace Map = new DocumentsTrace("FixedTextOM-FixedFlowMap"); public static DocumentsTrace Highlight = new DocumentsTrace("FixedTextOM-Highlight"); public static DocumentsTrace Builder = new DocumentsTrace("FixedTextOM-FixedTextBuilder"); public static DocumentsTrace FlowPosition = new DocumentsTrace("FixedTextOM-FlowPosition"); #else public static DocumentsTrace TextView = null; public static DocumentsTrace TextContainer = null; public static DocumentsTrace Map = null; public static DocumentsTrace Highlight = null; public static DocumentsTrace Builder = null; public static DocumentsTrace FlowPosition = null; #endif #if DEBUG // Note: // If you want to enable trace tags without recompiling. This is a good place to put a break point // during start-up. static FixedTextOM() { // FixedTextOM.TextView.Enable(); // FixedTextOM.TextContainer.Enable(); // FixedTextOM.Map.Enable(); // FixedTextOM.Highlight.Enable(); // FixedTextOM.Builder.Enable(); // FixedTextOM.FlowPosition.Enable(); } #endif } internal static class FixedDocumentSequence { #if DEBUG public static DocumentsTrace Content = new DocumentsTrace("FixedDocumentsSequence-Content"); public static DocumentsTrace IDF = new DocumentsTrace("FixedDocumentSequence-IDFAsync"); public static DocumentsTrace TextOM = new DocumentsTrace("FixedDocumentSequence-TextOM"); public static DocumentsTrace Highlights = new DocumentsTrace("FixedDocumentSequence-Highlights"); #else public static DocumentsTrace Content = null; public static DocumentsTrace IDF = null; public static DocumentsTrace TextOM = null; public static DocumentsTrace Highlights = null; #endif #if DEBUG static FixedDocumentSequence() { //FixedDocumentSequence.Content.Enable(); //FixedDocumentSequence.IDF.Enable(); //FixedDocumentSequence.TextOM.Enable(); //FixedDocumentSequence.Highlights.Enable(); } #endif } ////// Critical - it elevates to get trace listeners collection. /// TreatAsSafe - it doesn't disclose the information got through elevation. adding a well-known trace listener is considered safe. /// [SecurityCritical,SecurityTreatAsSafe] static DocumentsTrace() { #if DEBUG // we are adding console as a listener TextWriterTraceListener consoleListener = new TextWriterTraceListener( Console.Out ); // get the listeners collection TraceListenerCollection listeners = null; new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); try { listeners = System.Diagnostics.Trace.Listeners; } finally { SecurityPermission.RevertAssert(); } // add the console listener listeners.Add( consoleListener ); #endif } public DocumentsTrace(string switchName) { #if DEBUG string name = SafeSecurityHelper.GetAssemblyPartialName( Assembly.GetCallingAssembly() ); _switch = new BooleanSwitch(switchName, "[" + name + "]"); #endif } ////// Critical: sets BooleanSwitch.Enabled which LinkDemands /// TreatAsSafe: ok to enable tracing, and this is debug only /// [SecurityCritical, SecurityTreatAsSafe] public DocumentsTrace(string switchName, bool initialState) : this(switchName) { #if DEBUG _switch.Enabled = initialState; #endif } [Conditional("DEBUG")] public void Trace(string message) { #if DEBUG if (_switch.Enabled) { System.Diagnostics.Trace.WriteLine(_switch.Description + " " + _switch.DisplayName + " : " + message); } #endif } [Conditional("DEBUG")] public void TraceCallers(int Depth) { #if DEBUG if (_switch.Enabled) { System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1); if (Depth < 0) Depth = st.FrameCount; Indent(); for (int i=0; i < st.FrameCount && i < Depth; i++) { System.Diagnostics.StackFrame sf = st.GetFrame(i); Trace(sf.GetMethod()+"+"+sf.GetILOffset().ToString()); } Unindent(); } #endif } [Conditional("DEBUG")] public void Indent() { #if DEBUG System.Diagnostics.Trace.Indent(); #endif } [Conditional("DEBUG")] public void Unindent() { #if DEBUG System.Diagnostics.Trace.Unindent(); #endif } ////// Critical: sets BooleanSwitch.Enabled which LinkDemands /// TreatAsSafe: ok to enable tracing, and this is debug only /// [SecurityCritical, SecurityTreatAsSafe] [Conditional("DEBUG")] public void Enable() { #if DEBUG _switch.Enabled = true; #endif } ////// Critical: sets BooleanSwitch.Enabled which LinkDemands /// TreatAsSafe: ok to disable tracing, and this is debug only /// [SecurityCritical, SecurityTreatAsSafe] [Conditional("DEBUG")] public void Disable() { #if DEBUG _switch.Enabled = false; #endif } public bool IsEnabled { get { #if DEBUG return _switch.Enabled; #else return false; #endif } } #if DEBUG private System.Diagnostics.BooleanSwitch _switch; #endif } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //#define TRACE //---------------------------------------------------------------------------- //// Copyright (C) 2004 by Microsoft Corporation. All rights reserved. // // // Description: DocumentsTrace is a tracing utility for Fixed and Flow documents // // History: // 02/03/2004 - Zhenbin Xu (ZhenbinX) - Created based on System.Windows.Media.Utility.MediaTrace // //--------------------------------------------------------------------------- namespace MS.Internal.Documents { using System; using System.Diagnostics; using System.Reflection; using System.Security; using System.Security.Permissions; using MS.Internal.PresentationFramework; // SecurityHelper internal sealed class DocumentsTrace { internal static class FixedFormat { #if DEBUG public static DocumentsTrace FixedDocument = new DocumentsTrace("FixedFormat-FixedDocument"); public static DocumentsTrace PageContent= new DocumentsTrace("FixedFormat-PageContent"); public static DocumentsTrace IDF = new DocumentsTrace("FixedFormat-IDFAsync"); #else public static DocumentsTrace FixedDocument = null; public static DocumentsTrace PageContent = null; public static DocumentsTrace IDF = null; #endif #if DEBUG static FixedFormat() { // FixedFormat.IDF.Enable(); // FixedFormat.FixedDocument.Enable(); // FixedFormat.PageContent.Enable(); } #endif } internal static class FixedTextOM { #if DEBUG public static DocumentsTrace TextView = new DocumentsTrace("FixedTextOM-TextView"); public static DocumentsTrace TextContainer = new DocumentsTrace("FixedTextOM-TextContainer"); public static DocumentsTrace Map = new DocumentsTrace("FixedTextOM-FixedFlowMap"); public static DocumentsTrace Highlight = new DocumentsTrace("FixedTextOM-Highlight"); public static DocumentsTrace Builder = new DocumentsTrace("FixedTextOM-FixedTextBuilder"); public static DocumentsTrace FlowPosition = new DocumentsTrace("FixedTextOM-FlowPosition"); #else public static DocumentsTrace TextView = null; public static DocumentsTrace TextContainer = null; public static DocumentsTrace Map = null; public static DocumentsTrace Highlight = null; public static DocumentsTrace Builder = null; public static DocumentsTrace FlowPosition = null; #endif #if DEBUG // Note: // If you want to enable trace tags without recompiling. This is a good place to put a break point // during start-up. static FixedTextOM() { // FixedTextOM.TextView.Enable(); // FixedTextOM.TextContainer.Enable(); // FixedTextOM.Map.Enable(); // FixedTextOM.Highlight.Enable(); // FixedTextOM.Builder.Enable(); // FixedTextOM.FlowPosition.Enable(); } #endif } internal static class FixedDocumentSequence { #if DEBUG public static DocumentsTrace Content = new DocumentsTrace("FixedDocumentsSequence-Content"); public static DocumentsTrace IDF = new DocumentsTrace("FixedDocumentSequence-IDFAsync"); public static DocumentsTrace TextOM = new DocumentsTrace("FixedDocumentSequence-TextOM"); public static DocumentsTrace Highlights = new DocumentsTrace("FixedDocumentSequence-Highlights"); #else public static DocumentsTrace Content = null; public static DocumentsTrace IDF = null; public static DocumentsTrace TextOM = null; public static DocumentsTrace Highlights = null; #endif #if DEBUG static FixedDocumentSequence() { //FixedDocumentSequence.Content.Enable(); //FixedDocumentSequence.IDF.Enable(); //FixedDocumentSequence.TextOM.Enable(); //FixedDocumentSequence.Highlights.Enable(); } #endif } ////// Critical - it elevates to get trace listeners collection. /// TreatAsSafe - it doesn't disclose the information got through elevation. adding a well-known trace listener is considered safe. /// [SecurityCritical,SecurityTreatAsSafe] static DocumentsTrace() { #if DEBUG // we are adding console as a listener TextWriterTraceListener consoleListener = new TextWriterTraceListener( Console.Out ); // get the listeners collection TraceListenerCollection listeners = null; new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); try { listeners = System.Diagnostics.Trace.Listeners; } finally { SecurityPermission.RevertAssert(); } // add the console listener listeners.Add( consoleListener ); #endif } public DocumentsTrace(string switchName) { #if DEBUG string name = SafeSecurityHelper.GetAssemblyPartialName( Assembly.GetCallingAssembly() ); _switch = new BooleanSwitch(switchName, "[" + name + "]"); #endif } ////// Critical: sets BooleanSwitch.Enabled which LinkDemands /// TreatAsSafe: ok to enable tracing, and this is debug only /// [SecurityCritical, SecurityTreatAsSafe] public DocumentsTrace(string switchName, bool initialState) : this(switchName) { #if DEBUG _switch.Enabled = initialState; #endif } [Conditional("DEBUG")] public void Trace(string message) { #if DEBUG if (_switch.Enabled) { System.Diagnostics.Trace.WriteLine(_switch.Description + " " + _switch.DisplayName + " : " + message); } #endif } [Conditional("DEBUG")] public void TraceCallers(int Depth) { #if DEBUG if (_switch.Enabled) { System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1); if (Depth < 0) Depth = st.FrameCount; Indent(); for (int i=0; i < st.FrameCount && i < Depth; i++) { System.Diagnostics.StackFrame sf = st.GetFrame(i); Trace(sf.GetMethod()+"+"+sf.GetILOffset().ToString()); } Unindent(); } #endif } [Conditional("DEBUG")] public void Indent() { #if DEBUG System.Diagnostics.Trace.Indent(); #endif } [Conditional("DEBUG")] public void Unindent() { #if DEBUG System.Diagnostics.Trace.Unindent(); #endif } ////// Critical: sets BooleanSwitch.Enabled which LinkDemands /// TreatAsSafe: ok to enable tracing, and this is debug only /// [SecurityCritical, SecurityTreatAsSafe] [Conditional("DEBUG")] public void Enable() { #if DEBUG _switch.Enabled = true; #endif } ////// Critical: sets BooleanSwitch.Enabled which LinkDemands /// TreatAsSafe: ok to disable tracing, and this is debug only /// [SecurityCritical, SecurityTreatAsSafe] [Conditional("DEBUG")] public void Disable() { #if DEBUG _switch.Enabled = false; #endif } public bool IsEnabled { get { #if DEBUG return _switch.Enabled; #else return false; #endif } } #if DEBUG private System.Diagnostics.BooleanSwitch _switch; #endif } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AutoSizeToolBoxItem.cs
- PageCatalogPart.cs
- _SingleItemRequestCache.cs
- SiteMap.cs
- BitmapEffect.cs
- _NegoState.cs
- LocalizationParserHooks.cs
- TreeNode.cs
- SerializerProvider.cs
- ExpressionLink.cs
- HostingPreferredMapPath.cs
- Hash.cs
- LocalFileSettingsProvider.cs
- DynamicMethod.cs
- DataViewListener.cs
- SafeLibraryHandle.cs
- WmpBitmapDecoder.cs
- NumericPagerField.cs
- SqlCacheDependencySection.cs
- TreeViewBindingsEditor.cs
- RC2.cs
- TextBlockAutomationPeer.cs
- ListDictionaryInternal.cs
- CheckableControlBaseAdapter.cs
- SmtpTransport.cs
- SqlTopReducer.cs
- DesignerAttributeInfo.cs
- ZipIOLocalFileDataDescriptor.cs
- HttpRequestCacheValidator.cs
- ScriptResourceHandler.cs
- CalendarDataBindingHandler.cs
- StringSource.cs
- _TimerThread.cs
- StyleHelper.cs
- ProcessModelInfo.cs
- SystemResourceKey.cs
- TreeNodeSelectionProcessor.cs
- XmlDeclaration.cs
- XmlDocumentFragment.cs
- WindowsSecurityTokenAuthenticator.cs
- CodeGen.cs
- sqlstateclientmanager.cs
- TrackingLocationCollection.cs
- DataGridViewRowEventArgs.cs
- FormsAuthenticationConfiguration.cs
- MethodCallTranslator.cs
- XmlSignatureManifest.cs
- ExcludeFromCodeCoverageAttribute.cs
- PeerApplicationLaunchInfo.cs
- COM2PropertyDescriptor.cs
- EdmToObjectNamespaceMap.cs
- MobileControlsSectionHelper.cs
- HttpListenerPrefixCollection.cs
- DecimalMinMaxAggregationOperator.cs
- ToolStripItemCollection.cs
- WindowsContainer.cs
- XpsFixedPageReaderWriter.cs
- LayoutEditorPart.cs
- SctClaimSerializer.cs
- TypeCacheManager.cs
- XamlTypeMapper.cs
- Evaluator.cs
- UpdateCompiler.cs
- FixedTextContainer.cs
- ValuePatternIdentifiers.cs
- XmlFormatWriterGenerator.cs
- Region.cs
- ColorAnimationUsingKeyFrames.cs
- BitmapInitialize.cs
- XmlDataSourceView.cs
- DBCommand.cs
- ArraySortHelper.cs
- RtfControlWordInfo.cs
- CodeThrowExceptionStatement.cs
- GradientStopCollection.cs
- IODescriptionAttribute.cs
- CodeVariableReferenceExpression.cs
- WebPartActionVerb.cs
- WindowsScrollBarBits.cs
- loginstatus.cs
- MatrixCamera.cs
- TemplateAction.cs
- ColorConverter.cs
- StringAnimationBase.cs
- RowType.cs
- formatter.cs
- ProbeDuplexCD1AsyncResult.cs
- ReferenceCountedObject.cs
- DispatchChannelSink.cs
- PrinterResolution.cs
- DataGridViewRowConverter.cs
- TypeTypeConverter.cs
- BaseComponentEditor.cs
- RegexCode.cs
- _FtpDataStream.cs
- SpeechEvent.cs
- RemotingSurrogateSelector.cs
- NonClientArea.cs
- VarRefManager.cs
- XmlWriterSettings.cs