Esempio n. 1
0
        internal static IHtmlString MVCGrid(this HtmlHelper helper, string name, IMVCGridDefinition grid, object pageParameters)
        {
            GridEngine ge = new GridEngine();

            string html = ge.GetBasePageHtml(helper, name, grid, pageParameters);

            return MvcHtmlString.Create(html);
        }
Esempio n. 2
0
        private static string RenderPreloadedGridHtml(HtmlHelper helper, IMVCGridDefinition grid, string gridName, object pageParameters, QueryOptions options = null)
        {
            string preload = "";

            if (options == null)
            {
                options = GridOptionParser.ParseOptions(grid, gridName, System.Web.HttpContext.Current.Request);
            }

            // set the page parameters for the preloaded grid
            Dictionary <string, string> pageParamsDict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (pageParameters != null)
            {
                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(pageParameters))
                {
                    object obj2 = descriptor.GetValue(pageParameters);
                    pageParamsDict.Add(descriptor.Name, obj2.ToString());
                }
            }
            if (grid.PageParameterNames.Count > 0)
            {
                foreach (var aqon in grid.PageParameterNames)
                {
                    string val = "";

                    if (pageParamsDict.ContainsKey(aqon))
                    {
                        val = pageParamsDict[aqon];
                    }

                    options.PageParameters[aqon] = val;
                }
            }

            var gridContext = GridContextUtility.Create(HttpContext.Current, gridName, grid, options);

            GridEngine engine = new GridEngine();

            switch (grid.RenderingMode)
            {
            case Models.RenderingMode.RenderingEngine:
                preload = RenderUsingRenderingEngine(engine, gridContext);
                break;

            case Models.RenderingMode.Controller:
                preload = RenderUsingController(engine, gridContext, helper);
                break;

            default:
                throw new InvalidOperationException();
            }
            return(preload);
        }
Esempio n. 3
0
        private static string RenderUsingRenderingEngine(GridEngine engine, Models.GridContext gridContext)
        {
            IMVCGridRenderingEngine renderingEngine = GetRenderingEngine(gridContext);

            using (MemoryStream ms = new MemoryStream())
            {
                using (TextWriter tw = new StreamWriter(ms))
                {
                    engine.Run(renderingEngine, gridContext, tw);
                }

                string result = LocalEncoding.GetString(ms.ToArray());
                return(result);
            }
        }
Esempio n. 4
0
        private static string RenderUsingController(GridEngine engine, Models.GridContext gridContext, HtmlHelper helper)
        {
            var model = engine.GenerateModel(gridContext);

            var controllerContext  = helper.ViewContext.Controller.ControllerContext;
            ViewDataDictionary vdd = new ViewDataDictionary(model);
            TempDataDictionary tdd = new TempDataDictionary();

            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(controllerContext,
                                                                     gridContext.GridDefinition.ViewPath);
                var viewContext = new ViewContext(controllerContext, viewResult.View, vdd, tdd, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
                return(sw.GetStringBuilder().ToString());
            }
        }
        public ActionResult Grid()
        {
            var context = System.Web.HttpContext.Current;

            string gridName = context.Request["Name"];

            var grid = MVCGridDefinitionTable.GetDefinitionInterface(gridName);

            var options = QueryStringParser.ParseOptions(grid, context.Request);

            var gridContext = GridContextUtility.Create(context, gridName, grid, options);

            GridEngine engine = new GridEngine();
            if (!engine.CheckAuthorization(gridContext))
            {
                return new HttpStatusCodeResult(403, "Access denied");
            }

            var renderingModel = engine.GenerateModel(gridContext);

            return PartialView(grid.ViewPath, renderingModel);
        }
Esempio n. 6
0
        private static string RenderUsingRenderingEngine(GridEngine engine, Models.GridContext gridContext)
        {
            IMVCGridRenderingEngine renderingEngine = GetRenderingEngine(gridContext);

            using (MemoryStream ms = new MemoryStream())
            {
                using (TextWriter tw = new StreamWriter(ms))
                {
                    engine.Run(renderingEngine, gridContext, tw);
                }

                string result = LocalEncoding.GetString(ms.ToArray());
                return result;
            }
        }
Esempio n. 7
0
        private static string RenderUsingController(GridEngine engine, Models.GridContext gridContext, HtmlHelper helper)
        {
            var model = engine.GenerateModel(gridContext);

            var controllerContext = helper.ViewContext.Controller.ControllerContext;
            ViewDataDictionary vdd = new ViewDataDictionary(model);
            TempDataDictionary tdd = new TempDataDictionary();
            using (var sw = new StringWriter())
            {
                var viewResult = ViewEngines.Engines.FindPartialView(controllerContext,
                                                                         gridContext.GridDefinition.ViewPath);
                var viewContext = new ViewContext(controllerContext, viewResult.View, vdd, tdd, sw);
                viewResult.View.Render(viewContext, sw);
                viewResult.ViewEngine.ReleaseView(controllerContext, viewResult.View);
                return sw.GetStringBuilder().ToString();
            }
        }
Esempio n. 8
0
        private static string RenderPreloadedGridHtml(HtmlHelper helper, IMVCGridDefinition grid, string gridName, object pageParameters)
        {
            string preload = "";

            var options = QueryStringParser.ParseOptions(grid, System.Web.HttpContext.Current.Request);

            // set the page parameters for the preloaded grid
            Dictionary<string, string> pageParamsDict = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            if (pageParameters != null)
            {
                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(pageParameters))
                {
                    object obj2 = descriptor.GetValue(pageParameters);
                    pageParamsDict.Add(descriptor.Name, obj2.ToString());
                }
            }
            if (grid.PageParameterNames.Count > 0)
            {
                foreach (var aqon in grid.PageParameterNames)
                {
                    string val = "";

                    if (pageParamsDict.ContainsKey(aqon))
                    {
                        val = pageParamsDict[aqon];
                    }

                    options.PageParameters[aqon] = val;
                }
            }

            var gridContext = GridContextUtility.Create(HttpContext.Current, gridName, grid, options);

            GridEngine engine = new GridEngine();

            switch (grid.RenderingMode)
            {
                case Models.RenderingMode.RenderingEngine:
                    preload = RenderUsingRenderingEngine(engine, gridContext);
                    break;
                case Models.RenderingMode.Controller:
                    preload = RenderUsingController(engine, gridContext, helper);
                    break;
                default:
                    throw new InvalidOperationException();
            }
            return preload;
        }
Esempio n. 9
0
        private void HandleTable(HttpContext context)
        {
            string gridName = context.Request["Name"];

            //StringBuilder sbDebug = new StringBuilder();
            //foreach (string key in context.Request.QueryString.AllKeys)
            //{
            //    sbDebug.Append(key);
            //    sbDebug.Append(" = ");
            //    sbDebug.Append(context.Request.QueryString[key]);
            //    sbDebug.Append("<br />");
            //}

            var grid = MVCGridDefinitionTable.GetDefinitionInterface(gridName);

            var options = QueryStringParser.ParseOptions(grid, context.Request);

            var gridContext = GridContextUtility.Create(context, gridName, grid, options);

            GridEngine engine = new GridEngine();
            if (!engine.CheckAuthorization(gridContext))
            {
                //Forbidden
                context.Response.StatusCode = 403;
                context.Response.End();
                return;
            }

            IMVCGridRenderingEngine renderingEngine = GridEngine.GetRenderingEngine(gridContext);

            renderingEngine.PrepareResponse(context.Response);
            engine.Run(renderingEngine, gridContext, context.Response.Output);
        }