Переписывание на UniversalObjectIdentifier. Часть 1
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DefineConstants></DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DefineConstants></DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace mROA.Cbor
|
||||
{
|
||||
public class CborSerializationToolkit : IContextualSerializationToolKit
|
||||
{
|
||||
private List<Type> _remoteTypes;
|
||||
public byte[] Serialize(object objectToSerialize, IEndPointContext context)
|
||||
{
|
||||
var writer = new CborWriter();
|
||||
@@ -352,6 +353,7 @@ namespace mROA.Cbor
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
_remoteTypes = RemoteContextRepository.RemoteTypes.Keys.ToList();
|
||||
}
|
||||
|
||||
public byte[] Serialize<T>(T objectToSerialize)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using mROA.Implementation;
|
||||
|
||||
namespace mROA.Test;
|
||||
|
||||
public class UnSOization
|
||||
{
|
||||
private UniversalObjectIdentifier _uoi;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_uoi = new UniversalObjectIdentifier
|
||||
{
|
||||
ContextId = -123, OwnerId = 123
|
||||
};
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FlatTest()
|
||||
{
|
||||
var flat = _uoi.Flat;
|
||||
var next = new UniversalObjectIdentifier { Flat = flat };
|
||||
|
||||
Assert.That(_uoi, Is.EqualTo(next));
|
||||
}
|
||||
}
|
||||
@@ -10,23 +10,23 @@ namespace mROA.Implementation
|
||||
{
|
||||
public abstract class RemoteObjectBase : IDisposable
|
||||
{
|
||||
private readonly int _id;
|
||||
private readonly UniversalObjectIdentifier _identifier;
|
||||
private readonly IRepresentationModule _representationModule;
|
||||
|
||||
protected RemoteObjectBase(int id, IRepresentationModule representationModule)
|
||||
{
|
||||
_id = id;
|
||||
_identifier = new UniversalObjectIdentifier { ContextId = id, OwnerId = representationModule.Id };
|
||||
_representationModule = representationModule;
|
||||
}
|
||||
|
||||
public int Id => _id;
|
||||
public int OwnerId => _representationModule.Id;
|
||||
public int Id => _identifier.ContextId;
|
||||
public int OwnerId => _identifier.OwnerId;
|
||||
|
||||
protected async Task<T> GetResultAsync<T>(int methodId, object? parameter = default,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var request = new DefaultCallRequest
|
||||
{ CommandId = methodId, ObjectId = _id, Parameter = parameter
|
||||
{ CommandId = methodId, ObjectId = _identifier.ContextId, Parameter = parameter
|
||||
};
|
||||
|
||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
@@ -80,7 +80,7 @@ namespace mROA.Implementation
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var request = new DefaultCallRequest
|
||||
{ CommandId = methodId, ObjectId = _id, Parameter = parameter
|
||||
{ CommandId = methodId, ObjectId = _identifier.ContextId, Parameter = parameter
|
||||
};
|
||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||
|
||||
@@ -124,14 +124,14 @@ namespace mROA.Implementation
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_id == -1)
|
||||
if (_identifier.IsStatic)
|
||||
return;
|
||||
CallAsync(-1).Wait();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{{Id : {_id}, OwnerId : {OwnerId} }}";
|
||||
return _identifier.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,4 +121,45 @@ namespace mROA.Implementation
|
||||
public static implicit operator SharedObject<T>(T value) =>
|
||||
new(value);
|
||||
}
|
||||
|
||||
public struct UniversalObjectIdentifier : IEquatable<UniversalObjectIdentifier>
|
||||
{
|
||||
public int ContextId;
|
||||
public int OwnerId;
|
||||
|
||||
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;
|
||||
}
|
||||
set
|
||||
{
|
||||
OwnerId = (int)(value >> 32);
|
||||
ContextId = (int)(value & 0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(UniversalObjectIdentifier other)
|
||||
{
|
||||
return ContextId == other.ContextId && OwnerId == other.OwnerId;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is UniversalObjectIdentifier other && Equals(other);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(ContextId, OwnerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DefineConstants>TRACE;</DefineConstants>
|
||||
<DefineConstants></DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user