Синхронизировано с юнити
This commit is contained in:
@@ -73,6 +73,7 @@ class Program
|
|||||||
|
|
||||||
var page = disposingPrinter.Print("Test Page", new CancellationToken()).GetAwaiter().GetResult();
|
var page = disposingPrinter.Print("Test Page", new CancellationToken()).GetAwaiter().GetResult();
|
||||||
Console.WriteLine("Page printed");
|
Console.WriteLine("Page printed");
|
||||||
|
Console.WriteLine(page.Value.ToString());
|
||||||
var data = page.Value.GetData();
|
var data = page.Value.GetData();
|
||||||
Console.WriteLine("Data : {0}", Encoding.UTF8.GetString(data));
|
Console.WriteLine("Data : {0}", Encoding.UTF8.GetString(data));
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using mROA.Implementation;
|
||||||
|
|
||||||
namespace mROA.Abstract
|
namespace mROA.Abstract
|
||||||
{
|
{
|
||||||
@@ -6,7 +7,7 @@ namespace mROA.Abstract
|
|||||||
{
|
{
|
||||||
int ResisterObject(object o);
|
int ResisterObject(object o);
|
||||||
void ClearObject(int id);
|
void ClearObject(int id);
|
||||||
object GetObject(int id);
|
T GetObjectBySharedObject<T>(SharedObject<T> sharedObject);
|
||||||
T? GetObject<T>(int id);
|
T? GetObject<T>(int id);
|
||||||
object GetSingleObject(Type type);
|
object GetSingleObject(Type type);
|
||||||
int GetObjectIndex(object o);
|
int GetObjectIndex(object o);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace mROA.Implementation.Backend
|
|||||||
throw new Exception($"Command {command.CommandId} not found");
|
throw new Exception($"Command {command.CommandId} not found");
|
||||||
|
|
||||||
var context = command.ObjectId != -1
|
var context = command.ObjectId != -1
|
||||||
? contextRepository.GetObject(command.ObjectId)
|
? contextRepository.GetObject<object>(command.ObjectId)
|
||||||
: contextRepository.GetSingleObject(currentCommand.DeclaringType!);
|
: contextRepository.GetSingleObject(currentCommand.DeclaringType!);
|
||||||
var parameter = command.Parameter;
|
var parameter = command.Parameter;
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ namespace mROA.Implementation.Backend
|
|||||||
{
|
{
|
||||||
public class ContextRepository : IContextRepository
|
public class ContextRepository : IContextRepository
|
||||||
{
|
{
|
||||||
private Dictionary<int, object?>? _singletons;
|
private int _debugId = -1;
|
||||||
private object?[] _storage = new object[StartupSize];
|
private static int LastDebugId = -1;
|
||||||
|
// [CanBeNull]
|
||||||
|
private Dictionary<int, object?> _singletons;
|
||||||
|
private object?[] _storage;
|
||||||
|
|
||||||
private Task<int> _lastIndexFinder = Task.FromResult(0);
|
private Task<int> _lastIndexFinder = Task.FromResult(0);
|
||||||
|
|
||||||
@@ -19,6 +22,11 @@ namespace mROA.Implementation.Backend
|
|||||||
private const int GrowSize = 128;
|
private const int GrowSize = 128;
|
||||||
|
|
||||||
|
|
||||||
|
public ContextRepository()
|
||||||
|
{
|
||||||
|
_storage = new object[StartupSize];
|
||||||
|
}
|
||||||
|
|
||||||
public void FillSingletons(params Assembly[] assembly)
|
public void FillSingletons(params Assembly[] assembly)
|
||||||
{
|
{
|
||||||
var types = assembly.SelectMany(x => x.GetTypes()).Where(type =>
|
var types = assembly.SelectMany(x => x.GetTypes()).Where(type =>
|
||||||
@@ -50,8 +58,14 @@ namespace mROA.Implementation.Backend
|
|||||||
_lastIndexFinder = Task.FromResult(id);
|
_lastIndexFinder = Task.FromResult(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T GetObjectBySharedObject<T>(SharedObject<T> sharedObject)
|
||||||
|
{
|
||||||
|
return (T)GetObject(sharedObject.ContextId);
|
||||||
|
}
|
||||||
|
|
||||||
public object GetObject(int id)
|
public object GetObject(int id)
|
||||||
{
|
{
|
||||||
|
// Debug.Log($"Reading object {id} from repository with debug ID {_debugId}");
|
||||||
return (id == -1 || _storage.Length <= id ? null : _storage[id]) ?? throw new NullReferenceException();
|
return (id == -1 || _storage.Length <= id ? null : _storage[id]) ?? throw new NullReferenceException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,14 @@ namespace mROA.Implementation.Backend
|
|||||||
GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).ClearObject(id);
|
GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).ClearObject(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T GetObjectBySharedObject<T>(SharedObject<T> sharedObject)
|
||||||
|
{
|
||||||
|
return GetRepository(sharedObject.OwnerId).GetObject<T>(sharedObject.ContextId);
|
||||||
|
}
|
||||||
|
|
||||||
public object GetObject(int id)
|
public object GetObject(int id)
|
||||||
{
|
{
|
||||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetObject(id);
|
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetObject<object>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? GetObject<T>(int id)
|
public T? GetObject<T>(int id)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using mROA.Abstract;
|
||||||
|
|
||||||
|
namespace mROA.Implementation.CommandExecution
|
||||||
|
{
|
||||||
|
public class AsyncCommandExecution : ICommandExecution
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public int ClientId { get; set; }
|
||||||
|
public int CommandId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,11 +16,4 @@ namespace mROA.Implementation.CommandExecution
|
|||||||
return new RemoteException(Exception) { CallRequestId = Id };
|
return new RemoteException(Exception) { CallRequestId = Id };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AsyncCommandExecution : ICommandExecution
|
|
||||||
{
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
public int ClientId { get; set; }
|
|
||||||
public int CommandId { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
private IRepresentationModuleProducer? _representationProducer;
|
private IRepresentationModuleProducer? _representationProducer;
|
||||||
public static Dictionary<Type, Type> RemoteTypes = new();
|
public static Dictionary<Type, Type> RemoteTypes = new();
|
||||||
|
|
||||||
public int ResisterObject(object o)
|
public int ResisterObject(object o)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
@@ -18,6 +19,17 @@ namespace mROA.Implementation
|
|||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T GetObjectBySharedObject<T>(SharedObject<T> sharedObject)
|
||||||
|
{
|
||||||
|
if (_representationProducer == null)
|
||||||
|
throw new NullReferenceException("representation producer is not initialized");
|
||||||
|
|
||||||
|
if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
|
||||||
|
var remote = (T)Activator.CreateInstance(remoteType, sharedObject.ContextId,
|
||||||
|
_representationProducer.Produce(sharedObject.OwnerId))!;
|
||||||
|
return remote;
|
||||||
|
}
|
||||||
|
|
||||||
public object GetObject(int id)
|
public object GetObject(int id)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
@@ -29,7 +41,8 @@ namespace mROA.Implementation
|
|||||||
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 remote = (T)Activator.CreateInstance(remoteType, id, _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()))!;
|
var remote = (T)Activator.CreateInstance(remoteType, id,
|
||||||
|
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()))!;
|
||||||
return remote;
|
return remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +51,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");
|
||||||
|
|
||||||
return Activator.CreateInstance(RemoteTypes[type], -1, _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()))!;
|
return Activator.CreateInstance(RemoteTypes[type], -1,
|
||||||
|
_representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()))!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetObjectIndex(object o)
|
public int GetObjectIndex(object o)
|
||||||
@@ -47,6 +61,7 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
return remote.Id;
|
return remote.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,17 +39,28 @@ namespace mROA.Implementation
|
|||||||
_representationModule.GetMessageAsync<ExceptionCommandExecution>(requestId: request.Id,
|
_representationModule.GetMessageAsync<ExceptionCommandExecution>(requestId: request.Id,
|
||||||
MessageType.ExceptionCommandExecution, localTokenSource.Token);
|
MessageType.ExceptionCommandExecution, localTokenSource.Token);
|
||||||
|
|
||||||
|
cancellationToken.Register(async () =>
|
||||||
|
{
|
||||||
|
Console.WriteLine("Cancelling task");
|
||||||
|
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CancelRequest,
|
||||||
|
new CancelRequest
|
||||||
|
{
|
||||||
|
Id = request.Id
|
||||||
|
});
|
||||||
|
localTokenSource.Cancel();
|
||||||
|
});
|
||||||
|
|
||||||
Task.WaitAny(new Task[]
|
Task.WaitAny(new Task[]
|
||||||
{
|
{
|
||||||
successResponse, errorResponse
|
successResponse, errorResponse
|
||||||
}, cancellationToken);
|
}, cancellationToken);
|
||||||
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
// if (cancellationToken.IsCancellationRequested)
|
||||||
{
|
// {
|
||||||
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CancelRequest, request.Id);
|
// await _representationModule.PostCallMessageAsync(request.Id, MessageType.CancelRequest, request.Id);
|
||||||
localTokenSource.Cancel();
|
// localTokenSource.Cancel();
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
// cancellationToken.ThrowIfCancellationRequested();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (successResponse.IsCompletedSuccessfully)
|
if (successResponse.IsCompletedSuccessfully)
|
||||||
{
|
{
|
||||||
@@ -96,12 +107,6 @@ namespace mROA.Implementation
|
|||||||
|
|
||||||
Console.WriteLine($"Handling message");
|
Console.WriteLine($"Handling message");
|
||||||
|
|
||||||
// if (cancellationToken.IsCancellationRequested)
|
|
||||||
// {
|
|
||||||
// localTokenSource.Cancel();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (successResponse.IsCompletedSuccessfully)
|
if (successResponse.IsCompletedSuccessfully)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -115,5 +120,10 @@ namespace mROA.Implementation
|
|||||||
return;
|
return;
|
||||||
CallAsync(-1).Wait();
|
CallAsync(-1).Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{{Id : {_id}, OwnerId : {OwnerId} }}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ namespace mROA.Implementation
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_contextId = value;
|
_contextId = value;
|
||||||
Value = GetDefaultContextRepository().GetObject<T>(_contextId)!;
|
Value = GetDefaultContextRepository().GetObjectBySharedObject<T>(this)!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user