Exemplo n.º 1
0
        public void Process(ControllerContext ctx)
        {
            // Find the view file
            var view = app.ViewService.LoadViewTemplate(viewname, controller.GetType().Name);

            // Render it!
            view.Render(ctx, model, null, !partial);

            // Done!
            ctx.Response.End();
        }
Exemplo n.º 2
0
        public void Process(ControllerContext ctx)
        {
            if (contentType!=null)
                ctx.Response.SetHeader("Content-Type", contentType);

            if (contentEncoding != null)
            {
                ctx.Response.ContentEncoding = contentEncoding;
                ctx.Response.SetHeader("Content-Encoding", contentEncoding.HeaderName);
            }

            ctx.Response.End(content);
        }
Exemplo n.º 3
0
        public void Process(ControllerContext ctx)
        {
            ctx.Response.SetHeader("Content-Type", contentType ?? "application/json");

            if (contentEncoding != null)
            {
                ctx.Response.ContentEncoding = contentEncoding;
                ctx.Response.SetHeader("Content-Encoding", contentEncoding.HeaderName);
            }

            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            ctx.Response.Write(serializer.Serialize(data));
            ctx.Response.End();
        }
Exemplo n.º 4
0
        public void Render(ControllerContext ctx, object model, View innerView, bool runStartPage)
        {
            // Check model type matches on strongly typed views
            CheckDoesModelTypeMatch(ViewType, model==null ? null : model.GetType());

            // Create the view
            var viewbase = (View)Activator.CreateInstance(ViewType);

            // Pass it the view context
            viewbase.Context = ctx;
            viewbase.Model = model;
            viewbase.Html = new HtmlHelper(ctx);
            viewbase.InnerView = innerView;
            viewbase.StartPage = runStartPage ? Owner.CreateStartView() : null;

            // Execute it!
            viewbase.Execute();
        }
Exemplo n.º 5
0
        public void Process(ControllerContext ctx)
        {
            // Work out content type from fileName
            if (contentType==null && fileName!=null)
                contentType = ManosMimeTypes.GetMimeType(fileName);

            // Setup content type
            if (contentType != null)
            {
                ctx.Response.Headers.SetNormalizedHeader("Content-Type", contentType);
            }

            // Setup content disposition
            if (fileName != null)
            {
                ctx.Response.Headers.SetNormalizedHeader("Content-Disposition", "attachment; filename=" + fileName);
            }

            OnWriteFileData(ctx);
        }
Exemplo n.º 6
0
        void InvokeControllerInternal(IManosContext ctx)
        {
            try
            {
                // Create a context
                var Context = new ControllerContext()
                {
                    Application = owner.Service.Application,
                    CurrentAction = methodInfo,
                    ManosContext = ctx,
                };

                // Create the controller
                Context.Controller = owner.Service.CreateControllerInstance(Context, owner.ControllerType);
                Context.Controller.Context = Context;

                // Get parameters from the incoming data
                object[] data;
                var pi = methodInfo.GetParameters();
                if (pi.Length > 0)
                {
                    ParameterizedActionTarget.TryGetDataForParamList(methodInfo.GetParameters(), null, ctx, out data);
                }
                else
                {
                    data = null;
                }

                // Invoke the controller
                var result = actionDelegate(Context.Controller, data);

                // Process the result
                Context.ProcessResult(result);
            }
            catch (Exception x)
            {
                ExceptionRenderer.RenderException(ctx, x, true);
            }
        }
Exemplo n.º 7
0
 protected override void OnWriteFileData(ControllerContext ctx)
 {
     ctx.Response.Write(data);
     ctx.Response.End();
 }
Exemplo n.º 8
0
 public HtmlHelper(ControllerContext ctx)
 {
     this.Context = ctx;
 }
Exemplo n.º 9
0
        public static string GenerateUrl(ControllerContext ctx, Type controllerType, MethodInfo m, HttpMethodAttribute attr, IDictionary<string, object> routeData)
        {
            // Work out the pattern and pattern type
            if (attr.MatchType == Manos.Routing.MatchType.Regex)
            {
                // Regex not supported
                return null;
            }

            var pattern = attr.pattern == null ? m.Name : attr.pattern;

            // Replace all {variables} with value from either routeData or ctx.UriData
            bool AllMatched = true;
            var MatchedVariables = new List<string>();
            var url = rxReplaceVar.Replace(pattern, match=>{

                // Get the name of the variable
                var varName = match.Groups[1].ToString();

                // Remember this variable has been matched
                MatchedVariables.Add(varName);

                // Look it up in the routeData
                if (routeData != null)
                {
                    object varValue;
                    if (routeData.TryGetValue(varName, out varValue))
                    {
                        return HttpUtility.UrlEncode(varValue.ToString());
                    }
                }

                // Look it up in the UriData
                var unsafeValue = ctx.ManosContext.Request.UriData.Get(varName);
                if (unsafeValue!=null)
                {
                    return HttpUtility.UrlEncode(unsafeValue.UnsafeValue);
                }

                AllMatched = false;
                return "";
            });

            // Did we match all route values?
            if (!AllMatched)
                return null;

            var sb = new StringBuilder();

            if (url.StartsWith("/"))
            {
                // Absolute URL
                sb.Append(url);
            }
            else
            {
                // Get the controller path
                var controller_attr = (HttpControllerAttribute)controllerType.GetCustomAttributes(typeof(HttpControllerAttribute), false).FirstOrDefault();
                string controllerPath;
                if (controller_attr==null || controller_attr.pattern==null)
                {
                    controllerPath = "/" + ControllerService.CleanControllerName(controllerType.Name);
                }
                else
                {
                    controllerPath = controller_attr.pattern;
                }

                sb.Append(controllerPath);
                sb.Append("/");
                sb.Append(url);
            }

            // Append all other routeData variables as query string parameters
            if (routeData!=null)
            {
                bool first = true;
                foreach (var i in routeData)
                {
                    if (MatchedVariables.Contains(i.Key))
                        continue;
                    if (i.Value == null)
                        continue;

                    if (first)
                    {
                        sb.Append("?");
                        first = false;
                    }
                    else
                        sb.Append("&");

                    sb.Append(i.Key);
                    sb.Append("=");
                    sb.Append(HttpUtility.UrlEncode(i.Value.ToString()));
                }
            }

            return sb.ToString();
        }
Exemplo n.º 10
0
 public static string GenerateUrl(ControllerContext ctx, Type controllerType, string targetAction, object routeData, HttpMethod httpMethod = HttpMethod.HTTP_GET)
 {
     return GenerateUrl(ctx, controllerType, targetAction, DynamicDictionary.DictionaryFromObject(routeData), httpMethod);
 }
Exemplo n.º 11
0
        public static string GenerateUrl(ControllerContext ctx, Type controllerType, string targetAction, IDictionary<string, object> routeData, HttpMethod httpMethod = HttpMethod.HTTP_GET)
        {
            foreach (var m in (from i in controllerType.GetMethods() where i.Name == targetAction select i))
            {
                foreach (HttpMethodAttribute attr in m.GetCustomAttributes(typeof(HttpMethodAttribute), false))
                {
                    if (attr.methods.Contains(httpMethod))
                    {
                        var url = GenerateUrl(ctx, controllerType, m, attr, routeData);
                        if (url!=null)
                            return url;
                    }
                }
            }

            throw new InvalidOperationException(string.Format("Unable to match route for controller `{0}` action `{1}` method `{2}'", controllerType.FullName, targetAction, httpMethod));
        }
Exemplo n.º 12
0
 protected override void OnWriteFileData(ControllerContext ctx)
 {
     ctx.Response.SendFile(sourceFile);
 }
Exemplo n.º 13
0
 protected abstract void OnWriteFileData(ControllerContext ctx);
Exemplo n.º 14
0
 protected override void OnWriteFileData(ControllerContext ctx)
 {
     data.CopyTo(ctx.Response.Stream);
     ctx.Response.End();
 }
Exemplo n.º 15
0
 public HttpModelValueProvider(ControllerContext ctx)
 {
     m_Context = ctx;
 }
Exemplo n.º 16
0
        public void Process(ControllerContext ctx)
        {
            // Just store the pending context, we'll complete it later
            pendingContext = ctx;

            // Already finished?
            if (PendingOperations.Value == 0)
            {
                Complete();
            }
        }
Exemplo n.º 17
0
 public void Process(ControllerContext ctx)
 {
     ctx.Response.Redirect(url);
 }