< Summary - Results for net8.0, Release

Information
Class: LockCheck.ProcessInfo
Assembly: LockCheck
File(s): D:\a\LockCheck\LockCheck\src\LockCheck\ProcessInfo.cs
Tag: 117_11660770947
Line coverage
97%
Covered lines: 39
Uncovered lines: 1
Coverable lines: 40
Total lines: 152
Line coverage: 97.5%
Branch coverage
95%
Covered branches: 23
Total branches: 24
Branch coverage: 95.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_ProcessId()100%11100%
get_StartTime()100%11100%
get_ParentProcessId()100%210%
set_ParentProcessId(...)100%11100%
get_ExecutableName()100%11100%
set_ExecutableName(...)100%11100%
get_ApplicationName()100%11100%
set_ApplicationName(...)100%11100%
get_Owner()100%11100%
set_Owner(...)100%11100%
get_ExecutableFullPath()100%11100%
set_ExecutableFullPath(...)100%11100%
get_SessionId()100%11100%
set_SessionId(...)100%11100%
get_LockType()100%210%
set_LockType(...)100%11100%
get_LockMode()100%210%
set_LockMode(...)100%11100%
get_LockAccess()100%210%
set_LockAccess(...)100%11100%
get_IsCritical()100%210%
set_IsCritical(...)100%11100%
get_ProcessStartKey()100%210%
set_ProcessStartKey(...)100%11100%
GetHashCode()100%11100%
Equals(...)75%4.25475%
ToString()100%11100%
ToString(...)100%44100%
Format(...)100%1616100%

File(s)

D:\a\LockCheck\LockCheck\src\LockCheck\ProcessInfo.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Diagnostics;
 4using System.Linq;
 5using System.Text;
 6
 7namespace LockCheck;
 8
 9/// <summary>
 10/// Provides information about a process that is holding a lock on a file.
 11/// </summary>
 12[DebuggerDisplay("{ProcessId} {StartTime} {ExecutableName}")]
 13public abstract class ProcessInfo
 14{
 215    protected ProcessInfo(int processId, DateTime startTime)
 16    {
 217        ProcessId = processId;
 218        StartTime = startTime;
 219    }
 20
 21    /// <summary>
 22    /// The process identifier of the process holding a lock on a file.
 23    /// </summary>
 224    public int ProcessId { get; }
 25
 26    /// <summary>
 27    /// The start time (local) of the process holding a lock o a file.
 28    /// </summary>
 229    public DateTime StartTime { get; }
 30
 31    /// <summary>
 32    /// The process ID of this process' parent.
 33    /// </summary>
 234    public int? ParentProcessId { get; protected set; }
 35
 36    /// <summary>
 37    /// The executable name of the process holding a lock.
 38    /// </summary>
 239    public string? ExecutableName { get; protected set; }
 40
 41    /// <summary>
 42    /// The descriptive application name, if available. Otherwise
 43    /// the same as the executable name or another informative
 44    /// string.
 45    /// </summary>
 246    public string? ApplicationName { get; protected set; }
 47
 48    /// <summary>
 49    /// The owner of the process.
 50    /// </summary>
 251    public string? Owner { get; protected set; }
 52
 53    /// <summary>
 54    /// The full path to the process' executable, if available.
 55    /// </summary>
 256    public string? ExecutableFullPath { get; protected set; }
 57
 58    /// <summary>
 59    /// The platform specific session ID of the process.
 60    /// </summary>
 61    /// <value>
 62    /// On Windows, the Terminal Services ID. On Linux
 63    /// the process' session ID.
 64    /// </value>
 265    public int SessionId { get; protected set; }
 66
 67    /// <summary>
 68    /// A platform specific string that specifies the type of lock, if available.
 69    /// </summary>
 270    public string? LockType { get; protected set; }
 71
 72    /// <summary>
 73    /// A platform specific string that specifies the mode of the lock, if available.
 74    /// </summary>
 275    public string? LockMode { get; protected set; }
 76
 77    /// <summary>
 78    /// A platform specific string that specifies the access lock requested, if available.
 79    /// </summary>
 280    public string? LockAccess { get; protected set; }
 81
 82    /// <summary>
 83    /// A platform specific flag that indicates if the curren process is critical to the system's function.
 84    /// </summary>
 285    public bool? IsCritical { get; protected set; }
 86
 87    /// <summary>
 88    /// A platform specific process key. On Windows this is the value also available in ETW.
 89    /// </summary>
 290    public ulong? ProcessStartKey { get; protected set; }
 91
 92    public override int GetHashCode()
 93    {
 94#if NET
 295        return HashCode.Combine(ProcessId, StartTime);
 96#else
 97        int h1 = ProcessId.GetHashCode();
 98        int h2 = StartTime.GetHashCode();
 99        return ((h1 << 5) + h1) ^ h2;
 100#endif
 101    }
 102
 103    public override bool Equals(object? obj)
 104    {
 2105        var other = obj as ProcessInfo;
 2106        if (other != null)
 107        {
 2108            return other.ProcessId == ProcessId && other.StartTime == StartTime;
 109        }
 0110        return false;
 111    }
 112
 2113    public override string ToString() => ProcessId + "@" + StartTime.ToString("O");
 114
 115    public string ToString(string? format)
 116    {
 2117        string baseFormat = ToString();
 118
 2119        if (format != null)
 120        {
 2121            if (format == "F")
 122            {
 2123                return $"{baseFormat}/{ApplicationName}";
 124            }
 125        }
 126
 2127        return baseFormat;
 128    }
 129
 130    public static void Format(StringBuilder sb, IEnumerable<ProcessInfo> lockers, IEnumerable<string> fileNames, int? ma
 131    {
 2132        if (fileNames == null)
 2133            throw new ArgumentNullException(nameof(fileNames));
 134
 2135        if (lockers == null || !lockers.Any())
 2136            return;
 137
 2138        int count = lockers.Count();
 2139        int max = maxProcesses == -1 || !maxProcesses.HasValue ? int.MaxValue : maxProcesses.Value;
 140
 2141        sb.AppendFormat("File {0} locked by: ", string.Join(", ", fileNames));
 2142        foreach (ProcessInfo locker in lockers.Take(max))
 143        {
 2144            sb.AppendLine($"[{locker.ApplicationName}, pid={locker.ProcessId}, owner={ownerOverwrite ?? locker.Owner}, s
 145        }
 146
 2147        if (count > max)
 148        {
 2149            sb.AppendLine($"[{count - max} more processes...]");
 150        }
 2151    }
 152}