Переименование UOI в COI

This commit is contained in:
2025-03-10 21:56:22 +03:00
parent 96aa828808
commit 5e21d941df
11 changed files with 123 additions and 115 deletions
@@ -53,7 +53,7 @@ namespace mROA.Implementation.Backend
_lastIndexFinder = Task.FromResult(id);
}
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
{
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
}
@@ -6,23 +6,14 @@ namespace mROA.Implementation.Backend
{
public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub
{
private Dictionary<int, IContextRepository> _repositories = new();
private readonly Func<int, IContextRepository> _produceRepository;
private Dictionary<int, IContextRepository> _repositories = new();
public MultiClientContextRepository(Func<int, IContextRepository> produceRepository)
{
_produceRepository = produceRepository;
}
private IContextRepository GetRepositoryByClientId(int clientId)
{
if (_repositories.TryGetValue(clientId, out var repository))
return repository;
var created = _produceRepository(clientId);
_repositories.Add(clientId, created);
return created;
}
public void Inject<T>(T dependency)
{
}
@@ -39,18 +30,12 @@ namespace mROA.Implementation.Backend
repository.ClearObject(id);
}
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
{
var repository = GetRepository(sharedObjectShellShell.Identifier.OwnerId);
return repository.GetObject<T>(sharedObjectShellShell.Identifier.ContextId);
}
public object GetObject(int id)
{
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
return repository.GetObject<object>(id);
}
public T? GetObject<T>(int id)
{
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
@@ -74,5 +59,21 @@ namespace mROA.Implementation.Backend
var repository = GetRepositoryByClientId(clientId);
return repository;
}
private IContextRepository GetRepositoryByClientId(int clientId)
{
if (_repositories.TryGetValue(clientId, out var repository))
return repository;
var created = _produceRepository(clientId);
_repositories.Add(clientId, created);
return created;
}
public object GetObject(int id)
{
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
return repository.GetObject<object>(id);
}
}
}
+3 -3
View File
@@ -9,7 +9,7 @@ namespace mROA.Implementation
{
Guid Id { get; }
int CommandId { get; }
UniversalObjectIdentifier ObjectId { get; }
ComplexObjectIdentifier ObjectId { get; }
object?[]? Parameters { get; }
}
@@ -17,7 +17,7 @@ namespace mROA.Implementation
{
public Guid Id { get; set; } = Guid.NewGuid();
public int CommandId { get; set; }
public UniversalObjectIdentifier ObjectId { get; set; } = UniversalObjectIdentifier.Null;
public ComplexObjectIdentifier ObjectId { get; set; } = ComplexObjectIdentifier.Null;
public object?[]? Parameters { get; set; }
@@ -31,7 +31,7 @@ namespace mROA.Implementation
{
public Guid Id { get; set; }
public int CommandId { get; set; } = -2;
public UniversalObjectIdentifier ObjectId { get; set; } = UniversalObjectIdentifier.Null;
public ComplexObjectIdentifier ObjectId { get; set; } = ComplexObjectIdentifier.Null;
public object?[]? Parameters { get; set; } = null;
public override string ToString()
@@ -3,19 +3,19 @@ using System;
namespace mROA.Implementation
{
#pragma warning disable CS8618, CS9264
public struct UniversalObjectIdentifier : IEquatable<UniversalObjectIdentifier>
public struct ComplexObjectIdentifier : IEquatable<ComplexObjectIdentifier>
{
public int ContextId;
public int OwnerId;
public UniversalObjectIdentifier(int contextId, int ownerId)
public ComplexObjectIdentifier(int contextId, int ownerId)
{
ContextId = contextId;
OwnerId = ownerId;
}
public static UniversalObjectIdentifier Null = new UniversalObjectIdentifier { ContextId = -2, OwnerId = -1 };
public static UniversalObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 };
public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
public override string ToString()
{
@@ -34,14 +34,14 @@ namespace mROA.Implementation
}
}
public bool Equals(UniversalObjectIdentifier other)
public bool Equals(ComplexObjectIdentifier other)
{
return ContextId == other.ContextId && OwnerId == other.OwnerId;
}
public override bool Equals(object? obj)
{
return obj is UniversalObjectIdentifier other && Equals(other);
return obj is ComplexObjectIdentifier other && Equals(other);
}
public override int GetHashCode()
+11 -9
View File
@@ -6,8 +6,8 @@ namespace mROA.Implementation
{
public class RemoteContextRepository : IContextRepository
{
private IRepresentationModuleProducer? _representationProducer;
public static Dictionary<Type, Type> RemoteTypes = new();
private IRepresentationModuleProducer? _representationProducer;
public int ResisterObject<T>(object o, IEndPointContext context)
{
@@ -19,7 +19,7 @@ namespace mROA.Implementation
throw new NotSupportedException();
}
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
{
if (_representationProducer == null)
throw new NullReferenceException("representation producer is not initialized");
@@ -31,18 +31,14 @@ namespace mROA.Implementation
return remote;
}
public object GetObject(int id)
{
throw new NotSupportedException();
}
public T GetObject<T>(int id)
{
if (_representationProducer == null)
throw new NullReferenceException("representation producer is not initialized");
if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
var representationModule = _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
var representationModule =
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
var remote = (T)Activator.CreateInstance(remoteType, id,
representationModule)!;
return remote;
@@ -53,7 +49,8 @@ namespace mROA.Implementation
if (_representationProducer == null)
throw new NullReferenceException("representation producer is not initialized");
var representationModule = _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
var representationModule =
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId());
return Activator.CreateInstance(RemoteTypes[type], -1,
representationModule)!;
}
@@ -73,5 +70,10 @@ namespace mROA.Implementation
if (dependency is IRepresentationModuleProducer serialisationModule)
_representationProducer = serialisationModule;
}
public object GetObject(int id)
{
throw new NotSupportedException();
}
}
}
+19 -16
View File
@@ -10,25 +10,34 @@ namespace mROA.Implementation
{
public abstract class RemoteObjectBase : IDisposable
{
private readonly UniversalObjectIdentifier _identifier;
private readonly ComplexObjectIdentifier _identifier;
private readonly IRepresentationModule _representationModule;
protected RemoteObjectBase(int id, IRepresentationModule representationModule)
{
_identifier = new UniversalObjectIdentifier { ContextId = id, OwnerId = representationModule.Id };
_identifier = new ComplexObjectIdentifier { ContextId = id, OwnerId = representationModule.Id };
_representationModule = representationModule;
}
public int Id => _identifier.ContextId;
public int OwnerId => _identifier.OwnerId;
public UniversalObjectIdentifier Identifier => _identifier;
public ComplexObjectIdentifier Identifier => _identifier;
public void Dispose()
{
if (_identifier.IsStatic)
return;
CallAsync(-1).Wait();
}
protected async Task<T> GetResultAsync<T>(int methodId, object?[]? parameters = null,
CancellationToken cancellationToken = default)
{
var request = new DefaultCallRequest
{ CommandId = methodId, ObjectId = _identifier, Parameters = parameters
};
{
CommandId = methodId, ObjectId = _identifier, Parameters = parameters
};
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
var localTokenSource = new CancellationTokenSource();
@@ -53,7 +62,7 @@ namespace mROA.Implementation
});
localTokenSource.Cancel();
});
Task.WaitAny(new Task[]
{
successResponse, errorResponse
@@ -80,8 +89,9 @@ namespace mROA.Implementation
CancellationToken cancellationToken = default)
{
var request = new DefaultCallRequest
{ CommandId = methodId, ObjectId = _identifier, Parameters = parameters
};
{
CommandId = methodId, ObjectId = _identifier, Parameters = parameters
};
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
var localTokenSource = new CancellationTokenSource();
@@ -122,13 +132,6 @@ namespace mROA.Implementation
throw errorResponse.Result.GetException();
}
public void Dispose()
{
if (_identifier.IsStatic)
return;
CallAsync(-1).Wait();
}
public override string ToString()
{
return _identifier.ToString();
+4 -4
View File
@@ -11,13 +11,13 @@ namespace mROA.Implementation
public interface ISharedObjectShell
{
IEndPointContext EndPointContext { get; set; }
UniversalObjectIdentifier Identifier { get; set; }
ComplexObjectIdentifier Identifier { get; set; }
object UniversalValue { get; set; }
}
public class SharedObjectShellShell<T> : ISharedObjectShell where T : notnull
{
private UniversalObjectIdentifier _identifier = UniversalObjectIdentifier.Null;
private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null;
private T _value;
@@ -64,7 +64,7 @@ namespace mROA.Implementation
OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId
};
public UniversalObjectIdentifier Identifier
public ComplexObjectIdentifier Identifier
{
get
{
@@ -74,7 +74,7 @@ namespace mROA.Implementation
set
{
_identifier = value;
Value = GetDefaultContextRepository().GetObjectBySharedObject(this);
Value = GetDefaultContextRepository().GetObjectByShell(this);
}
}