/// <summary> /// Creates the specified page. /// </summary> /// <param name="page">The page.</param> /// <param name="controlUid">The control uid.</param> /// <param name="instanceUid">The instance uid.</param> /// <returns></returns> public static Control Create(TemplateControl page, string controlUid, string instanceUid) { if (page == null) { throw new ArgumentNullException("page"); } if (controlUid == null) { throw new ArgumentNullException("controlUid"); } Initialize(); Control retVal = null; // Load Control Info DynamicControlInfo info = GetControlInfo(controlUid); if (info == null) { return(null); } //throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid control Uid '{0}'", controlUid), "controlUid"); // Try Load Control if (!string.IsNullOrEmpty(info.Path)) { retVal = page.LoadControl(CreateControlVirtualPath(info.Path)); } else if (!string.IsNullOrEmpty(info.Type)) { retVal = (Control)AssemblyUtil.LoadObject(info.Type); } // Try Load Adapter if (retVal != null && (!string.IsNullOrEmpty(info.AdapterPath) || !string.IsNullOrEmpty(info.AdapterType))) { Control adapter = null; if (!string.IsNullOrEmpty(info.Path)) { adapter = page.LoadControl(CreateControlVirtualPath(info.AdapterPath)); } else if (!string.IsNullOrEmpty(info.Type)) { adapter = (Control)AssemblyUtil.LoadObject(info.AdapterType); } if (adapter != null) { // Add Control to adapter adapter.Controls.Add(retVal); // Return adapter retVal = adapter; } } return(retVal); }
/// <summary> /// Creates the property page. /// </summary> /// <param name="page">The page.</param> /// <param name="controlUid">The control uid.</param> /// <returns></returns> public static Control CreatePropertyPage(TemplateControl page, string controlUid) { if (page == null) { throw new ArgumentNullException("page"); } if (controlUid == null) { throw new ArgumentNullException("controlUid"); } Initialize(); Control retVal = null; // Load Control Info DynamicControlInfo info = GetControlInfo(controlUid); if (info == null) { return(null); } // throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid control Uid '{0}'", controlUid), "controlUid"); // Try Load Control if (!string.IsNullOrEmpty(info.PropertyPagePath)) { retVal = page.LoadControl(CreateControlVirtualPath(info.PropertyPagePath)); } else if (!string.IsNullOrEmpty(info.PropertyPageType)) { retVal = (Control)AssemblyUtil.LoadObject(info.PropertyPageType); } //TODO: Load default PP control //if (retVal == null) // retVal = page.LoadControl(); if (retVal == null) { throw new InvalidOperationException(String.Format("Cant load PropertyPageControl for control: {0}", controlUid)); } return(retVal); }
/// <summary> /// Loads all controls from given directory and its subdirectories. /// </summary> /// <param name="structureVirtualPath">The structure virtual path.</param> /// <returns></returns> public static DynamicControlInfo[] Load(string structureVirtualPath) { List <DynamicControlInfo> list = new List <DynamicControlInfo>(); string structurePath = HostingEnvironment.MapPath(structureVirtualPath); IList <Mediachase.Ibn.Web.UI.WebControls.FileResolverItem> files = Mediachase.Ibn.Web.UI.WebControls.FileResolver.GetFilesSingleSelector(structurePath, ControlsDir + Path.DirectorySeparatorChar + "Configs", "*.xml", new string[] { }); foreach (Mediachase.Ibn.Web.UI.WebControls.FileResolverItem file in files) { string controlDir = Path.GetDirectoryName(file.FilePath); if (!String.IsNullOrEmpty(controlDir)) { string configsDir = Path.DirectorySeparatorChar + ConfigDir; string tempControlDirString = controlDir.EndsWith(Convert.ToString(Path.DirectorySeparatorChar)) ? controlDir.Substring(0, controlDir.Length - 1) : controlDir; if (controlDir.EndsWith(configsDir, true, CultureInfo.InvariantCulture)) { controlDir = controlDir.Substring(0, controlDir.LastIndexOf(configsDir)); } } DynamicControlInfo dci = McXmlSerializer.GetObjectFromFile <DynamicControlInfo>(file.FilePath); if (string.IsNullOrEmpty(dci.Uid)) { dci.Uid = Path.GetFileNameWithoutExtension(file.FilePath); } dci.AdapterPath = MakeVirtualPath(structurePath, structureVirtualPath, controlDir, dci.AdapterPath); dci.IconPath = MakeVirtualPath(structurePath, structureVirtualPath, controlDir, dci.IconPath); dci.Path = dci.Path; //MakeVirtualPath(structurePath, structureVirtualPath, controlDir, dci.Path); dci.PropertyPagePath = dci.PropertyPagePath; //MakeVirtualPath(structurePath, structureVirtualPath, controlDir, dci.PropertyPagePath); list.Add(dci); } return(list.ToArray()); }
/// <summary> /// When overridden in an abstract class, creates the control hierarchy that is used to render the composite data-bound control based on the values from the specified data source. /// </summary> /// <param name="dataSource">An <see cref="T:System.Collections.IEnumerable"></see> that contains the values to bind to the control.</param> /// <param name="dataBinding">true to indicate that the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"></see> is called during data binding; otherwise, false.</param> /// <returns> /// The number of items created by the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"></see>. /// </returns> protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding) { int counter = 0; controlsJson = string.Empty; string _sourceInfo = string.Empty; int cpPartsCount = 3; if (dataBinding) { foreach (string val in dataSource) { if (val == string.Empty || val.Split('^').Length != cpPartsCount) { continue; } string _uid = val.Split('^')[0]; string _collapsed = val.Split('^')[1].ToLowerInvariant(); string _instanceUid = val.Split('^')[2].ToLowerInvariant(); counter++; DynamicControlInfo dci = DynamicControlFactory.GetControlInfo(_uid); //fix when user has deleted controls if (dci == null) { continue; } controlsJson += this.bindControl(dci, _collapsed, counter, _instanceUid, ref _sourceInfo); } if (_sourceInfo.Length > 0) { _sourceInfo = _sourceInfo.Remove(_sourceInfo.Length - 1); } this.ViewState[this.ID + "_sourceInfo"] = _sourceInfo; } else { if (this.ViewState[this.ID + "_sourceInfo"] == null) { throw new ArgumentNullException("SourceInfo"); } _sourceInfo = this.ViewState[this.ID + "_sourceInfo"].ToString(); if (_sourceInfo.Length == 0) { return(0); } foreach (string val in _sourceInfo.Split(':')) { if (val == string.Empty || val.Split('^').Length != cpPartsCount) { continue; } string _uid = val.Split('^')[0]; string _collapsed = val.Split('^')[1].ToLowerInvariant(); string _instanceUid = val.Split('^')[2].ToLowerInvariant(); counter++; DynamicControlInfo dci = DynamicControlFactory.GetControlInfo(_uid); controlsJson += this.bindControl(dci, _collapsed, counter, _instanceUid, ref _sourceInfo); } } if (controlsJson.Length > 0) { controlsJson = controlsJson.Remove(controlsJson.Length - 1); } return(counter); }
/// <summary> /// Binds the control. /// </summary> /// <param name="dci">The dci.</param> /// <param name="collapsed">The collapsed.</param> /// <param name="counter">The counter.</param> /// <param name="sourceInfo">The source info.</param> /// <returns></returns> private string bindControl(DynamicControlInfo dci, string collapsed, int counter, string instanceUid, ref string sourceInfo) { StringBuilder sb = new StringBuilder(); Control ctrl; if (dci != null) { ctrl = DynamicControlFactory.Create(this.Page, dci.Uid); } else { ctrl = this.Page.LoadControl("~/" + dci.Uid.Replace("..\\", string.Empty).Replace("\\", "/")); } // if control has been removed, return if (ctrl == null) { return(string.Empty); } HtmlGenericControl divContainer = new HtmlGenericControl("div"); HtmlGenericControl divHeader = new HtmlGenericControl("div"); #region Image ExpandCollapse ImageButton imgOpen = new ImageButton(); imgOpen.ID = String.Format("imgOpen_{0}", counter); if (!Convert.ToBoolean(collapsed, CultureInfo.InvariantCulture)) { imgOpen.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_up.gif"); imgOpen.Attributes.Add("changeUrl", this.ResolveUrl("~/Apps/Core/Images/btn_down.gif")); } else { imgOpen.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_down.gif"); imgOpen.Attributes.Add("changeUrl", this.ResolveUrl("~/Apps/Core/Images/btn_up.gif")); } imgOpen.Attributes.Add("class", "IbnHeaderWidgetButton"); imgOpen.Style.Add("right", "25px"); imgOpen.OnClientClick = "return false;"; #endregion #region Image Close ImageButton imgClose = new ImageButton(); imgClose.ID = String.Format("imgClose_{0}", counter); imgClose.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_close.gif"); imgClose.Attributes.Add("class", "IbnHeaderWidgetButton"); imgClose.Style.Add("right", "5px"); imgClose.OnClientClick = "return false;"; #endregion #region Image PropertyPage ImageButton imgProperty = new ImageButton(); imgProperty.ID = String.Format("imgProperty_{0}", counter); imgProperty.ImageUrl = this.ResolveUrl("~/Apps/Core/Images/btn_prop.gif"); imgProperty.Attributes.Add("class", "IbnHeaderWidgetButton"); imgProperty.Style.Add("right", "45px"); imgProperty.OnClientClick = "return false;"; #endregion #region Label Title Label lblTitle = new Label(); lblTitle.CssClass = "x-panel-header IbnHeaderWidgetButton"; lblTitle.Style.Add("left", "2px"); lblTitle.Style.Add("top", "1px"); lblTitle.Style.Add("right", "75px"); lblTitle.Style.Add(HtmlTextWriterStyle.BorderWidth, "0px"); #endregion List <WsButton> buttonList = new List <WsButton>(); divHeader.Attributes.Add("class", "IbnWidgetHeader"); divHeader.Attributes.Add("dragObj", "0"); ctrl.ID = String.Format("wrapControl{0}_{1}", dci.Uid.Replace("-", ""), instanceUid); IbnWidgetContainer c = new IbnWidgetContainer(ctrl, Convert.ToBoolean(collapsed, CultureInfo.InvariantCulture)); c.ID = String.Format("id{0}{1}", dci.Uid.Replace("-", ""), counter); //this.Controls.Add(c); //c.DataBind(); divContainer.Controls.Add(divHeader); divContainer.Controls.Add(c); this.Controls.Add(divContainer); c.DataBind(); sourceInfo += String.Format("{0}^{1}^{2}:", dci.Uid, collapsed, instanceUid); // _uid + ":"; System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer(); if (dci != null) { divHeader.Controls.Add(imgClose); divHeader.Controls.Add(imgOpen); divHeader.Controls.Add(lblTitle); buttonList.Add(new WsButton(imgClose.ClientID, "close")); buttonList.Add(new WsButton(imgOpen.ClientID, "expand")); lblTitle.Text = CHelper.GetResFileString(dci.Title); if (!string.IsNullOrEmpty(dci.PropertyPagePath) || !string.IsNullOrEmpty(dci.PropertyPageType)) { divHeader.Controls.Add(imgProperty); buttonList.Add(new WsButton(imgProperty.ClientID, "property")); sb.AppendFormat("{{ title: '{2}', tools: layoutExtender_tools2, contentEl: '{0}', id:'{4}_{1}', collapsed:{3}, buttons:{5} }},", c.ClientID, instanceUid, CHelper.GetResFileString(dci.Title), collapsed, dci.Uid, jss.Serialize(buttonList)); } else { sb.AppendFormat("{{ title: '{2}', tools: layoutExtender_tools, contentEl: '{0}', id:'{4}_{1}', collapsed:{3}, buttons:{5} }},", c.ClientID, instanceUid, CHelper.GetResFileString(dci.Title), collapsed, dci.Uid, jss.Serialize(buttonList)); } } else { sb.AppendFormat("{{ title: '', tools: layoutExtender_tools, contentEl: '{0}', id:'{3}_{1}', collapsed:{2} }},", c.ClientID, instanceUid, collapsed, dci.Uid.Replace("..\\", string.Empty).Replace("\\", "/")); } return(sb.ToString()); }