Example #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();
        }
Example #2
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();
            }
        }