public void TestRpcLocalAsyncSingleCall() { Console.WriteLine("LocalAsyncSingleCall"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Console.WriteLine("Calling RPC"); Console.WriteLine("Waiting for RPC Result"); CancellationTokenSource source = new CancellationTokenSource(); var task = RemoteProcedureCall.CallRpcWithResultAsync("func1", source.Token, RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) })); var completed = task.Wait(TimeSpan.FromSeconds(1)); if (!completed) { source.Cancel(); } Assert.That(completed, Is.True); Assert.That(task.IsCompleted); var call1Result = RemoteProcedureCall.UnpackRpcValues(task.Result, new [] { NtType.Double }); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestRpcSpeedAsyncSingleCall() { Console.WriteLine("SpeedAsyncSingleCall"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10000; ++i) { CancellationTokenSource source = new CancellationTokenSource(); var task = RemoteProcedureCall.CallRpcWithResultAsync("func1", source.Token, RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(i) })); var completed = task.Wait(TimeSpan.FromSeconds(1)); if (!completed) { source.Cancel(); } Assert.That(completed, Is.True); Assert.That(task.IsCompleted); var res = RemoteProcedureCall.UnpackRpcValues(task.Result, new [] { NtType.Double }); Assert.AreNotEqual(0, res.Count, "RPC Result empty"); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void TestRpcLocalTimeoutSuccess() { Console.WriteLine("LocalTimeoutSuccess"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Console.WriteLine("Calling RPC"); long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) })); Console.WriteLine("Waiting for RPC Result"); byte[] result = null; RemoteProcedureCall.GetRpcResult(true, call1Uid, TimeSpan.FromSeconds(1), out result); Assert.That(result, Is.Not.Null); var call1Result = RemoteProcedureCall.UnpackRpcValues(result, new [] { NtType.Double }); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestRpcSpeedTimeoutSuccess() { Console.WriteLine("SpeedTimeoutSuccess"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback1); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10000; ++i) { long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(i) })); byte[] call1Result = null; RemoteProcedureCall.GetRpcResult(true, call1Uid, TimeSpan.FromSeconds(1), out call1Result); Assert.That(call1Result, Is.Not.Null); var res = RemoteProcedureCall.UnpackRpcValues(call1Result, new [] { NtType.Double }); Assert.AreNotEqual(0, res.Count, "RPC Result empty"); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
public void TestPolledRpc() { Console.WriteLine("TestPolledRpc"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreatePolledRpc("func1", def); Console.WriteLine("Calling RPC"); long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) })); RpcCallInfo info; bool polled = RemoteProcedureCall.PollRpc(true, TimeSpan.FromSeconds(1), out info); Assert.That(polled, Is.True); IList <byte> toSendBack = Callback1(info.Name, info.Params, new ConnectionInfo()); Assert.That(toSendBack.Count, Is.Not.EqualTo(0)); RemoteProcedureCall.PostRpcResponse(info.RpcId, info.CallUid, toSendBack); Console.WriteLine("Waiting for RPC Result"); byte[] result = null; RemoteProcedureCall.GetRpcResult(true, call1Uid, out result); var call1Result = RemoteProcedureCall.UnpackRpcValues(result, new [] { NtType.Double }); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestRpcSpeed() { CoreMethods.SetLogger((level, file, line, message) => { //Console.Error.WriteLine(message); }, 0); var def = new NtRpcDefinition(1, "myfunc1", new[] { new NtRpcParamDef("param1", RpcValue.MakeDouble(0.0)) }, new[] { new NtRpcResultDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", def, Callback1); Stopwatch sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10000; ++i) { uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeDouble(i)); byte[] call1Result = RemoteProcedureCall.GetRpcResult(true, call1Uid); var res = RemoteProcedureCall.UnpackRpcValues(call1Result, NtType.Double); Assert.AreNotEqual(0, res.Count, "RPC Result empty"); } sw.Stop(); Console.WriteLine(sw.Elapsed); }
private static byte[] Callback2(string names, byte[] paramsStr) { var param = RemoteProcedureCall.UnpackRpcValues(paramsStr, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray); if (param.Count == 0) { Console.Error.WriteLine("Empty Params?"); return(new byte[] { 0 }); } return(RemoteProcedureCall.PackRpcValues(Value.MakeBoolean(true), Value.MakeBooleanArray(new[] { true, false }), Value.MakeDouble(2.2), Value.MakeDoubleArray(new[] { 2.8, 6.876 }), Value.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), Value.MakeString("NewString"), Value.MakeStringArray(new[] { "String1", "String2" }))); }
private static byte[] Callback1(string names, byte[] paramsStr) { var param = RemoteProcedureCall.UnpackRpcValues(paramsStr, NtType.Double); if (param.Count == 0) { Console.Error.WriteLine("Empty Params?"); return(new byte[] { 0 }); } double val = param[0].GetDouble(); return(RemoteProcedureCall.PackRpcValues(Value.MakeDouble(val + 1.2))); }
private static IList <byte> Callback1(string names, byte[] paramsStr, ConnectionInfo connInfo) { var param = RemoteProcedureCall.UnpackRpcValues(paramsStr, new[] { NtType.Double }); if (param.Count == 0) { Console.Error.WriteLine("Empty Params?"); return(new byte[] { 0 }); } double val = param[0].GetDouble(); return(RemoteProcedureCall.PackRpcValues(new[] { Value.MakeDouble(val + 1.2) })); }
public void TestPolledRpcAsync() { Console.WriteLine("TestPolledRpcAsync"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeDouble(0.0)) }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Double) }); RemoteProcedureCall.CreatePolledRpc("func1", def); Console.WriteLine("Calling RPC"); long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(new [] { Value.MakeDouble(2.0) })); CancellationTokenSource source = new CancellationTokenSource(); var task = RemoteProcedureCall.PollRpcAsync(source.Token); bool completed = task.Wait(TimeSpan.FromSeconds(1)); if (!completed) { source.Cancel(); } Assert.That(completed, Is.True); Assert.That(task.IsCompleted, Is.True); Assert.That(task.Result, Is.Not.Null); Assert.That(task.Result.HasValue); IList <byte> toSendBack = Callback1(task.Result.Value.Name, task.Result.Value.Params, new ConnectionInfo()); Assert.That(toSendBack.Count, Is.Not.EqualTo(0)); RemoteProcedureCall.PostRpcResponse(task.Result.Value.RpcId, task.Result.Value.CallUid, toSendBack); Console.WriteLine("Waiting for RPC Result"); byte[] result = null; RemoteProcedureCall.GetRpcResult(true, call1Uid, out result); var call1Result = RemoteProcedureCall.UnpackRpcValues(result, new [] { NtType.Double }); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestRpcAllTypes() { CoreMethods.SetLogger((level, file, line, message) => { //Console.Error.WriteLine(message); }, 0); var def = new NtRpcDefinition(1, "myfunc1", new[] { new NtRpcParamDef("param1", RpcValue.MakeBoolean(true)), new NtRpcParamDef("param2", RpcValue.MakeBooleanArray(new[] { true, false })), new NtRpcParamDef("param3", RpcValue.MakeDouble(0.0)), new NtRpcParamDef("param4", RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 })), new NtRpcParamDef("param5", RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 })), new NtRpcParamDef("param6", RpcValue.MakeString("NewString")), new NtRpcParamDef("param7", RpcValue.MakeStringArray(new[] { "String1", "String2" })), }, new[] { new NtRpcResultDef("result1", NtType.Boolean), new NtRpcResultDef("result2", NtType.BooleanArray), new NtRpcResultDef("result3", NtType.Double), new NtRpcResultDef("result4", NtType.DoubleArray), new NtRpcResultDef("result5", NtType.Raw), new NtRpcResultDef("result6", NtType.String), new NtRpcResultDef("result7", NtType.StringArray), }); RemoteProcedureCall.CreateRpc("func1", def, Callback2); Console.WriteLine("Calling RPC"); uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeBoolean(true), RpcValue.MakeBooleanArray(new[] { true, false }), RpcValue.MakeDouble(2.2), RpcValue.MakeDoubleArray(new[] { 2.8, 6.87 }), RpcValue.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), RpcValue.MakeString("NewString"), RpcValue.MakeStringArray(new[] { "String1", "String2" })); Console.WriteLine("Waiting for RPC Result"); byte[] result = RemoteProcedureCall.GetRpcResult(true, call1Uid); var call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestRpcAllTypes() { Console.WriteLine("AllTypes"); var def = new RpcDefinition(1, "myfunc1", new List <RpcParamDef> { new RpcParamDef("param1", Value.MakeBoolean(true)), new RpcParamDef("param2", Value.MakeBooleanArray(new[] { true, false })), new RpcParamDef("param3", Value.MakeDouble(0.0)), new RpcParamDef("param4", Value.MakeDoubleArray(new[] { 2.8, 6.87 })), new RpcParamDef("param5", Value.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 })), new RpcParamDef("param6", Value.MakeString("NewString")), new RpcParamDef("param7", Value.MakeStringArray(new[] { "String1", "String2" })), }, new List <RpcResultsDef> { new RpcResultsDef("result1", NtType.Boolean), new RpcResultsDef("result2", NtType.BooleanArray), new RpcResultsDef("result3", NtType.Double), new RpcResultsDef("result4", NtType.DoubleArray), new RpcResultsDef("result5", NtType.Raw), new RpcResultsDef("result6", NtType.String), new RpcResultsDef("result7", NtType.StringArray), }); RemoteProcedureCall.CreateRpc("func1", RemoteProcedureCall.PackRpcDefinition(def), Callback2); Console.WriteLine("Calling RPC"); long call1Uid = RemoteProcedureCall.CallRpc("func1", RemoteProcedureCall.PackRpcValues(Value.MakeBoolean(true), Value.MakeBooleanArray(new[] { true, false }), Value.MakeDouble(2.2), Value.MakeDoubleArray(new[] { 2.8, 6.87 }), Value.MakeRaw(new byte[] { 52, 0, 89, 0, 0, 98 }), Value.MakeString("NewString"), Value.MakeStringArray(new[] { "String1", "String2" }))); Console.WriteLine("Waiting for RPC Result"); byte[] result = null; RemoteProcedureCall.GetRpcResult(true, call1Uid, out result); var call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Boolean, NtType.BooleanArray, NtType.Double, NtType.DoubleArray, NtType.Raw, NtType.String, NtType.StringArray); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
public void TestRpcLocal() { CoreMethods.SetLogger((level, file, line, message) => { //Console.Error.WriteLine(message); }, 0); var def = new NtRpcDefinition(1, "myfunc1", new[] { new NtRpcParamDef("param1", RpcValue.MakeDouble(0.0)) }, new[] { new NtRpcResultDef("result1", NtType.Double) }); RemoteProcedureCall.CreateRpc("func1", def, Callback1); Console.WriteLine("Calling RPC"); uint call1Uid = RemoteProcedureCall.CallRpc("func1", RpcValue.MakeDouble(2.0)); Console.WriteLine("Waiting for RPC Result"); byte[] result = RemoteProcedureCall.GetRpcResult(true, call1Uid); var call1Result = RemoteProcedureCall.UnpackRpcValues(result, NtType.Double); Assert.AreNotEqual(0, call1Result.Count, "RPC Result empty"); Console.WriteLine(call1Result[0].ToString()); }
/// <inheritdoc cref="RemoteProcedureCall.UnpackRpcValues(byte[], List{NtType})"/> public List <Value> UnpackRpcValues(byte[] packed, List <NtType> types) { return(RemoteProcedureCall.UnpackRpcValues(packed, types)); }