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