Beispiel #1
0
        public void Test1A()
        {
            delegateRegister register = new delegateRegister(Register);

            Test2C(register);
            Test2C(new delegateRegister(Register));
            Test2D(new delegateRegister(Register));
        }
Beispiel #2
0
        /*
         *
         ## Test2C, json objects + Global
         ##
         ##[[[Nokia], [Lumia 800], [[[16GB], [512MB], [3.7]]]], [[Nokia], [Lumia 900], [[[8
         ##GB], [512MB], [4.3]]]], [[HTC ], [Titan II], [[[16GB], [512MB], [4.7]]]]]
         ##Nokia
         ##16GB
         ##["16GB"]16gb
         ##0f098...9fba{"Phones":[
         ##{"Brand":"Nokia","Type":"Lumia 800","Specs":{"Storage":"16GB","Memory":"512MB","Screensize":"3.7"}},
         ##{"Brand":"Nokia","Type":"Lumia 900","Specs":{"Storage":"8GB","Memory":"512MB","Screensize":"4.3"}},
         ##{"Brand":"HTC ","Type":"Titan II","Specs":{"Storage":"16GB","Memory":"512MB","Screensize":"4.7"}}]}
         ##
         */


        public void Test2D(delegateRegister Register)
        {
            return;

            // Init vars
            string theTemplate = @"{{
base.phones | jpathobj "".Phones""
""\n"" 
base.phones | jpathobj "".Phones.[*]""
""\n"" 
base.phones | jpathobj "".Phones.[*].Brand""
""\n"" 
base.phonea | jpatharr "".[*].Brand""
""\n"" 
base.phones | jpathobj ""..[*].Brand""
""\n"" 
base.phones | jpathobj "".Phones.[*].Brand"" | base.select_distinct_list
}}";

            string theModel = Phone.phones;
            var    parsed   = JsonConvert.DeserializeObject <JObject>(theModel);
            var    template = Template.Parse(theTemplate);
            var    model    = new { d = parsed };

            var scriptObject = new ScriptObject();

            scriptObject.Import(model);
            Register(scriptObject);

            // Render from Template
            var context = new TemplateContext();

            context.PushGlobal(scriptObject);
            template.Render(context);
            context.PopGlobal();
            string result = context.Output.ToString();

            Console.WriteLine("\n## Test2-2D, json select");
            Console.WriteLine(result);
        }
Beispiel #3
0
        public void Test2C(delegateRegister Register)
        {
            // Init vars
            string theTemplate = @"{{ d 
""\n"" 
d[1].Brand 
""\n"" 
d[0].Specs.Storage
""\n"" 
d[0].Specs.Storage | base.down_case
""\n"" 
base.get_uuid
base.phones
}}";
// d[0] | select "".Specs.Storage""

            string theModel = Phone.phonea;
            var    parsed   = JsonConvert.DeserializeObject <JArray>(theModel);
            var    template = Template.Parse(theTemplate);
            var    model    = new { d = parsed };

            var scriptObject = new ScriptObject();

            scriptObject.Import(model);
            Register(scriptObject);

            // Render from Template
            var context = new TemplateContext();

            context.PushGlobal(scriptObject);
            template.Render(context);
            context.PopGlobal();
            string result = context.Output.ToString();

            Console.WriteLine("\n## Test2-2C, json objects + Global");
            Console.WriteLine(result);
        }