public void ProcessRequest <Tin, TResult>(Func <IJSONAction, IJSONResponse> Processe) { JSONAction <Tin> Request = ListenForCommand <Tin>(); JSONResponse <TResult> Result = (JSONResponse <TResult>)Processe.Invoke(Request); SendResponseDataPackage(Result); }
public void ProcessRequest(Func <JSONAction <dynamic>, JSONResponse <dynamic> > Process) { JSONAction <dynamic> Request = ListenForCommand <dynamic>(); JSONResponse <dynamic> Result = Process.Invoke(Request); SendResponseDataPackage(Result); }
public static JSONAction <dynamic> ToDynamic <T>(this JSONAction <T> This) { return(new JSONAction <dynamic>() { ActionName = This.ActionName, ActionData = This.ActionData }); }
public void ProcessRequest <Tin, TResult>(Func <JSONAction <Tin>, JSONResponse <TResult> > Process) { JSONAction <Tin> Request = ListenForCommand <Tin>(); JSONResponse <TResult> Result = Process.Invoke(Request); SendResponseDataPackage(Result); }
public static JSONAction <T> DynamicAutoCast <T>(this JSONAction <dynamic> This) { return(new JSONAction <T>() { ActionData = (T)JsonConvert.DeserializeObject <T>(This.ActionData.ToString()), ActionName = This.ActionName }); }
public JSONResponse <TResult> SendCommandRequest <Tin, TResult>(JSONAction <Tin> Package, TimeSpan Timeout) { JSONResponse <TResult> Result = new JSONResponse <TResult>() { ActionName = Package.ActionName, RequestStatus = JSONResponseStatus.TimeOut, Message = "Client has timed out o its request to the server." }; Client = new JSONPipeClient(PipeServerName, URL); Client.Connect(); Task task = Task.Factory.StartNew(() => { Result = Client.SendCommandRequest <Tin, TResult>(Package); Client.CloseConnection(); return(Result); }); task.Wait(Timeout); if (Client.IsConnected) { Client.CloseConnection(); } return(Result); }
public static object ActionDynamicAutoCast(this JSONAction <dynamic> This, Type ReturnsSubType) { Type ReturnType = typeof(JSONAction <>).MakeGenericType(ReturnsSubType); MethodInfo GenericMethod = typeof(JSONActionDynamicExt).GetMethod("DynamicAutoCast"); MethodInfo Method = GenericMethod.MakeGenericMethod(ReturnsSubType); object ReturnObj = Method.Invoke(null, new object[] { This }); return(ReturnObj); }
public void ProcessRequest() { Server.WaitForConnect(); JSONAction <dynamic> Request = Server.ListenForCommand <dynamic>(); if (Processes.ContainsKey(Request.ActionName)) { InstancedAndMethodInfo MethodInfo = Processes[Request.ActionName]; Type TemplatedType = MethodInfo.MethodInfo.GetParameters()[0].ParameterType.GetProperties().Where(x => x.Name == "ActionData").FirstOrDefault().PropertyType; object Result = MethodInfo.MethodInfo.Invoke(MethodInfo.Instance, new object[] { Request.ActionDynamicAutoCast(TemplatedType) }); Type Return = MethodInfo.MethodInfo.ReturnType.GetProperties().Where(x => x.Name == "ActionData").FirstOrDefault().PropertyType; MethodInfo GenericMethod = typeof(JSONPipeServer).GetMethod("SendResponseDataPackage", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo SendResponseDataPackageMethod = GenericMethod.MakeGenericMethod(Return); if (Server.IsConnected) { SendResponseDataPackageMethod.Invoke(Server, new object[] { Result }); } if (Server.IsConnected) { Server.CloseConnection(); } } else { JSONResponse <dynamic> Response = new JSONResponse <dynamic>() { ActionData = new { }, RequestStatus = JSONResponseStatus.ActionNotFound, ActionName = Request.ActionName }; if (Server.IsConnected) { Server.SendResponseDataPackage(Response); } if (Server.IsConnected) { Server.CloseConnection(); } } }
/// <summary> /// A method to send a JSON command and data package /// </summary> /// <typeparam name="T"></typeparam> /// <param name="Package"></param> void SendCommandDataPackage <T>(JSONAction <T> Package) { Tx.WriteLine(Package.ToString()); Tx.Flush(); PipeClient.WaitForPipeDrain(); }
public JSONResponse <TResult> SendCommandRequest <Tin, TResult>(JSONAction <Tin> Package) { SendCommandDataPackage(Package); return(ListenForResponse <TResult>()); }
/// <summary> /// A command to start to Listen for a command run over the line /// </summary> /// <typeparam name="T">A templated Returns Data Type</typeparam> /// <returns>A Command has run over the line</returns> JSONAction <T> GetCommand <T>() { return(JSONAction <T> .FromString(Rx.ReadLine())); }
public JSONResponse <TResult> SendCommandRequest <Tin, TResult>(JSONAction <Tin> Package) { return(SendCommandRequest <Tin, TResult>(Package, StandardTimeout)); }