Beispiel #1
0
        public void BadXMLName()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("# bad name", null);
        }
Beispiel #2
0
        public void ReadOnlyErrorOnNodeDelete()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);
            conf.SetReadOnly(true);
            conf.Root["A"].Delete();
        }
Beispiel #3
0
        public void ReadOnlyErrorOnNodeRename()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);
            conf.SetReadOnly(true);
            conf.Root.Name = "changed-name";
        }
Beispiel #4
0
        public void NodeCreate()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);

            Aver.AreEqual("A", conf.Root["A"].Name);
        }
Beispiel #5
0
        /// <summary>
        /// Creates an instance of configuration initialized from XML content passed as string
        /// </summary>
        public static XMLConfiguration CreateFromXML(string content, bool strictNames = true)
        {
            var result = new XMLConfiguration();

            result.StrictNames = strictNames;
            result.readFromString(content);

            return(result);
        }
Beispiel #6
0
        public void StrictNamesFalse()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.StrictNames = false;
            var node = conf.Root.AddChildNode("bad name", null);

            Aver.AreEqual("bad-name", node.Name);
        }
Beispiel #7
0
        public void RootDelete()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);

            Aver.AreEqual(true, conf.Root.Exists);
            conf.Root.Delete();
            Aver.AreEqual(false, conf.Root.Exists);
        }
Beispiel #8
0
        public void NodeDelete()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);
            conf.Root.AddChildNode("B", null).AddChildNode("B1");
            conf.Root["A"].Delete();
            Aver.AreEqual(false, conf.Root["A"].Exists);
            Aver.AreEqual(true, conf.Root["B"].Exists);

            conf.Root.ResetModified();
            Aver.AreEqual(false, conf.Root["B"].Modified);
            conf.Root["B"]["B1"].Delete();
            Aver.AreEqual(true, conf.Root["B"].Modified);
        }
Beispiel #9
0
        public void NavigationAndValueAccessors()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", 10).AddChildNode("A.A", 20);
            conf.Root.AddChildNode("B", 789);
            conf.Root.AddChildNode("URI", UriKind.RelativeOrAbsolute);

            conf.Root["A"]["A.A"].AddChildNode("MARS", -1000);
            Aver.AreEqual(-1000, conf.Root["A"]["A.A"]["MARS"].ValueAsInt());
            Aver.AreEqual(-1000, conf.Root[0][0][0].ValueAsInt());
            Aver.AreEqual(789, conf.Root[1].ValueAsInt());
            Aver.IsTrue(UriKind.RelativeOrAbsolute == conf.Root["URI"].ValueAsEnum <UriKind>());
            Aver.IsTrue(UriKind.RelativeOrAbsolute == conf.Root["URI"].ValueAsEnum <UriKind>(UriKind.Absolute));
            Aver.IsTrue(UriKind.RelativeOrAbsolute == conf.Root["NONENTITY"].ValueAsEnum <UriKind>(UriKind.RelativeOrAbsolute));
        }
Beispiel #10
0
        public void EmptySectionAndAttributeNodes()
        {
            var conf = new Azos.Conf.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null).AddChildNode("A.A", "haha!").AddAttributeNode("good", true);

            Aver.AreEqual("haha!", conf.Root["A"]["A.A"].Value);
            Aver.AreEqual(true, conf.Root["A"]["A.A"].Exists);
            Aver.AreEqual(true, conf.Root["A"]["A.A"].AttrByName("good").Exists);
            Aver.AreEqual(true, conf.Root["A"]["A.A"].AttrByIndex(0).Exists);

            Aver.AreEqual(false, conf.Root["A1"]["A.A"].Exists);
            Aver.AreEqual(false, conf.Root["A"]["A.A1"].Exists);

            Aver.AreEqual(false, conf.Root["A"]["A.A"].AttrByName("bad").Exists);
            Aver.AreEqual(false, conf.Root["A"]["A.A"].AttrByIndex(100).Exists);
        }
Beispiel #11
0
        /// <summary>
        /// Loads the supplied string content in the specified format, which may be format name like "xml" or "laconfig" with or without extension period
        /// </summary>
        public static Configuration ProviderLoadFromString(string content, string format, string fallbackFormat = null)
        {
            if (format.IsNullOrWhiteSpace())
            {
                format = fallbackFormat; fallbackFormat = null;
            }

            if (format != null)
            {
                if (format.StartsWith("."))
                {
                    format = format.Remove(0, 1);
                }

                //since C# does not support first-class types, these if statements below must handle what AllSupportedFormat returns
                //in future Aum conversion replace with Dictionary<format, configType> lookup

                if (Azos.CodeAnalysis.Laconfig.LaconfigLanguage.Instance.FileExtensions.Any(e => string.Equals(e, format, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(LaconicConfiguration.CreateFromString(content));
                }

                if (Azos.CodeAnalysis.XML.XMLLanguage.Instance.FileExtensions.Any(e => string.Equals(e, format, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(XMLConfiguration.CreateFromXML(content));
                }

                if (Azos.CodeAnalysis.JSON.JsonLanguage.Instance.FileExtensions.Any(e => string.Equals(e, format, StringComparison.InvariantCultureIgnoreCase)))
                {
                    return(JSONConfiguration.CreateFromJson(content));
                }

                if (fallbackFormat.IsNotNullOrWhiteSpace())
                {
                    return(ProviderLoadFromString(content, fallbackFormat));
                }
            }

            throw new ConfigException(StringConsts.CONFIG_NO_PROVIDER_LOAD_FORMAT_ERROR + format);
        }