Задумка с отрицательным айдишником сработала глобально и кажется она работоспособна
This commit is contained in:
@@ -17,6 +17,7 @@ namespace Example.Frontend
|
|||||||
public string GetName()
|
public string GetName()
|
||||||
{
|
{
|
||||||
Console.WriteLine("ClientBasedPrinter called from server!!!!!!!!!!! Vova likes that:)");
|
Console.WriteLine("ClientBasedPrinter called from server!!!!!!!!!!! Vova likes that:)");
|
||||||
|
DemoCheck.BackwardCall = true;
|
||||||
|
|
||||||
return "ClientBasedPrinter from mroa";
|
return "ClientBasedPrinter from mroa";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Example.Frontend
|
||||||
|
{
|
||||||
|
public static class DemoCheck
|
||||||
|
{
|
||||||
|
public static bool ClientBasedImplementation;
|
||||||
|
public static bool TaskCancelation;
|
||||||
|
public static bool Dispose;
|
||||||
|
public static bool PropertySet;
|
||||||
|
public static bool PropertyGet;
|
||||||
|
public static bool TaskExecution;
|
||||||
|
public static bool BackwardCall;
|
||||||
|
public static bool BasicNonParamsCall;
|
||||||
|
public static bool EventCallback;
|
||||||
|
public static bool CreatingPrinter;
|
||||||
|
|
||||||
|
public static void Show()
|
||||||
|
{
|
||||||
|
Console.WriteLine("======================== Demo summary ========================");
|
||||||
|
var fields = typeof(DemoCheck).GetFields().OrderBy(i => i.Name).ToList();
|
||||||
|
foreach (var field in fields)
|
||||||
|
{
|
||||||
|
var value = (bool)field.GetValue(null)!;
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
Console.BackgroundColor = ConsoleColor.Green;
|
||||||
|
}else Console.BackgroundColor = ConsoleColor.Gray;
|
||||||
|
|
||||||
|
Console.Write($"{field.Name}");
|
||||||
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,25 +48,32 @@ class Program
|
|||||||
//правильный порядок команд 8-5-10-7
|
//правильный порядок команд 8-5-10-7
|
||||||
using (var disposingPrinter = factory.Create("Test"))
|
using (var disposingPrinter = factory.Create("Test"))
|
||||||
{
|
{
|
||||||
disposingPrinter.OnPrint += (_, _) => { Console.WriteLine("New page creater. Called from event!!!"); };
|
DemoCheck.CreatingPrinter = true;
|
||||||
|
disposingPrinter.OnPrint += (_, _) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine("New page creater. Called from event!!!");
|
||||||
|
DemoCheck.EventCallback = true;
|
||||||
|
};
|
||||||
Console.WriteLine("Printer created");
|
Console.WriteLine("Printer created");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
|
||||||
var name = disposingPrinter.GetName();
|
var name = disposingPrinter.GetName();
|
||||||
|
DemoCheck.BasicNonParamsCall = true;
|
||||||
Console.WriteLine("Printer name : {0}", name);
|
Console.WriteLine("Printer name : {0}", name);
|
||||||
|
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
|
||||||
factory.Register(new ClientBasedPrinter());
|
factory.Register(new ClientBasedPrinter());
|
||||||
|
DemoCheck.ClientBasedImplementation = true;
|
||||||
Console.WriteLine("Registered printer");
|
Console.WriteLine("Registered printer");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
|
||||||
var registred = factory.GetFirstPrinter();
|
var registered = factory.GetFirstPrinter();
|
||||||
Console.WriteLine("First printer");
|
Console.WriteLine("First printer");
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
|
|
||||||
Console.WriteLine(registred);
|
Console.WriteLine(registered);
|
||||||
Console.WriteLine("Collecting all printers");
|
Console.WriteLine("Collecting all printers");
|
||||||
var names = factory.CollectAllNames();
|
var names = factory.CollectAllNames();
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
@@ -76,11 +83,15 @@ class Program
|
|||||||
var page = disposingPrinter.Print("Test Page", false, default, CancellationToken.None).GetAwaiter()
|
var page = disposingPrinter.Print("Test Page", false, default, CancellationToken.None).GetAwaiter()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
Console.WriteLine("Page printed");
|
Console.WriteLine("Page printed");
|
||||||
|
DemoCheck.TaskExecution = true;
|
||||||
Console.WriteLine(page.ToString());
|
Console.WriteLine(page.ToString());
|
||||||
|
|
||||||
Console.WriteLine($"Printer resource : {disposingPrinter.Resource}");
|
Console.WriteLine($"Printer resource : {disposingPrinter.Resource}");
|
||||||
|
DemoCheck.PropertyGet = true;
|
||||||
|
|
||||||
Console.WriteLine("Restoring resource");
|
Console.WriteLine("Restoring resource");
|
||||||
disposingPrinter.Resource = 100;
|
disposingPrinter.Resource = 100;
|
||||||
|
DemoCheck.PropertySet = true;
|
||||||
Console.WriteLine($"Printer resource again : {disposingPrinter.Resource}");
|
Console.WriteLine($"Printer resource again : {disposingPrinter.Resource}");
|
||||||
|
|
||||||
var data = page.GetData();
|
var data = page.GetData();
|
||||||
@@ -88,6 +99,7 @@ class Program
|
|||||||
|
|
||||||
Console.WriteLine("Dispose printer");
|
Console.WriteLine("Dispose printer");
|
||||||
}
|
}
|
||||||
|
DemoCheck.Dispose = true;
|
||||||
|
|
||||||
|
|
||||||
var loadSingleton = context.GetSingleObject(typeof(ILoadTest), 0) as ILoadTest;
|
var loadSingleton = context.GetSingleObject(typeof(ILoadTest), 0) as ILoadTest;
|
||||||
@@ -100,6 +112,8 @@ class Program
|
|||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
cts.Cancel();
|
cts.Cancel();
|
||||||
Console.WriteLine($"Token state {cts.Token.IsCancellationRequested}");
|
Console.WriteLine($"Token state {cts.Token.IsCancellationRequested}");
|
||||||
|
DemoCheck.TaskCancelation = true;
|
||||||
|
DemoCheck.Show();
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
//
|
//
|
||||||
// const int iterations = 10000;
|
// const int iterations = 10000;
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace mROA.Implementation.Backend
|
|||||||
interaction.PostMessage(new NetworkMessage
|
interaction.PostMessage(new NetworkMessage
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(), SchemaId = MessageType.IdAssigning,
|
Id = Guid.NewGuid(), SchemaId = MessageType.IdAssigning,
|
||||||
Data = _serialization.Serialize(new IdAssingnment { Id = interaction.ConnectionId })
|
Data = _serialization.Serialize(new IdAssignment { Id = -interaction.ConnectionId })
|
||||||
});
|
});
|
||||||
_hub.RegisterInteraction(interaction);
|
_hub.RegisterInteraction(interaction);
|
||||||
Console.WriteLine("Client registered");
|
Console.WriteLine("Client registered");
|
||||||
|
|||||||
@@ -7,18 +7,19 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
public int ContextId;
|
public int ContextId;
|
||||||
public int OwnerId;
|
public int OwnerId;
|
||||||
|
|
||||||
public ComplexObjectIdentifier(int contextId, int ownerId)
|
public ComplexObjectIdentifier(int contextId, int ownerId)
|
||||||
{
|
{
|
||||||
ContextId = contextId;
|
ContextId = contextId;
|
||||||
OwnerId = ownerId;
|
OwnerId = ownerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId };
|
public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId };
|
||||||
|
|
||||||
public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 };
|
public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = 0 };
|
||||||
public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
|
public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
|
||||||
|
|
||||||
|
public int ClientId => Math.Abs(OwnerId);
|
||||||
|
public bool IsSererStored => OwnerId > 0;
|
||||||
|
public bool IsClientStored => OwnerId < 0;
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{{ {nameof(ContextId)}: {ContextId}, {nameof(OwnerId)}: {OwnerId} }}";
|
return $"{{ {nameof(ContextId)}: {ContextId}, {nameof(OwnerId)}: {OwnerId} }}";
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace mROA.Implementation.Frontend
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var assignment = _serialization.Deserialize<IdAssingnment>(welcomeMessage.Data)!;
|
var assignment = _serialization.Deserialize<IdAssignment>(welcomeMessage.Data)!;
|
||||||
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(assignment.Id);
|
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(assignment.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace mROA.Implementation
|
namespace mROA.Implementation
|
||||||
{
|
{
|
||||||
public class IdAssingnment
|
public class IdAssignment
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ namespace mROA.Implementation
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_identifier.OwnerId = EndPointContext.HostId;
|
_identifier.OwnerId = EndPointContext.OwnerId;
|
||||||
_identifier.ContextId = EndPointContext.RealRepository.GetObjectIndex<T>(Value, EndPointContext);
|
_identifier.ContextId = EndPointContext.RealRepository.GetObjectIndex<T>(Value, EndPointContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_identifier.OwnerId = _identifier.OwnerId == -1 ? EndPointContext.OwnerId : _identifier.OwnerId;
|
_identifier.OwnerId = _identifier.OwnerId == 0 ? EndPointContext.OwnerId : _identifier.OwnerId;
|
||||||
return _identifier;
|
return _identifier;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
|
|||||||
Reference in New Issue
Block a user