Пример #1
0
        private static int lastAppNumberAdded(string appName)
        {
            List <string> al = SSOConfigManager.GetApplications();

            int lastAppNumber = -1;

            foreach (string s in al)
            {
                if (s.Equals(appName))
                {
                    lastAppNumber = 0;
                }
                if (s.Contains(appName + "("))
                {
                    string regex = Regex.Match(s, @"\([0-9]+\)(?!.*(\([0-9]+\)))").Value;
                    if (regex == "")
                    {
                        continue;
                    }


                    int splitNumber = Int32.Parse(regex.Split('(')[1].Split(')')[0]);
                    if (splitNumber > lastAppNumber)
                    {
                        lastAppNumber = splitNumber;
                    }
                }
            }

            return(lastAppNumber);
        }
        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);
        }
 /// <summary>
 /// Create and Enable application in SSO Store
 /// </summary>
 /// <param name="appName">Application to create/enable</param>
 /// <param name="description"></param>
 /// <param name="ContactInfo"></param>
 /// <param name="AppUserAcct"></param>
 /// <param name="AppAdminAcct"></param>
 /// <param name="propertiesBag"></param>
 /// <param name="maskArray"></param>
 public static void CreateAndEnableAppInSSO(string appName, string description, string ContactInfo,
                                            string AppUserAcct, string AppAdminAcct, SSOPropBag propertiesBag, ArrayList maskArray)
 {
     //create and enable application
     SSOConfigManager.CreateConfigStoreApplication(appName, description, ContactInfo,
                                                   AppUserAcct, AppAdminAcct, propertiesBag, maskArray);
     //set default configuration field values
     SSOConfigManager.SetConfigProperties(appName, propertiesBag);
 }
Пример #4
0
 private bool appExist(string name)
 {
     foreach (string s in SSOConfigManager.GetApplications())
     {
         if (s.Equals(name))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
        private bool UpdateSSOApplication(string newName, string oldName)
        {
            //write to SSOPropBag to figure out how many rows we have
            ArrayList maskArray = new ArrayList();

            try
            {
                HybridDictionary props = new HybridDictionary();

                foreach (DataGridViewRow row in dgvSearch.Rows)
                {
                    int keyIndex   = 0;
                    int valueIndex = 1;

                    if (row.Cells[keyIndex].Value != null)
                    {
                        // insert values on grid from property bag, replace special characters like \r \t
                        object objPropValue = row.Cells[valueIndex].Value.ToString().Replace("\t", "").Replace("\r", "");
                        object objPropKey   = row.Cells[keyIndex].Value.ToString().Replace("\t", "").Replace("\r", "");
                        props.Add(objPropKey, objPropValue);
                        maskArray.Add(0);
                    }
                }

                //if (newApp)
                //{
                SSOConfigManager.DeleteApplication(oldName);
                //}

                SSOPropBag propertiesBag = new SSOPropBag(props);

                //create and enable application
                SSOConfigManager.CreateConfigStoreApplication(newName, "", ContactInfo,
                                                              AuserAcct, AdminAcct, propertiesBag, maskArray);

                //set default configuration field values
                SSOConfigManager.SetConfigProperties(newName, propertiesBag);
            }
            catch (NullReferenceException ex)
            {
                MessageBox.Show("Erro, verifique se existe alguma key repetida\n" + ex.ToString(),
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Occured.  Details: " + ex.ToString(),
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
Пример #6
0
        private void AddBlankApp()
        {
            string   appName  = copyAppName(_newapplication);
            TreeNode node     = new TreeNode(appName);
            TreeNode rootNode = tvApps.TopNode;

            rootNode.Nodes.Add(node);
            tvApps.SelectedNode = node;
            tvApps.LabelEdit    = true;
            tvApps.SelectedNode.BeginEdit();
            SSOConfigManager.CreateConfigStoreApplication(appName, "", ContactInfo,
                                                          AuserAcct, AdminAcct, new SSOPropBag(), new ArrayList());
            InicSearchGrid();
        }
Пример #7
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();
            }
        }
Пример #11
0
        private void ctmTreeDelete_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show(string.Format("Are you sure you wish to delete '{0}'?", tvApps.SelectedNode.Text),
                                "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                try
                {
                    SSOConfigManager.DeleteApplication(tvApps.SelectedNode.Text);

                    //confirmation
                    MessageBox.Show("Application deleted.", "Information", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error Occured.  Details: " + ex.ToString(), "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                Utils._gridChanged  = false;
                tvApps.SelectedNode = tvApps.Nodes[0];
                Utils.Search(tvApps, txbSearch.Text, dgvSearch);
            }
        }