Renaming context repository to instance repository
This commit is contained in:
@@ -30,11 +30,11 @@ class Program
|
||||
builder.Modules.Add(new CreativeRepresentationModuleProducer(
|
||||
new IInjectableModule[] { builder.GetModule<IContextualSerializationToolKit>()! },
|
||||
typeof(RepresentationModule)));
|
||||
builder.Modules.Add(new RemoteContextRepository());
|
||||
builder.Modules.Add(new RemoteInstanceRepository());
|
||||
// builder.UseCollectableContextRepository(typeof(PrinterFactory).Assembly);
|
||||
builder.Modules.Add(new MultiClientContextRepository(i =>
|
||||
builder.Modules.Add(new MultiClientInstanceRepository(i =>
|
||||
{
|
||||
var repo = new ContextRepository();
|
||||
var repo = new InstanceRepository();
|
||||
repo.FillSingletons(typeof(PrinterFactory).Assembly);
|
||||
repo.Inject(builder.Modules.OfType<CreativeRepresentationModuleProducer>().First());
|
||||
return repo;
|
||||
|
||||
@@ -23,7 +23,7 @@ class Program
|
||||
|
||||
builder.Modules.Add(new CborSerializationToolkit());
|
||||
builder.Modules.Add(new EndPointContext());
|
||||
builder.Modules.Add(new RemoteContextRepository());
|
||||
builder.Modules.Add(new RemoteInstanceRepository());
|
||||
builder.Modules.Add(new ChannelInteractionModule());
|
||||
builder.Modules.Add(new UdpUntrustedInteraction());
|
||||
builder.Modules.Add(new RepresentationModule());
|
||||
@@ -43,7 +43,7 @@ class Program
|
||||
_ = builder.GetModule<RequestExtractor>()!.StartExtraction();
|
||||
_ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint);
|
||||
Console.WriteLine(builder.GetModule<IEndPointContext>().HostId);
|
||||
var context = builder.GetModule<RemoteContextRepository>();
|
||||
var context = builder.GetModule<RemoteInstanceRepository>();
|
||||
|
||||
var factory =
|
||||
context.GetSingleObject(typeof(IPrinterFactory),
|
||||
|
||||
@@ -2,7 +2,7 @@ namespace mROA.Abstract
|
||||
{
|
||||
public interface IContextRepositoryHub
|
||||
{
|
||||
IContextRepository GetRepository(int clientId);
|
||||
IInstanceRepository GetRepository(int clientId);
|
||||
void FreeRepository(int clientId);
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
{
|
||||
public interface IEndPointContext : IInjectableModule
|
||||
{
|
||||
IContextRepository RealRepository { get; }
|
||||
IContextRepository RemoteRepository { get; }
|
||||
IInstanceRepository RealRepository { get; }
|
||||
IInstanceRepository RemoteRepository { get; }
|
||||
int HostId { get; set; }
|
||||
int OwnerId { get; set; }
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace mROA.Abstract
|
||||
{
|
||||
public interface IExecuteModule : IInjectableModule
|
||||
{
|
||||
ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
|
||||
ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
|
||||
IRepresentationModule representationModule, IEndPointContext context);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ using mROA.Implementation;
|
||||
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
public interface IContextRepository : IInjectableModule
|
||||
public interface IInstanceRepository : IInjectableModule
|
||||
{
|
||||
int HostId { get; set; }
|
||||
int ResisterObject<T>(object o, IEndPointContext context);
|
||||
@@ -21,7 +21,7 @@ namespace mROA.Implementation.Backend
|
||||
|
||||
public static void UseCollectableContextRepository(this FullMixBuilder builder, params Assembly[] assemblies)
|
||||
{
|
||||
var repo = new ContextRepository();
|
||||
var repo = new InstanceRepository();
|
||||
repo.FillSingletons(assemblies);
|
||||
builder.Modules.Add(repo);
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace mROA.Implementation.Backend
|
||||
}
|
||||
}
|
||||
|
||||
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository,
|
||||
public ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
|
||||
IRepresentationModule representationModule, IEndPointContext endPointContext)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
ThrowIfNotInjected(contextRepository);
|
||||
ThrowIfNotInjected(instanceRepository);
|
||||
if (command is CancelRequest)
|
||||
{
|
||||
return CancelExecution(command);
|
||||
@@ -43,7 +43,7 @@ namespace mROA.Implementation.Backend
|
||||
if (invoker == null)
|
||||
throw new Exception($"Command {command.CommandId} not found");
|
||||
|
||||
var context = GetContext(command, contextRepository, invoker, endPointContext);
|
||||
var context = GetContext(command, instanceRepository, invoker, endPointContext);
|
||||
|
||||
if (context == null)
|
||||
throw new NullReferenceException("Instance can't be null");
|
||||
@@ -70,7 +70,7 @@ namespace mROA.Implementation.Backend
|
||||
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
|
||||
if (command.CommandId == -1)
|
||||
{
|
||||
contextRepository.ClearObject(command.ObjectId, endPointContext);
|
||||
instanceRepository.ClearObject(command.ObjectId, endPointContext);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -86,12 +86,12 @@ namespace mROA.Implementation.Backend
|
||||
}
|
||||
}
|
||||
|
||||
private static object GetContext(ICallRequest command, IContextRepository contextRepository,
|
||||
private static object GetContext(ICallRequest command, IInstanceRepository instanceRepository,
|
||||
IMethodInvoker invoker, IEndPointContext endPointContext)
|
||||
{
|
||||
var context = command.ObjectId.ContextId != -1
|
||||
? contextRepository.GetObject<object>(command.ObjectId, endPointContext)
|
||||
: contextRepository.GetSingleObject(invoker.SuitableType, endPointContext);
|
||||
? instanceRepository.GetObject<object>(command.ObjectId, endPointContext)
|
||||
: instanceRepository.GetSingleObject(invoker.SuitableType, endPointContext);
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace mROA.Implementation.Backend
|
||||
return castedParams;
|
||||
}
|
||||
|
||||
private void ThrowIfNotInjected(IContextRepository contextRepository)
|
||||
private void ThrowIfNotInjected(IInstanceRepository instanceRepository)
|
||||
{
|
||||
if (_cancellationRepo is null)
|
||||
throw new NullReferenceException("Method repository was not defined");
|
||||
@@ -114,7 +114,7 @@ namespace mROA.Implementation.Backend
|
||||
if (_methodRepo is null)
|
||||
throw new NullReferenceException("Method repository was not defined");
|
||||
|
||||
if (contextRepository is null)
|
||||
if (instanceRepository is null)
|
||||
throw new NullReferenceException("Context repository was not defined");
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mROA.Implementation.Backend
|
||||
{
|
||||
private IConnectionHub? _hub;
|
||||
|
||||
private IContextRepository? _contextRepository;
|
||||
private IContextRepository? _remoteContextRepository;
|
||||
private IInstanceRepository? _contextRepository;
|
||||
private IInstanceRepository? _remoteContextRepository;
|
||||
private IMethodRepository? _methodRepository;
|
||||
private IContextualSerializationToolKit? _serializationToolkit;
|
||||
private IExecuteModule? _executeModule;
|
||||
@@ -21,11 +21,11 @@ namespace mROA.Implementation.Backend
|
||||
_hub = connectionHub;
|
||||
_hub.OnConnected += HubOnOnConnected;
|
||||
break;
|
||||
case MultiClientContextRepository:
|
||||
case ContextRepository:
|
||||
_contextRepository = dependency as IContextRepository;
|
||||
case MultiClientInstanceRepository:
|
||||
case InstanceRepository:
|
||||
_contextRepository = dependency as IInstanceRepository;
|
||||
break;
|
||||
case RemoteContextRepository remoteContextRepository:
|
||||
case RemoteInstanceRepository remoteContextRepository:
|
||||
_remoteContextRepository = remoteContextRepository;
|
||||
break;
|
||||
case IMethodRepository methodRepository:
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ using mROA.Implementation.Attributes;
|
||||
|
||||
namespace mROA.Implementation.Backend
|
||||
{
|
||||
public class ContextRepository : IContextRepository
|
||||
public class InstanceRepository : IInstanceRepository
|
||||
{
|
||||
public static object[] EventBinders = { };
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace mROA.Implementation.Backend
|
||||
private IStorage<object> _storage;
|
||||
|
||||
|
||||
public ContextRepository()
|
||||
public InstanceRepository()
|
||||
{
|
||||
_storage = new ExtensibleStorage<object>();
|
||||
}
|
||||
+6
-6
@@ -4,12 +4,12 @@ using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation.Backend
|
||||
{
|
||||
public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub
|
||||
public class MultiClientInstanceRepository : IInstanceRepository, IContextRepositoryHub
|
||||
{
|
||||
private readonly Func<int, IContextRepository> _produceRepository;
|
||||
private readonly Dictionary<int, IContextRepository> _repositories = new();
|
||||
private readonly Func<int, IInstanceRepository> _produceRepository;
|
||||
private readonly Dictionary<int, IInstanceRepository> _repositories = new();
|
||||
|
||||
public MultiClientContextRepository(Func<int, IContextRepository> produceRepository)
|
||||
public MultiClientInstanceRepository(Func<int, IInstanceRepository> produceRepository)
|
||||
{
|
||||
_produceRepository = produceRepository;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace mROA.Implementation.Backend
|
||||
return repository.GetObjectIndex<T>(o, context);
|
||||
}
|
||||
|
||||
public IContextRepository GetRepository(int clientId)
|
||||
public IInstanceRepository GetRepository(int clientId)
|
||||
{
|
||||
var repository = GetRepositoryByClientId(clientId);
|
||||
return repository;
|
||||
@@ -61,7 +61,7 @@ namespace mROA.Implementation.Backend
|
||||
_repositories.Remove(clientId);
|
||||
}
|
||||
|
||||
private IContextRepository GetRepositoryByClientId(int clientId)
|
||||
private IInstanceRepository GetRepositoryByClientId(int clientId)
|
||||
{
|
||||
if (_repositories.TryGetValue(clientId, out var repository))
|
||||
return repository;
|
||||
+1
-1
@@ -5,7 +5,7 @@ using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
public class ComplexContextRepository : IContextRepository
|
||||
public class ComplexInstanceRepository : IInstanceRepository
|
||||
{
|
||||
private List<KeyValuePair<int, ExtensibleStorage<object>>> _storages = new();
|
||||
public static object[] EventBinders = { };
|
||||
@@ -6,8 +6,8 @@ namespace mROA.Implementation
|
||||
{
|
||||
public class EndPointContext : IEndPointContext
|
||||
{
|
||||
public IContextRepository RealRepository { get; set; }
|
||||
public IContextRepository RemoteRepository { get; set; }
|
||||
public IInstanceRepository RealRepository { get; set; }
|
||||
public IInstanceRepository RemoteRepository { get; set; }
|
||||
public int HostId { get; set; }
|
||||
|
||||
public int OwnerId { get; set; }
|
||||
@@ -16,10 +16,10 @@ namespace mROA.Implementation
|
||||
{
|
||||
switch (dependency)
|
||||
{
|
||||
case RemoteContextRepository remoteRepository:
|
||||
case RemoteInstanceRepository remoteRepository:
|
||||
RemoteRepository = remoteRepository;
|
||||
break;
|
||||
case ContextRepository realRepository:
|
||||
case InstanceRepository realRepository:
|
||||
RealRepository = realRepository;
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
public class RemoteContextRepository : IContextRepository
|
||||
public class RemoteInstanceRepository : IInstanceRepository
|
||||
{
|
||||
private List<RemoteObjectBase> _producedRemoteEndpoints = new();
|
||||
public static Dictionary<Type, Type> RemoteTypes = new();
|
||||
@@ -20,12 +20,14 @@ namespace mROA.Implementation
|
||||
{
|
||||
private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null;
|
||||
|
||||
private T _value;
|
||||
private T? _value;
|
||||
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public SharedObjectShellShell()
|
||||
{
|
||||
_value = default;
|
||||
EndPointContext = new EndPointContext();
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
@@ -41,7 +43,7 @@ namespace mROA.Implementation
|
||||
// ReSharper disable once MemberCanBePrivate.Global
|
||||
public T Value
|
||||
{
|
||||
get => _value;
|
||||
get => _value!;
|
||||
set
|
||||
{
|
||||
_value = value;
|
||||
@@ -76,11 +78,11 @@ namespace mROA.Implementation
|
||||
|
||||
public object UniversalValue
|
||||
{
|
||||
get => _value;
|
||||
get => _value!;
|
||||
set => _value = (T)value;
|
||||
}
|
||||
|
||||
private IContextRepository GetDefaultContextRepository() =>
|
||||
private IInstanceRepository GetDefaultContextRepository() =>
|
||||
(_identifier.OwnerId == EndPointContext.HostId
|
||||
? EndPointContext.RealRepository
|
||||
: EndPointContext.RemoteRepository) ??
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
#pragma warning disable CS8618, CS9264
|
||||
public static class TransmissionConfig
|
||||
{
|
||||
#if TRACE
|
||||
public static int TotalTransmittedBytes { get; set; }
|
||||
#endif
|
||||
// private static IContextRepository? _realContextRepository;
|
||||
// private static IContextRepository? _remoteEndpointContextRepository;
|
||||
// private static IOwnershipRepository? _ownershipRepository;
|
||||
//
|
||||
// public static IContextRepository RealContextRepository
|
||||
// {
|
||||
// get => _realContextRepository ?? throw new NullReferenceException("RealContextRepository is null");
|
||||
// set => _realContextRepository = value;
|
||||
// }
|
||||
//
|
||||
// public static IContextRepository RemoteEndpointContextRepository
|
||||
// {
|
||||
// get => _remoteEndpointContextRepository ??
|
||||
// throw new NullReferenceException("RemoteEndpointContextRepository is null");
|
||||
// set => _remoteEndpointContextRepository = value;
|
||||
// }
|
||||
//
|
||||
// public static IOwnershipRepository OwnershipRepository
|
||||
// {
|
||||
// get => _ownershipRepository ?? throw new NullReferenceException("OwnershipRepository is null");
|
||||
// set => _ownershipRepository = value;
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user