Пример #1
0
    protected void gridSSO_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName.Equals("Insert"))
            {
                TextBox txtKeyName = gridSSO.FooterRow.FindControl("txtNewKeyName") as TextBox;
                TextBox txtKeyValue = gridSSO.FooterRow.FindControl("txtNewKeyValue") as TextBox;

                //Its found in the first cell of the first row.
                string applicationName = gridSSO.Rows[0].Cells[0].Text;

                if ((txtKeyName != null && txtKeyName.Text != string.Empty) && (txtKeyValue != null && txtKeyValue.Text != string.Empty))
                {
                    if (applicationName != null && applicationName.Length > 0)
                    {
                        SSOPropBag propBag = new SSOPropBag();
                        int rowCount = gridSSO.Rows.Count;

                        string keyName = txtKeyName.Text;
                        object keyValue = txtKeyValue.Text;

                        propBag.Write(keyName, ref keyValue);

                        string[] propNames = new string[rowCount + 1];
                        object[] propValues = new object[rowCount + 1];

                        Label gridKeyLabel = null;
                        Label gridValueLabel = null;

                        int loopCount = 0;

                        for (loopCount = 0; loopCount < rowCount; loopCount++)
                        {
                            gridKeyLabel = gridSSO.Rows[loopCount].FindControl("lblKeyName") as Label;
                            gridValueLabel = gridSSO.Rows[loopCount].FindControl("lblKeyValue") as Label;

                            propNames[loopCount] = gridKeyLabel.Text;
                            propValues[loopCount] = gridValueLabel.Text;

                            propBag.Write(propNames[loopCount], ref propValues[loopCount]);
                        }

                       // Finally update every thing.
                       SSOConfigManager.DeleteApplication(applicationName);
                       SSOConfigManager.CreateConfigStoreApplication(applicationName, "ControlCenter", "BizTalk Application Users", "BizTalk Server Administrators", propBag, null);

                    }
                }
            }
        }
        catch (Exception exception)
        {
            DisplayError("SSO Insert: " + exception.Message);
        }
    }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        public static string LoadSSOConfigXml(XmlDocument configDoc)
        {
            string appName = configDoc.SelectSingleNode("//application/@name").InnerText;
            string description = configDoc.SelectSingleNode("//description").InnerText;
            string appUserAcct = configDoc.SelectSingleNode("//appUserAccount").InnerText;
            string appAdminAcct = configDoc.SelectSingleNode("//appAdminAccount").InnerText;

            //grab fields
            XmlNodeList fields = configDoc.SelectNodes("//field");

            SSOPropBag propertiesBag = new SSOPropBag();
            ArrayList maskArray = new ArrayList();
            string label = string.Empty;
            string masked = string.Empty;
            string fieldValue = string.Empty;

            foreach (XmlNode field in fields)
            {
                label = field.Attributes["label"].InnerText;
                masked = field.Attributes["masked"].InnerText;

                if (label != null && label.Length > 0)
                {
                    fieldValue = field.InnerText;

                    if (fieldValue == null || fieldValue == string.Empty)
                    {
                        fieldValue = "none";
                    }

                    //set values
                    object objPropValue = fieldValue;
                    propertiesBag.Write(label, ref objPropValue);

                    //store mask
                    if (masked == "yes")
                    {
                        maskArray.Add(SSOFlag.SSO_FLAG_FIELD_INFO_MASK);
                    }
                    else
                    {
                        maskArray.Add(0);
                    }
                }
            }

            // First delete the application and then create a new one.
            try
            {
                SSOConfigManager.DeleteApplication(appName);
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.Write(exception.Message, "BCC.Core.SSOConfigHelper");
            }
            //create and enable application
            SSOConfigManager.CreateConfigStoreApplication(appName, description, appUserAcct, appAdminAcct, propertiesBag, maskArray);

            //set default configuration field values
            SSOConfigManager.SetConfigProperties(appName, propertiesBag);

            return appName;
        }