< Summary

Line coverage
88%
Covered lines: 23
Uncovered lines: 3
Coverable lines: 26
Total lines: 319
Line coverage: 88.4%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: CoRegisterMessageFilter(...)100%22100%
File 2: .ctor()100%11100%
File 2: Finalize()100%210%
File 2: Register()50%2266.66%
File 2: Unregister()100%11100%
File 2: HandleInComingCall(...)100%11100%
File 2: MessagePending(...)100%11100%
File 2: RetryRejectedCall(...)100%22100%

File(s)

D:\a\SolidEdge.Community\SolidEdge.Community\src\SolidEdgeCommunity\obj\Release\net10.0-windows\Microsoft.Interop.LibraryImportGenerator\Microsoft.Interop.LibraryImportGenerator\LibraryImports.g.cs

File 'D:\a\SolidEdge.Community\SolidEdge.Community\src\SolidEdgeCommunity\obj\Release\net10.0-windows\Microsoft.Interop.LibraryImportGenerator\Microsoft.Interop.LibraryImportGenerator\LibraryImports.g.cs' does not exist (any more).

D:\a\SolidEdge.Community\SolidEdge.Community\src\SolidEdgeCommunity\OleMessageFilter.cs

#LineLine coverage
 1using System;
 2using System.Runtime.InteropServices;
 3using System.Runtime.InteropServices.Marshalling;
 4using System.Threading;
 5
 6namespace SolidEdgeCommunity;
 7
 8internal enum SERVERCALL
 9{
 10    SERVERCALL_ISHANDLED = 0,
 11    SERVERCALL_REJECTED = 1,
 12    SERVERCALL_RETRYLATER = 2
 13}
 14
 15internal enum PENDINGMSG
 16{
 17    PENDINGMSG_CANCELCALL = 0,
 18    PENDINGMSG_WAITNOPROCESS = 1,
 19    PENDINGMSG_WAITDEFPROCESS = 2
 20}
 21
 22[GeneratedComInterface]
 23[Guid("00000016-0000-0000-C000-000000000046")]
 24[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
 25internal partial interface IMessageFilter
 26{
 27    [PreserveSig]
 28    int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo);
 29
 30    [PreserveSig]
 31    int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType);
 32
 33    [PreserveSig]
 34    int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType);
 35}
 36
 37/// <summary>
 38/// Class that implements the OLE IMessageFilter interface.
 39/// </summary>
 40[GeneratedComClass]
 41public sealed partial class OleMessageFilter : IMessageFilter
 42{
 43    [LibraryImport("Ole32.dll")]
 44    private static partial int CoRegisterMessageFilter(IMessageFilter newFilter, out IMessageFilter oldFilter);
 45
 46    /// <summary>
 47    /// Private constructor.
 48    /// </summary>
 49    /// <remarks>
 50    /// Instance of this class is only created by Register().
 51    /// </remarks>
 452    private OleMessageFilter()
 53    {
 454    }
 55
 56    /// <summary>
 57    /// Destructor.
 58    /// </summary>
 59    ~OleMessageFilter()
 60    {
 61        // Call Unregister() for good measure. It's fine if this gets called twice.
 062        Unregister();
 063    }
 64
 65    /// <summary>
 66    /// Registers this instance of IMessageFilter with OLE to handle concurrency issues on the current thread.
 67    /// </summary>
 68    /// <remarks>
 69    /// Only one message filter can be registered for each thread.
 70    /// Threads in multithreaded apartments cannot have message filters.
 71    /// Thread.CurrentThread.GetApartmentState() must equal ApartmentState.STA. In console applications, this can
 72    /// be achieved by applying the STAThreadAttribute to the Main() method. In WinForm applications, it is default.
 73    /// </remarks>
 74    public static void Register()
 75    {
 76        // 1st check the current thread's apartment state. It must be STA!
 177        if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
 78        {
 079            System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(CoRegisterMessageFilter(newFilter: new OleMessage
 80        }
 81        else
 82        {
 183            throw new Exception("The current thread's apartment state must be STA.");
 84        }
 85    }
 86
 87    /// <summary>
 88    /// Unregisters a previous instance of IMessageFilter with OLE on the current thread.
 89    /// </summary>
 90    /// <remarks>
 91    /// It is not necessary to call Unregister() unless you need to explicitly do so as it is handled
 92    /// in the destructor.
 93    /// </remarks>
 194    public static void Unregister() => CoRegisterMessageFilter(newFilter: null, oldFilter: out _); // Call CoRegisterMes
 95
 96    #region IMessageFilter
 97
 198    public int HandleInComingCall(int dwCallType, IntPtr hTaskCaller, int dwTickCount, IntPtr lpInterfaceInfo) => (int)S
 99
 100    // Cancel the outgoing call. This should be returned only under extreme conditions. Canceling a call that
 101    // has not replied or been rejected can create orphan transactions and lose resources. COM fails the original
 102    // call and returns RPC_E_CALL_CANCELLED.
 103    //return (int)NativeMethods.PENDINGMSG.PENDINGMSG_CANCELCALL;
 104
 105    // Continue waiting for the reply, and do not dispatch the message unless it is a task-switching or
 106    // window-activation message. A subsequent message will trigger another call to MessagePending.
 107    //return (int)NativeMethods.PENDINGMSG.PENDINGMSG_WAITNOPROCESS;
 108
 109    // Keyboard and mouse messages are no longer dispatched. However there are some cases where mouse and
 110    // keyboard messages could cause the system to deadlock, and in these cases, mouse and keyboard messages
 111    // are discarded. WM_PAINT messages are dispatched. Task-switching and activation messages are handled as before.
 1112    public int MessagePending(IntPtr hTaskCallee, int dwTickCount, int dwPendingType) => (int)PENDINGMSG.PENDINGMSG_WAIT
 113
 114    // 0 ≤ value < 100
 115    // The call is to be retried immediately.
 116
 117    // 100 ≤ value
 118    // COM will wait for this many milliseconds and then retry the call.
 119
 120    // -1 | The call should be canceled. COM then returns RPC_E_CALL_REJECTED from the original method call.
 121    public int RetryRejectedCall(IntPtr hTaskCallee, int dwTickCount, int dwRejectType)
 2122        => (dwRejectType == (int)SERVERCALL.SERVERCALL_RETRYLATER) ? 99 : -1;
 123
 124    #endregion IMessageFilter
 125}