Exemplo n.º 1
0
        public void LoopWithRealArithmetic()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(
                @"
root
{
       i=0
       _loop='$(/$i)<=1.2'
       {
           section_$(/$i) {}
           _set{path=/$i to=$(/$i)+0.2}
       }
}
");
            var result = new NFX.Environment.LaconicConfiguration();

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

            var got = result.SaveToString();

            Console.WriteLine(got);

            Assert.AreEqual("section_0", result.Root[0].Name);
            Assert.AreEqual("section_0.2", result.Root[1].Name);
            Assert.AreEqual("section_0.4", result.Root[2].Name);
            Assert.AreEqual("section_0.6", result.Root[3].Name);
            Assert.AreEqual("section_0.8", result.Root[4].Name);
            Assert.AreEqual("section_1", result.Root[5].Name);
            Assert.AreEqual("section_1.2", result.Root[6].Name);
            Assert.IsFalse(result.Root[7].Exists);
        }
Exemplo n.º 2
0
        public void SectionNameWithVar()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(
                @"
root
{
       i=0
       _loop=$(/$i)<10
       {
           section_$(/$i) {}
           _set{path=/$i to=$(/$i)+1}
       }
}
");
            var result = new NFX.Environment.LaconicConfiguration();

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

            var got = result.SaveToString();

            Console.WriteLine(got);

            Assert.AreEqual("section_0", result.Root[0].Name);
            Assert.AreEqual("section_9", result.Root[9].Name);
            Assert.IsFalse(result.Root[10].Exists);
        }
Exemplo n.º 3
0
        public void ExprEval1_TernaryIf()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(
                @"
root
{
   a=12
   b=true

   var1=0{script-only=true}
   var2=175.4{script-only=true}
   var3=true{script-only=true}

   _block
   {
       _set{ path=/var1 to=(?$(/var2)>10;15;-10)+100 }
       RESULT=$(/var1){}
   }
}
");
            var result = new NFX.Environment.LaconicConfiguration();

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

            var got = result.SaveToString();

            Console.WriteLine(got);

            Aver.AreEqual(115, result.Root["RESULT"].ValueAsInt());
        }
Exemplo n.º 4
0
        public void ExprEval1_TernaryIfWithMixingTypes()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(
                @"
root
{
   a=12
   b=true

   var1=0{script-only=true}
   var2=175.4{script-only=true}
   var3=true{script-only=true}

   _block
   {
       _set{ path=/var1 to='((?$(/var3);$(/var2);-10)+100)+kozel' }
       RESULT=$(/var1){}
   }
}
");
            var result = new NFX.Environment.LaconicConfiguration();

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

            var got = result.SaveToString();

            Console.WriteLine(got);

            Assert.AreEqual("275.4kozel", result.Root["RESULT"].Value);
        }
Exemplo n.º 5
0
        public void RSchema()
        {
            var src    = NFX.Environment.LaconicConfiguration.CreateFromString(rschema);
            var result = new NFX.Environment.LaconicConfiguration();

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

            var got = result.SaveToString();

            Console.WriteLine(got);
            Assert.AreEqual(rschemaExpected, got);
        }
Exemplo n.º 6
0
        public void VarsLoopIfElseCall()
        {
            var src    = NFX.Environment.LaconicConfiguration.CreateFromString(src1);
            var result = new NFX.Environment.LaconicConfiguration();

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

            var got = result.SaveToString();

            Console.WriteLine(got);
            Assert.AreEqual(expected1, got);
        }
Exemplo n.º 7
0
        public FieldAttribute(
                        Type protoType, 
                        string protoFieldName, //Schema:Field
                        string targetName   = ANY_TARGET,
                        object storeFlag    = null,
                        object key          = null,
                        object kind         = null,
                        object required     = null,
                        object visible      = null,
                        string valueList    = null,
                        object dflt         = null,
                        object min          = null,
                        object max          = null,
                        object minLength    = null,
                        object maxLength    = null,
                        object charCase     = null,
                        string backendName  = null,
                        string description  = null,
                        string metadata     = null,
                        object nonUI        = null
                    ) : base(targetName, null)
        {
            if (protoType==null || protoFieldName.IsNullOrWhiteSpace()) throw new CRUDException(StringConsts.ARGUMENT_ERROR+"FieldAttr.ctor(protoType|protoFieldName=null|empty)");
            try
            {
              var schema = Schema.GetForTypedRow(protoType);
              var protoTargetName = targetName;
              var segs = protoFieldName.Split(':');
              if (segs.Length>1)
              {
                protoTargetName = segs[0].Trim();
                protoFieldName = segs[1].Trim();
              }
              if (protoTargetName.IsNullOrWhiteSpace()) throw new Exception("Wrong target syntax");
              if (protoFieldName.IsNullOrWhiteSpace()) throw new Exception("Wrong field syntax");

              var protoFieldDef = schema[protoFieldName];
              if (protoFieldDef==null) throw new Exception("Prototype '{0}' field '{1}' not found".Args(protoType.FullName, protoFieldName));
              var protoAttr = protoFieldDef[protoTargetName];
            
              try
              {
                StoreFlag        = storeFlag    == null? protoAttr.StoreFlag   : (StoreFlag)storeFlag     ;
                BackendName      = backendName  == null? protoAttr.BackendName : backendName   ;
                Key              = key          == null? protoAttr.Key         : (bool)key           ;
                Kind             = kind         == null? protoAttr.Kind        : (DataKind)kind          ;
                Required         = required     == null? protoAttr.Required    : (bool)required      ;
                Visible          = visible      == null? protoAttr.Visible     : (bool)visible       ;
                Min              = min          == null? protoAttr.Min         : min           ;
                Max              = max          == null? protoAttr.Max         : max           ;
                Default          = dflt         == null? protoAttr.Default     : dflt          ;
                MinLength        = minLength    == null? protoAttr.MinLength   : (int)minLength     ;
                MaxLength        = maxLength    == null? protoAttr.MaxLength   : (int)maxLength     ;
                CharCase         = charCase     == null? protoAttr.CharCase    : (CharCase)charCase      ;
                ValueList        = valueList    == null? protoAttr.ValueList   : valueList     ;
                Description      = description  == null? protoAttr.Description : description   ;
                NonUI            = nonUI        == null? protoAttr.NonUI       : (bool)nonUI         ;
                
                if (metadata.IsNullOrWhiteSpace())
                 m_MetadataContent = protoAttr.m_MetadataContent;
                else
                if (protoAttr.m_MetadataContent.IsNullOrWhiteSpace()) m_MetadataContent = metadata;
                else
                {
                  var conf1 = ParseMetadataContent(protoAttr.m_MetadataContent);
                  var conf2 = ParseMetadataContent(metadata);
                  
                  var merged = new LaconicConfiguration();
                  merged.CreateFromMerge(conf1, conf2);
                  m_MetadataContent = merged.SaveToString();
                }
              }
              catch(Exception err)
              {
                throw new Exception("Invalid assignment of prototype override value: " + err.ToMessageWithType());
              }
            }
            catch(Exception error)
            {
              throw new CRUDException(StringConsts.CRUD_FIELD_ATTR_PROTOTYPE_CTOR_ERROR.Args(error.Message));
            }

        }
Exemplo n.º 8
0
        public void VarsLoopIfElseCall()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(src1);
              var result = new NFX.Environment.LaconicConfiguration();

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

              var got =  result.SaveToString();
              Console.WriteLine( got );
              Assert.AreEqual(expected1, got);
        }
Exemplo n.º 9
0
        public void SectionNameWithVar()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(
            @"
            root
            {
               i=0
               _loop=$(/$i)<10
               {
               section_$(/$i) {}
               _set{path=/$i to=$(/$i)+1}
               }
            }
            ");
              var result = new NFX.Environment.LaconicConfiguration();

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

              var got =  result.SaveToString();
              Console.WriteLine( got );

              Assert.AreEqual("section_0", result.Root[0].Name);
              Assert.AreEqual("section_9", result.Root[9].Name);
              Assert.IsFalse( result.Root[10].Exists);
        }
Exemplo n.º 10
0
        public void RSchema()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString( rschema );
              var result = new NFX.Environment.LaconicConfiguration();

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

              var got =  result.SaveToString();
              Console.WriteLine( got );
              Assert.AreEqual(rschemaExpected, got);
        }
Exemplo n.º 11
0
        public void LoopWithRealArithmetic()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(
            @"
            root
            {
               i=0
               _loop='$(/$i)<=1.2'
               {
               section_$(/$i) {}
               _set{path=/$i to=$(/$i)+0.2}
               }
            }
            ");
              var result = new NFX.Environment.LaconicConfiguration();

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

              var got =  result.SaveToString();
              Console.WriteLine( got );

              Assert.AreEqual("section_0", result.Root[0].Name);
              Assert.AreEqual("section_0.2", result.Root[1].Name);
              Assert.AreEqual("section_0.4", result.Root[2].Name);
              Assert.AreEqual("section_0.6", result.Root[3].Name);
              Assert.AreEqual("section_0.8", result.Root[4].Name);
              Assert.AreEqual("section_1", result.Root[5].Name);
              Assert.AreEqual("section_1.2", result.Root[6].Name);
              Assert.IsFalse( result.Root[7].Exists);
        }
Exemplo n.º 12
0
        public void ExprEval1_TernaryIfWithMixingTypes()
        {
            var src = NFX.Environment.LaconicConfiguration.CreateFromString(
            @"
            root
            {
               a=12
               b=true

               var1=0{script-only=true}
               var2=175.4{script-only=true}
               var3=true{script-only=true}

               _block
               {
               _set{ path=/var1 to='((?$(/var3);$(/var2);-10)+100)+kozel' }
               RESULT=$(/var1){}
               }
            }
            ");
              var result = new NFX.Environment.LaconicConfiguration();

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

              var got =  result.SaveToString();
              Console.WriteLine( got );

              Assert.AreEqual("275.4kozel", result.Root["RESULT"].Value);
        }
Exemplo n.º 13
0
Arquivo: Laconic.cs Projeto: yhhno/nfx
        public void SaveToString()
        {
            var conf = new LaconicConfiguration();
              conf.Create("very-root");
              conf.Root.AddChildNode("childSection1").AddAttributeNode("name", "Alex");
              conf.Root.AddChildNode("child2").AddAttributeNode("name", "Boris");
              conf.Root["child2"].Value = "Muxa";

              var child3 = conf.Root.AddChildNode("child3");
              child3.AddAttributeNode("atr with space", 1);
              child3.AddAttributeNode("atr2", "val with space");
              child3.AddAttributeNode("atr{3}", null);
              child3.AddAttributeNode("atr=4", null);

              child3.AddAttributeNode("atr5", "this goes on \n\r new\\next line");

              child3.AddChildNode("child3.1");
              child3.AddChildNode("child3.2").AddChildNode("child3.2.1");
              child3.AddChildNode("child3.3");

              var txt = conf.SaveToString(LaconfigWritingOptions.PrettyPrint);
              Console.WriteLine(txt);
              Assert.AreEqual(
            @"very-root
            {
              childSection1
              {
            name=Alex
              }
              child2=Muxa
              {
            name=Boris
              }
              child3
              {
            ""atr with space""=1
            atr2=""val with space""
            ""atr{3}""=''
            ""atr=4""=''
            atr5=""this goes on \n\r new\\next line""
            child3.1
            {
            }
            child3.2
            {
              child3.2.1
              {
              }
            }
            child3.3
            {
            }
              }
            }", txt);

            txt = conf.SaveToString(LaconfigWritingOptions.Compact);

            Console.WriteLine(txt);

            Assert.AreEqual(
             @"very-root{childSection1{name=Alex}child2=Muxa{name=Boris}child3{""atr with space""=1 atr2=""val with space"" ""atr{3}""='' ""atr=4""='' atr5=""this goes on \n\r new\\next line"" child3.1{}child3.2{child3.2.1{}}child3.3{}}}",
               txt);
        }
Exemplo n.º 14
0
Arquivo: Laconic.cs Projeto: yhhno/nfx
        public void SaveToPrettyStringThenReadBack()
        {
            var conf = new LaconicConfiguration();
              conf.Create("very-root");
              conf.Root.AddChildNode("childSection1").AddAttributeNode("name", "Alex");
              conf.Root.AddChildNode("child2").AddAttributeNode("name", "Boris");
              conf.Root["child2"].Value = "Muxa";

              var child3 = conf.Root.AddChildNode("child3");
              child3.AddAttributeNode("atr with space", 1);
              child3.AddAttributeNode("atr2", "val with space");
              child3.AddAttributeNode("atr{3}", null);
              child3.AddAttributeNode("atr=4", null);

              child3.AddAttributeNode("atr5", "this goes on \n\r new\\next line");

              child3.AddChildNode("child3.1");
              child3.AddChildNode("child3.2").AddChildNode("child3.2.1");
              child3.AddChildNode("child3.3");

              var txt =  conf.SaveToString(LaconfigWritingOptions.PrettyPrint);

              var conf2 = LaconicConfiguration.CreateFromString(txt);

              Assert.IsTrue(conf2.Root["childSection1"].Exists);
              Assert.IsTrue(conf2.Root["child3"].AttrByName("atr with space").Exists);
              Assert.IsTrue(conf2.Root.Navigate("childSection1/$name").Exists);
              Assert.IsTrue(conf2.Root.Navigate("child2/$name").Exists);
              Assert.IsTrue(conf2.Root.Navigate("child3/$atr{3}").Exists);
              Assert.IsTrue(conf2.Root.Navigate("child3/child3.2/child3.2.1").Exists);

              Assert.AreEqual("Muxa", conf2.Root.Navigate("child2").Value);
              Assert.AreEqual("1", conf2.Root.Navigate("child3/$atr with space").Value);
              Assert.AreEqual("val with space", conf2.Root.Navigate("child3/$atr2").Value);
              Assert.IsTrue( conf2.Root.Navigate("child3/$atr=4").Value.IsNullOrWhiteSpace() );
        }
Exemplo n.º 15
0
 private void btnScripting_Click(object sender, EventArgs e)
 {
     try
     {
         var src = LaconicConfiguration.CreateFromString(this.sourceScripting.Text);
         var res = new LaconicConfiguration();
         var runner = new ScriptRunner();
         runner.TimeoutMs = 500; // for slow computers may be increased
         runner.Execute(src, res);
         this.resultScripting.Text = res.SaveToString();
     }
     catch (Exception ex)
     {
         this.resultScripting.Text = ex.ToMessageWithType();
     }
 }