mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-26 21:13:13 +00:00
flow
This commit is contained in:
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
@ -19,5 +20,13 @@ namespace Test
|
||||
|
||||
[Export] public string HelloParent() => "Hi from Parent";
|
||||
|
||||
[Export]
|
||||
[Annotation("This function computes the standard deviation of a list")]
|
||||
public double StDev(double[] values)
|
||||
{
|
||||
double avg = values.Average();
|
||||
return Math.Sqrt(values.Average(v => Math.Pow(v - avg, 2)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -106,15 +106,28 @@ public partial class MyService
|
||||
[Export] object[] objectArray = new object[] { 1, 1.2f, Math.PI, "Hello World" };
|
||||
|
||||
[Export]
|
||||
public DistributedPropertyContext<int> PropertyContext
|
||||
public PropertyContext<int> PropertyContext
|
||||
{
|
||||
get => new DistributedPropertyContext<int>((sender) => sender.RemoteEndPoint.Port);
|
||||
get => new PropertyContext<int>((sender) => sender.RemoteEndPoint.Port);
|
||||
set
|
||||
{
|
||||
Console.WriteLine($"PropertyContext Set: {value.Value} {value.Connection.RemoteEndPoint.Port}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int MyPasscode = 2025;
|
||||
public PropertyContext<int> Passcode
|
||||
{
|
||||
get => new ((sender) => sender.Session.AuthorizedAccount == "alice" ? MyPasscode : 0);
|
||||
set
|
||||
{
|
||||
if (value.Connection.Session.AuthorizedAccount != "alice")
|
||||
throw new Exception("Only Alice is allowed.");
|
||||
MyPasscode = value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public SizeEnum Enum => SizeEnum.Medium;
|
||||
|
||||
|
||||
@ -144,8 +157,11 @@ public partial class MyService
|
||||
Console.WriteLine("Void()");
|
||||
|
||||
[Export]
|
||||
public void InvokeEvents(string msg)
|
||||
public void InvokeEvents(string msg, InvocationContext context)
|
||||
{
|
||||
if (context.Connection.Session.AuthorizedAccount != "Alice")
|
||||
throw new Exception("Only Alice is allowed.");
|
||||
|
||||
StringEvent?.Invoke(msg);
|
||||
ArrayEvent?.Invoke(new object[] { DateTime.UtcNow, "Event", msg });
|
||||
}
|
||||
|
@ -82,29 +82,29 @@ namespace Test
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
|
||||
var x = LogLevel.Warning;
|
||||
//var x = LogLevel.Warning;
|
||||
|
||||
TestSerialization(LogLevel.Warning);
|
||||
//TestSerialization(LogLevel.Warning);
|
||||
|
||||
TestSerialization(new Map<string, byte?>
|
||||
{
|
||||
["C++"] = 1,
|
||||
["C#"] = 2,
|
||||
["JS"] = null
|
||||
});
|
||||
//TestSerialization(new Map<string, byte?>
|
||||
//{
|
||||
// ["C++"] = 1,
|
||||
// ["C#"] = 2,
|
||||
// ["JS"] = null
|
||||
//});
|
||||
|
||||
|
||||
|
||||
TestSerialization(new StudentRecord() { Name = "Ali", Grade = 90 });
|
||||
//TestSerialization(new StudentRecord() { Name = "Ali", Grade = 90 });
|
||||
|
||||
var tn = Encoding.UTF8.GetBytes("Test.StudentRecord");
|
||||
var hash = System.Security.Cryptography.SHA256.Create().ComputeHash(tn).Clip(0, 16);
|
||||
hash[6] = (byte)((hash[6] & 0xF) | 0x80);
|
||||
hash[8] = (byte)((hash[8] & 0xF) | 0x80);
|
||||
//var tn = Encoding.UTF8.GetBytes("Test.StudentRecord");
|
||||
//var hash = System.Security.Cryptography.SHA256.Create().ComputeHash(tn).Clip(0, 16);
|
||||
//hash[6] = (byte)((hash[6] & 0xF) | 0x80);
|
||||
//hash[8] = (byte)((hash[8] & 0xF) | 0x80);
|
||||
|
||||
var g = new UUID(hash);
|
||||
//var g = new UUID(hash);
|
||||
|
||||
Console.WriteLine(g);
|
||||
//Console.WriteLine(g);
|
||||
|
||||
|
||||
var hhhh = Warehouse.GetTemplateByType(typeof(IMyRecord));
|
||||
@ -148,7 +148,7 @@ namespace Test
|
||||
var res3 = await Warehouse.Put("sys/service/c1", new MyChildResource() { ChildName = "Child 1", Description = "Child Testing 3", CategoryId = 12 });
|
||||
var res4 = await Warehouse.Put("sys/service/c2", new MyChildResource() { ChildName = "Child 2 Destroy", Description = "Testing Destroy Handler", CategoryId = 12 });
|
||||
|
||||
TestSerialization(res1);
|
||||
//TestSerialization(res1);
|
||||
|
||||
server.MapCall("Hello", (string msg, DateTime time, DistributedConnection sender) =>
|
||||
{
|
||||
|
Reference in New Issue
Block a user