Esempio n. 1
0
        public void ProcessRequest(Func <JSONAction <dynamic>, JSONResponse <dynamic> > Process)
        {
            JSONAction <dynamic>   Request = ListenForCommand <dynamic>();
            JSONResponse <dynamic> Result  = Process.Invoke(Request);

            SendResponseDataPackage(Result);
        }
Esempio n. 2
0
        public void ProcessRequest <Tin, TResult>(Func <JSONAction <Tin>, JSONResponse <TResult> > Process)
        {
            JSONAction <Tin>       Request = ListenForCommand <Tin>();
            JSONResponse <TResult> Result  = Process.Invoke(Request);

            SendResponseDataPackage(Result);
        }
Esempio n. 3
0
        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 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);
        }
Esempio n. 5
0
 public static JSONResponse <dynamic> ToDynamic <T>(this JSONResponse <T> This)
 {
     return(new JSONResponse <dynamic>()
     {
         ActionName = This.ActionName, RequestStatus = This.RequestStatus, ActionData = This.ActionData, Message = This.Message
     });
 }
Esempio n. 6
0
        public static object ResponseDynamicAutoCast(this JSONResponse <dynamic> This, Type ReturnsSubType)
        {
            Type ReturnType = typeof(JSONResponse <>).MakeGenericType(ReturnsSubType);

            MethodInfo GenericMethod = typeof(JSONResponseDynamicExt).GetMethod("DynamicAutoCast");
            MethodInfo Method        = GenericMethod.MakeGenericMethod(ReturnsSubType);
            object     ReturnObj     = Method.Invoke(null, new object[] { This });

            return(ReturnObj);
        }
Esempio n. 7
0
 public static JSONResponse <T> DynamicAutoCast <T>(this JSONResponse <dynamic> This)
 {
     try
     {
         return(new JSONResponse <T>()
         {
             ActionData = (T)JsonConvert.DeserializeObject <T>(This.ActionData.ToString()), RequestStatus = This.RequestStatus, ActionName = This.ActionName, Message = This.Message
         });
     }
     catch
     {
         return(new JSONResponse <T>()
         {
             ActionData = This.ActionData, RequestStatus = This.RequestStatus, ActionName = This.ActionName, Message = This.Message
         });
     }
 }
Esempio n. 8
0
        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();
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Get a response line from the server
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        JSONResponse <T> GetResponse <T>()
        {
            string Line = Rx.ReadLine();

            return(JSONResponse <T> .FromString(Line));
        }
Esempio n. 10
0
 /// <summary>
 /// A method that is used to send a JSON response package
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="Package"></param>
 void SendResponseDataPackage <T>(JSONResponse <T> Package)
 {
     Tx.WriteLine(Package.ToString());
     Tx.Flush();
     PipeClient.WaitForPipeDrain();
 }
 JSONResponse <T> GetResponse <T>()
 {
     return(JSONResponse <T> .FromString(Rx.ReadLine()));
 }
 internal void SendResponseDataPackage <T>(JSONResponse <T> Package)
 {
     Tx.WriteLine(Package.ToString());
     Tx.Flush();
     ServicePipe.WaitForPipeDrain();
 }