-
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2292 from marticliment/manager-loggers
Better Package Manager Loggers
- Loading branch information
Showing
23 changed files
with
1,025 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/UniGetUI.PackageEngine.ManagerLogger/ManagerLogger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System.Diagnostics; | ||
using UniGetUI.PackageEngine.ManagerClasses.Manager; | ||
|
||
namespace UniGetUI.PackageEngine.ManagerLogger | ||
{ | ||
public class ManagerLogger | ||
{ | ||
public enum OperationType | ||
{ | ||
SearchPackages, | ||
CheckUpdates, | ||
ListInstalledPackages, | ||
RefreshIndexes, | ||
ListSources, | ||
GetPackageDetails, | ||
GetPackageVersions, | ||
} | ||
|
||
public class OperationLog | ||
{ | ||
ManagerLogger Logger; | ||
OperationType Type; | ||
|
||
string Executable; | ||
string Arguments; | ||
int ReturnCode; | ||
DateTime StartTime; | ||
DateTime? EndTime; | ||
List<string> StdOut = new(); | ||
List<string> StdErr = new(); | ||
bool isComplete = false; | ||
bool isOpen = false; | ||
|
||
public OperationLog(ManagerLogger logger, OperationType type, string executable, string arguments) | ||
{ | ||
Type = type; | ||
Logger = logger; | ||
Executable = executable; | ||
Arguments = arguments; | ||
StartTime = DateTime.Now; | ||
isComplete = false; | ||
isOpen = true; | ||
} | ||
|
||
public void AddStdoutLine(string? line) | ||
{ | ||
if (!isOpen) throw new Exception("Attempted to write log into an already-closed OperationLog"); | ||
if (line != null) | ||
StdOut.Add(line); | ||
} | ||
|
||
public void AddStdoutLines(IEnumerable<string> lines) | ||
{ | ||
if (!isOpen) throw new Exception("Attempted to write log into an already-closed OperationLog"); | ||
foreach (string line in lines) | ||
StdOut.Add(line); | ||
} | ||
|
||
public void AddStderrLine(string? line) | ||
{ | ||
if (!isOpen) throw new Exception("Attempted to write log into an already-closed OperationLog"); | ||
if (line != null) | ||
StdErr.Add(line); | ||
} | ||
|
||
public void AddStderrLines(IEnumerable<string> lines) | ||
{ | ||
if (!isOpen) throw new Exception("Attempted to write log into an already-closed OperationLog"); | ||
foreach (string line in lines) | ||
StdErr.Add(line); | ||
} | ||
|
||
public void End() | ||
{ | ||
EndTime = DateTime.Now; | ||
isComplete = true; | ||
isOpen = false; | ||
Logger.LoadOperation(this); | ||
} | ||
} | ||
|
||
PackageManager Manager; | ||
List<OperationLog> Operations = new(); | ||
|
||
|
||
public ManagerLogger(PackageManager manager) | ||
{ | ||
Manager = manager; | ||
} | ||
|
||
private void LoadOperation(OperationLog operation) | ||
{ | ||
Operations.Add(operation); | ||
} | ||
|
||
public OperationLog CreateOperationLog(OperationType type, Process process) | ||
{ | ||
if (process.StartInfo == null) | ||
throw new Exception("Process instance did not have a valid StartInfo value"); | ||
|
||
return new OperationLog(this, type, process.StartInfo.FileName, process.StartInfo.Arguments); | ||
} | ||
|
||
public OperationLog CreateNativeOperation(OperationType type, string ExtraArgument = "N/A") | ||
{ | ||
return new OperationLog(this, type, $"{Manager.Name} native operation", ExtraArgument); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/UniGetUI.PackageEngine.ManagerLogger/UniGetUI.PackageEngine.ManagerLogger.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers> | ||
<RuntimeIdentifier>win-$(Platform)</RuntimeIdentifier> | ||
<Platforms>x64</Platforms> | ||
<TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion> | ||
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion> | ||
<SdkVersion>8.0.204</SdkVersion> | ||
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained> | ||
<PublishSelfContained>true</PublishSelfContained> | ||
<FileVersion>3.1.0.0</FileVersion> | ||
<InformationalVersion>3.1.0-alpha0</InformationalVersion> | ||
<Product>UniGetUI</Product> | ||
<Authors>Martí Climent and the contributors</Authors> | ||
<PublisherName>Martí Climent</PublisherName> | ||
<ApplicationVersion>3.1.0-alpha0</ApplicationVersion> | ||
<Copyright>2024, Martí Climent</Copyright> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\UniGetUI.Core.Logger\UniGetUI.Core.Logging.csproj" /> | ||
<ProjectReference Include="..\UniGetUI.Core.Settings\UniGetUI.Core.Settings.csproj" /> | ||
<ProjectReference Include="..\UniGetUI.Core.Tools\UniGetUI.Core.Tools.csproj" /> | ||
<ProjectReference Include="..\UniGetUI.PackageEngine.Enums\UniGetUI.PackageEngine.Enums.csproj" /> | ||
<ProjectReference Include="..\UniGetUI.PackageEngine.PackageManagerClasses\UniGetUI.PackageEngine.Classes.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.