Пример #1
0
        /// <summary>
        /// Updates the file that a setting is in.
        /// </summary>
        /// <param name="setting">The setting that has been changed.</param>
        private void UpdateSetting(ISecuritySetting setting)
        {
            // Load the file that the setting is in
            string      fileName       = settingFileMap[setting.Identifier];
            XmlDocument sourceDocument = new XmlDocument();

            sourceDocument.Load(executionEnvironment.EnsurePathIsRooted(fileName));

            // Find the item that is being updated
            foreach (XmlElement settingEl in sourceDocument.DocumentElement.SelectNodes("*"))
            {
                object loadedItem = reflectionReader.Read(settingEl);

                var dummy = loadedItem as ISecuritySetting;
                if (dummy != null)
                {
                    string identifier = dummy.Identifier;
                    if (identifier == setting.Identifier)
                    {
                        // Update the item with the new setting
                        StringWriter buffer = new StringWriter();
                        new ReflectorTypeAttribute(settingEl.Name).Write(new XmlTextWriter(buffer), setting);
                        XmlElement element = sourceDocument.CreateElement("changed");
                        element.InnerXml = buffer.ToString();
                        settingEl.ParentNode.ReplaceChild(element.FirstChild, settingEl);
                        break;
                    }
                }
            }

            // Save the updated document
            sourceDocument.Save(fileName);
        }
Пример #2
0
        public void RetrieveSettingReturnsNull()
        {
            NullSecurityManager manager = new NullSecurityManager();
            ISecuritySetting    setting = manager.RetrievePermission("anything");

            Assert.IsNull(setting);
        }
        /// <summary>
        /// Updates the file that a setting is in.
        /// </summary>
        /// <param name="setting">The setting that has been changed.</param>
        private void UpdateSetting(ISecuritySetting setting)
        {
            // Load the file that the setting is in
            string fileName = settingFileMap[setting.Identifier];
            XmlDocument sourceDocument = new XmlDocument();
            sourceDocument.Load(executionEnvironment.EnsurePathIsRooted(fileName));

            // Find the item that is being updated
            foreach (XmlElement settingEl in sourceDocument.DocumentElement.SelectNodes("*"))
            {
                object loadedItem = reflectionReader.Read(settingEl);

                if (loadedItem is ISecuritySetting)
                {
                    string identifier = (loadedItem as ISecuritySetting).Identifier;
                    if (identifier == setting.Identifier)
                    {
                        // Update the item with the new setting
                        StringWriter buffer = new StringWriter();
                        new ReflectorTypeAttribute(settingEl.Name).Write(new XmlTextWriter(buffer), setting);
                        XmlElement element = sourceDocument.CreateElement("changed");
                        element.InnerXml = buffer.ToString();
                        settingEl.ParentNode.ReplaceChild(element.FirstChild, settingEl);
                        break;
                    }
                }
            }

            // Save the updated document
            sourceDocument.Save(fileName);
        }