Example #1
0
        /// <summary>
        /// Removes the specified configuration from the selected configurations diplayed by this control, optionally attempts to restore the location
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="keepLocationIfPossible"></param>
        public void RemoveConfiguration(XmlConfiguration configuration, bool keepLocationIfPossible)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new RemoveConfigurationInvoker(this.RemoveConfiguration), new object[] { configuration, keepLocationIfPossible });
                return;
            }

            try
            {
                if (configuration != null)
                {
                    if (_selectedConfigurations.Contains(configuration))
                    {
                        string   path = null;
                        TreeNode n    = _treeView.SelectedNode;
                        if (n != null)
                        {
                            path = n.FullPath;
                        }

                        _selectedConfigurations.Remove(configuration);

                        this.RefreshDisplay(path, keepLocationIfPossible);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Example #2
0
        /// <summary>
        /// Adds the specified configuration to the selected configurations displayed by this control
        /// </summary>
        /// <param name="configuration"></param>
        public void AddConfiguration(XmlConfiguration configuration)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new AddConfigurationInvoker(this.AddConfiguration), new object[] { configuration });
                return;
            }

            try
            {
                if (configuration != null)
                {
                    configuration.Changed += new XmlConfigurationElementEventHandler(OnConfigurationChanged);
                    if (_placeElementsIntoEditMode)
                    {
                        configuration.BeginEdit();
                    }
                    _selectedConfigurations.Add(configuration);
                    this.AddNodesForCategories(_treeView, null, configuration.Categories);
                    //this.AddXmlTabForConfiguration(configuration);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Example #3
0
        /// <summary>
        /// Reads an XmlConfiguration from a System.IO.Stream
        /// </summary>
        /// <param name="stream">The stream that contains the XmlConfiguration file</param>
        /// <param name="configuration">The configuration to load into</param>
        /// <returns></returns>
        public XmlConfiguration Read(Stream stream, XmlConfiguration configuration)
        {
            try
            {
                /// create a new xml document
                XmlDocument doc = new XmlDocument();

                /// load it from the stream
                doc.Load(stream);

                /// create a new xpath navigator so that we can traverse the elements inside the xml
                XPathNavigator navigator = doc.CreateNavigator();

                /// move to the version element
                navigator.MoveToFirstChild();

                /// move to the file format description element
                navigator.MoveToNext();

                this.ReadConfiguration(navigator, configuration);

                return(configuration);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(null);
        }
        public override bool ApplyChanges(ISupportsEditing editableObject, SupportedEditingActions actions)
        {
            if (base.ApplyChanges(editableObject, actions))
            {
                XmlConfiguration configuration = editableObject as XmlConfiguration;
                if (configuration != null)
                {
                    if (_isBeingEdited)
                    {
                        this.BeginInit();
                    }

                    if (_categories != null)
                    {
                        _categories.ApplyChanges((ISupportsEditing)configuration.Categories, actions);
                    }

                    if (_isBeingEdited)
                    {
                        this.EndInit();
                    }
                }
                return(true);
            }
            return(false);
        }
Example #5
0
        /// <summary>
        /// Writes an entire configuration file using the specified configuration and stream.
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="stream"></param>
        /// <param name="alwaysPersist"></param>
        public void Write(XmlConfiguration configuration, Stream stream, bool alwaysPersist)
        {
            try
            {
                /// create a new xml document
                XmlDocument doc = new XmlDocument();

                /// create the root element
                XmlElement root = doc.CreateElement(@"ConfigurationFile");

                /// append the root element as the first element
                doc.AppendChild(root);

                /// mark the xml as version 1.0 compliant
                XmlDeclaration versionDeclaration = doc.CreateXmlDeclaration(@"1.0", null, null);

                /// insert the version element as the first element
                doc.InsertBefore(versionDeclaration, root);

                this.WriteConfiguration(doc, root, configuration, alwaysPersist);

                /// save the xml document to the stream
                doc.Save(stream);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex);
            }
        }
 public void Remove(XmlConfiguration configuration)
 {
     if (this.Contains(configuration))
     {
         base.InnerList.Remove(configuration);
     }
 }
Example #7
0
        /// <summary>
        /// Writes a configuration to the XmlDocument
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="parent"></param>
        /// <param name="configuration"></param>
        /// <param name="alwaysPersist"></param>
        private void WriteConfiguration(XmlDocument doc, XmlElement parent, XmlConfiguration configuration, bool alwaysPersist)
        {
            try
            {
                if (configuration.Persistent || alwaysPersist)
                {
//					System.Diagnostics.Debug.WriteLine("Writing configuration '" + configuration.ElementName + "'");

                    /// create an element for the category
                    XmlElement child = doc.CreateElement(@"Configuration");

                    /// write the properties of this category
                    child.SetAttribute(@"ElementName", configuration.ElementName);
                    child.SetAttribute(@"HasChanges", XmlConvert.ToString(configuration.HasChanges));
                    child.SetAttribute(@"Category", configuration.Category);
                    child.SetAttribute(@"Description", configuration.Description);
                    child.SetAttribute(@"DisplayName", configuration.DisplayName);
                    child.SetAttribute(@"Hidden", XmlConvert.ToString(configuration.Hidden));

                    /// append the child to our parent
                    parent.AppendChild(child);

                    this.WriteCategories(doc, child, configuration.Categories, alwaysPersist);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
        /// <summary>
        /// Gets an XmlConfiguration using a elementName, optionally creates a new or loads an existing configuration (.xml) file using the path specified, and optionally adds it to the collection if new
        /// </summary>
        /// <param name="elementName">The elementName by which this collection will be accessed</param>
        /// <param name="createIfNotFound">A flag indicating whether the configuration should be created if it does not exist</param>
        /// <param name="path">The path to the configuration</param>
        public XmlConfiguration this[string elementName, bool createIfNotFound, bool addToCollectionIfNew, string path]
        {
            get
            {
                /// try and find the configuration in the collection
                XmlConfiguration configuration = this[elementName];

                /// if it's not in the collection
                if (configuration == null)
                {
                    /// perhaps it does in the filesystem, if so then read it, and optionally add it to the collection
                    if (File.Exists(path))
                    {
                        try
                        {
                            FileStream             stream = new FileStream(path, FileMode.Open, FileAccess.Read);
                            XmlConfigurationReader reader = new XmlConfigurationReader();
                            configuration      = reader.Read(stream);
                            configuration.Path = path;
                            stream.Close();

                            if (addToCollectionIfNew)
                            {
                                this.Add(configuration);
                            }

                            return(configuration);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex);
                        }
                    }

                    /// apparently it doesnt' exist in the filesystem
                    if (createIfNotFound)
                    {
                        /// so create a new file
                        configuration             = new XmlConfiguration();
                        configuration.Path        = path;
                        configuration.ElementName = elementName;

                        /// save the blank config
                        Directory.CreateDirectory(path);
                        FileStream             stream = new FileStream(path, FileMode.Create, FileAccess.Write);
                        XmlConfigurationWriter writer = new XmlConfigurationWriter();
                        writer.Write(configuration, stream, false);
                        stream.Close();

                        /// add it to the config if so instructed
                        if (addToCollectionIfNew)
                        {
                            this.Add(configuration);
                        }
                    }
                }
                return(configuration);
            }
        }
 public bool Contains(XmlConfiguration configuration)
 {
     foreach (XmlConfiguration config in base.InnerList)
     {
         if (config.ElementName == configuration.ElementName)
         {
             return(true);
         }
     }
     return(false);
 }
        public int Add(XmlConfiguration configuration)
        {
            if (this.Contains(configuration))
            {
                throw new ArgumentException("ElementName already exists. ElementName in collection: " + configuration.ElementName + " ElementName being added: " + configuration.ElementName);
            }

            int index = base.InnerList.Add(configuration);

            /// bind to events

            return(0);
        }
Example #11
0
        /// <summary>
        /// Reads a configuration using the specified XPathNavigator
        /// </summary>
        /// <param name="navigator"></param>
        /// <returns></returns>
        private XmlConfiguration ReadConfiguration(XPathNavigator navigator, XmlConfiguration configuration)
        {
            if (navigator.MoveToFirstChild())
            {
                if (string.Compare(navigator.Name, @"Configuration", true) == 0)
                {
                    // does the cateogry have attributes, it should!
                    if (navigator.HasAttributes)
                    {
                        // break off yet another clone to navigate the attributes of this element
                        XPathNavigator attributesNavigator = navigator.Clone();
                        if (attributesNavigator.MoveToFirstAttribute())
                        {
                            configuration.ElementName = attributesNavigator.Value;

                            while (attributesNavigator.MoveToNextAttribute())
                            {
                                switch (attributesNavigator.Name)
                                {
                                case @"HasChanges":
                                    configuration.HasChanges = XmlConvert.ToBoolean(attributesNavigator.Value);
                                    break;

                                case @"Category":
                                    configuration.Category = attributesNavigator.Value;
                                    break;

                                case @"Description":
                                    configuration.Description = attributesNavigator.Value;
                                    break;

                                case @"DisplayName":
                                    configuration.DisplayName = attributesNavigator.Value;
                                    break;

                                case @"Hidden":
                                    configuration.Hidden = XmlConvert.ToBoolean(attributesNavigator.Value);
                                    break;
                                }
                                ;
                            }
                        }
                    }
                }
            }

            // recursively read the categories within this configuration file
            this.ReadCategories(navigator, configuration.Categories);

            return(configuration);
        }
        /// <summary>
        /// Clones this configuration
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            XmlConfiguration        clone   = null;
            XmlConfigurationElement element = (XmlConfigurationElement)base.Clone();

            if (element != null)
            {
                clone = new XmlConfiguration(element);
                clone.ResetBeforeEdit();
                clone.ResetChanged();
                clone.ResetAfterEdit();
                clone.Path = this.Path;
                clone.SetHasUnpersistedChanges(this.HasUnpersistedChanges());
                clone.Categories = (XmlConfigurationCategoryCollection)this.Categories.Clone();
            }
            return(clone);
        }
        public override bool ApplyToSelf(ISupportsEditing editableObject, SupportedEditingActions actions)
        {
            if (base.ApplyToSelf(editableObject, actions))
            {
                XmlConfiguration configuration = editableObject as XmlConfiguration;
                if (configuration != null)
                {
                    if (_categories != null)
                    {
                        _categories.ApplyToSelf((ISupportsEditing)configuration.Categories, actions);
                    }
                }
                return(true);
            }

            this.ItIsNowTimeToSave();

            return(false);
        }
Example #14
0
        /// <summary>
        /// Reads an XmlConfiguration from a System.IO.Stream
        /// </summary>
        /// <param name="stream">The stream that contains the XmlConfiguration file</param>
        /// <returns></returns>
        public XmlConfiguration Read(Stream stream)
        {
            try
            {
                // create a new xml document
                XmlDocument doc = new XmlDocument();

                // load it from the stream
                doc.Load(stream);

                // create a new xpath navigator so that we can traverse the elements inside the xml
                XPathNavigator navigator = doc.CreateNavigator();

                // move to the version element
                navigator.MoveToFirstChild();

                // move to the file format description element
                navigator.MoveToNext();

                // create a new configuration
                XmlConfiguration configuration = new XmlConfiguration();

                // begin initialization so that events do not fire inside the configuration
                configuration.BeginInit();

                // using the xpath navigator, read the xml document and turn it into a configuration
                this.ReadConfiguration(navigator, configuration);

                // end initialization
                configuration.EndInit();

                return(configuration);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(null);
        }
Example #15
0
 public XmlConfigurationEventArgs(XmlConfiguration configuration, XmlConfigurationElementActions action) : base(configuration, action)
 {
 }
        protected override XmlConfigurationElement GetElementToEdit()
        {
            XmlConfiguration configuration = (XmlConfiguration)this.Clone();

            return((XmlConfigurationElement)configuration);
        }
 /// <summary>
 /// Initializes a new instance of the XmlConfigurationOption class
 /// </summary>
 /// <param name="option">The option to base this option on</param>
 public XmlConfiguration(XmlConfiguration configuration) : base((XmlConfigurationElement)configuration)
 {
     _path       = configuration.Path;
     _categories = configuration.Categories;
 }
Example #18
0
 public void AddConfiguration(XmlConfiguration configuration)
 {
     _xmlConfigurationView.AddConfiguration(configuration);
 }
Example #19
0
 public void RemoveConfiguration(XmlConfiguration configuration, bool keepLocationIfPossible)
 {
     _xmlConfigurationView.RemoveConfiguration(configuration, keepLocationIfPossible);
 }