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); } } }
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()); }