protected void SaveParamsButton_Click(object sender, EventArgs e) { ConLibControl control = SearchSelectedControl(HiddenControlName.Value); if (control != null) { foreach (GridViewRow row in ParamsGrid.Rows) { string paramName = string.Empty; string customValue = string.Empty; Label nameLabel = row.FindControl("Name") as Label; if (nameLabel != null) { paramName = nameLabel.Text.Trim(); } TextBox valueTextBox = row.FindControl("CustomValue") as TextBox; if (valueTextBox != null) { customValue = valueTextBox.Text.Trim(); } if (!string.IsNullOrEmpty(paramName)) { ConLibControlParam param = SearchParamByName(control.Params, paramName); param.CustomValue = customValue; } } UpdateHiddenControlsViewState(); } }
/// <summary> /// Generates the register control tag and returns a unique tag name /// </summary> /// <param name="control">control to register</param> /// <param name="registeredControls">List of existing registered controls</param> /// <returns>Unique tagname for this control with which it is registered</returns> private static string RegisterControl(ConLibControl control, List <RegisteredControl> registeredControls) { // check if its already registered, then return existing tagname foreach (RegisteredControl registeredControl in registeredControls) { if (registeredControl.Control.FilePath == control.FilePath) { return(registeredControl.TagName); } } // otherwise generate tagname and look if tagname is already registered string tagName = control.Name; if (tagName.Contains("/")) { tagName = tagName.Substring(tagName.LastIndexOf("/") + 1); } int postfix = 0; bool tagnameIsUnique = false; List <string> tagNames = new List <string>(); string testTagname = tagName; foreach (RegisteredControl registeredControl in registeredControls) { tagNames.Add(registeredControl.TagName); } while (!tagnameIsUnique) { tagnameIsUnique = true; tagnameIsUnique = !tagNames.Contains(testTagname); // if registered append a suffix number and look again until we find a unique name postfix++; if (!tagnameIsUnique) { testTagname = tagName + postfix.ToString(); } } tagName = testTagname; // register the control string registrationTag = string.Format(REGISTER_CONTROL_PATTERN, "~/ConLib/" + control.Name + ".ascx", tagName); registeredControls.Add(new RegisteredControl(control, tagName, registrationTag)); // retrun the tagname return(tagName); }
protected void SelectedControls_DataBound(object sender, EventArgs e) { if (_ControlSelectionPopupVisibile) { // ADD CONTROL DESCRIPTIONS AS TOOLTIPS FOR ITEMS foreach (ListItem item in AvailableControls.Items) { ConLibControl control = SearchAvailableControl(item.Value, false); if (control != null) { item.Attributes["title"] = control.Summary; } } } }
protected void SelectControl_SelectedIndexChanged(object sender, EventArgs e) { string controlName = SelectControl.SelectedValue; if (!string.IsNullOrEmpty(controlName)) { ConLibControl control = ConLibControls.TryGetValue(controlName); if (control != null) { phControlDetails.Visible = true; Usage.Text = control.Usage; Summary.Text = control.Summary; if (control.Params.Count > 0) { ParamList.Visible = true; ParamList.DataSource = control.Params; ParamList.DataBind(); } } } }
/// <summary> /// Register the ConLib control and generate the Tag output for specified section /// </summary> /// <param name="control">The ConLib control</param> /// <param name="pageSection">The page section</param> /// <param name="registeredControls">Already registered controls</param> /// <returns>Generated tag output as string</returns> private static string GenerateControlTag(ConLibControl control, PageSection pageSection, List <RegisteredControl> registeredControls) { string tagName = RegisterControl(control, registeredControls); string controlId = tagName; // if there are multiple instances of same control, generate the control id using number if (control.InstanceId.Contains("$")) { controlId = tagName + "_" + control.InstanceId.Split('$')[1]; } switch (pageSection) { case PageSection.Header: controlId += "_H"; break; case PageSection.LeftSideBar: controlId += "_Left"; break; case PageSection.RightSidebar: controlId += "_Right"; break; case PageSection.Footer: controlId += "_F"; break; } // CHECK IF ANY PARAMETERS SPECIFIED string parameterString = string.Empty; foreach (ConLibControlParam param in control.Params) { if (!string.IsNullOrEmpty(param.CustomValue)) { parameterString += string.Format(" {0}=\"{1}\"", param.Name, param.CustomValue); } } return(string.Format(CONTROL_TAG_PATTERN, tagName, controlId, parameterString)); }
/// <summary> /// Create a copy of some existing control instance /// </summary> /// <param name="existingControl"></param> /// <param name="instanceId">new instance id for newly copied control</param> /// <param name="copyParamValues">Indicate wheter to copy the parameter custom values</param> /// <returns></returns> protected ConLibControl CopyControl(ConLibControl existingControl, string instanceId, bool copyParamValues = false) { ConLibControl copy = new ConLibControl(existingControl.Name, existingControl.FilePath, existingControl.ClassType); copy.InstanceId = instanceId; copy.Summary = existingControl.Summary; copy.DisplayName = existingControl.DisplayName; // copy params and custom values copy.Params = new Collection <ConLibControlParam>(); foreach (ConLibControlParam param in existingControl.Params) { ConLibControlParam copyParam = new ConLibControlParam(param.Name, param.DefaultValue, param.Summary); if (copyParamValues) { copyParam.CustomValue = param.CustomValue; } copy.Params.Add(copyParam); } return(copy); }
private void UpdateInstances(ConLibControl control) { // check if there are duplicate instatnces of this control then fix the numbering List <ConLibControl> instances = new List <ConLibControl>(); foreach (ConLibControl selectedControl in SelectedControls) { if (selectedControl.Name == control.Name) { instances.Add(selectedControl); } } if (instances.Count > 0) { instances[0].InstanceId = control.Name; } for (int i = 1; i < instances.Count; i++) { ConLibControl instance = instances[i]; instance.InstanceId = control.Name + "$" + i; } }
public RegisteredControl(ConLibControl control, string tagName, string registrationTag) { this.Control = control; this.TagName = tagName; this.RegisterationTag = registrationTag; }
protected List <ConLibControl> ParseExistingLayout(string layoutContents, string placeHolderName) { List <ConLibControl> controls = new List <ConLibControl>(); Match placeHolderMatch = Regex.Match(layoutContents, "<asp:ContentPlaceHolder ID=\"" + placeHolderName + "\" runat=\"server\">(.*?)</asp:ContentPlaceHolder>", RegexOptions.Singleline); if (placeHolderMatch.Success) { Dictionary <string, string> tagNameToControlPathDic = new Dictionary <string, string>(); List <string> controlNames = new List <string>(); // parse registered controls and prepare tagname to control path dictionary Match registerMatch = Regex.Match(layoutContents, "<%@ Register src=\"(.*?)\" tagname=\"(.*?)\" tagprefix=\"uc\" %>", RegexOptions.Singleline); while (registerMatch.Success) { tagNameToControlPathDic.Add(registerMatch.Groups[2].Value, registerMatch.Groups[1].Value); registerMatch = registerMatch.NextMatch(); } Match controlsMatch = Regex.Match(placeHolderMatch.Groups[1].Value, "<uc:(.*?) ID=\"(.*?)\"(.*?)runat=\"server\"(.*?)/>"); while (controlsMatch.Success) { // TAG NAME SHOULD BE USED TO FIND THE CONTROL PATH string tagName = controlsMatch.Groups[1].Value; if (!tagNameToControlPathDic.Keys.Contains(tagName)) { controlsMatch = controlsMatch.NextMatch(); continue; // skip non-registered controls to avoid errors } // determine control path and use it to identify control string controlPath = tagNameToControlPathDic[tagName]; string controlName = controlPath.Substring(9); controlName = controlName.Substring(0, controlName.Length - 5); controlName = controlName.Replace("\\", "/"); string instanceName = controlName; if (controlNames.Contains(controlName)) { // count instanses int count = 0; foreach (string name in controlNames) { if (name == controlName) { count++; } } instanceName = controlName + "$" + count; } ConLibControl control = SearchAvailableControl(instanceName); if (control != null) { string paramsPart = controlsMatch.Groups[4].Value.Trim(); if (!string.IsNullOrEmpty(paramsPart)) { Match paramsMatch = Regex.Match(paramsPart, @"(\S+)=[""']?((?:.(?![""']?\s+(?:\S+)=|[>""']))+.)[""']?"); while (paramsMatch.Success) { string paramName = paramsMatch.Groups[1].Value; string paramValue = paramsMatch.Groups[2].Value; if (!string.IsNullOrEmpty(paramValue)) { if (paramValue.StartsWith("\"")) { paramValue = paramValue.Substring(1); } ConLibControlParam paramObject = SearchParamByName(control.Params, paramName); if (paramObject != null) { paramObject.CustomValue = paramValue; } } paramsMatch = paramsMatch.NextMatch(); } } controlNames.Add(controlName); controls.Add(control); } controlsMatch = controlsMatch.NextMatch(); } } return(controls); }
protected bool IsEditIconVisible(object name) { ConLibControl control = SearchSelectedControl(name as string); return(control.Params.Count > 0); }
protected void SelectedControls_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { if (e.CommandName.StartsWith("Do_")) { string controlInstanceId = e.CommandArgument.ToString(); int index = controlInstanceId.IndexOf("("); if (index > 0) { controlInstanceId = controlInstanceId.Substring(0, index); } int numIndex = controlInstanceId.IndexOf("$"); string controlName = controlInstanceId; if (numIndex > 0) { controlName = controlInstanceId.Substring(0, numIndex); } ConLibControl control = SearchSelectedControl(controlInstanceId); if (control != null) { switch (e.CommandName) { case "Do_Edit": HiddenControlName.Value = controlInstanceId; ParamSelectionCaption.Text = controlInstanceId; ParamsGrid.DataSource = control.Params; ParamsGrid.DataBind(); ParamsPopup.Show(); _ParamSelectionPopupVisible = true; break; case "Do_Delete": SelectedControls.Remove(control); UpdateInstances(control); UpdateHiddenControlsViewState(); break; case "Do_Up": int controlIndex = SelectedControls.IndexOf(control); if (controlIndex > 0) { SelectedControls.RemoveAt(controlIndex); SelectedControls.Insert(controlIndex - 1, control); UpdateInstances(control); UpdateHiddenControlsViewState(); } break; case "Do_Down": controlIndex = SelectedControls.IndexOf(control); if (controlIndex < SelectedControls.Count - 1) { SelectedControls.RemoveAt(controlIndex); SelectedControls.Insert(controlIndex + 1, control); UpdateInstances(control); UpdateHiddenControlsViewState(); } break; case "Do_Copy": // IDENTIFY THE CONTROL TO BE COPIED string newName = controlName; int count = 0; // check for existing copies of this control foreach (ConLibControl selectedControl in SelectedControls) { if (selectedControl.Name.StartsWith(controlName)) { count++; } } // number this copy if (count > 0) { newName = controlName + "$" + count; } else { newName = controlName + "$" + 1; } // create a duplicate control instance with new name ConLibControl copy = CopyControl(control, newName, true); SelectedControls.Add(copy); UpdateHiddenControlsViewState(); break; } } } }