Esempio n. 1
0
        private static void FindResources(Control seed, InsertOrderedDictionary <string, string> scripts, InsertOrderedDictionary <string, string> styles, List <string> ns)
        {
            if (ReflectionUtils.IsTypeOf(seed, typeof(BaseControl), false))
            {
                BaseControl ctrl = (BaseControl)seed;

                ComponentLoader.CheckNS(ctrl, ns);
                ComponentLoader.CheckResources(ctrl, scripts, styles);
                ctrl.EnsureChildControlsInternal();
            }


            foreach (Control control in seed.Controls)
            {
                bool isBaseControl = ReflectionUtils.IsTypeOf(control, typeof(BaseControl), false);

                if (isBaseControl && !(control is UserControlLoader))
                {
                    BaseControl ctrl = (BaseControl)control;
                    ComponentLoader.CheckNS(ctrl, ns);
                    ComponentLoader.CheckResources(ctrl, scripts, styles);
                    ctrl.EnsureChildControlsInternal();
                }

                if (ControlUtils.HasControls(control))
                {
                    ComponentLoader.FindResources(control, scripts, styles, ns);
                }
            }
        }
Esempio n. 2
0
        private static void CheckResources(BaseControl control, InsertOrderedDictionary <string, string> scripts, InsertOrderedDictionary <string, string> styles)
        {
            foreach (ClientScriptItem item in control.GetScripts())
            {
                string resourcePath = GlobalConfig.Settings.ScriptMode == ScriptMode.Debug && item.PathEmbeddedDebug.IsNotEmpty() ? item.PathEmbeddedDebug : item.PathEmbedded;

                if (!scripts.ContainsKey(resourcePath))
                {
                    scripts.Add(resourcePath, ExtNetTransformer.GetWebResourceUrl(item.Type, resourcePath));
                }
            }

            foreach (ClientStyleItem item in control.GetStyles())
            {
                if (!styles.ContainsKey(item.PathEmbedded) && item.Theme.Equals(Theme.Default))
                {
                    styles.Add(item.PathEmbedded, ExtNetTransformer.GetWebResourceUrl(item.Type, item.PathEmbedded));
                }
            }
        }
Esempio n. 3
0
        private static string AttachResources(IEnumerable <AbstractComponent> components, string config)
        {
            InsertOrderedDictionary <string, string> scripts = new InsertOrderedDictionary <string, string>();
            InsertOrderedDictionary <string, string> styles  = new InsertOrderedDictionary <string, string>();
            List <string> ns = new List <string>();

            foreach (AbstractComponent seed in components)
            {
                ComponentLoader.FindResources(seed, scripts, styles, ns);
            }

            if (scripts.Count == 0 && styles.Count == 0 && ns.Count == 0)
            {
                return(config);
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("{'x.res':{");


            if (ns.Count > 0)
            {
                sb.Append("ns:");
                sb.Append(JSON.Serialize(ns));
            }

            if (scripts.Count == 0 || styles.Count == 0)
            {
                if (ns.Count > 0)
                {
                    sb.Append(",");
                }

                sb.Append("res:[");

                bool comma = false;
                foreach (KeyValuePair <string, string> item in scripts)
                {
                    if (comma)
                    {
                        sb.Append(",");
                    }

                    comma = true;
                    sb.Append("{url:").Append(JSON.Serialize(item.Value)).Append("}");
                }

                foreach (KeyValuePair <string, string> item in styles)
                {
                    if (comma)
                    {
                        sb.Append(",");
                    }

                    comma = true;
                    sb.Append("{mode:\"css\",url:").Append(JSON.Serialize(item.Value)).Append("}");
                }

                sb.Append("]");
            }

            sb.Append("},config:").Append(JSON.Serialize(config));
            sb.Append("}");
            return(sb.ToString());
        }