Example #1
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)
        {
            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 (NFX.CodeAnalysis.Laconfig.LaconfigLanguage.Instance.FileExtensions.Any(e => string.Equals(e, format, StringComparison.InvariantCultureIgnoreCase)))
            {
                return(LaconicConfiguration.CreateFromString(content));
            }

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

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

            throw new ConfigException(StringConsts.CONFIG_NO_PROVIDER_LOAD_FORMAT_ERROR + format);
        }
Example #2
0
        public void BadXMLName()
        {
            var conf = new NFX.Environment.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("# bad name", null);
        }
Example #3
0
        /// <summary>
        /// Creates an instance of configuration initialized from XML content passed as string
        /// </summary>
        public static XMLConfiguration CreateFromXML(string content)
        {
            var result = new XMLConfiguration();
              result.readFromString(content);

              return result;
        }
Example #4
0
        public static void Run()
        {
            var conf = new XMLConfiguration();

            conf.Create();

            conf.Root.Name = "This-is-Root";
            var child1 = conf.Root.AddChildNode("Child_Node_1");
            child1.AddChildNode("Grand-Child-1", "this is my value");

            child1.AddAttributeNode("AttrWithoutValue");
            child1.AddAttributeNode("Important", true);
            child1.AddAttributeNode("Age", 88);
            child1.AddAttributeNode("DateOf-Enlightement", App.LocalizedTime);
            child1.AddAttributeNode("HowFakeFakeAreYou", FakeType.TotalFraud);

            conf.Root.AddChildNode("Child2").AddChildNode("A").AddChildNode("B").AddChildNode("C");

            conf.Root["Child2"]["A"]["B"]["C"].Value = "175";
            Console.WriteLine(conf.Root["Child2"]["A"]["B"]["C"].ValueAsInt());

            Console.WriteLine(conf.SaveToString(null));

            conf.SaveAs("c:\\TEST.xml");

            conf = new XMLConfiguration("c:\\TEST.xml");
            Console.WriteLine(conf.Root["Child2"]["A"]["B"]["C"].ValueAsInt());
            Console.WriteLine(conf.Root["Child_Node_1"].AttrByName("HowFakeFakeAreYou").ValueAsEnum<FakeType>(FakeType.RealStuff));

            Console.ReadLine();
        }
Example #5
0
        public override void Report(System.IO.TextWriter writer)
        {
            var conf = new XMLConfiguration();
            conf.StrictNames = false;

            conf.Create();
            conf.Root.Name = "health-check-list";

            conf.Root.AddAttributeNode("successful", CheckList.Successful);

            var runNode = conf.Root.AddChildNode("run", null);
            if (CheckList.Status == CheckListStatus.Run)
            {
                runNode.AddAttributeNode("started", CheckList.RunStart); 
                runNode.AddAttributeNode("finished", CheckList.RunFinish);
                runNode.AddAttributeNode("duration", CheckList.RunFinish - CheckList.RunStart);
            }
            else
                runNode.AddAttributeNode("started", "never ran");

            var checksNode = conf.Root.AddChildNode("checks", null); 
            
            foreach(var check in CheckList.Checks)
             reportCheck(checksNode, check);
             
            
            
            writer.Write(conf.ToString());  
        }
Example #6
0
        /// <summary>
        /// Creates an instance of configuration initialized from XML content passed as string
        /// </summary>
        public static XMLConfiguration CreateFromXML(string content)
        {
            var result = new XMLConfiguration();

            result.readFromString(content);

            return(result);
        }
Example #7
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);
        }
Example #8
0
        public void ReadOnlyErrorOnNodeRename()
        {
            var conf = new NFX.Environment.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);
            conf.SetReadOnly(true);
            conf.Root.Name = "changed-name";
        }
Example #9
0
        public void ReadOnlyErrorOnNodeDelete()
        {
            var conf = new NFX.Environment.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);
            conf.SetReadOnly(true);
            conf.Root["A"].Delete();
        }
Example #10
0
        public void NodeCreate()
        {
            var conf = new NFX.Environment.XMLConfiguration();

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

            Aver.AreEqual("A", conf.Root["A"].Name);
        }
Example #11
0
        public void NodeRename()
        {
            var conf = new NFX.Environment.XMLConfiguration();

            conf.Create();
            conf.Root.AddChildNode("A", null);
            conf.Root["A"].Name = "B";
            Assert.AreEqual("B", conf.Root["B"].Name);
        }
Example #12
0
        public void StrictNamesFalse()
        {
            var conf = new NFX.Environment.XMLConfiguration();

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

            Aver.AreEqual("bad-name", node.Name);
        }
Example #13
0
        public void RootDelete()
        {
            var conf = new NFX.Environment.XMLConfiguration();

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

            Aver.AreEqual(true, conf.Root.Exists);
            conf.Root.Delete();
            Aver.AreEqual(false, conf.Root.Exists);
        }
Example #14
0
        public void NodeDelete()
        {
            var conf = new NFX.Environment.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);
        }
Example #15
0
        public void EmptySectionAndAttributeNodes()
        {
            var conf = new NFX.Environment.XMLConfiguration();
               conf.Create();
               conf.Root.AddChildNode("A", null).AddChildNode("A.A", "haha!").AddAttributeNode("good", true);

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

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

               Assert.AreEqual(false, conf.Root["A"]["A.A"].AttrByName("bad").Exists);
               Assert.AreEqual(false, conf.Root["A"]["A.A"].AttrByIndex(100).Exists);
        }
Example #16
0
        public void NavigationAndValueAccessors()
        {
            var conf = new NFX.Environment.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));
        }
Example #17
0
        public void EmptySectionAndAttributeNodes()
        {
            var conf = new NFX.Environment.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);
        }
Example #18
0
 public void BadXMLName()
 {
     var conf = new NFX.Environment.XMLConfiguration();
       conf.Create();
       conf.Root.AddChildNode("# bad name", null);
 }
Example #19
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);

              if (config.Root["?"].Exists ||
              config.Root["h"].Exists ||
              config.Root["help"].Exists)
              {
             ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Help.txt") );
             return;
              }

              if (!config.Root.AttrByIndex(0).Exists)
              {
            Console.WriteLine("Specify ';'-delimited assembly list");
            return;
              }

              var manager = new InventorizationManager(config.Root.AttrByIndex(0).Value);

              var fnode = config.Root["f"];
              if (!fnode.Exists) fnode = config.Root["filter"];
              if (fnode.Exists)
               ConfigAttribute.Apply(manager, fnode);

              foreach(var n in config.Root.Children.Where(chi=>chi.IsSameName("s") || chi.IsSameName("strat") || chi.IsSameName("strategy")))
              {
            var tname = n.AttrByIndex(0).Value ?? "<unspecified>";
            Type t = Type.GetType(tname);
            if (t == null)
               throw new NFXException("Can not create strategy type: " + tname);

            var strategy = Activator.CreateInstance(t) as IInventorization;

            if (strategy == null)
               throw new NFXException("The supplied type is not strategy: " + tname);

            manager.Strategies.Add(strategy);
              }

              if (manager.Strategies.Count==0)
              {
            manager.Strategies.Add( new BasicInventorization());
            manager.Strategies.Add( new RecordModelInventorization());
              }

               // if (config.Root["any"].Exists)
               //  manager.OnlyAttributed = false;

            var result = new XMLConfiguration();
            result.Create("inventory");
            manager.Run(result.Root);
            Console.WriteLine(result.SaveToString());
        }
Example #20
0
        public void NavigationAndValueAccessors()
        {
            var conf = new NFX.Environment.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);
               Assert.AreEqual(-1000, conf.Root["A"]["A.A"]["MARS"].ValueAsInt());
               Assert.AreEqual(-1000, conf.Root[0][0][0].ValueAsInt());
               Assert.AreEqual(789, conf.Root[1].ValueAsInt());
               Assert.AreEqual(UriKind.RelativeOrAbsolute, conf.Root["URI"].ValueAsEnum<UriKind>());
               Assert.AreEqual(UriKind.RelativeOrAbsolute, conf.Root["URI"].ValueAsEnum<UriKind>(UriKind.Absolute));
               Assert.AreEqual(UriKind.RelativeOrAbsolute, conf.Root["NONENTITY"].ValueAsEnum<UriKind>(UriKind.RelativeOrAbsolute));
        }
Example #21
0
        public void NodeDelete()
        {
            var conf = new NFX.Environment.XMLConfiguration();
               conf.Create();
               conf.Root.AddChildNode("A", null);
               conf.Root.AddChildNode("B", null).AddChildNode("B1");
               conf.Root["A"].Delete();
               Assert.AreEqual(false, conf.Root["A"].Exists);
               Assert.AreEqual(true, conf.Root["B"].Exists);

               conf.Root.ResetModified();
               Assert.AreEqual(false, conf.Root["B"].Modified);
               conf.Root["B"]["B1"].Delete();
               Assert.AreEqual(true, conf.Root["B"].Modified);
        }
Example #22
0
 public void NodeRename()
 {
     var conf = new NFX.Environment.XMLConfiguration();
        conf.Create();
        conf.Root.AddChildNode("A", null);
        conf.Root["A"].Name = "B";
        Assert.AreEqual("B", conf.Root["B"].Name);
 }
Example #23
0
 public void ReadOnlyErrorOnNodeDelete()
 {
     var conf = new NFX.Environment.XMLConfiguration();
        conf.Create();
        conf.Root.AddChildNode("A", null);
        conf.SetReadOnly(true);
        conf.Root["A"].Delete();
 }
Example #24
0
 public void ReadOnlyErrorOnNodeRename()
 {
     var conf = new NFX.Environment.XMLConfiguration();
        conf.Create();
        conf.Root.AddChildNode("A", null);
        conf.SetReadOnly(true);
        conf.Root.Name = "changed-name";
 }
Example #25
0
        public void RootDelete()
        {
            var conf = new NFX.Environment.XMLConfiguration();
               conf.Create();
               conf.Root.AddChildNode("A", null);

               Assert.AreEqual(true, conf.Root.Exists);
               conf.Root.Delete();
               Assert.AreEqual(false, conf.Root.Exists);
        }
Example #26
0
 public void StrictNamesFalse()
 {
     var conf = new NFX.Environment.XMLConfiguration();
       conf.Create();
       conf.StrictNames = false;
       var node = conf.Root.AddChildNode("bad name", null);
       Assert.AreEqual("bad-name", node.Name);
 }