private static TagBuilder GetParamsBuilder(Type type, string methodName, string wrapperTagName, Dictionary <string, object> defaults, object htmlAttributes, out int paramCount)
        {
            InputFormBuilder builder = new InputFormBuilder(type);

            builder.AddLabels = true;
            TagBuilder form = builder.MethodForm(wrapperTagName, methodName, defaults, out paramCount)
                              .AttrsIf(htmlAttributes != null, htmlAttributes);

            return(form);
        }
        private bool SendMethodForm(IHttpContext context, string appName)
        {
            bool     result          = false;
            IRequest request         = context.Request;
            string   path            = request.Url.AbsolutePath;
            string   prefix          = MethodFormPrefixFormat._Format(ResponderSignificantName.ToLowerInvariant());
            string   partsICareAbout = path.TruncateFront(prefix.Length);

            string[] segments = partsICareAbout.DelimitSplit("/", "\\");

            if (segments.Length == 2)
            {
                Incubator         providers;
                List <ProxyAlias> aliases;
                GetServiceProxies(appName, out providers, out aliases);
                string className  = segments[0];
                string methodName = segments[1];
                Type   type       = providers[className];
                if (type == null)
                {
                    ProxyAlias alias = aliases.FirstOrDefault(a => a.Alias.Equals(className));
                    if (alias != null)
                    {
                        type = providers[alias.ClassName];
                    }
                }

                if (type != null)
                {
                    InputFormBuilder            builder    = new InputFormBuilder(type);
                    QueryStringParameter[]      parameters = request.Url.Query.DelimitSplit("?", "&").ToQueryStringParameters();
                    Dictionary <string, object> defaults   = new Dictionary <string, object>();
                    foreach (QueryStringParameter param in parameters)
                    {
                        defaults.Add(param.Name, param.Value);
                    }
                    TagBuilder  form        = builder.MethodForm(methodName, defaults);
                    LayoutModel layoutModel = GetLayoutModel(appName);
                    layoutModel.PageContent = form.ToMvcHtml().ToString();
                    ContentResponder.CommonTemplateRenderer.RenderLayout(layoutModel, context.Response.OutputStream);
                    result = true;
                }
            }

            return(result);
        }
Beispiel #3
0
        public override void ExecuteResult(ControllerContext context)
        {
            StringBuilder output = new StringBuilder();

            if (string.IsNullOrEmpty(ClassName))
            {
                Tag message = new Tag("div", new { Class = "error" }).Text("ClassName not specified");
                output = new StringBuilder(message.ToHtmlString());
            }
            else
            {
                Incubator incubator = ServiceProxySystem.Incubator;
                Type      type;
                incubator.Get(ClassName, out type);
                if (type == null)
                {
                    Tag message = new Tag("div", new { Class = "error" }).Text("The specified className ({0}) was not registered in the ServiceProxySystem"._Format(ClassName));
                    output = new StringBuilder(message.ToHtmlString());
                }
                else
                {
                    InputFormBuilder formBuilder = new InputFormBuilder(type);
                    formBuilder.Layout = Layout;
                    Dictionary <string, object> defaults = new Dictionary <string, object>();
                    if (Defaults != null)
                    {
                        defaults = Defaults.PropertiesToDictionary();
                    }

                    TagBuilder tag = formBuilder.MethodForm(MethodName, defaults);
                    output = new StringBuilder(tag.ToMvcHtml().ToString());
                }
            }

            HttpResponseBase response = context.HttpContext.Response;

            response.Write(output.ToString());
        }