public async Task SetSessionDataTest(PitayaSession pitayaSession, RPCMsg msg) { pitayaSession.Set("msg", "testingMsg"); pitayaSession.Set("int", 3); pitayaSession.Set("double", 3.33); await pitayaSession.PushToFrontend(); }
public async Task TestKick(PitayaSession pitayaSession) { var ok = await pitayaSession.Kick(); if (!ok) { Logger.Error("kick user failed!"); } }
public async Task <RPCRes> Entry(PitayaSession pitayaSession, RPCMsg msg) { var response = new NPitaya.Protos.RPCRes { Msg = $"hello from csharp handler!!! :) {Guid.NewGuid().ToString()}", Code = 200 }; return(response); }
public async Task TestKick(PitayaSession pitayaSession) { try { await pitayaSession.Kick(); } catch (Exception e) { Logger.Error($"kick user failed! {e}"); } }
public async Task TestPush(PitayaSession pitayaSession) { Console.WriteLine("got empty notify"); var msg = Encoding.UTF8.GetBytes("test felipe"); var ok = await pitayaSession.Push(new RPCRes { Code = 200, Msg = "testFelipe" }, "test.route"); if (!ok) { Logger.Error("push to user failed!"); } }
public async Task NotifyBind(PitayaSession pitayaSession, RPCMsg msg) { var response = new MyResponse { Msg = $"hello from csharp handler!!! :) {Guid.NewGuid().ToString()}", Code = 200 }; await pitayaSession.Bind("uidbla"); Console.WriteLine("handler executed with arg {0}", msg); Console.WriteLine("handler executed with session ipversion {0}", pitayaSession.GetString("ipversion")); }
public async Task TestPush(PitayaSession pitayaSession) { Console.WriteLine("got empty notify"); var msg = Encoding.UTF8.GetBytes("test felipe"); try { await pitayaSession.Push(new MyResponse { Code = 200, Msg = "testFelipe" }, "test.route"); } catch (Exception e) { Logger.Error($"push to user failed!: {e}", e); } }
public async Task <Answer> ChangeName(PitayaSession session, ChangeNameArgs arg) { using (var context = new ExampleContext()) { var userModel = await GetUserFromToken(new Guid(arg.Token), context); userModel.Name = arg.Name; context.Update(userModel); await context.SaveChangesAsync(); return(new Answer { Code = "OK!" }); } }
public async Task <User> Authenticate(PitayaSession session, AuthenticateArgs args) { using (var context = new ExampleContext()) { if (args.Token.Length > 0) { return(ModelsUserToProtosUser(await GetUserFromToken(new Guid(args.Token), context))); } // if token was not sent, create an user and return! var newUser = new Models.User(); newUser = context.Users.Add(newUser).Entity; await context.SaveChangesAsync(); return(ModelsUserToProtosUser(newUser)); } }
public async Task <MyResponse> Entry(PitayaSession session, RPCMsg msg) { try { await session.Bind("CSHARP_UID"); } catch (Exception e) { Console.WriteLine($"session bind error: {e.Message}"); } var response = new MyResponse { Msg = $"WUJOQWIEJOIQWJEOIQWJEOIQJWEOIJQWIOJE", Code = 200 }; return(response); }
public async Task <TestClass> OnlyValidWithJson(PitayaSession s, TestClass t) { return(t); }
internal static async Task <Response> HandleRpc(Protos.Request req, RPCType type, Stopwatch sw) { byte[] data = req.Msg.Data.ToByteArray(); Route route = Route.FromString(req.Msg.Route); string handlerName = $"{route.service}.{route.method}"; PitayaSession s = null; var response = new Response(); RemoteMethod handler; if (type == RPCType.Sys) { s = new Models.PitayaSession(req.Session, req.FrontendID); if (!HandlersDict.ContainsKey(handlerName)) { response = GetErrorResponse("PIT-404", $"remote/handler not found! remote/handler name: {handlerName}"); return(response); } handler = HandlersDict[handlerName]; MetricsReporters.ReportMessageProccessDelay(req.Msg.Route, "local", sw); } else { if (!RemotesDict.ContainsKey(handlerName)) { response = GetErrorResponse("PIT-404", $"remote/handler not found! remote/handler name: {handlerName}"); return(response); } handler = RemotesDict[handlerName]; MetricsReporters.ReportMessageProccessDelay(req.Msg.Route, "remote", sw); } Task ans; if (handler.ArgType != null) { var arg = _serializer.Unmarshal(data, handler.ArgType); if (type == RPCType.Sys) { ans = handler.Method.Invoke(handler.Obj, new[] { s, arg }) as Task; } else { ans = handler.Method.Invoke(handler.Obj, new[] { arg }) as Task; } } else { if (type == RPCType.Sys) { ans = handler.Method.Invoke(handler.Obj, new object[] { s }) as Task; } else { ans = handler.Method.Invoke(handler.Obj, new object[] { }) as Task; } } await ans; byte[] ansBytes; if (handler.ReturnType != typeof(void)) { ansBytes = SerializerUtils.SerializeOrRaw(ans.GetType(). GetProperty("Result") ?.GetValue(ans), _serializer); } else { ansBytes = new byte[] {}; } response.Data = ByteString.CopyFrom(ansBytes); return(response); }