Пример #1
0
        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();
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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);
        }