예제 #1
0
        public string TransformStringContext(string templateName, string context, object o)
        {
            templateName = templateName.ToLowerInvariant();

            CheckTemplate(templateName);
            var expression = string.Format("chevronTemplate_{0}({1});", templateName, context);

            return((string)engine.Evaluate(expression));
        }
예제 #2
0
        public string TransformStringContext(string templateName, string context, object o)
        {
            Guard.AgainstNullAndEmpty(templateName, "templateName");
            Guard.AgainstNull(context, "context");
            templateName = templateName.ToLowerInvariant();

            CheckTemplate(templateName);
            var expression = $"chevronTemplate_{templateName}({context});";

            return((string)engine.Evaluate(expression));
        }
예제 #3
0
        public string TransformStringContext(string templateName, string context)
        {
            templateName = templateName.ToLowerInvariant();

            if (!registeredTemplates.Contains(templateName))
            {
                throw new Exception(string.Format("Could not find a template named '{0}'.", templateName));
            }
            var expression = string.Format("chevronTemplate_{0}({1});", templateName, context);

            return((string)engine.Evaluate(expression));
        }
        protected override object InnerEvaluate(string expression)
        {
            object result;

            try
            {
                result = _jsEngine.Evaluate(expression);
            }
            catch (OriginalJsRuntimeException e)
            {
                throw ConvertMsieJsRuntimeExceptionToJsRuntimeException(e);
            }

            result = MapToHostType(result);

            return(result);
        }
        protected override object InnerEvaluate(string expression, string documentName)
        {
            object result;

            try
            {
                result = _jsEngine.Evaluate(expression, documentName);
            }
            catch (OriginalException e)
            {
                throw WrapJsException(e);
            }

            result = MapToHostType(result);

            return(result);
        }
예제 #6
0
        public string Execute(string script)
        {
            try
            {
                var engine = new Engine(_useEcmaScript5Polyfill, _useJson2Library);

                var     stringifiedResult = engine.Evaluate(script) as string;
                var     sampleResult      = new { successful = false, result = "", error = "" };
                dynamic json = JsonConvert.DeserializeAnonymousType(stringifiedResult, sampleResult);
                if (!json.successful)
                {
                    throw new ScriptException(json.error);
                }
                return(json.result);
            }
            catch (ActiveScriptException ex)
            {
                throw new ScriptException(ex.Message, ex);
            }
        }