Skip to content

Commit

Permalink
Merge pull request #1790 from erri120/feat/1763-library
Browse files Browse the repository at this point in the history
Send shadow traffic to `ILibraryService`
  • Loading branch information
erri120 authored Jul 18, 2024
2 parents 3867787 + 441736f commit c84e791
Show file tree
Hide file tree
Showing 58 changed files with 528 additions and 102 deletions.
23 changes: 22 additions & 1 deletion NexusMods.App.sln
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interprocess", "Interproces
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Settings.Tests", "tests\NexusMods.Settings.Tests\NexusMods.Settings.Tests.csproj", "{0D289DCE-1B17-4B63-B8B3-47CB852BF5B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Abstractions.Library", "src\Abstractions\NexusMods.Abstractions.Library\NexusMods.Abstractions.Library.csproj", "{0044D340-E435-489C-A425-139AAB2EA205}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Abstractions.Library.Models", "src\Abstractions\NexusMods.Abstractions.Library.Models\NexusMods.Abstractions.Library.Models.csproj", "{0044D340-E435-489C-A425-139AAB2EA205}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Abstractions.NexusModsLibrary", "src\Abstractions\NexusMods.Abstractions.NexusModsLibrary\NexusMods.Abstractions.NexusModsLibrary.csproj", "{5D85EBB2-755F-4148-BFC4-8D2245A3105B}"
EndProject
Expand All @@ -228,6 +228,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Abstractions.Jobs
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Jobs.Tests", "tests\NexusMods.Jobs.Tests\NexusMods.Jobs.Tests.csproj", "{01043F6A-121B-4B3C-A694-B823D9CD0BB0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Abstractions.Library", "src\Abstractions\NexusMods.Abstractions.Library\NexusMods.Abstractions.Library.csproj", "{C47C59F4-1C6C-4F78-9A27-F328F1C02BF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Jobs", "src\NexusMods.Jobs\NexusMods.Jobs.csproj", "{44E6BD8A-7A82-49CC-91FA-AF3B3E5FBEE9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NexusMods.Abstractions.Library.Installers", "src\Abstractions\NexusMods.Abstractions.Library.Installers\NexusMods.Abstractions.Library.Installers.csproj", "{F6482055-698C-492A-9FC2-0FCDC9FC2E23}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -586,6 +592,18 @@ Global
{01043F6A-121B-4B3C-A694-B823D9CD0BB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01043F6A-121B-4B3C-A694-B823D9CD0BB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01043F6A-121B-4B3C-A694-B823D9CD0BB0}.Release|Any CPU.Build.0 = Release|Any CPU
{C47C59F4-1C6C-4F78-9A27-F328F1C02BF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C47C59F4-1C6C-4F78-9A27-F328F1C02BF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C47C59F4-1C6C-4F78-9A27-F328F1C02BF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C47C59F4-1C6C-4F78-9A27-F328F1C02BF0}.Release|Any CPU.Build.0 = Release|Any CPU
{44E6BD8A-7A82-49CC-91FA-AF3B3E5FBEE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{44E6BD8A-7A82-49CC-91FA-AF3B3E5FBEE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44E6BD8A-7A82-49CC-91FA-AF3B3E5FBEE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44E6BD8A-7A82-49CC-91FA-AF3B3E5FBEE9}.Release|Any CPU.Build.0 = Release|Any CPU
{F6482055-698C-492A-9FC2-0FCDC9FC2E23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6482055-698C-492A-9FC2-0FCDC9FC2E23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6482055-698C-492A-9FC2-0FCDC9FC2E23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6482055-698C-492A-9FC2-0FCDC9FC2E23}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -690,6 +708,9 @@ Global
{821C1DA9-040E-44F3-BFCA-BF026C3F254B} = {0CB73565-1207-4A56-A79F-6A8E9BBD795C}
{D15413CA-E727-40DA-8CD8-29ED052BF427} = {0CB73565-1207-4A56-A79F-6A8E9BBD795C}
{01043F6A-121B-4B3C-A694-B823D9CD0BB0} = {52AF9D62-7D5B-4AD0-BA12-86F2AA67428B}
{C47C59F4-1C6C-4F78-9A27-F328F1C02BF0} = {0CB73565-1207-4A56-A79F-6A8E9BBD795C}
{44E6BD8A-7A82-49CC-91FA-AF3B3E5FBEE9} = {E7BAE287-D505-4D6D-A090-665A64309B2D}
{F6482055-698C-492A-9FC2-0FCDC9FC2E23} = {0CB73565-1207-4A56-A79F-6A8E9BBD795C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F9F8352-34DD-42C0-8564-EE9AF34A3501}
Expand Down
4 changes: 4 additions & 0 deletions src/Abstractions/NexusMods.Abstractions.Games/AGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NexusMods.Abstractions.Games.Loadouts;
using NexusMods.Abstractions.Installers;
using NexusMods.Abstractions.IO;
using NexusMods.Abstractions.Library.Installers;
using NexusMods.Abstractions.Loadouts.Mods;
using NexusMods.Abstractions.Loadouts.Synchronizers;
using NexusMods.Abstractions.Serialization;
Expand Down Expand Up @@ -70,6 +71,9 @@ protected virtual ILoadoutSynchronizer MakeSynchronizer(IServiceProvider provide
/// <inheritdoc />
public virtual IEnumerable<IModInstaller> Installers => _installers.Value;

/// <inheritdoc />
public virtual ILibraryItemInstaller[] LibraryItemInstallers { get; } = [];

/// <inheritdoc/>
public virtual IDiagnosticEmitter[] DiagnosticEmitters { get; } = Array.Empty<IDiagnosticEmitter>();

Expand Down
6 changes: 6 additions & 0 deletions src/Abstractions/NexusMods.Abstractions.Games/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Installers;
using NexusMods.Abstractions.IO;
using NexusMods.Abstractions.Library.Installers;
using NexusMods.Abstractions.Loadouts.Mods;
using NexusMods.Abstractions.Loadouts.Synchronizers;
using NexusMods.Abstractions.Serialization;
Expand Down Expand Up @@ -31,6 +32,11 @@ public interface IGame : ILocatableGame
/// </summary>
public IEnumerable<IModInstaller> Installers { get; }

/// <summary>
/// Gets all available installers this game supports.
/// </summary>
public ILibraryItemInstaller[] LibraryItemInstallers { get; }

/// <summary>
/// An array of all instances of <see cref="IDiagnosticEmitter"/> supported
/// by the game.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ProjectReference Include="..\NexusMods.Abstractions.Activities\NexusMods.Abstractions.Activities.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.DiskState\NexusMods.Abstractions.DiskState.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.Installers\NexusMods.Abstractions.Installers.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.Library.Installers\NexusMods.Abstractions.Library.Installers.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.Loadouts.Synchronizers\NexusMods.Abstractions.Loadouts.Synchronizers.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.Loadouts\NexusMods.Abstractions.Loadouts.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.NexusWebApi\NexusMods.Abstractions.NexusWebApi.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System.Collections.Immutable;
using NexusMods.Abstractions.FileStore.Trees;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Loadouts.Files;
using NexusMods.Abstractions.Loadouts.Mods;
using NexusMods.Abstractions.Serialization;
using NexusMods.MnemonicDB.Abstractions.Models;
using NexusMods.Paths;
using NexusMods.Paths.Trees;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using NexusMods.Abstractions.Activities;
using NexusMods.Abstractions.FileStore.Downloads;
using NexusMods.Abstractions.Loadouts;
using NexusMods.Abstractions.Loadouts.Ids;
using NexusMods.Abstractions.Loadouts.Mods;

namespace NexusMods.Abstractions.Installers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.FileStore.ArchiveMetadata;
using NexusMods.Abstractions.FileStore.Downloads;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Loadouts.Ids;
using NexusMods.Abstractions.Loadouts.Mods;
using ModFileTreeNode = NexusMods.Paths.Trees.KeyedBox<NexusMods.Paths.RelativePath, NexusMods.Abstractions.FileStore.Trees.ModFileTree>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.DataModel.Entities.Sorting;
using NexusMods.Abstractions.Loadouts.Ids;
using NexusMods.Abstractions.Loadouts.Mods;
using NexusMods.MnemonicDB.Abstractions.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('NuGet.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<!-- TODO: This library needs stabilized -->
<PackageReference Include="TransparentValueObjects" PrivateAssets="all" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

Expand All @@ -16,21 +15,6 @@
</ItemGroup>

<ItemGroup>
<Compile Update="ILibraryFileInstaller.cs">
<DependentUpon>ILibraryItemInstaller.cs</DependentUpon>
</Compile>
<Compile Update="ILibraryArchiveInstaller.cs">
<DependentUpon>ILibraryItemInstaller.cs</DependentUpon>
</Compile>
<Compile Update="ALibraryItemInstaller.cs">
<DependentUpon>ILibraryItemInstaller.cs</DependentUpon>
</Compile>
<Compile Update="ALibraryFileInstaller.cs">
<DependentUpon>ILibraryFileInstaller.cs</DependentUpon>
</Compile>
<Compile Update="ALibraryArchiveInstaller.cs">
<DependentUpon>ILibraryArchiveInstaller.cs</DependentUpon>
</Compile>
<Compile Update="AModInstaller.cs">
<DependentUpon>IModInstaller.cs</DependentUpon>
</Compile>
Expand Down
5 changes: 4 additions & 1 deletion src/Abstractions/NexusMods.Abstractions.Jobs/AJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public abstract class AJob : IJobGroup, IDisposable, IAsyncDisposable
protected AJob(
MutableProgress progress,
IJobGroup? group = default,
IJobWorker? worker = default)
IJobWorker? worker = default,
IJobMonitor? monitor = default)
{
Id = JobId.NewId();
Status = JobStatus.None;
Expand All @@ -64,6 +65,8 @@ protected AJob(
_collection = [];
_observableCollection = new ObservableCollection<IJob>(_collection);
ObservableCollection = new ReadOnlyObservableCollection<IJob>(_observableCollection);

monitor?.RegisterJob(this);
}

public IEnumerator<IJob> GetEnumerator() => _collection.GetEnumerator();
Expand Down
27 changes: 27 additions & 0 deletions src/Abstractions/NexusMods.Abstractions.Jobs/IJobMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.ObjectModel;
using DynamicData;
using JetBrains.Annotations;

namespace NexusMods.Abstractions.Jobs;

/// <summary>
/// Represents a monitor for jobs.
/// </summary>
[PublicAPI]
public interface IJobMonitor
{
/// <summary>
/// Gets an observable collection containing every job the monitor knows about.
/// </summary>
ReadOnlyObservableCollection<IJob> Jobs { get; }

/// <summary>
/// Gets an observable with changeset for jobs of type <typeparamref name="TJob"/>.
/// </summary>
IObservable<IChangeSet<TJob, JobId>> GetObservableChangeSet<TJob>() where TJob : IJob;

/// <summary>
/// Registers a job with the monitor.
/// </summary>
void RegisterJob(IJob job);
}
31 changes: 28 additions & 3 deletions src/Abstractions/NexusMods.Abstractions.Jobs/JobResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,25 @@ public bool TryGetFailed([NotNullWhen(true)] out JobResultFailed? failed)
return true;
}

/// <summary>
/// Returns the data in the completed result or thrown an exception.
/// </summary>
/// <exception cref="InvalidOperationException">The result isn't of type <see cref="JobResultCompleted{TData}"/></exception>
public TData RequireData<TData>()
where TData : notnull
{
if (!TryGetCompleted(out var completed))
throw new InvalidOperationException($"JobResult is of type `{ResultType}` but expected `{JobResultType.Completed}`");
throw new InvalidOperationException($"JobResult is of type `{ResultType}` but expected `{JobResultType.Completed}`: `{ToString()}`");

if (!completed.TryGetData<TData>(out var data))
throw new InvalidOperationException("Completed JobResult doesn't have data!");
throw new InvalidOperationException($"Completed JobResult doesn't have data: `{ToString()}`");

return data;
}

/// <summary>
/// Creates a failed job result from an exception.
/// </summary>
[StackTraceHidden]
public static JobResult CreateFailed(Exception exception)
{
Expand All @@ -99,15 +106,23 @@ public static JobResult CreateFailed(Exception exception)
});
}

/// <summary>
/// Creates a failed job result from an error message.
/// </summary>
[StackTraceHidden]
public static JobResult CreateFailed(string message)
{
return CreateFailed(new Exception(message));
}

/// <summary>
/// Creates a cancelled job result.
/// </summary>
[StackTraceHidden] public static JobResult CreateCancelled() => new(new JobResultCancelled());
[StackTraceHidden] public static JobResult CreateCompleted() => new(new JobResultCompleted());

/// <summary>
/// Creates a completed job result with data.
/// </summary>
[StackTraceHidden]
public static JobResult CreateCompleted<TData>(TData data)
where TData : notnull
Expand All @@ -117,4 +132,14 @@ public static JobResult CreateCompleted<TData>(TData data)
Data = data,
});
}

/// <inheritdoc/>
public override string ToString()
{
return _value.Match(
f0: x => x.ToString(),
f1: x => x.ToString(),
f2: x => x.ToString()
);
}
}
2 changes: 1 addition & 1 deletion src/Abstractions/NexusMods.Abstractions.Jobs/JobWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public delegate Task<TData> ExecuteAsyncDelegateWithData<TJob, TData>(TJob job,
public delegate Task<JobResult> ExecuteAsyncDelegate<TJob>(TJob job, AJobWorker<TJob> worker, CancellationToken cancellationToken)
where TJob : AJob;

public static AJobWorker<TJob> Create<TJob, TData>(TJob job, ExecuteAsyncDelegateWithData<TJob, TData> func)
public static AJobWorker<TJob> CreateWithData<TJob, TData>(TJob job, ExecuteAsyncDelegateWithData<TJob, TData> func)
where TJob : AJob
where TData : notnull
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.Library;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
using NexusMods.MnemonicDB.Abstractions;

namespace NexusMods.Abstractions.Installers;
namespace NexusMods.Abstractions.Library.Installers;

/// <summary>
/// Base implementation of <see cref="ILibraryArchiveInstaller"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.Library;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
using NexusMods.MnemonicDB.Abstractions;

namespace NexusMods.Abstractions.Installers;
namespace NexusMods.Abstractions.Library.Installers;

/// <summary>
/// Base implementation of <see cref="ILibraryFileInstaller"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.Library;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
using NexusMods.MnemonicDB.Abstractions;

namespace NexusMods.Abstractions.Installers;
namespace NexusMods.Abstractions.Library.Installers;

/// <summary>
/// Base implementation of <see cref="ILibraryItemInstaller"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.Library;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
using NexusMods.MnemonicDB.Abstractions;

namespace NexusMods.Abstractions.Installers;
namespace NexusMods.Abstractions.Library.Installers;

/// <summary>
/// Variant of <see cref="ILibraryFileInstaller"/> for <see cref="LibraryArchive"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.Library;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
using NexusMods.MnemonicDB.Abstractions;

namespace NexusMods.Abstractions.Installers;
namespace NexusMods.Abstractions.Library.Installers;

/// <summary>
/// Variant of <see cref="ILibraryItemInstaller"/> for <see cref="LibraryFile"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using JetBrains.Annotations;
using NexusMods.Abstractions.Library;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
using NexusMods.MnemonicDB.Abstractions;

namespace NexusMods.Abstractions.Installers;
namespace NexusMods.Abstractions.Library.Installers;

/// <summary>
/// Turns <see cref="LibraryItem"/> into <see cref="LoadoutItem"/>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- NuGet Package Shared Details -->
<Import Project="$([MSBuild]::GetPathOfFileAbove('NuGet.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup>
<ProjectReference Include="..\NexusMods.Abstractions.Library.Models\NexusMods.Abstractions.Library.Models.csproj" />
<ProjectReference Include="..\NexusMods.Abstractions.Loadouts\NexusMods.Abstractions.Loadouts.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="ALibraryArchiveInstaller.cs">
<DependentUpon>ILibraryArchiveInstaller.cs</DependentUpon>
</Compile>
<Compile Update="ALibraryFileInstaller.cs">
<DependentUpon>ILibraryFileInstaller.cs</DependentUpon>
</Compile>
<Compile Update="ALibraryItemInstaller.cs">
<DependentUpon>ILibraryItemInstaller.cs</DependentUpon>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using NexusMods.MnemonicDB.Abstractions.Attributes;
using NexusMods.MnemonicDB.Abstractions.Models;

namespace NexusMods.Abstractions.Library;
namespace NexusMods.Abstractions.Library.Models;

/// <summary>
/// Represents an archive in the library.
Expand Down
Loading

0 comments on commit c84e791

Please sign in to comment.