Skip to content

Commit

Permalink
Review chanegs
Browse files Browse the repository at this point in the history
  • Loading branch information
lilla28 committed May 8, 2023
1 parent 181bc05 commit d584ce1
Show file tree
Hide file tree
Showing 34 changed files with 400 additions and 614 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.10.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ namespace ProcessExplorer.Abstractions.Extensions;

public static class EnumExtensions
{
public static string ToStringCached(this Status status)
public static string ToStringCached(this ProcessStatus status)
{
return status switch
{
Status.Terminated => nameof(Status.Terminated),
Status.Running => nameof(Status.Running),
Status.Stopped => nameof(Status.Stopped),
ProcessStatus.Modified => nameof(ProcessStatus.Modified),
ProcessStatus.Terminated => nameof(ProcessStatus.Terminated),
ProcessStatus.Running => nameof(ProcessStatus.Running),
ProcessStatus.Stopped => nameof(ProcessStatus.Stopped),
_ => status.ToString(),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ProcessExplorer.Abstractions.Handlers;
/// Used for sending status change update of a process to the UI(s).
/// </summary>
/// <param name="process"></param>
public delegate void ProcessStatusChangedHandler(KeyValuePair<int, Status> process);
public delegate void ProcessStatusChangedHandler(KeyValuePair<int, ProcessStatus> process);

/// <summary>
/// Used for sending updated processes to the UI(s).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

namespace ProcessExplorer.Abstractions;

public interface IProcessInfoAggregator : IDisposable
public interface IProcessInfoAggregator
{
/// <summary>
/// Main process id to watch.
/// The main id, which childprocesses should be watched.
/// </summary>
public int MainProcessId { get; }
public int MainProcessId { get; set; }

/// <summary>
/// Delay for actually sending terminate request for the UI.
Expand All @@ -35,7 +35,7 @@ public interface IProcessInfoAggregator : IDisposable
/// <summary>
/// Controls the initialized subsystems.
/// </summary>
public ISubsystemController? SubsystemController { get; }
public ISubsystemController SubsystemController { get; }

/// <summary>
/// Handles the communication between the server and clients.
Expand All @@ -48,18 +48,6 @@ public interface IProcessInfoAggregator : IDisposable
/// <param name="assembly"></param>
void RemoveRuntimeInformation(string assembly);

/// <summary>
/// Sets Compose PID.
/// </summary>
/// <param name="processId"></param>
void SetMainProcessId(int processId);

/// <summary>
/// Sets the SubsystemController.
/// </summary>
/// <param name="subsystemController"></param>
void SetSubsystemController(ISubsystemController subsystemController);

/// <summary>
/// Sets the delay time for keeping a process after it was terminated.(s)
/// Default: 1 minute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public interface IUiHandler
/// </summary>
/// <param name="process"></param>
/// <returns></returns>
Task UpdateProcessStatus(KeyValuePair<int, Status> process);
Task UpdateProcessStatus(KeyValuePair<int, ProcessStatus> process);

/// <summary>
/// Updates the client that the connection has been established.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ option csharp_namespace = "ProcessExplorer.Abstractions.Infrastructure.Protos";

import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/wrappers.proto";

service ProcessExplorerMessageHandler{
rpc Send(Message) returns (google.protobuf.Empty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,18 @@ namespace ProcessExplorer.Abstractions.Logging;

public static partial class SourceGeneratedLoggerExtensions
{
[LoggerMessage(Level = LogLevel.Debug, Message = "Starting to watch processes, due it is enabled by the user.", SkipEnabledCheck = false)]
public static partial void ProcessMonitorEnabledDebug(this ILogger logger);

[LoggerMessage(Level = LogLevel.Debug, Message = "Couldn't find the PPID for the PID `{pid}`. Detailed exception: `{exception}`", SkipEnabledCheck = true)]
private static partial void ManagementObjectPpid(this ILogger logger, int pid, Exception ex, Exception exception);

[LoggerMessage(Level = LogLevel.Debug, Message = "ProcessInfoManager is not initialized in the ProcessMonitor class", SkipEnabledCheck = false)]
public static partial void ProcessInfoManagerNotInitializedDebug(this ILogger logger);

[LoggerMessage(Level = LogLevel.Debug, Message = "Starting a subsystem with id: {id}", SkipEnabledCheck = false)]
public static partial void SubsystemStartedDebug(this ILogger logger, string id);

[LoggerMessage(Level = LogLevel.Debug, Message = "Subsystem with id: {id} is already started", SkipEnabledCheck = false)]
public static partial void SubsystemAlreadyStartedDebug(this ILogger logger, string id);

[LoggerMessage(Level = LogLevel.Debug, Message = "Stopping a subsystem with id: {id}", SkipEnabledCheck = false)]
public static partial void SubsystemStoppingDebug(this ILogger logger, string id);

[LoggerMessage(Level = LogLevel.Debug, Message = "Subsystem with id: {id} is already stopped", SkipEnabledCheck = false)]
public static partial void SubsystemAlreadyStoppedDebug(this ILogger logger, string id);

[LoggerMessage(Level = LogLevel.Debug, Message = "ProcessMonitor UICommunicator is set.", SkipEnabledCheck = false)]
public static partial void ProcessMonitorCommunicatorIsSetDebug(this ILogger logger);

[LoggerMessage(Level = LogLevel.Error, Message = "Cannot add the connections to collection. Detailed exception: `{exception}`", SkipEnabledCheck = true)]
private static partial void ConnectionCollectionCannotBeAdded(this ILogger logger, Exception ex, Exception exception);

Expand All @@ -52,18 +43,9 @@ public static partial class SourceGeneratedLoggerExtensions
[LoggerMessage(Level = LogLevel.Error, Message = "Modules cannot be updated. Detailed exception: `{exception}`", SkipEnabledCheck = true)]
private static partial void ModulesCannotBeUpdated(this ILogger logger, Exception ex, Exception exception);

[LoggerMessage(Level = LogLevel.Debug, Message = "A UIHandler is removed from the collection", SkipEnabledCheck = false)]
public static partial void UiCommunicatorIsRemovedDebug(this ILogger logger);

[LoggerMessage(Level = LogLevel.Error, Message = "Cannot modify subsystem's state with ID `{subsystemId}`. Detailed exception: `{exception}`", SkipEnabledCheck = true)]
private static partial void ModifyingSubsystemsState(this ILogger logger, string subsystemId, Exception ex, Exception exception);

[LoggerMessage(Level = LogLevel.Error, Message = "Error while terminating the process, ID: {pid}. Detailed exception: `{exception}`", SkipEnabledCheck = true)]
private static partial void CannotTerminateProcess(this ILogger logger, int pid, Exception ex, Exception exception);

[LoggerMessage(Level = LogLevel.Error, Message = "Error while terminating the process, ID: {pid}", SkipEnabledCheck = true)]
public static partial void CannotTerminateProcessError(this ILogger logger, int pid);

[LoggerMessage(Level = LogLevel.Error, Message = "Updating the information on UI cannot be completed. Detailed exception: `{exception}`", SkipEnabledCheck = true)]
private static partial void UiInformationCannotBeUpdated(this ILogger logger, Exception ex, Exception exception);

Expand All @@ -73,9 +55,6 @@ public static partial class SourceGeneratedLoggerExtensions
[LoggerMessage(Level = LogLevel.Error, Message = "Cannot terminate a subsystem/subsystems. Detailed exception: `{exception}`", SkipEnabledCheck = true)]
private static partial void CannotTerminateSubsystem(this ILogger logger, Exception ex, Exception exception);

[LoggerMessage(Level = LogLevel.Debug, Message = "The Process Explorer list is initialized", SkipEnabledCheck = false)]
public static partial void ProcessListIsInitializedDebug(this ILogger logger);

[LoggerMessage(Level = LogLevel.Information, Message = "A process with PID: `{pid}` is terminated", SkipEnabledCheck = false)]
public static partial void ProcessTerminatedInformation(this ILogger logger, int pid);

Expand All @@ -85,9 +64,6 @@ public static partial class SourceGeneratedLoggerExtensions
[LoggerMessage(Level = LogLevel.Debug, Message = "A process with PID: `{pid}` is modified", SkipEnabledCheck = false)]
public static partial void ProcessModifiedDebug(this ILogger logger, int pid);

[LoggerMessage(Level = LogLevel.Warning, Message = "The process `{pid}` does not exist in the ProcessMonitor list", SkipEnabledCheck = false)]
public static partial void ProcessNotFoundWarning(this ILogger logger, int pid);

[LoggerMessage(Level = LogLevel.Warning, Message = "The subsystem with `{id}` couldn't be terminated. Subsystem name: `{name}`", SkipEnabledCheck = false)]
public static partial void SubsystemTerminationAddWarning(this ILogger logger, string id, string name);

Expand Down Expand Up @@ -136,6 +112,9 @@ public static partial class SourceGeneratedLoggerExtensions
[LoggerMessage(Level = LogLevel.Error, Message = "Error while adding a subsystem with id: {id}, name: `{name}`", SkipEnabledCheck = true)]
private static partial void SubsystemAddFailure(this ILogger logger, string id, string name);

[LoggerMessage(Level = LogLevel.Error, Message = "Unable to remove ProcessInfoCollectorData from collection. Id: `{assemblyId}`", SkipEnabledCheck = false)]
public static partial void UnableToRemoveRuntimeInformationError(this ILogger logger, string assemblyId);

public static void SubsystemAddError(this ILogger logger, string id, string name)
{
if (logger.IsEnabled(LogLevel.Error))
Expand All @@ -152,14 +131,6 @@ public static void SubsystemStopError(this ILogger logger, string id, Exception
}
}

public static void SubsystemRestartError(this ILogger logger, string id, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.SubsystemRestartFailure(id, exception, exception);
}
}

public static void SubsystemRestartError(this ILogger logger, string id)
{
if (logger.IsEnabled(LogLevel.Error))
Expand Down Expand Up @@ -224,54 +195,6 @@ public static void PpidExpected(this ILogger logger, int pid, Exception exceptio
}
}

public static void StoppingWatcherExpected(this ILogger logger, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.CannotStopProcessWatcher(exception, exception);
}
}

public static void ModifiableProcessExpected(this ILogger logger, int pid, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.CouldNotFoundModifiableProcess(pid, exception, exception);
}
}

public static void PidExpected(this ILogger logger, int pid, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.PidNotExists(pid, exception, exception);
}
}

public static void PidIndexExpected(this ILogger logger, int pid, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.IndexDoesNotExists(pid, exception, exception);
}
}

public static void KillProcessError(this ILogger logger, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.CannotKillProcess(exception, exception);
}
}

public static void ListInitializationError(this ILogger logger, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.CannotFillList(exception, exception);
}
}

public static void UiInformationCannotBeUpdatedError(this ILogger logger, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
Expand All @@ -295,14 +218,6 @@ public static void CannotSendLaunchRequestError(this ILogger logger, Exception e
}
}

public static void ManagementObjectPPID(this ILogger logger, int pid, Exception exception)
{
if (logger.IsEnabled(LogLevel.Debug))
{
logger.ManagementObjectPpid(pid, exception, exception);
}
}

public static void ConnectionCollectionCannotBeAddedError(this ILogger logger, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
Expand Down Expand Up @@ -343,14 +258,6 @@ public static void ModulesCannotBeUpdatedError(this ILogger logger, Exception ex
}
}

public static void CannotTerminateProcessError(this ILogger logger, int pid, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
{
logger.CannotTerminateProcess(pid, exception, exception);
}
}

public static void ModifyingSubsystemsStateError(this ILogger logger, Guid subsystemId, Exception exception)
{
if (logger.IsEnabled(LogLevel.Error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JetBrains.Annotations" Version="10.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="protobuf-net.Core" Version="3.2.16" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.0" />
<PackageReference Include="System.Management" Version="6.0.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.10.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
// or implied. See the License for the specific language governing permissions
// and limitations under the License.

using ProcessExplorer.Abstractions.Handlers;

namespace ProcessExplorer.Abstractions.Processes;

//TODO(Lilla): should be async?
public interface IProcessInfoMonitor : IDisposable
{
/// <summary>
/// Returns the collection of processes.
/// </summary>
public IObservable<KeyValuePair<int, ProcessStatus>> ProcessIds { get; }

/// <summary>
/// Clears the currently initilialzed processes.
/// </summary>
Expand Down Expand Up @@ -52,19 +54,6 @@ public interface IProcessInfoMonitor : IDisposable
/// <returns></returns>
ReadOnlySpan<int> GetProcessIds();

/// <summary>
/// Sets the behaviors of the process changed events.
/// </summary>
/// <param name="processModifiedHandler"></param>
/// <param name="processTerminatedHandler"></param>
/// <param name="processCreatedHandler"></param>
void SetHandlers(
ProcessModifiedHandler processModifiedHandler,
ProcessTerminatedHandler processTerminatedHandler,
ProcessCreatedHandler processCreatedHandler,
ProcessesModifiedHandler processesModifiedHandler,
ProcessStatusChangedHandler processStatusChangedHandler);

/// <summary>
/// Sets the watchable process list.
/// </summary>
Expand All @@ -77,4 +66,9 @@ void SetHandlers(
/// </summary>
/// <param name="mainProcessId"></param>
void WatchProcesses(int mainProcessId);

/// <summary>
/// Disables to watch processes.
/// </summary>
void StopWatchingProcesses();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ProcessInfoData
public long? VirtualMemorySize { get; set; }
public int? ParentId { get; set; }
public long? PrivateMemoryUsage { get; set; }
public string? ProcessStatus { get; set; } = Status.Running.ToStringCached();
public string? ProcessStatus { get; set; } = Processes.ProcessStatus.Running.ToStringCached();
public float? MemoryUsage { get; set; }
public float? ProcessorUsage { get; set; }
}
Loading

0 comments on commit d584ce1

Please sign in to comment.