mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-26 21:13:13 +00:00
2.2
This commit is contained in:
15
Test/MyChildRecord.cs
Normal file
15
Test/MyChildRecord.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
[Public]
|
||||
public class MyChildRecord : MyRecord
|
||||
{
|
||||
public string ChildName { get; set; }
|
||||
}
|
||||
}
|
16
Test/MyChildResource.cs
Normal file
16
Test/MyChildResource.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
[Resource]
|
||||
public partial class MyChildResource : MyResource
|
||||
{
|
||||
[Public] string childName;
|
||||
[Public] public int ChildMethod(string childName) => 111;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
using Esiur.Data;
|
||||
using Esiur.Core;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Authority;
|
||||
using Esiur.Security.Membership;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public class MyMembership : IMembership
|
||||
{
|
||||
public Instance Instance { get; set; }
|
||||
|
||||
public event DestroyedEvent OnDestroy;
|
||||
|
||||
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
}
|
||||
|
||||
public AsyncReply<byte[]> GetPassword(string username, string domain)
|
||||
{
|
||||
return new AsyncReply<byte[]>(DC.ToBytes("1234"));
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Login(Session session)
|
||||
{
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Logout(Session session)
|
||||
{
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
public AsyncReply<bool> Trigger(ResourceTrigger trigger)
|
||||
{
|
||||
return new AsyncReply<bool>(true);
|
||||
}
|
||||
|
||||
|
||||
public AsyncReply<bool> UserExists(string username, string domain)
|
||||
{
|
||||
return new AsyncReply<bool>(username == "demo");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
156
Test/MyObject.cs
156
Test/MyObject.cs
@ -1,156 +0,0 @@
|
||||
using Esiur.Data;
|
||||
using Esiur.Core;
|
||||
using Esiur.Net.IIP;
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
public class MyObject : EntryPoint
|
||||
{
|
||||
|
||||
[ResourceEvent]
|
||||
public event ResourceEventHanlder LevelUp;
|
||||
[ResourceEvent]
|
||||
public event ResourceEventHanlder LevelDown;
|
||||
|
||||
public MyObject()
|
||||
{
|
||||
Info = new Structure();
|
||||
Info["size"] = 200;
|
||||
Info["age"] = 28;
|
||||
Info["name"] = "Esiur";
|
||||
Name = "Esiur Project";
|
||||
Level = 5;
|
||||
}
|
||||
|
||||
|
||||
[ResourceFunction]
|
||||
public int Add(int? value)
|
||||
{
|
||||
Level += (int)value;
|
||||
LevelUp?.Invoke(null, "going up", value);
|
||||
return Level;
|
||||
}
|
||||
|
||||
[ResourceFunction("Divide takes two arguments nominator and denominator")]
|
||||
public double Divide(float n, float d, DistributedConnection sender)
|
||||
{
|
||||
return n / d;
|
||||
}
|
||||
|
||||
[ResourceFunction]
|
||||
public int Subtract(int value)
|
||||
{
|
||||
Level -= value;
|
||||
LevelDown?.Invoke(null, "going down", value);
|
||||
return Level;
|
||||
}
|
||||
|
||||
[ResourceFunction("use it with next()")]
|
||||
public IEnumerable<string> Enum(int count)
|
||||
{
|
||||
var msg = new string[] { "Have you throught what if a function has multiple returns ?", "So you can return chunks of IO operation that not yet finished.", "Also, what about the progress ?", "This is an example of both.", "Use it anyway you like" };
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
yield return msg[(int)(i % msg.Length)];
|
||||
}
|
||||
}
|
||||
|
||||
[ResourceFunction("Stream returns progress")]
|
||||
public AsyncReply<string> Stream(int count)
|
||||
{
|
||||
var reply = new AsyncReply<string>();
|
||||
var msg = new object[] { "Have you throught what if a function has multiple returns ?", "So you can return chunks of IO operation that not yet finished.", "Also, what about the progress ?", "This is an example of both.", "Use it anyway you like" };
|
||||
Timer timer = null;
|
||||
var msgCounter = 0;
|
||||
|
||||
timer = new Timer((x) =>
|
||||
{
|
||||
|
||||
reply.TriggerProgress(ProgressType.Execution, count, 22);
|
||||
|
||||
if (count % 2 == 0 && msgCounter < msg.Length)
|
||||
reply.TriggerChunk(msg[msgCounter++]);
|
||||
|
||||
count--;
|
||||
if (count <= 0)
|
||||
{
|
||||
timer.Dispose();
|
||||
reply.Trigger("Done");
|
||||
}
|
||||
|
||||
}, null, 10, 3000);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override AsyncReply<IResource[]> Query(string path, DistributedConnection sender)
|
||||
{
|
||||
return new AsyncReply<IResource[]>(new IResource[] { this });
|
||||
}
|
||||
|
||||
public override bool Create()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
[ResourceProperty]
|
||||
public Structure Info
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[ResourceProperty]
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[ResourceProperty]
|
||||
public MyObject Me
|
||||
{
|
||||
get
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int level;
|
||||
[ResourceProperty]
|
||||
public int Level
|
||||
{
|
||||
get { return level; }
|
||||
set
|
||||
{
|
||||
level = value;
|
||||
Instance?.Modified();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
[ResourceProperty]
|
||||
public virtual int Level
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[ResourceProperty]
|
||||
public int Level3
|
||||
{
|
||||
get => 0;
|
||||
set => Instance?.Modified();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
20
Test/MyRecord.cs
Normal file
20
Test/MyRecord.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Esiur.Data;
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
[Public]
|
||||
public class MyRecord:IRecord
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Id { get; set; }
|
||||
|
||||
public double Score { get; set; }
|
||||
|
||||
}
|
||||
}
|
16
Test/MyResource.cs
Normal file
16
Test/MyResource.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
[Resource]
|
||||
public partial class MyResource
|
||||
{
|
||||
[Public] string description;
|
||||
[Public] int categoryId;
|
||||
}
|
||||
}
|
171
Test/MyService.cs
Normal file
171
Test/MyService.cs
Normal file
@ -0,0 +1,171 @@
|
||||
using Esiur.Data;
|
||||
using Esiur.Core;
|
||||
using Esiur.Net.IIP;
|
||||
using Esiur.Resource;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Test;
|
||||
|
||||
|
||||
public enum SizeEnum:short
|
||||
{
|
||||
xSmall = -11,
|
||||
Small,
|
||||
Medium = 0,
|
||||
Large,
|
||||
XLarge = 22
|
||||
}
|
||||
|
||||
[Resource]
|
||||
public partial class MyService
|
||||
{
|
||||
|
||||
[Public] public event ResourceEventHandler<string> StringEvent;
|
||||
[Public] public event ResourceEventHandler<object[]> ArrayEvent;
|
||||
|
||||
[Public] bool boolean = true;
|
||||
[Public] bool[] booleanArray = new bool[] { true, false, true, false, true };
|
||||
|
||||
[Public] byte uInt8Test = 8;
|
||||
[Public] byte? uInt8Null = null;
|
||||
[Public] byte[] uInt8Array = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||
[Public] byte?[] uInt8ArrayNull = new byte?[] { 0, null, 2, null, 4, null };
|
||||
|
||||
[Public] sbyte int8 = -8;
|
||||
[Public] sbyte[] int8Array = new sbyte[] { -3, -2, -1, 0, 1, 2 };
|
||||
|
||||
[Public] char char16 = 'ح';
|
||||
[Public] char[] char16Array = new char[] { 'م', 'ر', 'ح', 'ب', 'ا' };
|
||||
|
||||
[Public] short int16 = -16;
|
||||
[Public] short[] int16Array = new short[] { -3, -2, -1, 0, 1, 2 };
|
||||
|
||||
[Public] ushort uInt16 = 16;
|
||||
[Public] ushort[] uInt16Array = new ushort[] { 0, 1, 2, 3, 4, 5 };
|
||||
|
||||
|
||||
[Public] int int32Prop = -32;
|
||||
[Public] int[] int32Array = new int[] { -3, -2, -1, 0, 1, 2 };
|
||||
|
||||
[Public] uint uInt32 = 32;
|
||||
[Public] uint[] uInt32Array = new uint[] { 0, 1, 2, 3, 4, 5 };
|
||||
|
||||
[Public] long int64 = 323232323232;
|
||||
[Public] long[] int64Array = new long[] { -3, -2, -1, 0, 1, 2 };
|
||||
|
||||
[Public] ulong uInt64;
|
||||
[Public] ulong[] uInt64Array = new ulong[] { 0, 1, 2, 3, 4, 5 };
|
||||
|
||||
[Public] float float32 = 32.32f;
|
||||
[Public] float[] float32Array = new float[] { -3.3f, -2.2f, -1.1f, 0, 1.1f, 2.2f };
|
||||
|
||||
[Public] double float64 = 32.323232;
|
||||
[Public] double[] float64Array = new double[] { -3.3, -2.2, -1.1, 0, 1.1, 2.2 };
|
||||
|
||||
[Public] decimal float128 = 3232.323232323232m;
|
||||
[Public] decimal[] float128Array = new decimal[] { -3.3m, -2.2m, -1.1m, 0, 1.1m, 2.2m };
|
||||
|
||||
[Public("Text")] string stringTest = "Hello World";
|
||||
[Public] string[] stringArray = new string[] { "Hello", "World" };
|
||||
|
||||
[Public] DateTime time = DateTime.Now;
|
||||
|
||||
|
||||
[Public]
|
||||
Map<string, object> stringMap = new Map<string, object>()
|
||||
{
|
||||
["int"] = 33,
|
||||
["string"] = "Hello World"
|
||||
};
|
||||
|
||||
[Public]
|
||||
Map<int, string> intStringMap = new()
|
||||
{
|
||||
[4] = "Abcd",
|
||||
[44] = "EfG"
|
||||
};
|
||||
|
||||
|
||||
[Public("Object")] object objectTest = "object";
|
||||
|
||||
[Public] object[] objectArray = new object[] { 1, 1.2f, Math.PI, "Hello World" };
|
||||
|
||||
[Public]
|
||||
public DistributedPropertyContext<int> PropertyContext
|
||||
{
|
||||
get => new DistributedPropertyContext<int>((sender) => sender.RemoteEndPoint.Port);
|
||||
set
|
||||
{
|
||||
Console.WriteLine($"PropertyContext Set: {value.Value} {value.Connection.RemoteEndPoint.Port}");
|
||||
}
|
||||
}
|
||||
|
||||
[Public] public SizeEnum Enum => SizeEnum.Medium;
|
||||
|
||||
|
||||
[Public] public MyRecord Record => new MyRecord() { Id = 33, Name = "Test", Score = 99.33 };
|
||||
|
||||
[Public] public List<int> IntList => new List<int>() { 1, 2, 3, 4, 5 };
|
||||
|
||||
[Public] public IRecord[] RecordsArray => new IRecord[] { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } };
|
||||
[Public] public List<MyRecord> RecordsList => new() { new MyRecord() { Id = 22, Name = "Test", Score = 22.1 } };
|
||||
|
||||
|
||||
[Public] public MyResource[] myResources;
|
||||
|
||||
[Public] public MyResource Resource { get; set; }
|
||||
[Public] public MyChildResource ChildResource { get; set; }
|
||||
|
||||
[Public] public MyChildRecord ChildRecord { get; set; } = new MyChildRecord() { ChildName = "Child", Id = 12, Name = "Parent", Score = 12.2 };
|
||||
|
||||
[Public] public IResource[] Resources { get; set; }
|
||||
|
||||
[Public]
|
||||
public void Void() =>
|
||||
Console.WriteLine("Void()");
|
||||
|
||||
[Public]
|
||||
public void InvokeEvents(string msg)
|
||||
{
|
||||
StringEvent?.Invoke(msg);
|
||||
ArrayEvent?.Invoke(new object[] { DateTime.UtcNow, "Event", msg });
|
||||
}
|
||||
|
||||
[Public]
|
||||
public double Optional(object a1, int a2, string a3 = "Hello", string a4 = "World")
|
||||
{
|
||||
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
||||
return new Random().NextDouble();
|
||||
}
|
||||
|
||||
[Public]
|
||||
public void Connection(object a1, int a2, DistributedConnection a3) =>
|
||||
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
||||
|
||||
|
||||
[Public]
|
||||
public void ConnectionOptional(object a1, int a2, string a3 = "sss", DistributedConnection a4 = null) =>
|
||||
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
|
||||
|
||||
[Public]
|
||||
public (int, string) GetTuple2(int a1, string a2) => (a1, a2);
|
||||
|
||||
[Public]
|
||||
public (int, string, double) GetTuple3(int a1, string a2, double a3) => (a1, a2, a3);
|
||||
|
||||
[Public]
|
||||
public (int, string, double, bool) GetTuple4(int a1, string a2, double a3, bool a4) => (a1, a2, a3, a4);
|
||||
|
||||
[Public] public MyRecord SendRecord(MyRecord record)
|
||||
{
|
||||
Console.WriteLine(record.ToString());
|
||||
return record;
|
||||
}
|
||||
|
||||
[Public] public const double PI = Math.PI;
|
||||
|
||||
[Public] public MyService Me => this;
|
||||
}
|
245
Test/Program.cs
245
Test/Program.cs
@ -30,178 +30,149 @@ using Esiur.Net.Sockets;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Permissions;
|
||||
using Esiur.Stores;
|
||||
using Esiur.Stores.MongoDB;
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Esiur.Security.Integrity;
|
||||
using System.Linq;
|
||||
using Esiur.Resource.Template;
|
||||
using System.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Esiur.Proxy;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static MyObject localObject;
|
||||
static IResource remoteObject;
|
||||
|
||||
|
||||
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
|
||||
|
||||
Warehouse.GetTemplateByType(typeof(MyChildRecord));
|
||||
|
||||
// Create stores to keep objects.
|
||||
var system = Warehouse.New<MemoryStore>("system");
|
||||
var remote = Warehouse.New<MemoryStore>("remote");
|
||||
var mongo = Warehouse.New<MongoDBStore>("db");
|
||||
var system = await Warehouse.Put("mem", new MemoryStore());
|
||||
var server = await Warehouse.Put("mem/server", new DistributedServer());
|
||||
var service = await Warehouse.Put("mem/service", new MyService());
|
||||
var res1 = await Warehouse.Put("mem/service/r1", new MyResource() { Description = "Testing 1", CategoryId = 10 });
|
||||
var res2 = await Warehouse.Put("mem/service/r2", new MyResource() { Description = "Testing 2", CategoryId = 11 });
|
||||
var res3 = await Warehouse.Put("mem/service/c1", new MyChildResource() { ChildName = "Child 1", Description = "Child Testing 3", CategoryId = 12 });
|
||||
|
||||
|
||||
// Create new distributed server object
|
||||
var iip = Warehouse.New<DistributedServer>("iip", system);
|
||||
// Set membership which handles authentication.
|
||||
iip.Membership = Warehouse.New<MyMembership>("ms", system);
|
||||
// Start the server on port 5000.
|
||||
iip.Start(new TCPSocket(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 500)), 600000, 60000);
|
||||
|
||||
|
||||
// Create http server to handle IIP over Websockets
|
||||
var http = Warehouse.New<HTTPServer>("http", system);
|
||||
http.Start(new TCPSocket(new System.Net.IPEndPoint(System.Net.IPAddress.Any, 501)), 600000, 60000);
|
||||
|
||||
// Create IIP over Websocket HTTP module and give it to HTTP server.
|
||||
var wsOverHttp = Warehouse.New<IIPoWS>("IIPoWS", system, http);
|
||||
|
||||
wsOverHttp.DistributedServer = iip;
|
||||
|
||||
|
||||
/*
|
||||
var system = await Warehouse.Get("mem://system").Task;
|
||||
var remote = await Warehouse.Get("mem://remote").Task;
|
||||
var mongo = await Warehouse.Get("mongo://db").Task;
|
||||
var iip = await Warehouse.Get("iip://:5000").Task;
|
||||
var iws = await Warehouse.Get("iipows://:5001", new Structure() { ["iip"] = iip }).Task;
|
||||
*/
|
||||
service.Resource = res1;
|
||||
service.ChildResource = res3;
|
||||
service.Resources = new MyResource[] { res1, res2, res1 , res3 };
|
||||
|
||||
var ok = await Warehouse.Open();
|
||||
|
||||
|
||||
// Open the warehouse
|
||||
|
||||
|
||||
// Create new object if the store is empty
|
||||
if (mongo.Count == 0)
|
||||
localObject = Warehouse.New<MyObject>("my", mongo, null,
|
||||
new UserPermissionsManager(new Structure()
|
||||
{
|
||||
["demo@localhost"] = new Structure()
|
||||
{
|
||||
["Subtract"] = new Structure { ["Execute"] = "yes" },
|
||||
["Stream"] = new Structure { ["Execute"] = "yes" },
|
||||
["_attach"] = "yes",
|
||||
["_get_attributes"] = "yes",
|
||||
["_set_attributes"] = "yes",
|
||||
}
|
||||
}));
|
||||
else
|
||||
localObject = (MyObject)(await Warehouse.Get("db/my"));
|
||||
|
||||
|
||||
iip.EntryPoint = localObject;
|
||||
|
||||
Warehouse.StoreConnected += (store, name) =>
|
||||
{
|
||||
if (store.Instance.Parents.Contains(iip))
|
||||
{
|
||||
store.Get("local/js").Then((r) =>
|
||||
{
|
||||
if (r != null)
|
||||
{
|
||||
dynamic d = r;
|
||||
d.send("Welcome");
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Console.WriteLine(String.Join(" ", service.Instance.Template.ClassId.ToByteArray()));
|
||||
// Start testing
|
||||
TestClient();
|
||||
TestClient(service);
|
||||
// TestClient(service);
|
||||
}
|
||||
|
||||
var running = true;
|
||||
|
||||
while (running)
|
||||
enum aa
|
||||
{
|
||||
a,
|
||||
b,
|
||||
c,
|
||||
d
|
||||
}
|
||||
|
||||
public static (int, string) tuple() => (33, "sss");
|
||||
|
||||
private static async void TestClient(IResource local)
|
||||
{
|
||||
dynamic remote = await Warehouse.Get<IResource>("iip://localhost/mem/service");
|
||||
|
||||
TestObjectProps(local, remote);
|
||||
|
||||
var opt = await remote.Optional(new { a1 = 22, a2 = 33, a4 = "What?" });
|
||||
Console.WriteLine(opt);
|
||||
|
||||
await remote.Void();
|
||||
await remote.Connection("ss", 33);
|
||||
await remote.ConnectionOptional("Test 2", 88);
|
||||
var rt = await remote.Optional("Optiona", 311);
|
||||
Console.WriteLine(rt);
|
||||
|
||||
var t2 = await remote.GetTuple2(1, "A");
|
||||
Console.WriteLine(t2);
|
||||
var t3 = await remote.GetTuple3(1, "A", 1.3);
|
||||
Console.WriteLine(t3);
|
||||
var t4 = await remote.GetTuple4(1, "A", 1.3, true);
|
||||
Console.WriteLine(t4);
|
||||
|
||||
remote.StringEvent += new DistributedResourceEvent((sender, args) =>
|
||||
Console.WriteLine($"StringEvent {args}")
|
||||
);
|
||||
|
||||
remote.ArrayEvent += new DistributedResourceEvent((sender, args) =>
|
||||
Console.WriteLine($"ArrayEvent {args}")
|
||||
);
|
||||
|
||||
await remote.InvokeEvents("Hello");
|
||||
|
||||
//var childTemplate = remote.Child.Instance.Template;
|
||||
|
||||
|
||||
var path = TemplateGenerator.GetTemplate("iip://localhost/mem/service", "Generated");
|
||||
|
||||
Console.WriteLine(path);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void TestObjectProps(IResource local, DistributedResource remote)
|
||||
{
|
||||
|
||||
foreach(var pt in local.Instance.Template.Properties)
|
||||
{
|
||||
var cmd = Console.ReadLine();
|
||||
if (cmd.ToLower() == "exit")
|
||||
Warehouse.Close().Then((x) =>
|
||||
{
|
||||
if (!x)
|
||||
Console.WriteLine("Failed to close the warehouse.");
|
||||
else
|
||||
Console.WriteLine("Successfully closed the warehouse.");
|
||||
|
||||
running = false;
|
||||
});
|
||||
var lv = pt.PropertyInfo.GetValue(local);
|
||||
object v;
|
||||
var rv = remote.TryGetPropertyValue(pt.Index, out v);
|
||||
if (!rv)
|
||||
Console.WriteLine($" ** {pt.Name } Failed");
|
||||
else
|
||||
{
|
||||
localObject.Level = 88;
|
||||
Console.WriteLine(localObject.Name + " " + localObject.Level);
|
||||
}
|
||||
Console.WriteLine($"{pt.Name } {GetString(lv)} == {GetString(v)}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static async void TestClient()
|
||||
static string GetString(object value)
|
||||
{
|
||||
if (value == null)
|
||||
return "NULL";
|
||||
|
||||
remoteObject = await Warehouse.Get("iip://localhost:500/db/my", new { username= "demo", password = 1234 });
|
||||
|
||||
dynamic x = remoteObject;
|
||||
var t = value.GetType();
|
||||
var nt = Nullable.GetUnderlyingType(t);
|
||||
if (nt != null)
|
||||
t = nt;
|
||||
if (t.IsArray)
|
||||
{
|
||||
var ar = (Array)value;
|
||||
if (ar.Length == 0)
|
||||
return "[]";
|
||||
var rt = "[";
|
||||
for (var i = 0; i < ar.Length - 1; i++)
|
||||
rt += GetString(ar.GetValue(i)) + ",";
|
||||
rt += GetString(ar.GetValue(ar.Length - 1)) + "]";
|
||||
|
||||
return rt;
|
||||
} else if (value is IRecord)
|
||||
{
|
||||
return "{" + String.Join(", ", t.GetProperties().Select(x => x.Name + ": " + x.GetValue(value))) + "}";
|
||||
}
|
||||
|
||||
Console.WriteLine("My Name is: " + x.Name);
|
||||
x.Name = "Hamoo";
|
||||
x.LevelUp += new DistributedResourceEvent((sender, parameters) =>
|
||||
{
|
||||
Console.WriteLine("LevelUp " + parameters[0] + " " + parameters[1]);
|
||||
});
|
||||
|
||||
x.LevelDown += new DistributedResourceEvent((sender, parameters) =>
|
||||
{
|
||||
Console.WriteLine("LevelUp " + parameters[0] + " " + parameters[1]);
|
||||
});
|
||||
|
||||
|
||||
(x.Stream(10) as AsyncReply<object>).Then(r =>
|
||||
{
|
||||
Console.WriteLine("Stream ended: " + r);
|
||||
}).Chunk(r =>
|
||||
{
|
||||
Console.WriteLine("Chunk..." + r);
|
||||
}).Progress((t, v, m) => Console.WriteLine("Processing {0}/{1}", v, m));
|
||||
|
||||
var rt = await x.Subtract(10);
|
||||
|
||||
|
||||
Console.WriteLine(rt);
|
||||
// Getting object record
|
||||
(remoteObject.Instance.Store as DistributedConnection).GetRecord(remoteObject, DateTime.Now - TimeSpan.FromDays(1), DateTime.Now).Then(record =>
|
||||
{
|
||||
Console.WriteLine("Records received: " + record.Count);
|
||||
});
|
||||
|
||||
//var timer = new Timer(T_Elapsed, null, 5000, 5000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void T_Elapsed(object state)
|
||||
{
|
||||
localObject.Level++;
|
||||
dynamic o = remoteObject;
|
||||
Console.WriteLine(localObject.Level + " " + o.Level + o.Me.Me.Level);
|
||||
else
|
||||
return value.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,11 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Esiur.Stores.MongoDB\Esiur.Stores.MongoDB.csproj" />
|
||||
<ProjectReference Include="..\Esiur\Esiur.csproj" />
|
||||
<ProjectReference Include="..\Esiur\Esiur.csproj" OutputItemType="Analyzer" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Reference in New Issue
Block a user