Beispiel #1
0
        public ScriptedController(ControllerContext context, LoadedModule module) : base(module, true)
        {
            _ctx         = context;
            HttpRequest  = new HttpRequestImpl(_ctx.HttpContext.Request);
            HttpResponse = new HttpResponseImpl(_ctx.HttpContext.Response);

            if (_ctx.RouteData != null)
            {
                RouteValues = new MapImpl();
                foreach (var routeData in _ctx.RouteData.Values)
                {
                    var rv = RouteValues.AsObject();
                    rv.SetIndexedValue(
                        ValueFactory.Create(routeData.Key),
                        CustomMarshaller.ConvertToIValueSafe(routeData.Value, routeData.Value?.GetType())
                        );
                }
            }
            else
            {
                RouteValues = ValueFactory.Create();
            }

            var typeClr = (Type)context.ActionDescriptor.Properties["type"];
            var type    = TypeManager.RegisterType("Контроллер." + typeClr.Name, typeof(ScriptedController));

            DefineType(type);
            InitOwnData();
        }
Beispiel #2
0
        public ScriptedViewComponent(LoadedModule module, string dynamicTypeName) : base(module, true)
        {
            var td = TypeManager.RegisterType(dynamicTypeName, typeof(ScriptedViewComponent));

            DefineType(td);
            InitOwnData();


            var methId = GetScriptMethod(InvokeMethodNameRu, InvokeMethodNameEn);

            if (methId == -1)
            {
                throw new RuntimeException("Invoke method not found");
            }

            object Invoker(IDictionary <string, object> arguments)
            {
                var args   = MapArguments(methId, arguments);
                var result = CallScriptMethod(methId, args);

                return(CustomMarshaller.ConvertToCLRObject(result));
            }

            _invoker = Invoker;
        }
Beispiel #3
0
        private void OnContextChange()
        {
            HttpRequest  = new HttpRequestImpl(ComponentContext.ViewContext.HttpContext.Request);
            HttpResponse = new HttpResponseImpl(ComponentContext.ViewContext.HttpContext.Response);
            ViewData     = new ViewDataDictionaryWrapper(ComponentContext.ViewData);

            var routeData = _ctx.ViewContext.RouteData;

            if (routeData != null)
            {
                RouteValues = new MapImpl();
                var rv = RouteValues.AsObject();
                foreach (var routeValue in routeData.Values)
                {
                    rv.SetIndexedValue(
                        ValueFactory.Create(routeValue.Key),
                        CustomMarshaller.ConvertToIValueSafe(routeValue.Value, routeValue.Value.GetType())
                        );
                }
            }
            else
            {
                RouteValues = ValueFactory.Create();
            }
        }
        private IValue[] MapArguments(int methId, IDictionary <string, object> arguments)
        {
            var parameters = GetMethodInfo(methId + GetOwnMethodCount()).Params;

            IValue[] args = new IValue[parameters.Length];

            if (parameters.Length == 0 && arguments.Count != 0)
            {
                throw RuntimeException.TooManyArgumentsPassed();
            }

            for (int i = 0; i < parameters.Length; i++)
            {
                var obj  = arguments[parameters[i].Name];
                var type = obj is IValue ? typeof(IValue) : obj.GetType();

                if (obj is DynamicContextWrapper dyn)
                {
                    obj = dyn.UnderlyingObject;

                    if (type == typeof(DynamicContextWrapper))
                    {
                        type = obj.GetType();
                    }
                }

                args[i] = CustomMarshaller.ConvertToIValueSafe(obj, type);
            }

            return(args);
        }