Beispiel #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);
        }
Beispiel #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);
        }