public static void LoadGrid(string appName, DataGridView dgvSearch)
        {
            dgvSearch.Enabled = true;
            dgvSearch.Rows.Clear();
            dgvSearch.DefaultCellStyle.BackColor = SystemColors.Window;
            _gridChanged = false;

            string appUserAcct, appAdminAcct, description, contactInfo;


            HybridDictionary props = SSOConfigManager.GetConfigProperties(appName, out description, out contactInfo,
                                                                          out appUserAcct, out appAdminAcct);

            foreach (DictionaryEntry appProp in props)
            {
                //// for level 2
                //if (prefix != null && !appProp.Key.ToString().StartsWith(prefix + ".")) continue;

                //if (string.IsNullOrWhiteSpace(search) ||
                //    appProp.Key.ToString().ToLower().Contains(search.ToLower()) ||
                //    appProp.Value.ToString().ToLower().Contains(search.ToLower()))
                //{
                int             index = dgvSearch.Rows.Add();
                DataGridViewRow dgvr  = dgvSearch.Rows[index];

                dgvr.Cells[0].Value = appProp.Key.ToString();
                dgvr.Cells[1].Value = appProp.Value.ToString();
                dgvr.Cells[2].Value = 0;
                //}
            }
            dgvSearch.Sort(dgvSearch.Columns[0], ListSortDirection.Ascending);
        }
Exemplo n.º 2
0
        private void save(string name)
        {
            SSOPropBag propertiesBag = new SSOPropBag();

            ISSOAdmin a = new ISSOAdmin();

            string appUserAcct, appAdminAcct, description, contactInfo;

            HybridDictionary props = SSOConfigManager.GetConfigProperties(tvApps.SelectedNode.Text, out description, out contactInfo, out appUserAcct, out appAdminAcct);

            foreach (DataGridViewRow row in dgvSearch.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    if (row.Cells[1].Value == null)
                    {
                        MessageBox.Show("The key value cannot be blank!", "Blank key value", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //set values
                    string propName     = row.Cells[0].Value.ToString();
                    object objPropValue = row.Cells[1].Value;

                    propertiesBag.Write(propName, ref objPropValue);

                    if (!props.Contains(propName))
                    {
                        a.CreateFieldInfo(tvApps.SelectedNode.Text, propName, 0);
                    }
                }
            }

            UpdateSSOApplication(name, name);
            //didn't work properly in BTS2013R2
            //a.UpdateApplication(tvApps.SelectedNode.Text, null, null, null, null, SSOFlag.SSO_FLAG_ENABLED, SSOFlag.SSO_FLAG_ENABLED);

            try
            {
                SSOConfigManager.SetConfigProperties(tvApps.SelectedNode.Text, propertiesBag);

                MessageBox.Show("Properties saved successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Occured.  Details: " + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Rename nodes/keys (level 2) from treeview
        /// </summary>
        /// <param name="node">Node already renamed</param>
        /// <param name="oldNode">Old node name</param>
        /// <param name="parentSelectedNode">Parent of node renamed</param>
        public static bool RenameKeyValueFromSSOApp(TreeNode node, string oldNode, string parentSelectedNode)
        {
            ArrayList maskArray = new ArrayList();
            string    appUserAcct = string.Empty, appAdminAcct = string.Empty,
                      contactInfo = string.Empty, description = string.Empty;

            try
            {
                HybridDictionary props = SSOConfigManager.GetConfigProperties(parentSelectedNode, out description,
                                                                              out contactInfo, out appUserAcct, out appAdminAcct);
                HybridDictionary propsTemp = new HybridDictionary();

                //save nodes to rename
                foreach (DictionaryEntry item in props)
                {
                    if (item.Key.ToString().Contains(oldNode))
                    {
                        propsTemp.Add(item.Key.ToString().Replace(oldNode, node.Text.ToString()), item.Value.ToString());
                    }
                    maskArray.Add(0);
                }

                Utils.RemoveKeyValueFromSSOApp(oldNode, parentSelectedNode);

                props = SSOConfigManager.GetConfigProperties(parentSelectedNode, out description,
                                                             out contactInfo, out appUserAcct, out appAdminAcct);

                foreach (DictionaryEntry item in propsTemp)
                {
                    props.Add(item.Key.ToString(), item.Value.ToString());
                }

                SSOConfigManager.DeleteApplication(parentSelectedNode);
                SSOPropBag propertiesBag = new SSOPropBag(props);
                Utils.CreateAndEnableAppInSSO(parentSelectedNode, string.Empty, contactInfo,
                                              appUserAcct, appAdminAcct, propertiesBag, maskArray);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format("Cannot rename key(s) '{0}' to '{1}' \n\n{2}", oldNode, node.Text.ToString(), ex.Message.ToString()),
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
        /// <summary>
        /// Remove nodes/keys (level 2) from treeview
        /// </summary>
        /// <param name="KeyValueToBeRemoved">Node/key to remove</param>
        /// <param name="parentNode">Parent of node/key to remove</param>
        public static bool RemoveKeyValueFromSSOApp(string KeyValueToBeRemoved, string parentNode)
        {
            string appUserAcct = string.Empty, appAdminAcct = string.Empty,
                   contactInfo = string.Empty, description = string.Empty;
            List <String> keysToRemove = new List <string>();
            ArrayList     maskArray    = new ArrayList();

            try
            {
                //Gets the configuration information from the configuration store about parentNode
                HybridDictionary props = SSOConfigManager.GetConfigProperties(parentNode, out description,
                                                                              out contactInfo, out appUserAcct, out appAdminAcct);

                //search in 'props' if exists some key/prefix that contains 'KeyValueToBeRemoved'
                //if exists, store it in a list
                foreach (var item in props.Keys)
                {
                    if (item.ToString().Contains(KeyValueToBeRemoved))
                    {
                        keysToRemove.Add(item.ToString());
                        //in this foreach i cannot remove the key directly from 'props'
                    }
                    maskArray.Add(0);
                }

                //remove keys from 'props':
                foreach (string key in keysToRemove)
                {
                    props.Remove(key);
                    maskArray.Remove(0);
                }

                SSOConfigManager.DeleteApplication(parentNode);
                SSOPropBag propertiesBag = new SSOPropBag(props);
                CreateAndEnableAppInSSO(parentNode, string.Empty, contactInfo, appUserAcct, appAdminAcct, propertiesBag, maskArray);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Cannot delete key(s) '{0}'\n\n{1}", KeyValueToBeRemoved, ex.Message.ToString()),
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
        public static void Search(TreeView tvApps, string searchText, DataGridView dgvSearch)
        {
            tvApps.Nodes.Clear();
            TreeNode rootNode = new TreeNode("Applications");

            tvApps.Nodes.Add(rootNode);

            foreach (var application in SSOConfigManager.GetApplications())
            {
                string           appUserAcct, appAdminAcct, description, contactInfo;
                HybridDictionary props = SSOConfigManager.GetConfigProperties(application, out description, out contactInfo,
                                                                              out appUserAcct, out appAdminAcct);
                // search string in all keys and values
                if (!string.IsNullOrWhiteSpace(searchText) &&
                    //!application.Equals(searchText, StringComparison.InvariantCultureIgnoreCase) &&
                    !ContainsIgnoreCase(application, searchText, StringComparison.OrdinalIgnoreCase) &&
                    !SSOConfigManager.SearchKeys(props, searchText) &&
                    !SSOConfigManager.SearchValues(props, searchText))
                {
                    continue;
                }
                var node = new TreeNode(application)
                {
                    ToolTipText = description
                };

                // add node if found
                rootNode.Nodes.Add(node);
            }

            TreeNodeCollection nodes = rootNode.Nodes;

            if (nodes.Count > 0)
            {
                // Select the root node
                tvApps.SelectedNode = nodes[0];
                tvApps.SelectedNode.Expand();
                LoadGrid(nodes[0].Text, dgvSearch);
                tvApps.Focus();
            }
        }