예제 #1
0
        static void Main()
        {
            //testing
            //TestExistingTemplates.Test();

            var orderModel = new Order()
                                {
                                    Name = "Bob's order",
                                    TransactionID = "10000",
                                    OrderItems = new List<OrderItem>()
                                                {
                                                    new OrderItem
                                                    {
                                                        ProductTypeName = "MobileRecharge",
                                                        Detail1 = "Mobile Detail 1",
                                                        Detail2 = "Mobile Detail 2",
                                                        Amount = new Money{Value = 10.4, Currency = "USD"},
                                                        PromotionalDiscount = "100 USD"
                                                    },
                                                    new OrderItem
                                                    {
                                                        ProductTypeName = "ILDTopup",
                                                        Detail1 = "ILD Detail 1",
                                                        Detail2 = "ILD Detail 2",
                                                    },
                                                    new OrderItem
                                                    {
                                                        ProductTypeName = "Nauta",
                                                        Detail1 = "Nauta Detail 1",
                                                        Detail2 = "Nauta Detail 2"
                                                    }
                                                }
                                };

            var dict = new Dictionary<string, object>
                        {
                            {"Value1", "Value1"}
                        };

            ITemplate template = new HtmlTemplate();

            FormatCompiler compiler = new FormatCompiler();

            var templateParser = new MustacheTemplateConverter();

            var convertDingConditionalToMustache = templateParser.ConvertDingConditionalToMustache(template.Template);
            Generator generator = compiler.Compile(convertDingConditionalToMustache);
            generator.KeyNotFound += (obj, args) =>
                                    {
                                        args.Substitute = string.Empty;
                                        args.Handled = true;
                                    };

            string result = generator.Render(MyConvert.DictionaryToDynamic(dict));

            Console.ReadKey();
        }
예제 #2
0
        public static void Test()
        {
            var files = Directory.GetFiles("ToTest");
            var templateParser = new MustacheTemplateConverter();

            Console.WriteLine("Number of files {0}", files.Length);

            var i = 0;
            foreach (var file in files)
            {
                //var xfile = "ToTest\\DotCom_Ding_IldTopupSuccessfulAfterRiskAccepted_en-us_2015-10-16_11-35.json";

                Console.WriteLine("Testing {0}", file);

                var content = File.ReadAllText(file);

                var xx = new Regex(Regex.Escape("[?")).Matches(content).Count;

                var temp = templateParser.ConvertDingConditionalToMustache(content);

                if (temp.Contains("[?") || temp.Contains("?]"))
                    throw new Exception("Conversion failed");

                Console.WriteLine("Tested {0} files", i++);

            }

            Console.WriteLine("Tested all files");
        }