コード例 #1
0
        public virtual string Render(ControllerContext context, string viewName, ViewDataDictionary viewData, object model, TempDataDictionary tempData, IDMode idMode, string controlId)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(viewName))
            {
                viewName = context.RouteData.GetRequiredString("action");
            }

            //string path = PartialViewResult.FindView(context, viewName);
            string id = controlId ?? "ID_" + Guid.NewGuid().ToString().Replace("-", "");
            string ct = "ID_" + Guid.NewGuid().ToString().Replace("-", "");

            ViewDataDictionary newViewData = null;

            if (model == null)
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary();
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData);
                }
            }
            else
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary(model);
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData)
                    {
                        Model = model
                    };
                }
            }

            ViewEngineResult result = ViewEngines.Engines.FindPartialView(context, viewName);
            IView            view   = result.View;
            string           path   = ((WebFormView)view).ViewPath;

            ViewContext viewContext = new ViewContext(context, view, newViewData, tempData ?? new TempDataDictionary(), context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData    = newViewData,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];

            HttpContext.Current.Items[typeof(ResourceManager)] = null;
            object oldPageRM = null;

            if (context.HttpContext.CurrentHandler is Page)
            {
                oldPageRM = ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)];
                ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)] = null;
            }

            ResourceManager rm = new ResourceManager();

            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles  = ResourceLocationType.None;
            rm.IDMode        = idMode;
            pageHolder.Controls.Add(rm);
            Panel p = new Panel {
                ID = id, IDMode = idMode, Border = false, Header = false
            };

            pageHolder.Controls.Add(p);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);

            uc.ID       = id + "_UC";
            uc.ViewData = newViewData;
            p.ContentControls.Add(uc);

            pageHolder.InitHelpers();

            string wScript = DefaultScriptBuilder.Create(p).Build(RenderMode.RenderTo, ct, null, true, true);
            string script  = string.Format("<div id=\"{0}\"></div><script type=\"text/javascript\">Ext.onReady(function(){{{1}}});</script>", ct, wScript);

            IDisposable disposable = view as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;
            if (context.HttpContext.CurrentHandler is Page)
            {
                ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)] = oldPageRM;
            }

            return(script);
        }
コード例 #2
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                ViewName = context.RouteData.GetRequiredString("action");
            }


            string id = this.ControlId ?? "ID_" + Guid.NewGuid().ToString().Replace("-", "");
            string ct = this.ContainerId ?? "Ext.getBody()";

            ViewDataDictionary dict = new ViewDataDictionary(ViewData);

            ViewEngineResult result = null;

            if (View == null)
            {
                result = this.ViewEngineCollection.FindPartialView(context, this.ViewName);
                //result = this.FindView(context);
                View = result.View;
            }

            string path = ((WebFormView)View).ViewPath;

            ViewContext viewContext = new ViewContext(context, View, ViewData, TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData    = dict,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];

            HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();

            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles  = ResourceLocationType.None;
            rm.IDMode        = this.IDMode;
            pageHolder.Controls.Add(rm);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);

            uc.ID       = id + "_UC";
            uc.ViewData = ViewData;

            XControl controlToRender = null;

            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Panel p;
                if (this.PanelConfig != null)
                {
                    p        = new Panel(this.PanelConfig);
                    p.ID     = id;
                    p.IDMode = this.IDMode;
                }
                else
                {
                    p = new Panel {
                        ID = id, IDMode = this.IDMode, Border = false, Header = false
                    };
                }

                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                XControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <XControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <XControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (controlToRender.IDMode == IDMode.Inherit)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            string script = controlToRender.ToScript(this.RenderMode, ct, true);

            if (X.IsAjaxRequest)
            {
                script = "<Ext.Net.Direct.Response>" + script + "</Ext.Net.Direct.Response>";
            }
            else if (this.WrapByScriptTag)
            {
                script = "<script type=\"text/javascript\">" + script + "</script>";
            }

            IDisposable disposable = View as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            context.HttpContext.Response.Write(script);
        }
コード例 #3
0
        public virtual string Render(ControllerContext context, string viewName, ViewDataDictionary viewData, object model, TempDataDictionary tempData, IDMode idMode, string controlId)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(viewName))
            {
                viewName = context.RouteData.GetRequiredString("action");
            }

            //string path = PartialViewResult.FindView(context, viewName);
            string id = controlId ?? "ID_" + Guid.NewGuid().ToString().Replace("-", "");
            string ct = "ID_" + Guid.NewGuid().ToString().Replace("-", "");

            ViewDataDictionary newViewData = null;

            if (model == null)
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary();
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData);
                }
            }
            else
            {
                if (viewData == null)
                {
                    newViewData = new ViewDataDictionary(model);
                }
                else
                {
                    newViewData = new ViewDataDictionary(viewData) { Model = model };
                }
            }

            ViewEngineResult result = ViewEngines.Engines.FindPartialView(context, viewName);
            IView view = result.View;
            string path = ((WebFormView)view).ViewPath;

            ViewContext viewContext = new ViewContext(context, view, newViewData, tempData ?? new TempDataDictionary(), context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData = newViewData,
                ViewContext = viewContext
            };
			
			var curRM = HttpContext.Current.Items[typeof(ResourceManager)];
			HttpContext.Current.Items[typeof(ResourceManager)] = null;
			object oldPageRM = null;

            if (context.HttpContext.CurrentHandler is Page)
            {
                oldPageRM = ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)];
                ((Page) HttpContext.Current.CurrentHandler).Items[typeof (ResourceManager)] = null;
            }

            ResourceManager rm = new ResourceManager();
            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles = ResourceLocationType.None;
            rm.IDMode = idMode;
            pageHolder.Controls.Add(rm);
            Panel p = new Panel { ID = id, IDMode = idMode, Border = false, Header = false };
            pageHolder.Controls.Add(p);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);
            uc.ID = id + "_UC";
            uc.ViewData = newViewData;
            p.ContentControls.Add(uc);

            pageHolder.InitHelpers();

            string wScript = DefaultScriptBuilder.Create(p).Build(RenderMode.RenderTo, ct, null, true, true);            
            string script = string.Format("<div id=\"{0}\"></div><script type=\"text/javascript\">Ext.onReady(function(){{{1}}});</script>", ct, wScript);

            IDisposable disposable = view as IDisposable;
            if (disposable != null)
            {
                disposable.Dispose();
            }
			
			HttpContext.Current.Items[typeof(ResourceManager)] = curRM;
			if (context.HttpContext.CurrentHandler is Page)
            {
                ((Page)HttpContext.Current.CurrentHandler).Items[typeof(ResourceManager)] = oldPageRM;
            }

            return script;
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var instanceScript = HttpContext.Current.Items[ResourceManager.INSTANCESCRIPT];

            if (instanceScript != null)
            {
                this.afterScript = instanceScript.ToString();
                HttpContext.Current.Items.Remove(ResourceManager.INSTANCESCRIPT);
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                this.ViewName = context.RouteData.GetRequiredString("action");
            }

            string id = this.ControlId ?? BaseControl.GenerateID();
            string ct = this.ContainerId ?? "Ext.getBody()";

            if (this.Model != null)
            {
                this.ViewData.Model = this.Model;
            }

            ViewDataDictionary dict   = new ViewDataDictionary(this.ViewData);
            ViewEngineResult   result = null;

            if (this.View == null)
            {
                result    = this.ViewEngineCollection.FindPartialView(context, this.ViewName);
                this.View = result != null ? result.View : null;
            }

            if (this.View == null)
            {
                throw new Exception("View with name '{0}' is not found".FormatWith(this.ViewName));
            }

            if (this.View is RazorView)
            {
                if (this.SingleControl)
                {
                    throw new Exception("Razor view doesn't support SingleControl option");
                }

                if (this.ControlToRender.IsNotEmpty())
                {
                    throw new Exception("Razor view doesn't support ControlToRender option");
                }

                if (this.Items)
                {
                    throw new Exception("Razor view doesn't support Items option");
                }

                this.RenderRazorView(context, (RazorView)this.View);

                if (result != null)
                {
                    result.ViewEngine.ReleaseView(context, this.View);
                }

                return;
            }

            if (this.Items && this.RenderMode != Ext.Net.RenderMode.AddTo && this.RenderMode != Ext.Net.RenderMode.InsertTo)
            {
                throw new Exception("Items mode can be used with AddTo/InsertTo only");
            }

            if (this.Items && this.SingleControl)
            {
                throw new Exception("Items and SingleControl cannot be used at one time");
            }

            if (this.Items && this.ControlToRender.IsNotEmpty())
            {
                throw new Exception("Items and ControlToRender cannot be used at one time");
            }

            if (this.SingleControl && this.ControlToRender.IsNotEmpty())
            {
                throw new Exception("SingleControl and ControlToRender cannot be used at one time");
            }

            string path = ((WebFormView)this.View).ViewPath;

            ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData    = dict,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];

            HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();

            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles  = ResourceLocationType.None;
            rm.IDMode        = this.IDMode;
            pageHolder.Controls.Add(rm);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);

            uc.ID       = id + "_UC";
            uc.ViewData = ViewData;

            if (uc is IDynamicUserControl)
            {
                ((IDynamicUserControl)uc).BeforeRender();
            }

            BaseControl controlToRender = null;

            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Container p;

                if (this.ContainerConfig != null)
                {
                    p        = new Container(this.ContainerConfig);
                    p.ID     = id;
                    p.IDMode = this.IDMode;
                }
                else
                {
                    p = new Container {
                        ID = id, IDMode = this.IDMode, Border = false
                    };
                }

                if (this.Namespace != null)
                {
                    p.Namespace = this.Namespace;
                }

                if (this.Items || this.Config)
                {
                    p.Layout = "auto";
                    p.AddBeforeClientInitScript("<ext.net.container>");
                    p.AddAfterClientInitScript("</ext.net.container>");
                    p.ID     = "Ext_Net_Temp_Container";
                    p.IDMode = Ext.Net.IDMode.Static;
                }

                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                BaseControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (!controlToRender.HasOwnIDMode)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            StringBuilder sb = new StringBuilder();

            string script;

            if (this.Items || this.Config)
            {
                script = controlToRender.ToScript(Ext.Net.RenderMode.AddTo, "Ext_Net_Partial_Items", true);

                script = ItemsAddToContainer_RE.Replace(script, delegate
                {
                    return("");
                }, 1);

                script = ItemsDestroyCmpContainer_RE.Replace(script, delegate
                {
                    return("");
                }, 1);

                script = TempIDRemove_RE.Replace(script, delegate
                {
                    return("");
                }, 1);

                if (this.Config)
                {
                    Match match = ItemsContainer_RE.Match(script);
                    if (match != null && match.Success)
                    {
                        this.Output = "[" + match.Groups[1].Value + "]";
                    }
                    else
                    {
                        this.Output = "[]";
                    }

                    IDisposable disposable = this.View as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }

                    if (result != null)
                    {
                        result.ViewEngine.ReleaseView(context, this.View);
                    }

                    return;
                }

                script = ItemsContainer_RE.Replace(script, delegate(Match m)
                {
                    string elementGet     = ct.Contains(".") ? ct : "Ext.getCmp({0})".FormatWith(JSON.Serialize(ct));
                    string methodTemplate = string.Concat(".", "add", "([");

                    if (this.RenderMode == RenderMode.InsertTo)
                    {
                        methodTemplate = string.Concat(".", "insert", "(", this.Index, ",[");
                    }

                    string replace = elementGet.ConcatWith(methodTemplate, m.Groups[1].Value, "]);");

                    return(this.ClearContainer ? (elementGet + ".removeAll();" + replace) : replace);
                }, 1);
            }
            else
            {
                if (this.RenderMode == Ext.Net.RenderMode.InsertTo)
                {
                    script = controlToRender.ToScript(mode: this.RenderMode, element: ct, index: this.Index, selfRendering: true, clearContainer: this.ClearContainer);
                }
                else
                {
                    script = controlToRender.ToScript(mode: this.RenderMode, element: ct, selfRendering: true, clearContainer: this.ClearContainer);
                }
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            if (this.RenderMode == Ext.Net.RenderMode.AddTo || this.RenderMode == Ext.Net.RenderMode.InsertTo || this.RenderMode == Ext.Net.RenderMode.Replace)
            {
                string cmpId = this.ContainerId.Contains(".") ? this.ContainerId.RightOfRightmostOf(".") : this.ContainerId;
                sb.AppendFormat("Ext.ComponentManager.onAvailable(\"{0}\",function(){{{1}{2}{3}}});", cmpId, this.beforeScript ?? "", script, this.afterScript ?? "");
            }
            else
            {
                sb.AppendFormat("Ext.onReady(function(){{{0}{1}{2}}});", this.beforeScript ?? "", script, this.afterScript ?? "");
            }

            this.RenderScript(context, sb.ToString());

            if (result != null)
            {
                result.ViewEngine.ReleaseView(context, this.View);
            }
        }
コード例 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                this.ViewName = context.RouteData.GetRequiredString("action");
            }
            
            string id = this.ControlId ?? BaseControl.GenerateID();
            string ct = this.ContainerId ?? "Ext.getBody()";

            ViewDataDictionary dict = new ViewDataDictionary(this.ViewData);
            ViewEngineResult result = null;

            if (this.View == null)
            {
                result = this.ViewEngineCollection.FindPartialView(context, this.ViewName);            
                this.View = result.View;
            }

            if (this.View is RazorView)
            {
                if (this.SingleControl)
                {
                    throw new Exception("Razor view doesn't support SingleControl option");
                }

                if (this.ControlToRender.IsNotEmpty())
                {
                    throw new Exception("Razor view doesn't support ControlToRender option");
                }
                
                this.RenderRazorView(context, (RazorView)this.View);

                if (result != null)
                {
                    result.ViewEngine.ReleaseView(context, this.View);
                }

                return;
            }

            string path = ((WebFormView)this.View).ViewPath;

            ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData = dict,
                ViewContext = viewContext
            };
			
			var curRM = HttpContext.Current.Items[typeof(ResourceManager)];
			HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();
            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles = ResourceLocationType.None;
            rm.IDMode = this.IDMode;
            pageHolder.Controls.Add(rm);
            
            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);
            uc.ID = id+"_UC";
            uc.ViewData = ViewData;

            if (uc is IDynamicUserControl)
            {
                ((IDynamicUserControl)uc).BeforeRender();
            }

            BaseControl controlToRender = null;            
            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Panel p;
                if(this.PanelConfig != null)
                {
                    p = new Panel(this.PanelConfig);
                    p.ID = id;
                    p.IDMode = this.IDMode;
                }
                else
                {
                    p = new Panel { ID = id, IDMode = this.IDMode, Border = false, Header = false };
                }
                
                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                BaseControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl<BaseControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl<BaseControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (!controlToRender.HasOwnIDMode)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            string script = controlToRender.ToScript(this.RenderMode, ct, true);
            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            this.RenderScript(context, script);

            if (result != null)
            {
                result.ViewEngine.ReleaseView(context, this.View);
            }
        }
コード例 #6
0
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                ViewName = context.RouteData.GetRequiredString("action");
            }

            string id = this.ControlId ?? "ID_"+Guid.NewGuid().ToString().Replace("-", "");
            string ct = this.ContainerId ?? "Ext.getBody()";

            ViewDataDictionary dict = new ViewDataDictionary(ViewData);

            ViewEngineResult result = null;

            if (View == null)
            {
                result = this.ViewEngineCollection.FindPartialView(context, this.ViewName);
                //result = this.FindView(context);
                View = result.View;
            }

            string path = ((WebFormView)View).ViewPath;

            ViewContext viewContext = new ViewContext(context, View, ViewData, TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData = dict,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];
            HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();
            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles = ResourceLocationType.None;
            rm.IDMode = this.IDMode;
            pageHolder.Controls.Add(rm);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);
            uc.ID = id+"_UC";
            uc.ViewData = ViewData;

            XControl controlToRender = null;
            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Panel p = new Panel { ID = id, IDMode = this.IDMode, Border = false, Header = false };
                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                XControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl<XControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl<XControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (controlToRender.IDMode == IDMode.Inherit)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            string script = controlToRender.ToScript(this.RenderMode, ct, true);

            if(X.IsAjaxRequest)
            {
                script = "<Ext.Net.Direct.Response>" + script + "</Ext.Net.Direct.Response>";
            }
            else if(this.WrapByScriptTag)
            {
                script = "<script type=\"text/javascript\">" + script + "</script>";
            }

            IDisposable disposable = View as IDisposable;
            if (disposable != null)
            {
                disposable.Dispose();
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            context.HttpContext.Response.Write(script);
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                this.ViewName = context.RouteData.GetRequiredString("action");
            }

            string id = this.ControlId ?? BaseControl.GenerateID();
            string ct = this.ContainerId ?? "Ext.getBody()";

            ViewDataDictionary dict   = new ViewDataDictionary(this.ViewData);
            ViewEngineResult   result = null;

            if (this.View == null)
            {
                result    = this.ViewEngineCollection.FindPartialView(context, this.ViewName);
                this.View = result.View;
            }

            if (this.View is RazorView)
            {
                if (this.SingleControl)
                {
                    throw new Exception("Razor view doesn't support SingleControl option");
                }

                if (this.ControlToRender.IsNotEmpty())
                {
                    throw new Exception("Razor view doesn't support ControlToRender option");
                }

                this.RenderRazorView(context, (RazorView)this.View);

                if (result != null)
                {
                    result.ViewEngine.ReleaseView(context, this.View);
                }

                return;
            }

            string path = ((WebFormView)this.View).ViewPath;

            ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData    = dict,
                ViewContext = viewContext
            };

            var curRM = HttpContext.Current.Items[typeof(ResourceManager)];

            HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();

            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles  = ResourceLocationType.None;
            rm.IDMode        = this.IDMode;
            pageHolder.Controls.Add(rm);

            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);

            uc.ID       = id + "_UC";
            uc.ViewData = ViewData;

            if (uc is IDynamicUserControl)
            {
                ((IDynamicUserControl)uc).BeforeRender();
            }

            BaseControl controlToRender = null;

            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Panel p;
                if (this.PanelConfig != null)
                {
                    p        = new Panel(this.PanelConfig);
                    p.ID     = id;
                    p.IDMode = this.IDMode;
                }
                else
                {
                    p = new Panel {
                        ID = id, IDMode = this.IDMode, Border = false, Header = false
                    };
                }

                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                BaseControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (!controlToRender.HasOwnIDMode)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            string script = controlToRender.ToScript(this.RenderMode, ct, true);

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            this.RenderScript(context, script);

            if (result != null)
            {
                result.ViewEngine.ReleaseView(context, this.View);
            }
        }
コード例 #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var instanceScript = HttpContext.Current.Items[ResourceManager.INSTANCESCRIPT];

            if (instanceScript != null)
            {
                this.afterScript = instanceScript.ToString();
                HttpContext.Current.Items.Remove(ResourceManager.INSTANCESCRIPT);
            }

            if (String.IsNullOrEmpty(this.ViewName))
            {
                this.ViewName = context.RouteData.GetRequiredString("action");
            }
            
            string id = this.ControlId ?? BaseControl.GenerateID();
            string ct = this.ContainerId ?? "Ext.getBody()";

            if (this.Model != null)
            {
                this.ViewData.Model = this.Model;
            }

            ViewDataDictionary dict = new ViewDataDictionary(this.ViewData);
            ViewEngineResult result = null;

            if (this.View == null)
            {
                result = this.ViewEngineCollection.FindPartialView(context, this.ViewName);
                this.View = result != null ? result.View : null;
            }

            if (this.View == null)
            {
                throw new Exception("View with name '{0}' is not found".FormatWith(this.ViewName));
            }

            if (this.View is RazorView)
            {
                if (this.SingleControl)
                {
                    throw new Exception("Razor view doesn't support SingleControl option");
                }

                if (this.ControlToRender.IsNotEmpty())
                {
                    throw new Exception("Razor view doesn't support ControlToRender option");
                }

                if (this.Items)
                {
                    throw new Exception("Razor view doesn't support Items option");
                }
                
                this.RenderRazorView(context, (RazorView)this.View);

                if (result != null)
                {
                    result.ViewEngine.ReleaseView(context, this.View);
                }

                return;
            }

            if (this.Items && this.RenderMode != Ext.Net.RenderMode.AddTo && this.RenderMode != Ext.Net.RenderMode.InsertTo)
            {
                throw new Exception("Items mode can be used with AddTo/InsertTo only");
            }

            if (this.Items && this.SingleControl)
            {
                throw new Exception("Items and SingleControl cannot be used at one time");
            }

            if (this.Items && this.ControlToRender.IsNotEmpty())
            {
                throw new Exception("Items and ControlToRender cannot be used at one time");
            }

            if (this.SingleControl && this.ControlToRender.IsNotEmpty())
            {
                throw new Exception("SingleControl and ControlToRender cannot be used at one time");
            }

            string path = ((WebFormView)this.View).ViewPath;

            ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, context.HttpContext.Response.Output);

            PartialViewPage pageHolder = new PartialViewPage
            {
                ViewData = dict,
                ViewContext = viewContext
            };
			
			var curRM = HttpContext.Current.Items[typeof(ResourceManager)];
			HttpContext.Current.Items[typeof(ResourceManager)] = null;

            ResourceManager rm = new ResourceManager();
            rm.RenderScripts = ResourceLocationType.None;
            rm.RenderStyles = ResourceLocationType.None;
            rm.IDMode = this.IDMode;
            pageHolder.Controls.Add(rm);
            
            ViewUserControl uc = (ViewUserControl)pageHolder.LoadControl(path);
            uc.ID = id + "_UC";
            uc.ViewData = ViewData;

            if (uc is IDynamicUserControl)
            {
                ((IDynamicUserControl)uc).BeforeRender();
            }

            BaseControl controlToRender = null;

            if (this.ControlToRender.IsEmpty() && !this.SingleControl)
            {
                Container p;

                if (this.ContainerConfig != null)
                {
                    p = new Container(this.ContainerConfig);
                    p.ID = id;
                    p.IDMode = this.IDMode;                    
                }
                else
                {
                    p = new Container { ID = id, IDMode = this.IDMode, Border = false };
                }

                if (this.Namespace != null)
                {
                    p.Namespace = this.Namespace;
                }

                if (this.Items || this.Config)
                {
                    p.Layout = "auto";
                    p.AddBeforeClientInitScript("<ext.net.container>");
                    p.AddAfterClientInitScript("</ext.net.container>");
                    p.ID = "Ext_Net_Temp_Container";                    
                    p.IDMode = Ext.Net.IDMode.Static;
                }
                
                pageHolder.Controls.Add(p);
                p.ContentControls.Add(uc);
                controlToRender = p;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                BaseControl c = null;

                if (this.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl<BaseControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl<BaseControl>(pageHolder, this.ControlToRender);
                }

                if (c == null)
                {
                    if (this.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + this.ControlToRender);
                    }
                }

                controlToRender = c;

                if (!controlToRender.HasOwnIDMode)
                {
                    controlToRender.IDMode = this.IDMode;
                }
            }

            pageHolder.InitHelpers();

            StringBuilder sb = new StringBuilder();

            string script;
            if (this.Items || this.Config)
            {
                script = controlToRender.ToScript(Ext.Net.RenderMode.AddTo, "Ext_Net_Partial_Items", true);

                script = ItemsAddToContainer_RE.Replace(script, delegate
                {                    
                    return "";
                }, 1);

                script = ItemsDestroyCmpContainer_RE.Replace(script, delegate
                {
                    return "";
                }, 1);

                script = TempIDRemove_RE.Replace(script, delegate
                {
                    return "";
                }, 1);

                if (this.Config)
                {
                    Match match = ItemsContainer_RE.Match(script);
                    if (match != null && match.Success)
                    {
                        this.Output = "[" + match.Groups[1].Value + "]";
                    }
                    else
                    {
                        this.Output = "[]";
                    }
                    
                    IDisposable disposable = this.View as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }

                    if (result != null)
                    {
                        result.ViewEngine.ReleaseView(context, this.View);
                    }

                    return;
                }
                
                script = ItemsContainer_RE.Replace(script, delegate(Match m)
                {
                    string elementGet = ct.Contains(".") ? ct : "Ext.getCmp({0})".FormatWith(JSON.Serialize(ct));
                    string methodTemplate = string.Concat(".", "add","([");

                    if (this.RenderMode == RenderMode.InsertTo)
                    {
                        methodTemplate = string.Concat(".", "insert", "(", this.Index, ",[");
                    }

                    string replace = elementGet.ConcatWith(methodTemplate, m.Groups[1].Value, "]);");

                    return this.ClearContainer ? (elementGet + ".removeAll();" + replace) : replace;
                }, 1);
            }
            else
            {
                if(this.RenderMode == Ext.Net.RenderMode.InsertTo)
                {
                    script = controlToRender.ToScript(mode:this.RenderMode, element:ct, index:this.Index, selfRendering:true, clearContainer:this.ClearContainer);
                }
                else
                {
                    script = controlToRender.ToScript(mode: this.RenderMode, element: ct, selfRendering: true, clearContainer: this.ClearContainer);
                }
            }

            HttpContext.Current.Items[typeof(ResourceManager)] = curRM;

            if (this.RenderMode == Ext.Net.RenderMode.AddTo || this.RenderMode == Ext.Net.RenderMode.InsertTo || this.RenderMode == Ext.Net.RenderMode.Replace)
            {
                string cmpId = this.ContainerId.Contains(".") ? this.ContainerId.RightOfRightmostOf(".") : this.ContainerId;
                sb.AppendFormat("Ext.ComponentManager.onAvailable(\"{0}\",function(){{{1}{2}{3}}});", cmpId, this.beforeScript ?? "", script, this.afterScript ?? "");
            }
            else
            {
                sb.AppendFormat("Ext.onReady(function(){{{0}{1}{2}}});", this.beforeScript ?? "", script, this.afterScript ?? "");
            }           

            this.RenderScript(context, sb.ToString());

            if (result != null)
            {
                result.ViewEngine.ReleaseView(context, this.View);
            }
        }