Ejemplo n.º 1
0
        /// <summary>
        /// Processes worker process requests.
        /// </summary>
        /// <param name="request"> The request to process. </param>
        public WorkerProcessResponse ProcessRequest(WorkerProcessRequest request)
        {
            var engine = new ScriptEngine();

            var response = new WorkerProcessResponse();

            try
            {
                // Execute the provided script.
                object result = engine.Evaluate(request.Script);
                response.JsonResult = JSONObject.Stringify(engine, result);
                if (request.VariablesToReturn != null)
                {
                    response.Variables = new Dictionary <string, string>();
                    foreach (var variableName in request.VariablesToReturn)
                    {
                        response.Variables[variableName] = engine.GetGlobalValue <string>(variableName);
                    }
                }
            }
            catch (Exception e)
            {
                // There was an error.
                response.ErrorType    = e.GetType().Name;
                response.ErrorMessage = e.Message;
            }

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes worker process requests.
        /// </summary>
        /// <param name="request"> The request to process. </param>
        public WorkerProcessResponse ProcessRequest(WorkerProcessRequest request)
        {
            var engine = new ScriptEngine();

            var response = new WorkerProcessResponse();

            try
            {
                // Execute the provided script.
                object result = engine.Evaluate(request.Script);
                response.JsonResult = JSONObject.Stringify(engine, result);
            }
            catch (Exception e)
            {
                // There was an error.
                response.ErrorType    = e.GetType().Name;
                response.ErrorMessage = e.Message;
            }

            return(response);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sends a request to a child process, then waits for the response.
 /// </summary>
 /// <param name="pipe"> The pipe to use to send the message. </param>
 /// <param name="request"> The request to send. </param>
 /// <returns> The response. </returns>
 private WorkerProcessResponse Send(PipeServer pipe, WorkerProcessRequest request)
 {
     return(JsonConvert.DeserializeObject <WorkerProcessResponse>(pipe.Send(JsonConvert.SerializeObject(request))));
 }