public string Serialize(object obj, bool ignoreCustomSerialization) { if (this.owner == null) { if (obj is Control) { this.owner = ((Control)obj); if (obj is Observable) { foreach (ConfigItem item in ((Observable)obj).CustomConfig) { this.exclude.Add(item.Name); } } } else if (obj is StateManagedItem) { this.owner = ((StateManagedItem)obj).Owner; } } if (obj is ICustomConfigSerialization && !ignoreCustomSerialization) { return((obj as ICustomConfigSerialization).ToScript(owner)); } this.sb = new StringBuilder(); this.sw = new StringWriter(sb); this.writer = new JsonTextWriter(sw); // PG Change - this makes the JSON to standards this.writer.QuoteName = true; if (this.owner is XControl) { XControl wc = (XControl)this.owner; if (wc != null) { ResourceManager sm = null; sm = wc.SafeResourceManager; if (sm != null && sm.SourceFormatting) { this.writer.Formatting = Formatting.Indented; } } } this.writer.WriteStartObject(); this.Process(obj); this.writer.WriteEndObject(); this.writer.Flush(); return(sw.GetStringBuilder().ToString()); }
void DataBindPoint(object sender, EventArgs e) { XControl owner = this.Owner as XControl; if (this.AutoDataBind || (owner != null && owner.AutoDataBind)) { this.DataBind(); } }
protected BaseScriptBuilder(XControl control) { this.control = control; if (!this.control.HasOwnIDMode || this.control.IDMode == IDMode.Inherit) { this.control.IDMode = IDMode.Client; } }
public void EnsureDataBind() { XControl owner = this.Owner as XControl; if (!this.dataBindRegistered && (this.AutoDataBind || (owner != null && owner.AutoDataBind))) { this.dataBindRegistered = true; this.DataBind(); } }
protected virtual void CheckIcon(XControl control, List <Icon> icons) { if (control is IIcon) { List <Icon> cIcons = ((IIcon)control).Icons; foreach (Icon icon in cIcons) { if (!icons.Contains(icon) && icon != Icon.None) { icons.Add(icon); } } } }
public string GetScript(XControl c, PropertyInfo property) { StringBuilder sb = new StringBuilder(); if (!c.CallbackValues.ContainsKey(property.Name)) { return(null); } object value = c.CallbackValues[property.Name]; if (this.Script.IsNotEmpty()) { sb.AppendFormat(this.Script, c.ClientID, JSON.Serialize(value)); } else if (this.MethodName.IsNotEmpty()) { MethodInfo method = c.GetType().GetMethod(this.MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { property.PropertyType }, null); if (method != null) { method.Invoke(c, new object[] { value }); } } else //simple script generating { switch (this.GenerateMode) { case AutoGeneratingScript.Simple: sb.AppendFormat(DirectEventUpdateAttribute.AutoGenerateFormat, c.ClientID, JSON.Serialize(value), property.Name.ToLowerCamelCase()); break; case AutoGeneratingScript.WithSet: sb.AppendFormat("{0}.set{2}({1});", c.ClientID, JSON.Serialize(value), property.Name); break; default: throw new ArgumentOutOfRangeException(); } } return(sb.ToString()); }
protected ContentScriptBuilder(XControl control) : base(control) { items = new List<object>(0); if (control is IItems) { items = ((IItems) control).ItemsList; if (items.Count == 1 && items[0] is Layout) { layoutItems = ((Layout) items[0]).Items; } else { layoutItems = items; } } if (control is IContent) { contentContainer = ((IContent) control).ContentContainer; } }
protected ContentScriptBuilder(XControl control) : base(control) { items = new List <object>(0); if (control is IItems) { items = ((IItems)control).ItemsList; if (items.Count == 1 && items[0] is Layout) { layoutItems = ((Layout)items[0]).Items; } else { layoutItems = items; } } if (control is IContent) { contentContainer = ((IContent)control).ContentContainer; } }
protected virtual void CheckResources(XControl control) { if (HttpContext.Current.CurrentHandler is Page && !(HttpContext.Current.CurrentHandler is ISelfRenderingPage) && !this.ForceResources) { return; } foreach (ClientScriptItem item in control.GetScripts()) { if (!scriptsResources.ContainsKey(item.PathEmbedded)) { scriptsResources.Add(item.PathEmbedded, GetWebResourceUrl(item.Type, item.PathEmbedded)); } } foreach (ClientStyleItem item in control.GetStyles()) { if (!stylesResources.ContainsKey(item.PathEmbedded) && item.Theme.Equals(Theme.Default)) { stylesResources.Add(item.PathEmbedded, GetWebResourceUrl(item.Type, item.PathEmbedded)); } } }
/// <summary> /// /// </summary> /// <param name="userControlPath"></param> /// <param name="controlIdToRender"></param> /// <param name="mode"></param> /// <param name="element"></param> /// <param name="index"></param> /// <returns></returns> public virtual string Build(string userControlPath, string controlIdToRender, RenderMode mode, string element, int?index) { string id = "ID_" + Guid.NewGuid().ToString().Replace("-", ""); UserControl uc = UserControlRenderer.LoadControl(userControlPath, id); Page pageHolder = uc.Page; XControl controlToRender = null; if (controlIdToRender.IsEmpty()) { Container ct = new Container { ID = id, IDMode = IDMode.Explicit }; pageHolder.Controls.Add(ct); ct.ContentControls.Add(uc); controlToRender = ct; } else { pageHolder.Controls.Add(uc); XControl c = Ext.Net.Utilities.ControlUtils.FindControl <XControl>(pageHolder, controlIdToRender); if (c == null) { throw new Exception("Cannot find the control with ID=" + controlIdToRender); } controlToRender = c; if (controlToRender.IDMode == IDMode.Inherit) { controlToRender.IDMode = IDMode.Explicit; } } return(index.HasValue ? controlToRender.ToScript(mode, element, index.Value, true) : controlToRender.ToScript(mode, element, true)); }
public Menu GetParentMenu(XControl control) { return((Menu)ReflectionUtils.GetTypeOfParent(this, typeof(Menu))); }
internal ListItem(XControl parent) { this.parent = parent; }
public void RegisterScript(XControl c, PropertyInfo property) { c.AddScript(this.GetScript(c, property)); }
protected override void CheckResources(XControl control) { }
public Menu GetParentMenu(XControl control) { return (Menu)ReflectionUtils.GetTypeOfParent(this, typeof(Menu)); }
protected DefaultScriptBuilder(XControl control) : base(control) { }
public static DefaultScriptBuilder Create(XControl control) { return(new DefaultScriptBuilder(control)); }
/// <summary> /// /// </summary> public virtual Spotlight.Builder Show(XControl control) { this.ToComponent().Show(control); return(this); }
/// <summary> /// /// </summary> public SimpleStore(XControl control, ListItemCollection <T> items) { this.control = control; this.items = items; }
public ConfigScriptBuilder(XControl control) : base(control) { }
public static DefaultScriptBuilder Create(XControl control) { return new DefaultScriptBuilder(control); }
protected override void CheckIcon(XControl control, List<Icon> icons) { }
protected List <XControl> FindControls(Control seed, bool searchOnly, StringBuilder sb, List <Icon> icons) { if (seed == null) { return(null); } ResourceManager manager = ResourceManager.GetInstance(HttpContext.Current); if (icons == null) { icons = new List <Icon>(); } if (sb != null && !searchOnly && manager != null) { try { List <UserControl> userControls = ControlUtils.FindControls <UserControl>(this.Control); foreach (UserControl userControl in userControls) { manager.AddDirectMethodControl(userControl, true); } string proxies = manager.BuildDirectMethodProxies(true); foreach (UserControl userControl in userControls) { manager.RemoveDirectMethodControl(userControl, true); } if (!string.IsNullOrEmpty(proxies)) { sb.Append(proxies); } } catch (Exception e) { } } if (ReflectionUtils.IsTypeOf(seed, typeof(XControl), false)) { XControl ctrl = (XControl)seed; if (!searchOnly) { this.CheckIcon(ctrl, icons); this.CheckResources(ctrl); } ctrl.IsDynamic = true; ctrl.EnsureChildControlsInternal(); if (!searchOnly) { ctrl.CallOnPreRender(); ctrl.RegisterStyles(manager); ctrl.RegisterScripts(manager); } } List <XControl> foundControls = new List <XControl>(); foreach (Control control in seed.Controls) { if (this.ExcludeControl(seed, control)) { continue; } if (ReflectionUtils.IsTypeOf(control, typeof(XControl), false)) { XControl ctrl = (XControl)control; if (!searchOnly) { this.CheckIcon(ctrl, icons); this.CheckResources(ctrl); } foundControls.Add(ctrl); ctrl.IsDynamic = true; ctrl.EnsureChildControlsInternal(); if (!searchOnly) { ctrl.CallOnPreRender(); ctrl.RegisterStyles(manager); ctrl.RegisterScripts(manager); } } if (ControlUtils.HasControls(control)) { foundControls.AddRange(this.FindControls(control, searchOnly, null, icons)); } } if (sb != null && !searchOnly && 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(");"); sb.Append(script); } return(foundControls); }
public string GetScript(XControl c, PropertyInfo property) { StringBuilder sb = new StringBuilder(); if (!c.CallbackValues.ContainsKey(property.Name)) { return null; } object value = c.CallbackValues[property.Name]; if (this.Script.IsNotEmpty()) { sb.AppendFormat(this.Script, c.ClientID, JSON.Serialize(value)); } else if (this.MethodName.IsNotEmpty()) { MethodInfo method = c.GetType().GetMethod(this.MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { property.PropertyType }, null); if (method != null) { method.Invoke(c, new object[] { value }); } } else //simple script generating { switch (this.GenerateMode) { case AutoGeneratingScript.Simple: sb.AppendFormat(DirectEventUpdateAttribute.AutoGenerateFormat, c.ClientID, JSON.Serialize(value), property.Name.ToLowerCamelCase()); break; case AutoGeneratingScript.WithSet: sb.AppendFormat("{0}.set{2}({1});", c.ClientID, JSON.Serialize(value), property.Name); break; default: throw new ArgumentOutOfRangeException(); } } return sb.ToString(); }
protected virtual void CheckIcon(XControl control, List<Icon> icons) { if (control is IIcon) { List<Icon> cIcons = ((IIcon)control).Icons; foreach (Icon icon in cIcons) { if (!icons.Contains(icon) && icon != Icon.None) { icons.Add(icon); } } } }
public static ContentScriptBuilder Create(XControl control) { return new ContentScriptBuilder(control); }
public virtual void Show(XControl control) { this.Call("show", new JRawValue(control.ClientID)); }
public ViewStateProxy(XControl control, StateBag viewState) { this.control = control; this.ViewState = viewState; }
protected override void CheckIcon(XControl control, List <Icon> icons) { }
public static ConfigScriptBuilder Create(XControl control) { return(new ConfigScriptBuilder(control)); }