Теперь без шела работает

This commit is contained in:
2025-03-01 19:06:18 +03:00
parent b5b766342e
commit bd3c623626
16 changed files with 219 additions and 176 deletions
@@ -58,9 +58,9 @@ namespace mROA.Implementation.Backend
_lastIndexFinder = Task.FromResult(id);
}
public T GetObjectBySharedObject<T>(SharedObject<T> sharedObject)
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
{
return (T)GetObject(sharedObject.Identifier.ContextId);
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
}
public object GetObject(int id)
@@ -39,10 +39,10 @@ namespace mROA.Implementation.Backend
repository.ClearObject(id);
}
public T GetObjectBySharedObject<T>(SharedObject<T> sharedObject)
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
{
var repository = GetRepository(sharedObject.Identifier.OwnerId);
return repository.GetObject<T>(sharedObject.Identifier.ContextId);
var repository = GetRepository(sharedObjectShellShell.Identifier.OwnerId);
return repository.GetObject<T>(sharedObjectShellShell.Identifier.ContextId);
}
public object GetObject(int id)
@@ -19,14 +19,14 @@ namespace mROA.Implementation
throw new NotSupportedException();
}
public T GetObjectBySharedObject<T>(SharedObject<T> sharedObject)
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
{
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(sharedObject.Identifier.OwnerId);
var remote = (T)Activator.CreateInstance(remoteType, sharedObject.Identifier.ContextId,
var representationModule = _representationProducer.Produce(sharedObjectShellShell.Identifier.OwnerId);
var remote = (T)Activator.CreateInstance(remoteType, sharedObjectShellShell.Identifier.ContextId,
representationModule)!;
return remote;
}
-140
View File
@@ -1,140 +0,0 @@
using System;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using mROA.Abstract;
using mROA.Implementation.Attributes;
// ReSharper disable UnusedMember.Global
#pragma warning disable CS8618, CS9264
namespace mROA.Implementation
{
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;
}
}
public interface ISharedObject
{
IEndPointContext EndPointContext { get; set; }
}
public class SharedObject<T> : ISharedObject where T : notnull
{
[SerializationIgnore]
[JsonIgnore]
public IEndPointContext EndPointContext { get; set; } = new EndPointContext
{
RealRepository = TransmissionConfig.RealContextRepository,
RemoteRepository = TransmissionConfig.RemoteEndpointContextRepository,
HostId = TransmissionConfig.OwnershipRepository.GetHostOwnershipId(),
OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId
};
private IContextRepository GetDefaultContextRepository() =>
(_identifier.OwnerId == EndPointContext.HostId
? EndPointContext.RealRepository
: EndPointContext.RemoteRepository) ??
throw new NullReferenceException(
"DefaultContextRepository was not defined");
private UniversalObjectIdentifier _identifier = UniversalObjectIdentifier.Null;
public UniversalObjectIdentifier Identifier
{
get
{
_identifier.OwnerId = _identifier.OwnerId == -1 ? EndPointContext.OwnerId : _identifier.OwnerId;
return _identifier;
}
set
{
_identifier = value;
Value = GetDefaultContextRepository().GetObjectBySharedObject(this);
}
}
// public int OwnerId
// {
// get
// {
// _ownerId = _ownerId == -1 ? EndPointContext.OwnerId : _ownerId;
// return _ownerId;
// }
// set => _ownerId = value;
// }
//
// // ReSharper disable once MemberCanBePrivate.Global
// public int ContextId
// {
// // ReSharper disable once UnusedMember.Global
// get
// {
// if (_contextId != -2)
// return _contextId;
//
// _contextId = EndPointContext.RealRepository.GetObjectIndex(Value);
// return _contextId;
// }
// set
// {
// _contextId = value;
// Value = GetDefaultContextRepository().GetObjectBySharedObject(this);
// }
// }
[JsonIgnore] [SerializationIgnore] public T Value { get; private set; }
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once UnusedMember.Global
public SharedObject()
{
}
// ReSharper disable once UnusedMember.Global
public SharedObject(T value)
{
Value = value;
if (value is RemoteObjectBase ro)
{
_identifier = ro.Identifier;
}
else
{
_identifier.OwnerId = EndPointContext.HostId;
_identifier.ContextId = EndPointContext.RealRepository.GetObjectIndex(Value);
}
}
public static implicit operator T(SharedObject<T> value) => value.Value;
public static implicit operator SharedObject<T>(T value) =>
new(value);
}
}
+100
View File
@@ -0,0 +1,100 @@
using System;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using mROA.Abstract;
using mROA.Implementation.Attributes;
// ReSharper disable UnusedMember.Global
#pragma warning disable CS8618, CS9264
namespace mROA.Implementation
{
public interface ISharedObjectShell
{
IEndPointContext EndPointContext { get; set; }
UniversalObjectIdentifier Identifier { get; set; }
object UniversalValue { get; set; }
}
public class SharedObjectShellShell<T> : ISharedObjectShell where T : notnull
{
[SerializationIgnore]
[JsonIgnore]
public IEndPointContext EndPointContext { get; set; } = new EndPointContext
{
RealRepository = TransmissionConfig.RealContextRepository,
RemoteRepository = TransmissionConfig.RemoteEndpointContextRepository,
HostId = TransmissionConfig.OwnershipRepository.GetHostOwnershipId(),
OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId
};
private IContextRepository GetDefaultContextRepository() =>
(_identifier.OwnerId == EndPointContext.HostId
? EndPointContext.RealRepository
: EndPointContext.RemoteRepository) ??
throw new NullReferenceException(
"DefaultContextRepository was not defined");
private UniversalObjectIdentifier _identifier = UniversalObjectIdentifier.Null;
public UniversalObjectIdentifier Identifier
{
get
{
_identifier.OwnerId = _identifier.OwnerId == -1 ? EndPointContext.OwnerId : _identifier.OwnerId;
return _identifier;
}
set
{
_identifier = value;
Value = GetDefaultContextRepository().GetObjectBySharedObject(this);
}
}
public object UniversalValue
{
get => _value;
set => _value = (T)value;
}
private T _value;
[JsonIgnore]
[SerializationIgnore]
public T Value
{
get => _value;
set
{
_value = value;
if (value is RemoteObjectBase ro)
{
_identifier = ro.Identifier;
}
else
{
_identifier.OwnerId = EndPointContext.HostId;
_identifier.ContextId = EndPointContext.RealRepository.GetObjectIndex(Value);
}
}
}
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once UnusedMember.Global
public SharedObjectShellShell()
{
}
// ReSharper disable once UnusedMember.Global
public SharedObjectShellShell(T value)
{
Value = value;
}
public static implicit operator T(SharedObjectShellShell<T> value) => value.Value;
public static implicit operator SharedObjectShellShell<T>(T value) =>
new(value);
}
}
+35
View File
@@ -0,0 +1,35 @@
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;
}
}
}
@@ -9,19 +9,18 @@ namespace mROA.Implementation
public int OwnerId;
public static UniversalObjectIdentifier Null = new UniversalObjectIdentifier { ContextId = -2, OwnerId = -1 };
public static UniversalObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
public override string ToString()
{
return $"{{ {nameof(ContextId)}: {ContextId}, {nameof(OwnerId)}: {OwnerId} }}";
}
public bool IsStatic => ContextId == -1;
public ulong Flat
{
get
{
return (ulong)OwnerId << 32 | (uint)ContextId;
}
get { return (ulong)OwnerId << 32 | (uint)ContextId; }
set
{
OwnerId = (int)(value >> 32);