Exemple #1
0
        private static void ShareStyles(StringBuilder sb, MVC.MvcResourceManagerConfig config)
        {
            if (HttpContext.Current.Items["Ext.Net.GlobaResources"] != null)
            {
                List <ResourceItem> styles = (List <ResourceItem>)HttpContext.Current.Items["Ext.Net.GlobalResources"];

                foreach (var item in styles)
                {
                    if (item is ClientStyleItem)
                    {
                        var styleItem = (ClientStyleItem)item;

                        switch (config.RenderStyles)
                        {
                        case ResourceLocationType.File:
                            sb.AppendFormat(ResourceManager.StyleIncludeTemplate, config.ResourcePath.ConcatWith(styleItem.Path));
                            break;

                        default:
                        case ResourceLocationType.Embedded:
                            sb.AppendFormat(ResourceManager.StyleIncludeTemplate, ExtNetTransformer.GetWebResourceUrl(styleItem.Type, styleItem.PathEmbedded, config));
                            break;
                        }
                    }
                }
            }
        }
Exemple #2
0
        private static void ShareScripts(StringBuilder sb, MVC.MvcResourceManagerConfig config)
        {
            if (HttpContext.Current.Items[Ext.Net.ResourceManager.GLOBAL_RESOURCES] != null)
            {
                var placeholder = HttpContext.Current.Items["Ext.Net.InitScriptFiles"] != null;
                sb.AppendFormat("<#:item {0}='{1}' index='21'>", placeholder ? "ref" : "selector", placeholder ? "ext.net.initscriptfiles" : "headstart");

                List <ResourceItem> scripts = (List <ResourceItem>)HttpContext.Current.Items[Ext.Net.ResourceManager.GLOBAL_RESOURCES];

                foreach (var item in scripts)
                {
                    if (item is ClientScriptItem)
                    {
                        var scriptItem = (ClientScriptItem)item;

                        if (config.RenderScripts == ResourceLocationType.Embedded)
                        {
                            if (config.ScriptMode == ScriptMode.Release || scriptItem.PathEmbeddedDebug.IsEmpty())
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ExtNetTransformer.GetWebResourceUrl(scriptItem.Type, scriptItem.PathEmbedded, config));
                            }
                            else
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ExtNetTransformer.GetWebResourceUrl(scriptItem.Type, scriptItem.PathEmbeddedDebug, config));
                            }
                        }
                        else if (config.RenderScripts == ResourceLocationType.File)
                        {
                            if (config.ScriptMode == ScriptMode.Release || scriptItem.PathDebug.IsEmpty())
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, config.ResourcePath.ConcatWith(scriptItem.Path));
                            }
                            else
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, config.ResourcePath.ConcatWith(scriptItem.PathDebug));
                            }
                        }
#if ISPRO
                        else if (config.RenderScripts == ResourceLocationType.CDN)
                        {
                            if (config.ScriptMode == ScriptMode.Release || scriptItem.PathDebug.IsEmpty())
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ResourceManager.CDNPath.ConcatWith(scriptItem.Path));
                            }
                            else
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ResourceManager.CDNPath.ConcatWith(scriptItem.PathDebug));
                            }
                        }
#endif
                    }
                }

                sb.Append("</#:item>");
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="resourceName"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static string GetWebResourceUrl(Type type, string resourceName, MVC.MvcResourceManagerConfig config)
        {
            if (resourceName.StartsWith(ResourceManager.ASSEMBLYSLUG) && config.CleanResourceUrl && ResourceHandler.HasHandler())
            {
                string buster = (resourceName.EndsWith(".js") || resourceName.EndsWith(".css")) ? "?v=".ConcatWith(ResourceManager.CacheBuster) : "";

                return(CachedPageInstance.ResolveUrl("~/{0}/ext.axd{1}".FormatWith(resourceName.Replace(ResourceManager.ASSEMBLYSLUG, "").Replace('.', '/').ReplaceLastInstanceOf("/", "-"), buster)));
            }

            return(HttpUtility.HtmlAttributeEncode(CachedPageInstance.ClientScript.GetWebResourceUrl(type, resourceName)));
        }
Exemple #4
0
        private static void ShareScripts(StringBuilder sb, MVC.MvcResourceManagerConfig config)
        {
            if (HttpContext.Current.Items["Ext.Net.GlobaResources"] != null)
            {
                List <ResourceItem> scripts = (List <ResourceItem>)HttpContext.Current.Items["Ext.Net.GlobalResources"];

                foreach (var item in scripts)
                {
                    if (item is ClientScriptItem)
                    {
                        var scriptItem = (ClientScriptItem)item;

                        if (config.RenderScripts == ResourceLocationType.Embedded)
                        {
                            if (config.ScriptMode == ScriptMode.Release || scriptItem.PathEmbeddedDebug.IsEmpty())
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ExtNetTransformer.GetWebResourceUrl(scriptItem.Type, scriptItem.PathEmbedded, config));
                            }
                            else
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ExtNetTransformer.GetWebResourceUrl(scriptItem.Type, scriptItem.PathEmbeddedDebug, config));
                            }
                        }
                        else if (config.RenderScripts == ResourceLocationType.File)
                        {
                            if (config.ScriptMode == ScriptMode.Release || scriptItem.PathDebug.IsEmpty())
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, config.ResourcePath.ConcatWith(scriptItem.Path));
                            }
                            else
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, config.ResourcePath.ConcatWith(scriptItem.PathDebug));
                            }
                        }
                        else if (config.RenderScripts == ResourceLocationType.CDN)
                        {
                            if (config.ScriptMode == ScriptMode.Release || scriptItem.PathDebug.IsEmpty())
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ResourceManager.CDNPath.ConcatWith(scriptItem.Path));
                            }
                            else
                            {
                                sb.AppendFormat(ResourceManager.ScriptIncludeTemplate, ResourceManager.CDNPath.ConcatWith(scriptItem.PathDebug));
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        public MvcResourceManagerBuilder(MvcResourceManagerConfig config)
        {
            MvcResourceManager.MarkAsMVC();
            this.config           = config ?? new MvcResourceManagerConfig();
            this.mgr              = new MvcResourceManager();
            this.mgr.IsSelfRender = true;

            if (HttpContext.Current != null)
            {
                HttpContext.Current.Items[typeof(MvcResourceManager)] = this.mgr;
            }

            this.config.Listeners          = this.mgr.Listeners;
            this.config.CustomListeners    = this.mgr.CustomListeners;
            this.config.DirectEvents       = this.mgr.DirectEvents;
            this.config.CustomDirectEvents = this.mgr.CustomDirectEvents;
        }
Exemple #6
0
        private static void ShareStyles(StringBuilder sb, MVC.MvcResourceManagerConfig config)
        {
            if (HttpContext.Current.Items[Ext.Net.ResourceManager.GLOBAL_RESOURCES] != null)
            {
                var placeholder = HttpContext.Current.Items["Ext.Net.InitStyle"] != null;
                sb.AppendFormat("<#:item {0}='{1}' index='11'>", placeholder ? "ref" : "selector", placeholder ? "ext.net.initstyle" : "headstart");

                List <ResourceItem> styles = (List <ResourceItem>)HttpContext.Current.Items[Ext.Net.ResourceManager.GLOBAL_RESOURCES];

                foreach (var item in styles)
                {
                    if (item is ClientStyleItem)
                    {
                        var styleItem = (ClientStyleItem)item;

                        switch (config.RenderStyles)
                        {
                        case ResourceLocationType.File:
                            sb.AppendFormat(ResourceManager.StyleIncludeTemplate, config.ResourcePath.ConcatWith(styleItem.Path));
                            break;

#if ISPRO
                        case ResourceLocationType.CDN:
                            sb.AppendFormat(ResourceManager.StyleIncludeTemplate, ResourceManager.CDNPath.ConcatWith(styleItem.Path));
                            break;
#endif
                        default:
                        case ResourceLocationType.Embedded:
                            sb.AppendFormat(ResourceManager.StyleIncludeTemplate, ExtNetTransformer.GetWebResourceUrl(styleItem.Type, styleItem.PathEmbedded, config));
                            break;
                        }
                    }
                }

                sb.Append("</#:item>");
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        public MvcResourceManagerBuilder(MvcResourceManagerConfig config)
        {
            MvcResourceManager.MarkAsMVC();
            this.config = config ?? new MvcResourceManagerConfig();
            this.mgr = new MvcResourceManager();
            this.mgr.IsSelfRender = true;

            if(HttpContext.Current != null)
            {
                HttpContext.Current.Items[typeof(MvcResourceManager)] = this.mgr;
            }

            this.config.Listeners = this.mgr.Listeners;
            this.config.CustomListeners = this.mgr.CustomListeners;
            this.config.DirectEvents = this.mgr.DirectEvents;
            this.config.CustomDirectEvents = this.mgr.CustomDirectEvents;
        }
        protected virtual string RegisterRazorResources(string script, List <ResourceItem> resources)
        {
            StringBuilder sb = new StringBuilder();

            List <Icon> icons = ResourceManager.GlobalIcons;

            HttpContext.Current.Items.Remove("Ext.Net.GlobalIcons");
            if (icons.Count > 0)
            {
                string[] arr = new string[icons.Count];
                for (int i = 0; i < icons.Count; i++)
                {
                    arr[i] = icons[i].ToString();
                }

                sb.Append("Ext.net.ResourceMgr.registerIcon(");
                sb.Append(JSON.Serialize(arr));
                sb.Append(");");
            }

            if (resources != null && resources.Count > 0 || ResourceManager.GlobalClientResources.Count > 0)
            {
                MvcResourceManagerConfig config = MVC.MvcResourceManager.SharedConfig;

                sb.Append("Ext.net.ResourceMgr.load([");
                bool   comma = false;
                string url;

                List <ClientResourceItem> gbScripts = ResourceManager.GlobalClientResources;
                HttpContext.Current.Items.Remove(ResourceManager.GLOBAL_CLIENT_RESOURCES);

                if (gbScripts.Count > 0)
                {
                    foreach (ClientResourceItem item in gbScripts)
                    {
                        if (item.Path.IsNotEmpty())
                        {
                            sb.AppendFormat("{{url:{0}{1}}}", JSON.Serialize(item.Path.StartsWith("~") ? ExtNetTransformer.ResolveUrl(item.Path) : item.Path), item.IsCss ? ",mode:\"css\"" : "");
                        }
                        else if (item.PathEmbedded.IsNotEmpty())
                        {
                            sb.AppendFormat("{{url:{0}{1}}{1}}", JSON.Serialize(HttpUtility.HtmlAttributeEncode(ExtNetTransformer.GetWebResourceUrl(item.Type, item.PathEmbedded))), item.IsCss ? ",mode:\"css\"" : "");
                        }
                    }
                }

                if (resources != null)
                {
                    foreach (ResourceItem item in resources)
                    {
                        if (comma)
                        {
                            sb.Append(",");
                        }

                        comma = true;

                        if (item is ClientStyleItem)
                        {
                            ClientStyleItem styleItem = (ClientStyleItem)item;

                            if (styleItem.IgnoreResourceMode)
                            {
                                if (styleItem.PathEmbedded.IsNotEmpty())
                                {
                                    url = ExtNetTransformer.GetWebResourceUrl(styleItem.Type, styleItem.PathEmbedded);
                                }
                                else
                                {
                                    url = styleItem.Path.StartsWith("~") ? ExtNetTransformer.ResolveUrl(styleItem.Path) : styleItem.Path;
                                }
                            }
                            else
                            {
                                url = config.RenderStyles == ResourceLocationType.File ? config.ResourcePath.ConcatWith(styleItem.Path) : ExtNetTransformer.GetWebResourceUrl(styleItem.Type, styleItem.PathEmbedded);
                            }

                            sb.Append("{mode:\"css\",url:").Append(JSON.Serialize(url)).Append("}");
                        }
                        else if (item is ClientScriptItem)
                        {
                            ClientScriptItem scriptItem = (ClientScriptItem)item;

                            if (scriptItem.IgnoreResourceMode)
                            {
                                if (scriptItem.PathEmbedded.IsNotEmpty())
                                {
                                    url = (config.ScriptMode == ScriptMode.Release || scriptItem.PathEmbeddedDebug.IsEmpty()) ? scriptItem.PathEmbedded : scriptItem.PathEmbeddedDebug;
                                }
                                else
                                {
                                    bool isDebug = !(config.ScriptMode == ScriptMode.Release || scriptItem.PathEmbeddedDebug.IsEmpty());
                                    url = (isDebug ? scriptItem.PathDebug : scriptItem.Path).StartsWith("~") ? ExtNetTransformer.ResolveUrl(isDebug ? scriptItem.PathDebug : scriptItem.Path) : (isDebug ? scriptItem.PathDebug : scriptItem.Path);
                                }
                            }
                            else if (config.RenderScripts == ResourceLocationType.File)
                            {
                                if (config.ScriptMode == ScriptMode.Release || scriptItem.PathDebug.IsEmpty())
                                {
                                    url = config.ResourcePath.ConcatWith(scriptItem.Path);
                                }
                                else
                                {
                                    url = config.ResourcePath.ConcatWith(scriptItem.PathDebug);
                                }
                            }
                            else
                            {
                                if (config.ScriptMode == ScriptMode.Release || scriptItem.PathEmbeddedDebug.IsEmpty())
                                {
                                    url = ExtNetTransformer.GetWebResourceUrl(scriptItem.Type, scriptItem.PathEmbedded);
                                }
                                else
                                {
                                    url = ExtNetTransformer.GetWebResourceUrl(scriptItem.Type, scriptItem.PathEmbeddedDebug);
                                }
                            }
                            // CDN is not supported by loading via Ext.net.ResourceMgr.load (another domain)

                            sb.Append("{url:").Append(JSON.Serialize(url)).Append("}");
                        }
                    }
                }

                sb.Append("], function(){");
                sb.Append(script);
                sb.Append("});");
            }
            else
            {
                sb.Append(script);
            }

            return(sb.ToString());
        }
        private void RenderRazorView(ControllerContext context, RazorView razorView)
        {
            using (StringWriter sw = new StringWriter())
            {
                if (this.RenderMode != Ext.Net.RenderMode.RenderTo)
                {
                    BaseControl.SectionsStack.Push(new List <string>());
                }

                ViewContext viewContext = new ViewContext(context, razorView, this.ViewData, this.TempData, sw);

                RequestManager.SuppressAjaxRequestMarker();

                razorView.Render(viewContext, sw);
                string result = sw.GetStringBuilder().ToString();

                RequestManager.ResumeAjaxRequestMarker();

                StringBuilder sb = new StringBuilder();

                if (this.RenderMode != Ext.Net.RenderMode.RenderTo)
                {
                    List <string> idsToRender = BaseControl.SectionsStack.Pop();

                    sb.Append("<Ext.Net.RazorItems>[");
                    foreach (string item in idsToRender)
                    {
                        sb.Append(Transformer.NET.Net.CreateToken(typeof(Transformer.NET.AnchorTag), new Dictionary <string, string> {
                            { "id", item }
                        }));
                        sb.Append(",");
                    }
                    if (idsToRender.Count > 0)
                    {
                        sb.Remove(sb.Length - 1, 1);
                    }
                    sb.Append("]</Ext.Net.RazorItems>");
                }

                sb.Append("<Ext.Net.RazorBeforeScript>");
                sb.Append("<#:anchor id='ext.net.global.script.before' />");
                sb.Append("</Ext.Net.RazorBeforeScript>");

                sb.Append("<Ext.Net.RazorRenderToItems>");
                sb.Append(Transformer.NET.Net.CreateToken(typeof(Transformer.NET.AnchorTag), new Dictionary <string, string> {
                    { "id", "init_script" }
                }));
                sb.Append("</Ext.Net.RazorRenderToItems>");

                sb.Append("<Ext.Net.RazorAfterScript>");
                sb.Append("<#:anchor id='ext.net.global.script.after' />");
                sb.Append("</Ext.Net.RazorAfterScript>");

                MvcResourceManagerConfig config = MVC.MvcResourceManager.SharedConfig;
                config.RenderScripts = ResourceLocationType.None;
                config.RenderStyles  = ResourceLocationType.None;
                MVC.MvcResourceManager.SharedConfig = config;

                List <ResourceItem> resources = null;

                if (HttpContext.Current.Items[Ext.Net.ResourceManager.GLOBAL_RESOURCES] != null)
                {
                    resources = (List <ResourceItem>)HttpContext.Current.Items[Ext.Net.ResourceManager.GLOBAL_RESOURCES];
                }

                sb.Insert(0, result);

                result = Ext.Net.ExtNetTransformer.Transform(sb.ToString());

                string items = "";

                string html = RazorItems_RE.Replace(result, delegate(Match m){
                    items = m.Groups[1].Value;
                    return("");
                });

                if (this.Config)
                {
                    this.Output = !string.IsNullOrWhiteSpace(items) ? items : "[]";

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

                    return;
                }

                string renderToItems = "";

                html = RazorRenderToItems_RE.Replace(html, delegate(Match m)
                {
                    renderToItems = m.Groups[1].Value;
                    return("");
                });

                string beforeScript = "";

                html = RazorBeforeScript_RE.Replace(html, delegate(Match m)
                {
                    beforeScript = m.Groups[1].Value;
                    return("");
                });

                string afterScript = "";

                html = RazorAfterScript_RE.Replace(html, delegate(Match m)
                {
                    afterScript = m.Groups[1].Value;
                    return("");
                });

                sb.Length = 0;

                if (this.ClearContainer && this.RenderMode == Ext.Net.RenderMode.RenderTo)
                {
                    sb.AppendFormat("Ext.net.getEl(\"{0}\").update();", this.ContainerId);
                }

                if (!string.IsNullOrWhiteSpace(html))
                {
                    string[] lines = html.Split(new string[] { "\r\n", "\n", "\r", "\t" }, StringSplitOptions.RemoveEmptyEntries);

                    if (lines.Length > 0)
                    {
                        html = JSON.Serialize(lines).ConcatWith(".join('')");
                        html = html.Replace("</script>", "<\\/script>");
                        sb.AppendFormat("Ext.net.append({0},{1});", this.RenderMode == Ext.Net.RenderMode.RenderTo ? string.Concat("Ext.net.getEl('", this.ContainerId, "')") : "Ext.getBody()", html);
                    }
                }

                if (beforeScript.IsNotEmpty())
                {
                    sb.Append(beforeScript);
                }

                if (!string.IsNullOrWhiteSpace(items))
                {
                    if (this.RenderMode == Ext.Net.RenderMode.AddTo || this.RenderMode == Ext.Net.RenderMode.InsertTo)
                    {
                        sb.AppendFormat("Ext.net.addTo({0}, {1}, {2});", JSON.Serialize(this.ContainerId), items, JSON.Serialize(this.ClearContainer));
                    }
                    else if (this.RenderMode == RenderMode.Replace)
                    {
                        sb.Append("Ext.net._renderTo(arguments[0]," + items + ");");
                    }
                    else
                    {
                        sb.AppendFormat("Ext.net.renderTo({0}, {1});", JSON.Serialize(this.ContainerId), items);
                    }
                }

                if (renderToItems.IsNotEmpty())
                {
                    sb.Append(renderToItems);
                }

                if (afterScript.IsNotEmpty())
                {
                    sb.Append(afterScript);
                }

                if (this.RenderMode == RenderMode.Replace)
                {
                    string elementGet = this.ContainerId.Contains(".") ? this.ContainerId : "Ext.getCmp({0})".FormatWith(JSON.Serialize(this.ContainerId));

                    sb.Insert(0, elementGet + ".replace(function(){");
                    sb.Append("});");
                }

                string script = sb.ToString();

                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;

                    script = string.Format("Ext.ComponentManager.onAvailable(\"{0}\",function(){{{1}{2}{3}}});", cmpId, this.beforeScript ?? "", script, this.afterScript ?? "");
                }
                else
                {
                    script = string.Format("Ext.onReady(function(){{{0}{1}{2}}});", this.beforeScript ?? "", script, this.afterScript ?? "");
                }

                this.RenderScript(context, this.RegisterRazorResources(script, resources));
            }
        }
Exemple #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="config"></param>
 public MvcResourceManagerBuilder(MvcResourceManagerConfig config)
 {
     this.config = config;
 }
Exemple #11
0
 /// <summary>
 ///
 /// </summary>
 public MvcResourceManagerBuilder()
 {
     this.config = new MvcResourceManagerConfig();
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="config"></param>
 public MvcResourceManagerBuilder(MvcResourceManagerConfig config)
 {
     this.config = config;
 }
 /// <summary>
 /// 
 /// </summary>
 public MvcResourceManagerBuilder()
 {
     this.config = new MvcResourceManagerConfig();
 }