Ejemplo n.º 1
0
 public void Remove(UrlConfigElement url)
 {
     if (BaseIndexOf(url) >= 0)
     {
         BaseRemove(url.Name);
     }
 }
Ejemplo n.º 2
0
        // </Snippet80>

        // <Snippet81>
        static public void IsElementCollection()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            // Get the collection element.
            UrlsCollection urls = section.Urls;

            bool isCollection =
                url.ElementInformation.IsCollection;

            Console.WriteLine("Url element is a collection? {0}",
                              isCollection.ToString());

            isCollection =
                urls.ElementInformation.IsCollection;
            Console.WriteLine("Urls element is a collection? {0}",
                              isCollection.ToString());
        }
Ejemplo n.º 3
0
        // </Snippet84>

        // <Snippet85>
        static public void GetElementProperties()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            // Get the element properties.
            PropertyInformationCollection properties =
                url.ElementInformation.Properties;

            foreach (PropertyInformation prop in properties)
            {
                Console.WriteLine(
                    "Name: {0} Type: {1}", prop.Name,
                    prop.Type.ToString());
            }
        }
Ejemplo n.º 4
0
        // </Snippet7>

        // Remove a UrlConfigElement from the collection.
        static void RemoveElement(string name, string url, int port)
        {
            // Get the configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the MyUrls section.
            UrlsSection myUrlsSection =
                config.GetSection("MyUrls") as UrlsSection;

            UrlsCollection urls = myUrlsSection.Urls;

            UrlConfigElement element =
                new UrlConfigElement(name, url, port);

            if (!myUrlsSection.ElementInformation.IsLocked)
            {
                myUrlsSection.Urls.Remove(element);

                config.Save(ConfigurationSaveMode.Minimal);

                // This to obsolete the cached section and
                // read the new updated one.
                ConfigurationManager.RefreshSection("MyUrls");
            }
            else
            {
                Console.WriteLine(
                    "Section was locked, could not update.");
            }
        }
Ejemplo n.º 5
0
        public UrlsCollection()
        {
            // Add one url to the collection.  This is
            // not necessary; could leave the collection
            // empty until items are added to it outside
            // the constructor.
            UrlConfigElement url =
                (UrlConfigElement)CreateNewElement();

            Add(url);
        }
Ejemplo n.º 6
0
        // </Snippet2>

        // <Snippet3>
        // Show how to set LockItem
        // It adds a new UrlConfigElement to
        // the collection.
        static void LockItem()
        {
            string name = "Contoso";
            string url  = "http://www.contoso.com/";
            int    port = 8080;

            try
            {
                // Get the current configuration file.
                System.Configuration.Configuration config =
                    ConfigurationManager.OpenExeConfiguration(
                        ConfigurationUserLevel.None);

                // Get the MyUrls section.
                UrlsSection myUrls =
                    config.Sections["MyUrls"] as UrlsSection;


                // Create the new  element.
                UrlConfigElement newElement =
                    new UrlConfigElement(name, url, port);

                // Set its lock.
                newElement.LockItem = true;

                // Save the new element to the
                // configuration file.
                if (!myUrls.ElementInformation.IsLocked)
                {
                    myUrls.Urls.Add(newElement);

                    config.Save(ConfigurationSaveMode.Full);

                    // This is used to obsolete the cached
                    // section and read the updated
                    // bersion from the configuration file.
                    ConfigurationManager.RefreshSection("MyUrls");
                }
                else
                {
                    Console.WriteLine(
                        "Section was locked, could not update.");
                }
            }
            catch (ConfigurationErrorsException e)
            {
                Console.WriteLine("[LockItem: {0}]",
                                  e.ToString());
            }
        }
Ejemplo n.º 7
0
        GetElementInformation()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            ElementInformation eInfo =
                url.ElementInformation;

            return(eInfo);
        }
Ejemplo n.º 8
0
        // </Snippet82>

        // <Snippet83>
        static public void IsElementPresent()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            bool isPresent =
                url.ElementInformation.IsPresent;

            Console.WriteLine("Url element is present? {0}",
                              isPresent.ToString());
        }
Ejemplo n.º 9
0
        // </Snippet88>

        // <Snippet89>
        static public void GetElementErrors()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            // Get the errors.
            ICollection errors =
                url.ElementInformation.Errors;

            Console.WriteLine("Number of errors: {0)",
                              errors.Count.ToString());
        }
Ejemplo n.º 10
0
        // </Snippet87>

        // <Snippet88>
        static public void GetElementValidator()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            // Get the element source file.
            ConfigurationValidatorBase elValidator =
                url.ElementInformation.Validator;

            Console.WriteLine("Url element validator: {0}",
                              elValidator.ToString());
        }
Ejemplo n.º 11
0
        // </Snippet86>

        // <Snippet87>
        static public void GetElementType()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            // Get the element type.
            Type elType =
                url.ElementInformation.Type;

            Console.WriteLine("Url element type: {0}",
                              elType.ToString());
        }
Ejemplo n.º 12
0
        // </Snippet85>

        // <Snippet86>
        static public void GetElementSource()
        {
            // Get the current configuration file.
            System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                    ConfigurationUserLevel.None);

            // Get the section.
            UrlsSection section =
                (UrlsSection)config.GetSection("MyUrls");

            // Get the element.
            UrlConfigElement url = section.Simple;

            // Get the element source file.
            string sourceFile =
                url.ElementInformation.Source;

            Console.WriteLine("Url element source file: {0}",
                              sourceFile);
        }
Ejemplo n.º 13
0
 public void Add(UrlConfigElement url)
 {
     BaseAdd(url);
     // Add custom code here.
 }
Ejemplo n.º 14
0
 public int IndexOf(UrlConfigElement url)
 {
     return(BaseIndexOf(url));
 }