コード例 #1
0
        /// <summary>
        /// Retrieve dictionary of field/value pairs
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="description"></param>
        /// <param name="contactInfo"></param>
        /// <param name="appUserAcct"></param>
        /// <param name="appAdminAcct"></param>
        /// <returns></returns>
        public static HybridDictionary GetConfigProperties(string appName, out string description, out string contactInfo, out string appUserAcct, out string appAdminAcct)
        {
            int flags;
            int count;

            //get config info
            ISSOAdmin ssoAdmin = new ISSOAdmin();

            ssoAdmin.GetApplicationInfo(appName, out description, out contactInfo, out appUserAcct, out appAdminAcct, out flags, out count);

            //get properties
            ISSOConfigStore configStore   = new ISSOConfigStore();
            SSOPropBag      propertiesBag = new SSOPropBag();

            try
            {
                configStore.GetConfigInfo(appName, idenifierGUID, SSOFlag.SSO_FLAG_RUNTIME, propertiesBag);
            }
            catch (COMException e)
            {
                if (!e.Message.StartsWith("The application is currently disabled."))
                {
                    throw;
                }
            }

            return(propertiesBag.properties);
        }
        /// <summary>
        /// Create application in SSO Store from app.config
        /// </summary>
        /// <param name="appName">Application to create/enable</param>
        public static bool CreateAppFromTemplate(string appName)
        {
            var       settings       = ConfigurationManager.GetSection("settings") as NameValueCollection;
            var       templateOfKeys = ConfigurationManager.GetSection("TemplateOfKeys") as NameValueCollection;
            ArrayList maskArray      = new ArrayList();

            try
            {
                HybridDictionary props = new HybridDictionary();

                foreach (var item in templateOfKeys)
                {
                    string value = templateOfKeys.GetValues(item.ToString()).FirstOrDefault();
                    props.Add(item.ToString(), value);
                    maskArray.Add(0);
                }

                SSOPropBag propertiesBag = new SSOPropBag(props);;

                CreateAndEnableAppInSSO(appName, string.Empty, settings.Get("ContactInfo"),
                                        settings.Get("AppUserAcct"), settings.Get("AppAdminAcct"), propertiesBag, maskArray);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Cannot create app '{0}'\n\n{1}", appName, ex.Message.ToString()),
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
        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);
        }
        public static bool ImportAppFromXML(string path, string password)
        {
            var settings = ConfigurationManager.GetSection("appSettings") as NameValueCollection;

            XmlDocument configDoc = new XmlDocument();

            try
            {
                configDoc.LoadXml(Encryption.DecryptGeral(File.ReadAllText(@path), password));

                string appName = Path.GetFileNameWithoutExtension(@path);

                //grab fields
                XmlNodeList fields    = configDoc.SelectNodes("//applicationData/add");
                ArrayList   maskArray = new ArrayList();

                try
                {
                    HybridDictionary props = new HybridDictionary();

                    foreach (XmlNode field in fields)
                    {
                        props.Add(field.Attributes["key"].InnerText, field.Attributes["value"].InnerText);
                        maskArray.Add(0);
                    }


                    SSOPropBag propertiesBag = new SSOPropBag(props);;

                    CreateAndEnableAppInSSO(appName, string.Empty, settings.Get("ContactInfo"),
                                            settings.Get("AppUserAcct"), settings.Get("AppAdminAcct"), propertiesBag, maskArray);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Cannot create app '{0}'\n\n{1}", appName, ex.Message.ToString()),
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                return(true);
            }
            catch (XmlException)
            {
                MessageBox.Show("Password incorrect!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
        /// <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);
            }
        }
        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);
                    }
                }
            }

            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>
        /// 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);
            }
        }
コード例 #8
0
        /// <summary>
        /// Set values for application fields
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="propertyBag"></param>
        public static void SetConfigProperties(string appName, SSOPropBag propertyBag)
        {
            ISSOConfigStore configStore = new ISSOConfigStore();

            configStore.SetConfigInfo(appName, idenifierGUID, propertyBag);
        }
コード例 #9
0
        /// <summary>
        /// Creates a new SSO ConfigStore application.
        /// </summary>
        /// <param name="appName"></param>
        /// <param name="description"></param>
        /// <param name="uAccountName"></param>
        /// <param name="adminAccountName"></param>
        /// <param name="propertiesBag"></param>
        /// <param name="maskArray"></param>
        public static void CreateConfigStoreApplication(string appName, string description, string contactInfo, string uAccountName, string adminAccountName, SSOPropBag propertiesBag, ArrayList maskArray)
        {
            int appFlags = 0;

            //bitwise operation for flags
            appFlags |= SSOFlag.SSO_FLAG_APP_CONFIG_STORE;
            appFlags |= SSOFlag.SSO_FLAG_SSO_WINDOWS_TO_EXTERNAL;
            appFlags |= SSOFlag.SSO_FLAG_APP_ALLOW_LOCAL;

            ISSOAdmin ssoAdmin = new ISSOAdmin();

            //create app
            if (propertiesBag.PropertyCount > 0)
            {
                ssoAdmin.CreateApplication(appName, description, contactInfo, uAccountName, adminAccountName, appFlags, propertiesBag.PropertyCount);
            }
            else
            {
                ssoAdmin.CreateApplication(appName, description, contactInfo, uAccountName, adminAccountName, appFlags, 1);
            }


            //create property fields
            int counter = 0;

            //create dummy field in first slot
            ssoAdmin.CreateFieldInfo(appName, "dummy", 0);
            //create real fields
            foreach (DictionaryEntry de in propertiesBag.properties)
            {
                string propName   = de.Key.ToString();
                int    fieldFlags = 0;
                fieldFlags |= Convert.ToInt32(maskArray[counter]);

                //create property
                ssoAdmin.CreateFieldInfo(appName, propName, fieldFlags);

                counter++;
            }

            //enable application
            ssoAdmin.UpdateApplication(appName, null, null, null, null, SSOFlag.SSO_FLAG_ENABLED, SSOFlag.SSO_FLAG_ENABLED);
        }
 /// <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);
 }