Переименование UOI в COI
This commit is contained in:
@@ -65,6 +65,50 @@ namespace mROA.Cbor
|
|||||||
return Convert.ChangeType(nonCasted, type);
|
return Convert.ChangeType(nonCasted, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Inject<T>(T dependency)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Serialize<T>(T objectToSerialize)
|
||||||
|
{
|
||||||
|
return Serialize(objectToSerialize, typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] Serialize(object objectToSerialize, Type type)
|
||||||
|
{
|
||||||
|
return Serialize(objectToSerialize, context: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Deserialize<T>(byte[] rawData)
|
||||||
|
{
|
||||||
|
return Deserialize<T>(rawData: rawData, context: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? Deserialize(byte[] rawData, Type type)
|
||||||
|
{
|
||||||
|
return Deserialize(rawData: rawData, type, context: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Deserialize<T>(Span<byte> rawData)
|
||||||
|
{
|
||||||
|
return Deserialize<T>(rawData.ToArray().AsMemory(), context: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? Deserialize(Span<byte> rawData, Type type)
|
||||||
|
{
|
||||||
|
return Deserialize(rawData: rawData.ToArray(), type: type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Cast<T>(object nonCasted)
|
||||||
|
{
|
||||||
|
return Cast<T>(nonCasted: nonCasted, context: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object Cast(object nonCasted, Type type)
|
||||||
|
{
|
||||||
|
return Cast(nonCasted: nonCasted, type: type, context: null);
|
||||||
|
}
|
||||||
|
|
||||||
private void WriteData(object? obj, CborWriter writer, IEndPointContext? context)
|
private void WriteData(object? obj, CborWriter writer, IEndPointContext? context)
|
||||||
{
|
{
|
||||||
switch (obj)
|
switch (obj)
|
||||||
@@ -322,7 +366,7 @@ namespace mROA.Cbor
|
|||||||
var identifier = reader.ReadUInt64();
|
var identifier = reader.ReadUInt64();
|
||||||
reader.ReadEndArray();
|
reader.ReadEndArray();
|
||||||
|
|
||||||
so.Identifier = UniversalObjectIdentifier.FromFlat(identifier);
|
so.Identifier = ComplexObjectIdentifier.FromFlat(identifier);
|
||||||
return so.UniversalValue;
|
return so.UniversalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,49 +431,5 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
return finalProperties;
|
return finalProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Inject<T>(T dependency)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] Serialize<T>(T objectToSerialize)
|
|
||||||
{
|
|
||||||
return Serialize(objectToSerialize, typeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] Serialize(object objectToSerialize, Type type)
|
|
||||||
{
|
|
||||||
return Serialize(objectToSerialize, context: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Deserialize<T>(byte[] rawData)
|
|
||||||
{
|
|
||||||
return Deserialize<T>(rawData: rawData, context: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public object? Deserialize(byte[] rawData, Type type)
|
|
||||||
{
|
|
||||||
return Deserialize(rawData: rawData, type, context: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Deserialize<T>(Span<byte> rawData)
|
|
||||||
{
|
|
||||||
return Deserialize<T>(rawData.ToArray().AsMemory(), context: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public object? Deserialize(Span<byte> rawData, Type type)
|
|
||||||
{
|
|
||||||
return Deserialize(rawData: rawData.ToArray(), type: type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public T Cast<T>(object nonCasted)
|
|
||||||
{
|
|
||||||
return Cast<T>(nonCasted: nonCasted, context: null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public object Cast(object nonCasted, Type type)
|
|
||||||
{
|
|
||||||
return Cast(nonCasted: nonCasted, type: type, context: null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,16 +12,15 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
public class PreParsedValue : IPreParsedValue
|
public class PreParsedValue : IPreParsedValue
|
||||||
{
|
{
|
||||||
private List<object> _properties { get; set; }
|
|
||||||
|
|
||||||
public PreParsedValue(List<object> properties)
|
public PreParsedValue(List<object> properties)
|
||||||
{
|
{
|
||||||
_properties = properties;
|
_properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<object> _properties { get; set; }
|
||||||
|
|
||||||
public object? ToObject(Type type, IEndPointContext? context)
|
public object? ToObject(Type type, IEndPointContext? context)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (type.IsInterface)
|
if (type.IsInterface)
|
||||||
{
|
{
|
||||||
var sharedShell = typeof(SharedObjectShellShell<>).MakeGenericType(type);
|
var sharedShell = typeof(SharedObjectShellShell<>).MakeGenericType(type);
|
||||||
@@ -31,10 +30,10 @@ namespace mROA.Cbor
|
|||||||
if (context != null)
|
if (context != null)
|
||||||
so.EndPointContext = context;
|
so.EndPointContext = context;
|
||||||
|
|
||||||
so.Identifier = UniversalObjectIdentifier.FromFlat((ulong)_properties[0]);
|
so.Identifier = ComplexObjectIdentifier.FromFlat((ulong)_properties[0]);
|
||||||
return so.UniversalValue;
|
return so.UniversalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var instance = Activator.CreateInstance(type);
|
var instance = Activator.CreateInstance(type);
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
return null;
|
return null;
|
||||||
@@ -48,7 +47,10 @@ namespace mROA.Cbor
|
|||||||
for (var index = 0; index < properties.Count; index++)
|
for (var index = 0; index < properties.Count; index++)
|
||||||
{
|
{
|
||||||
var property = properties[index];
|
var property = properties[index];
|
||||||
property.SetValue(instance, _properties[index] is IPreParsedValue ppv ? ppv.ToObject(property.PropertyType, context) : _properties[index]);
|
property.SetValue(instance,
|
||||||
|
_properties[index] is IPreParsedValue ppv
|
||||||
|
? ppv.ToObject(property.PropertyType, context)
|
||||||
|
: _properties[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
@@ -57,13 +59,13 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
public class ParsedValue : IPreParsedValue
|
public class ParsedValue : IPreParsedValue
|
||||||
{
|
{
|
||||||
|
private object? _value;
|
||||||
|
|
||||||
public ParsedValue(object? value)
|
public ParsedValue(object? value)
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private object? _value;
|
|
||||||
|
|
||||||
|
|
||||||
public object? ToObject(Type type, IEndPointContext? context)
|
public object? ToObject(Type type, IEndPointContext? context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ namespace mROA.Test;
|
|||||||
|
|
||||||
public class UnSOization
|
public class UnSOization
|
||||||
{
|
{
|
||||||
private UniversalObjectIdentifier _uoi;
|
private ComplexObjectIdentifier _uoi;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
_uoi = new UniversalObjectIdentifier
|
_uoi = new ComplexObjectIdentifier
|
||||||
{
|
{
|
||||||
ContextId = -123, OwnerId = 123
|
ContextId = -123, OwnerId = 123
|
||||||
};
|
};
|
||||||
@@ -19,8 +19,8 @@ public class UnSOization
|
|||||||
public void FlatTest()
|
public void FlatTest()
|
||||||
{
|
{
|
||||||
var flat = _uoi.Flat;
|
var flat = _uoi.Flat;
|
||||||
var next = new UniversalObjectIdentifier { Flat = flat };
|
var next = new ComplexObjectIdentifier { Flat = flat };
|
||||||
|
|
||||||
Assert.That(_uoi, Is.EqualTo(next));
|
Assert.That(_uoi, Is.EqualTo(next));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ namespace mROA.Abstract
|
|||||||
{
|
{
|
||||||
int ResisterObject<T>(object o, IEndPointContext context);
|
int ResisterObject<T>(object o, IEndPointContext context);
|
||||||
void ClearObject(int id);
|
void ClearObject(int id);
|
||||||
T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell);
|
T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell);
|
||||||
T? GetObject<T>(int id);
|
T? GetObject<T>(int id);
|
||||||
object GetSingleObject(Type type);
|
object GetSingleObject(Type type);
|
||||||
int GetObjectIndex<T>(object o, IEndPointContext context);
|
int GetObjectIndex<T>(object o, IEndPointContext context);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace mROA.Implementation.Backend
|
|||||||
_lastIndexFinder = Task.FromResult(id);
|
_lastIndexFinder = Task.FromResult(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
||||||
{
|
{
|
||||||
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
|
return (T)GetObject(sharedObjectShellShell.Identifier.ContextId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,14 @@ namespace mROA.Implementation.Backend
|
|||||||
{
|
{
|
||||||
public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub
|
public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub
|
||||||
{
|
{
|
||||||
private Dictionary<int, IContextRepository> _repositories = new();
|
|
||||||
private readonly Func<int, IContextRepository> _produceRepository;
|
private readonly Func<int, IContextRepository> _produceRepository;
|
||||||
|
private Dictionary<int, IContextRepository> _repositories = new();
|
||||||
|
|
||||||
public MultiClientContextRepository(Func<int, IContextRepository> produceRepository)
|
public MultiClientContextRepository(Func<int, IContextRepository> produceRepository)
|
||||||
{
|
{
|
||||||
_produceRepository = 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)
|
public void Inject<T>(T dependency)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -39,18 +30,12 @@ namespace mROA.Implementation.Backend
|
|||||||
repository.ClearObject(id);
|
repository.ClearObject(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
||||||
{
|
{
|
||||||
var repository = GetRepository(sharedObjectShellShell.Identifier.OwnerId);
|
var repository = GetRepository(sharedObjectShellShell.Identifier.OwnerId);
|
||||||
return repository.GetObject<T>(sharedObjectShellShell.Identifier.ContextId);
|
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)
|
public T? GetObject<T>(int id)
|
||||||
{
|
{
|
||||||
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
var repository = GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||||
@@ -74,5 +59,21 @@ namespace mROA.Implementation.Backend
|
|||||||
var repository = GetRepositoryByClientId(clientId);
|
var repository = GetRepositoryByClientId(clientId);
|
||||||
return repository;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
Guid Id { get; }
|
Guid Id { get; }
|
||||||
int CommandId { get; }
|
int CommandId { get; }
|
||||||
UniversalObjectIdentifier ObjectId { get; }
|
ComplexObjectIdentifier ObjectId { get; }
|
||||||
object?[]? Parameters { get; }
|
object?[]? Parameters { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
public int CommandId { get; set; }
|
public int CommandId { get; set; }
|
||||||
public UniversalObjectIdentifier ObjectId { get; set; } = UniversalObjectIdentifier.Null;
|
public ComplexObjectIdentifier ObjectId { get; set; } = ComplexObjectIdentifier.Null;
|
||||||
|
|
||||||
public object?[]? Parameters { get; set; }
|
public object?[]? Parameters { get; set; }
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public int CommandId { get; set; } = -2;
|
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 object?[]? Parameters { get; set; } = null;
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|||||||
+6
-6
@@ -3,19 +3,19 @@ using System;
|
|||||||
namespace mROA.Implementation
|
namespace mROA.Implementation
|
||||||
{
|
{
|
||||||
#pragma warning disable CS8618, CS9264
|
#pragma warning disable CS8618, CS9264
|
||||||
public struct UniversalObjectIdentifier : IEquatable<UniversalObjectIdentifier>
|
public struct ComplexObjectIdentifier : IEquatable<ComplexObjectIdentifier>
|
||||||
{
|
{
|
||||||
public int ContextId;
|
public int ContextId;
|
||||||
public int OwnerId;
|
public int OwnerId;
|
||||||
|
|
||||||
public UniversalObjectIdentifier(int contextId, int ownerId)
|
public ComplexObjectIdentifier(int contextId, int ownerId)
|
||||||
{
|
{
|
||||||
ContextId = contextId;
|
ContextId = contextId;
|
||||||
OwnerId = ownerId;
|
OwnerId = ownerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UniversalObjectIdentifier Null = new UniversalObjectIdentifier { ContextId = -2, OwnerId = -1 };
|
public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 };
|
||||||
public static UniversalObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
|
public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
|
||||||
|
|
||||||
public override string ToString()
|
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;
|
return ContextId == other.ContextId && OwnerId == other.OwnerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object? obj)
|
public override bool Equals(object? obj)
|
||||||
{
|
{
|
||||||
return obj is UniversalObjectIdentifier other && Equals(other);
|
return obj is ComplexObjectIdentifier other && Equals(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
@@ -6,8 +6,8 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
public class RemoteContextRepository : IContextRepository
|
public class RemoteContextRepository : IContextRepository
|
||||||
{
|
{
|
||||||
private IRepresentationModuleProducer? _representationProducer;
|
|
||||||
public static Dictionary<Type, Type> RemoteTypes = new();
|
public static Dictionary<Type, Type> RemoteTypes = new();
|
||||||
|
private IRepresentationModuleProducer? _representationProducer;
|
||||||
|
|
||||||
public int ResisterObject<T>(object o, IEndPointContext context)
|
public int ResisterObject<T>(object o, IEndPointContext context)
|
||||||
{
|
{
|
||||||
@@ -19,7 +19,7 @@ namespace mROA.Implementation
|
|||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetObjectBySharedObject<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
public T GetObjectByShell<T>(SharedObjectShellShell<T> sharedObjectShellShell)
|
||||||
{
|
{
|
||||||
if (_representationProducer == null)
|
if (_representationProducer == null)
|
||||||
throw new NullReferenceException("representation producer is not initialized");
|
throw new NullReferenceException("representation producer is not initialized");
|
||||||
@@ -31,18 +31,14 @@ namespace mROA.Implementation
|
|||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public object GetObject(int id)
|
|
||||||
{
|
|
||||||
throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public T GetObject<T>(int id)
|
public T GetObject<T>(int id)
|
||||||
{
|
{
|
||||||
if (_representationProducer == null)
|
if (_representationProducer == null)
|
||||||
throw new NullReferenceException("representation producer is not initialized");
|
throw new NullReferenceException("representation producer is not initialized");
|
||||||
|
|
||||||
if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
|
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,
|
var remote = (T)Activator.CreateInstance(remoteType, id,
|
||||||
representationModule)!;
|
representationModule)!;
|
||||||
return remote;
|
return remote;
|
||||||
@@ -53,7 +49,8 @@ namespace mROA.Implementation
|
|||||||
if (_representationProducer == null)
|
if (_representationProducer == null)
|
||||||
throw new NullReferenceException("representation producer is not initialized");
|
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,
|
return Activator.CreateInstance(RemoteTypes[type], -1,
|
||||||
representationModule)!;
|
representationModule)!;
|
||||||
}
|
}
|
||||||
@@ -73,5 +70,10 @@ namespace mROA.Implementation
|
|||||||
if (dependency is IRepresentationModuleProducer serialisationModule)
|
if (dependency is IRepresentationModuleProducer serialisationModule)
|
||||||
_representationProducer = serialisationModule;
|
_representationProducer = serialisationModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public object GetObject(int id)
|
||||||
|
{
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,25 +10,34 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
public abstract class RemoteObjectBase : IDisposable
|
public abstract class RemoteObjectBase : IDisposable
|
||||||
{
|
{
|
||||||
private readonly UniversalObjectIdentifier _identifier;
|
private readonly ComplexObjectIdentifier _identifier;
|
||||||
private readonly IRepresentationModule _representationModule;
|
private readonly IRepresentationModule _representationModule;
|
||||||
|
|
||||||
protected RemoteObjectBase(int id, 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;
|
_representationModule = representationModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Id => _identifier.ContextId;
|
public int Id => _identifier.ContextId;
|
||||||
public int OwnerId => _identifier.OwnerId;
|
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,
|
protected async Task<T> GetResultAsync<T>(int methodId, object?[]? parameters = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{ CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
{
|
||||||
};
|
CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
||||||
|
};
|
||||||
|
|
||||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||||
|
|
||||||
var localTokenSource = new CancellationTokenSource();
|
var localTokenSource = new CancellationTokenSource();
|
||||||
@@ -53,7 +62,7 @@ namespace mROA.Implementation
|
|||||||
});
|
});
|
||||||
localTokenSource.Cancel();
|
localTokenSource.Cancel();
|
||||||
});
|
});
|
||||||
|
|
||||||
Task.WaitAny(new Task[]
|
Task.WaitAny(new Task[]
|
||||||
{
|
{
|
||||||
successResponse, errorResponse
|
successResponse, errorResponse
|
||||||
@@ -80,8 +89,9 @@ namespace mROA.Implementation
|
|||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{ CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
{
|
||||||
};
|
CommandId = methodId, ObjectId = _identifier, Parameters = parameters
|
||||||
|
};
|
||||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||||
|
|
||||||
var localTokenSource = new CancellationTokenSource();
|
var localTokenSource = new CancellationTokenSource();
|
||||||
@@ -122,13 +132,6 @@ namespace mROA.Implementation
|
|||||||
throw errorResponse.Result.GetException();
|
throw errorResponse.Result.GetException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
if (_identifier.IsStatic)
|
|
||||||
return;
|
|
||||||
CallAsync(-1).Wait();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return _identifier.ToString();
|
return _identifier.ToString();
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ namespace mROA.Implementation
|
|||||||
public interface ISharedObjectShell
|
public interface ISharedObjectShell
|
||||||
{
|
{
|
||||||
IEndPointContext EndPointContext { get; set; }
|
IEndPointContext EndPointContext { get; set; }
|
||||||
UniversalObjectIdentifier Identifier { get; set; }
|
ComplexObjectIdentifier Identifier { get; set; }
|
||||||
object UniversalValue { get; set; }
|
object UniversalValue { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SharedObjectShellShell<T> : ISharedObjectShell where T : notnull
|
public class SharedObjectShellShell<T> : ISharedObjectShell where T : notnull
|
||||||
{
|
{
|
||||||
private UniversalObjectIdentifier _identifier = UniversalObjectIdentifier.Null;
|
private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null;
|
||||||
|
|
||||||
private T _value;
|
private T _value;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ namespace mROA.Implementation
|
|||||||
OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId
|
OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId
|
||||||
};
|
};
|
||||||
|
|
||||||
public UniversalObjectIdentifier Identifier
|
public ComplexObjectIdentifier Identifier
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
@@ -74,7 +74,7 @@ namespace mROA.Implementation
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_identifier = value;
|
_identifier = value;
|
||||||
Value = GetDefaultContextRepository().GetObjectBySharedObject(this);
|
Value = GetDefaultContextRepository().GetObjectByShell(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user