< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.ExceptionUtility
Assembly: CoreWCF.RabbitMQ
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/src/CoreWCF/DiagnosticUtility.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 21
Coverable lines: 21
Total lines: 214
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/Common/src/CoreWCF/DiagnosticUtility.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Diagnostics;
 6using System.Runtime.CompilerServices;
 7using System.Xml;
 8using CoreWCF.Runtime;
 9
 10namespace CoreWCF
 11{
 12    internal class DiagnosticUtility
 13    {
 14        private static ExceptionUtility s_exceptionUtility = (ExceptionUtility)null;
 15        private static readonly object s_lockObject = new object();
 16
 17        internal static ExceptionUtility ExceptionUtility
 18        {
 19            get
 20            {
 21                return s_exceptionUtility ?? GetExceptionUtility();
 22            }
 23        }
 24
 25        private static ExceptionUtility GetExceptionUtility()
 26        {
 27            lock (s_lockObject)
 28            {
 29                if (s_exceptionUtility == null)
 30                {
 31                    // TODO: Make this generic shared code used by multiple assemblies
 32                    //exceptionUtility = new ExceptionUtility("System.ServiceModel", "System.ServiceModel 4.0.0.0", (obj
 33                    s_exceptionUtility = new ExceptionUtility();
 34                }
 35            }
 36
 37            return s_exceptionUtility;
 38        }
 39
 40        internal static void TraceHandledException(Exception exception, TraceEventType traceEventType)
 41        {
 42            Fx.Exception.TraceHandledException(exception, traceEventType);
 43        }
 44
 45        [Conditional("DEBUG")]
 46        internal static void DebugAssert(bool condition, string message)
 47        {
 48            if (!condition)
 49            {
 50                DebugAssert(message);
 51            }
 52        }
 53
 54        [MethodImpl(MethodImplOptions.NoInlining)]
 55        [Conditional("DEBUG")]
 56        internal static void DebugAssert(string message)
 57        {
 58            Fx.Assert(message);
 59        }
 60
 61        [MethodImpl(MethodImplOptions.NoInlining)]
 62        internal static Exception FailFast(string message)
 63        {
 64            try
 65            {
 66                try
 67                {
 68                    ExceptionUtility.TraceFailFast(message);
 69                }
 70                finally
 71                {
 72                    Environment.FailFast(message);
 73                }
 74            }
 75            catch
 76            {
 77            }
 78            Environment.FailFast(message);
 79            return (Exception)null;
 80        }
 81    }
 82
 83    internal class ExceptionUtility
 84    {
 85        internal ArgumentException ThrowHelperArgument(string message)
 86        {
 087            return (ArgumentException)ThrowHelperError(new ArgumentException(message));
 88        }
 89
 90        internal ArgumentException ThrowHelperArgument(string paramName, string message)
 91        {
 092            return (ArgumentException)ThrowHelperError(new ArgumentException(message, paramName));
 93        }
 94
 95        internal ArgumentNullException ThrowHelperArgumentNull(string paramName)
 96        {
 097            return (ArgumentNullException)ThrowHelperError(new ArgumentNullException(paramName));
 98        }
 99
 100        internal Exception ThrowHelperFatal(string message, Exception innerException)
 101        {
 0102            return ThrowHelperError(new FatalException(message, innerException));
 103        }
 104
 105        internal Exception ThrowHelperError(Exception exception)
 106        {
 0107            return ThrowHelper(exception, TraceEventType.Error);
 108        }
 109
 110        internal Exception ThrowHelperWarning(Exception exception)
 111        {
 0112            return ThrowHelper(exception, TraceEventType.Warning);
 113        }
 114
 115        internal Exception ThrowHelper(Exception exception, TraceEventType eventType)
 116        {
 0117            return ThrowHelper(exception, eventType, null);
 118        }
 119
 120        internal Exception ThrowHelper(Exception exception, TraceEventType eventType, TraceRecord extendedData)
 121        {
 122            //if ((_diagnosticTrace == null ? 0 : (_diagnosticTrace.ShouldTrace(eventType) ? 1 : 0)) != 0)
 123            //{
 124            //    using (
 125            //        ExceptionUtility.useStaticActivityId
 126            //            ? Activity.CreateActivity(ExceptionUtility.activityId)
 127            //            : (Activity)null)
 128            //        _diagnosticTrace.TraceEvent(eventType, 131075,
 129            //            LegacyDiagnosticTrace.GenerateMsdnTraceCode("System.ServiceModel.Diagnostics",
 130            //                "ThrowingException"), TraceSRCommon.Format("ThrowingException"), extendedData, exception,
 131            //            (object)null);
 132            //    IDictionary data = exception.Data;
 133            //    if (data != null && !data.IsReadOnly && !data.IsFixedSize)
 134            //    {
 135            //        object obj =
 136            //            data[(object)"System.ServiceModel.Diagnostics.ExceptionUtility.ExceptionStackAsString"];
 137            //        string str1 = obj == null ? "" : obj as string;
 138            //        if (str1 != null)
 139            //        {
 140            //            string stackTrace = exception.StackTrace;
 141            //            if (!string.IsNullOrEmpty(stackTrace))
 142            //            {
 143            //                string str2 = str1 + (str1.Length == 0 ? "" : Environment.NewLine) + "throw" +
 144            //                              Environment.NewLine + stackTrace + Environment.NewLine + "catch" +
 145            //                              Environment.NewLine;
 146            //                data[(object)"System.ServiceModel.Diagnostics.ExceptionUtility.ExceptionStackAsString"]
 147            //                    = (object)str2;
 148            //            }
 149            //        }
 150            //    }
 151            //}
 152            //this.exceptionTrace.TraceEtwException(exception, eventType);
 0153            return exception;
 154        }
 155
 156        public Exception ThrowHelperXml(XmlReader reader, string message)
 157        {
 0158            return ThrowHelperXml(reader, message, null);
 159        }
 160
 161        public Exception ThrowHelperXml(XmlReader reader, string message, Exception inner)
 162        {
 0163            IXmlLineInfo lineInfo = reader as IXmlLineInfo;
 0164            return ThrowHelperError(new XmlException(
 0165                message,
 0166                inner,
 0167                (null != lineInfo) ? lineInfo.LineNumber : 0,
 0168                (null != lineInfo) ? lineInfo.LinePosition : 0));
 169        }
 170
 171        internal Exception ThrowHelperCallback(Exception innerException)
 172        {
 0173            return ThrowHelperCallback(TraceSR.GenericCallbackException, innerException);
 174        }
 175
 176        internal Exception ThrowHelperCallback(string message, Exception innerException)
 177        {
 0178            return ThrowHelperCritical(new CallbackException(message, innerException));
 179        }
 180
 181        internal Exception ThrowHelperCritical(Exception exception)
 182        {
 0183            return ThrowHelper(exception, TraceEventType.Critical);
 184        }
 185
 186        internal class TraceRecord
 187        {
 188        }
 189
 190        [MethodImpl(MethodImplOptions.NoInlining)]
 191        internal void TraceFailFast(string message)
 192        {
 193            //Microsoft.Runtime.Diagnostics.EventLogger logger = null;
 194            //try
 195            //{
 196            //    logger = new Microsoft.Runtime.Diagnostics.EventLogger(this.eventSourceName, this.diagnosticTrace);
 197            //}
 198            //finally
 199            //{
 200            //    TraceFailFast(message, logger);
 201            //}
 0202        }
 203
 204        internal Exception ThrowHelperArgumentNull(string paramName, string message)
 205        {
 0206            return (ArgumentNullException)ThrowHelperError(new ArgumentNullException(paramName, message));
 207        }
 208
 209        public Exception ThrowHelperInvalidOperation(string message)
 210        {
 0211            return ThrowHelperError(new InvalidOperationException(message));
 212        }
 213    }
 214}