< Summary

Line coverage
55%
Covered lines: 25
Uncovered lines: 20
Coverable lines: 45
Total lines: 245
Line coverage: 55.5%
Branch coverage
50%
Covered branches: 4
Total branches: 8
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
File 1: GetEnhancedMetafile(...)50%5466.66%
File 1: SaveAsEnhancedMetafile(...)50%6447.05%
File 2: CloseClipboard()100%11100%
File 2: IsClipboardFormatAvailable(...)100%11100%
File 2: OpenClipboard(...)100%11100%
File 2: DeleteEnhMetaFile(...)100%210%
File 2: GetEnhMetaFileBits(...)100%210%

File(s)

D:\a\SolidEdge.Community\SolidEdge.Community\src\SolidEdgeCommunity\Extensions\SheetExtensions.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.Runtime.InteropServices;
 4
 5namespace SolidEdgeCommunity.Extensions;
 6
 7public static partial class SheetExtensions
 8{
 9    [LibraryImport("user32.dll")]
 10    [return: MarshalAs(UnmanagedType.Bool)]
 11    private static partial bool CloseClipboard();
 12
 13    [LibraryImport("user32.dll")]
 14    [UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvStdcall)])]
 15    private static partial IntPtr GetClipboardData(uint format);
 16
 17    [LibraryImport("user32.dll")]
 18    private static partial IntPtr GetClipboardOwner();
 19
 20    [LibraryImport("user32.dll")]
 21    [return: MarshalAs(UnmanagedType.Bool)]
 22    private static partial bool IsClipboardFormatAvailable(uint format);
 23
 24    [LibraryImport("user32.dll")]
 25    [return: MarshalAs(UnmanagedType.Bool)]
 26    private static partial bool OpenClipboard(IntPtr hWndNewOwner);
 27
 28    [LibraryImport("gdi32.dll")]
 29    [return: MarshalAs(UnmanagedType.Bool)]
 30    private static partial bool DeleteEnhMetaFile(IntPtr hemf);
 31
 32    [LibraryImport("gdi32.dll")]
 33    private static partial uint GetEnhMetaFileBits(IntPtr hemf, uint cbBuffer, [Out] byte[] lpbBuffer);
 34
 35    private const uint _cf_ENHMETAFILE = 14;
 36
 37    public static System.Drawing.Imaging.Metafile GetEnhancedMetafile(this SolidEdgeDraft.Sheet sheet)
 38    {
 39        try
 40        {
 41            // Copy the sheet as an EMF to the windows clipboard.
 142            sheet.CopyEMFToClipboard();
 43
 144            if (OpenClipboard(IntPtr.Zero))
 45            {
 146                if (IsClipboardFormatAvailable(_cf_ENHMETAFILE))
 47                {
 48                    // Get the handle to the EMF.
 049                    IntPtr henhmetafile = GetClipboardData(_cf_ENHMETAFILE);
 50
 051                    return new System.Drawing.Imaging.Metafile(henhmetafile, true);
 52                }
 53                else
 54                {
 155                    throw new Exception("CF_ENHMETAFILE is not available in clipboard.");
 56                }
 57            }
 58            else
 59            {
 060                throw new Exception("Error opening clipboard.");
 61            }
 62        }
 163        catch (Exception)
 64        {
 165            throw;
 66        }
 67        finally
 68        {
 169            CloseClipboard();
 170        }
 071    }
 72
 73    public static void SaveAsEnhancedMetafile(this SolidEdgeDraft.Sheet sheet, string filename)
 74    {
 75        try
 76        {
 77            // Copy the sheet as an EMF to the windows clipboard.
 178            sheet.CopyEMFToClipboard();
 79
 180            if (OpenClipboard(IntPtr.Zero))
 81            {
 182                if (IsClipboardFormatAvailable(_cf_ENHMETAFILE))
 83                {
 84                    // Get the handle to the EMF.
 085                    IntPtr hEMF = GetClipboardData(_cf_ENHMETAFILE);
 86
 87                    // Query the size of the EMF.
 088                    uint len = GetEnhMetaFileBits(hEMF, 0, null);
 089                    byte[] rawBytes = new byte[len];
 90
 91                    // Get all of the bytes of the EMF.
 092                    GetEnhMetaFileBits(hEMF, len, rawBytes);
 93
 94                    // Write all of the bytes to a file.
 095                    File.WriteAllBytes(filename, rawBytes);
 96
 97                    // Delete the EMF handle.
 098                    DeleteEnhMetaFile(hEMF);
 99                }
 100                else
 101                {
 1102                    throw new Exception("CF_ENHMETAFILE is not available in clipboard.");
 103                }
 104            }
 105            else
 106            {
 0107                throw new Exception("Error opening clipboard.");
 108            }
 0109        }
 1110        catch (Exception)
 111        {
 1112            throw;
 113        }
 114        finally
 115        {
 1116            CloseClipboard();
 1117        }
 0118    }
 119}

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).