コード例 #1
0
        /// <summary>
        /// Creates a new empty config root based on laconic format
        /// </summary>
        public static ConfigSectionNode NewEmptyRoot(string name = null)
        {
            var cfg = new LaconicConfiguration();

            cfg.Create(name);
            return(cfg.Root);
        }
コード例 #2
0
ファイル: LaconicConfiguration.cs プロジェクト: azist/azos
        /// <summary>
        /// Creates an instance of configuration initialized from laconfig passed as string
        /// </summary>
        public static LaconicConfiguration CreateFromString(string content)
        {
            var result = new LaconicConfiguration();

            result.readFromString(content);

            return(result);
        }
コード例 #3
0
ファイル: ScriptingTests.cs プロジェクト: azist/azos
        public void RSchema()
        {
            var src    = Azos.Conf.LaconicConfiguration.CreateFromString(rschema);
            var result = new Azos.Conf.LaconicConfiguration();

            new ScriptRunner().Execute(src, result);

            var got = result.SaveToString();

            got.See();
            Aver.AreEqual(rschemaExpected.ToWindowsLines(), got.ToWindowsLines());
        }
コード例 #4
0
ファイル: ScriptingTests.cs プロジェクト: azist/azos
        public void VarsLoopIfElseCall()
        {
            var src    = Azos.Conf.LaconicConfiguration.CreateFromString(src1);
            var result = new Azos.Conf.LaconicConfiguration();

            new ScriptRunner().Execute(src, result);

            var got = result.SaveToString();

            got.See();
            Aver.AreEqual(expected1.ToWindowsLines(), got.ToWindowsLines());
        }
コード例 #5
0
ファイル: ScriptingTests.cs プロジェクト: sergey-msu/azos
        public void Error_Timeout()
        {
            var src = Azos.Conf.LaconicConfiguration.CreateFromString(
                @"
root
{
       _loop=true {}
}
");
            var result = new Azos.Conf.LaconicConfiguration();

            new ScriptRunner().Execute(src, result);
        }
コード例 #6
0
ファイル: ScriptingTests.cs プロジェクト: sergey-msu/azos
        public void Error_ELSEWithoutIF()
        {
            var src = Azos.Conf.LaconicConfiguration.CreateFromString(
                @"
root
{
       _else{  }
}
");
            var result = new Azos.Conf.LaconicConfiguration();

            new ScriptRunner().Execute(src, result);
        }
コード例 #7
0
ファイル: ScriptingTests.cs プロジェクト: sergey-msu/azos
        public void Error_SetVarDoesNotExist()
        {
            var src = Azos.Conf.LaconicConfiguration.CreateFromString(
                @"
root
{
       _set{ path=/NONE to=5+5 }
}
");
            var result = new Azos.Conf.LaconicConfiguration();

            new ScriptRunner().Execute(src, result);
        }
コード例 #8
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);
        }