コード例 #1
0
        public void TestDropDoesNotOutputItself()
        {
            string output = Template.Parse(" {{ product }} ")
                            .Render(Hash.FromAnonymousObject(new { product = new ProductDrop() }));

            Assert.AreEqual("  ", output);
        }
コード例 #2
0
        public void TestNestedContextDrop()
        {
            string output = Template.Parse(" {{ product.context.foo }} ")
                            .Render(Hash.FromAnonymousObject(new { product = new ProductDrop(), foo = "monkey" }));

            Assert.AreEqual(" monkey ", output);
        }
コード例 #3
0
        public override void Render(Context context, TextWriter result)
        {
            DotLiquid.Hash hash = context[_Parts[0]] as DotLiquid.Hash;

            if (hash == null)
            {
                return;
            }

            List <GenParameter> list = hash[_Parts[1]] as List <GenParameter>;

            if (list == null)
            {
                return;
            }

            bool first = true;

            foreach (var p in list)
            {
                if (!first)
                {
                    result.Write(", ");
                }

                result.Write("{0} _{1}", p.ManagedType, p.Name);
                first = false;
            }
        }
コード例 #4
0
        public void TestProtected()
        {
            string output = Template.Parse(" {{ product.call_me_not }} ")
                            .Render(Hash.FromAnonymousObject(new { product = new ProductDrop() }));

            Assert.AreEqual("  ", output);
        }
コード例 #5
0
        public void TestTextArrayDrop()
        {
            string output = Template.Parse("{% for text in product.texts.array %} {{text}} {% endfor %}")
                            .Render(Hash.FromAnonymousObject(new { product = new ProductDrop() }));

            Assert.AreEqual(" text1  text2 ", output);
        }
コード例 #6
0
        public void TestContextDrop()
        {
            string output = Template.Parse(" {{ context.bar }} ")
                            .Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), bar = "carrot" }));

            Assert.AreEqual(" carrot ", output);
        }
コード例 #7
0
        public void TestTextDrop2()
        {
            string output = Template.Parse(" {{ product.catchall.unknown }} ")
                            .Render(Hash.FromAnonymousObject(new { product = new ProductDrop() }));

            Assert.AreEqual(" method: unknown ", output);
        }
コード例 #8
0
        public void TestTextDrop()
        {
            string output = Template.Parse(" {{ product.texts.text }} ")
                            .Render(Hash.FromAnonymousObject(new { product = new ProductDrop() }));

            Assert.AreEqual(" text1 ", output);
        }
コード例 #9
0
        public void Mytest()
        {
            string output = Template.Parse(" {{ object.any.name }} ")
                            .Render(Hash.FromAnonymousObject(new { @object = new ObjectDrop() }));

            Console.Write(output);
        }
コード例 #10
0
        public override void Render(Context context, TextWriter result)
        {
            DotLiquid.Hash hash = context[_Parts[0]] as DotLiquid.Hash;

            if (hash == null)
            {
                return;
            }
        }
コード例 #11
0
        public void TestNestedObj()
        {
            Template template = Template.Parse("{{ value.nested.c }}");

            Assert.AreEqual("test", template.Render(Hash.FromAnonymousObject(new
            {
                value = new { name = "hello", test = "test", nested = new { c = "test" } }
            })));
        }
コード例 #12
0
        public override void Render(Context context, TextWriter result)
        {
            DotLiquid.Hash hash = context[_Parts[0]] as DotLiquid.Hash;

            if (hash == null)
            {
                return;
            }

            List <GenParameter> list = hash[_Parts[1]] as List <GenParameter>;

            if (list == null)
            {
                return;
            }

            bool first = true;

            foreach (var p in list)
            {
                if (!first)
                {
                    result.Write(", ");
                }

                if (IsNativeToManaged || IsNativeInternal)
                {
                    if (p.Type == typeof(String))
                    {
                        result.Write("const char* _sz{0}Buff, size_t _n{0}Size", p.Name);
                    }
                    else
                    {
                        result.Write("{0} _{1}", p.NativeType, p.Name);
                    }
                }
                else if (IsNativeExternal)
                {
                    if (p.Type.IsClass && p.Type != typeof(String))
                    {
                        result.Write("C{0} &_{1}", p.NativeType.Replace("I*", ""), p.Name);
                    }
                    else
                    {
                        result.Write("{0} _{1}", p.NativeType, p.Name);
                    }
                }
                else
                {
                    result.Write("{0} _{1}", p.NativeType, p.Name);
                }

                first = false;
            }
        }
コード例 #13
0
        public void TestDropWithFilters()
        {
            string output = Template.Parse(" {{ product | product_text }} ")
                            .Render(new RenderParameters
            {
                LocalVariables = Hash.FromAnonymousObject(new { product = new ProductDrop() }),
                Filters        = new[] { typeof(ProductFilter) }
            });

            Assert.AreEqual(" text1 ", output);
        }
コード例 #14
0
        public void TestJobjectToDotLiquid()
        {
            Template template = Template.Parse("{{ value.name }}");

            Assert.AreEqual("salam", template.Render(Hash.FromAnonymousObject(new
            {
                value = JObject.FromObject(new Boy()
                {
                    Age = 10, Name = "salam"
                }).ToObject <Boy>()
            })));
        }
コード例 #15
0
 public void Render(FileInfo templateFile, FileInfo outputFile, Hash data)
 {
     using (var template = new ExcelPackage(templateFile))
     {
         using (var output = new ExcelPackage(outputFile, templateFile))
         {
             for (int i = 1; i <= template.Workbook.Worksheets.Count; i++)
             {
                 var templateSheet = template.Workbook.Worksheets[i];
                 var outputSheet   = output.Workbook.Worksheets[i];
                 var parser        = new ExcelTemplateParser(templateSheet, outputSheet, data);
                 parser.Render();
             }
             output.Save();
         }
     }
 }
コード例 #16
0
    public static void Prepare()
    {
        compile = DotLiquid.Template.Parse(template);
        List <object> rows = new List <object>();

        for (int i = 0; i < 100; i++)
        {
            rows.Add(new Dictionary <string, object> {
                { "ID", i },
                { "Message", string.Format("message {0}", i) },
                { "Print", i % 2 == 0 },
            });
        }
        hash = DotLiquid.Hash.FromDictionary(new Dictionary <string, object> {
            { "rows", rows }
        });
    }
コード例 #17
0
ファイル: Program.cs プロジェクト: AlexBroecker/WIP_PC
    public static void Main()
    {
        try
        {
            // preparation for use with Fody.Costura:
            DotLiquid.Hash h = new DotLiquid.Hash();
            Nancy.ViewEngines.DotLiquid.DotLiquidRegistrations r = new Nancy.ViewEngines.DotLiquid.DotLiquidRegistrations();

            Nancy.Json.JsonSettings.MaxJsonLength = Int32.MaxValue;

            string cwd = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
            System.IO.Directory.SetCurrentDirectory(cwd ?? ".");

            log.InfoFormat("{0} started.", Environment.GetCommandLineArgs()[0]);
        }
        catch (Exception)
        {
        }

        HostFactory.Run(x =>
        {
            var log4net_config = new System.IO.FileInfo("log4net.xml");
            log4net.Config.XmlConfigurator.ConfigureAndWatch(log4net_config);
            BauerLib.log4netAdoProviderHelper.ConfigureConnectionStringToAllLoggers();
            BauerLib.MemoryAppenderWithEvents.RemoveAppender("HttpAppender"); // prevent recursion
            BauerLib.MemoryAppenderWithEvents.AddAppenderToAllLoggersEvent(HandleLogEvent);

            //x.UseLog4Net();
            x.RunAsLocalSystem();
            x.SetDescription("Bauer Logistics Site redirect");
            x.SetDisplayName("WIP Redirect");
            x.SetServiceName("WIP Redirect");

            x.Service <BauerWIPService>(s =>
            {
                s.ConstructUsing(name => new BauerWIPService());
                s.WhenStarted(tc => { tc.Start(); /*gel_plc_status_timer.Start();*/ });
                s.WhenStopped(tc => { tc.Stop(); /*gel_plc_status_timer.Stop();*/ });
            });
        });
    }
コード例 #18
0
 public void TestAccessContextFromDrop()
 {
     Assert.AreEqual("123", Template.Parse("{% for a in dummy %}{{ context.loop_pos }}{% endfor %}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), dummy = new[] { 1, 2, 3 } })));
 }
コード例 #19
0
        public override void Render(Context context, TextWriter result)
        {
            DotLiquid.Hash hash = context[_Parts[0]] as DotLiquid.Hash;

            if (hash == null)
            {
                return;
            }

            List <GenParameter> list = hash[_Parts[1]] as List <GenParameter>;

            if (list == null)
            {
                return;
            }

            bool first = true;

            foreach (var p in list)
            {
                if (!first)
                {
                    result.Write(", ");
                }

                first = false;

                if (IsNativeToNative)
                {
                    if (p.Type == typeof(String))
                    {
                        result.Write("_{0}.c_str(), _{0}.size()", p.Name);
                    }
                    else
                    {
                        result.Write("_{0}", p.Name);
                    }
                }
                else if (IsInternalToExternalSetup)
                {
                    first = true;

                    if (p.Type.IsClass && p.Type != typeof(String))
                    {
                        result.WriteLine("C{0} ref{1}(_{1});", p.NativeType.Replace("I*", ""), p.Name);
                    }
                }
                else if (IsInternalToExternal)
                {
                    if (p.Type == typeof(String))
                    {
                        result.Write("std::string(_sz{0}Buff, _n{0}Size)", p.Name);
                    }
                    else if (p.Type.IsClass)
                    {
                        result.Write("ref{0}", p.Name);
                    }
                    else
                    {
                        result.Write("_{0}", p.Name);
                    }
                }
                else if (IsManagedToNativeSetup)
                {
                    if (p.Type == typeof(String))
                    {
                        result.WriteLine("std::string sz{0} = {1};", p.Name, p.CallName);
                    }

                    first = true;
                }
                else if (IsManagedToNative)
                {
                    if (p.Type == typeof(String))
                    {
                        result.Write("sz{0}.c_str(), sz{0}.size()", p.Name);
                    }
                    else
                    {
                        result.Write(p.CallName);
                    }
                }
                else
                {
                    result.Write(p.CallName);
                }
            }
        }
コード例 #20
0
 public void TestScopeThroughProc()
 {
     Assert.AreEqual("1", Template.Parse("{{ s }}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), s = (Proc)(c => c["context.scopes"]) })));
     Assert.AreEqual("2", Template.Parse("{%for i in dummy%}{{ s }}{%endfor%}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), s = (Proc)(c => c["context.scopes"]), dummy = new[] { 1 } })));
     Assert.AreEqual("3", Template.Parse("{%for i in dummy%}{%for i in dummy%}{{ s }}{%endfor%}{%endfor%}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), s = (Proc)(c => c["context.scopes"]), dummy = new[] { 1 } })));
 }
コード例 #21
0
 public void TestScopeWithAssigns()
 {
     Assert.AreEqual("variable", Template.Parse("{% assign a = 'variable'%}{{a}}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop() })));
     Assert.AreEqual("variable", Template.Parse("{% assign a = 'variable'%}{%for i in dummy%}{{a}}{%endfor%}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), dummy = new[] { 1 } })));
     Assert.AreEqual("test", Template.Parse("{% assign header_gif = \"test\"%}{{header_gif}}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop() })));
     Assert.AreEqual("test", Template.Parse("{% assign header_gif = 'test'%}{{header_gif}}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop() })));
 }
コード例 #22
0
 public void TestScopeFromTags()
 {
     Assert.AreEqual("1", Template.Parse("{% for i in context.scopes_as_array %}{{i}}{% endfor %}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), dummy = new[] { 1 } })));
     Assert.AreEqual("12", Template.Parse("{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), dummy = new[] { 1 } })));
     Assert.AreEqual("123", Template.Parse("{%for a in dummy%}{%for a in dummy%}{% for i in context.scopes_as_array %}{{i}}{% endfor %}{% endfor %}{% endfor %}").Render(Hash.FromAnonymousObject(new { context = new ContextDrop(), dummy = new[] { 1 } })));
 }
コード例 #23
0
 public void TestEnumerableDropSize()
 {
     Assert.AreEqual("3", Template.Parse("{{collection.size}}").Render(Hash.FromAnonymousObject(new { collection = new EnumerableDrop() })));
 }
コード例 #24
0
        public void TestRubyNamingConventionPrintsHelpfulErrorIfMissingPropertyWouldMatchCSharpNamingConvention()
        {
            INamingConvention savedNamingConvention = Template.NamingConvention;

            Template.NamingConvention = new RubyNamingConvention();
            Template template = Template.Parse("{{ value.ProductID }}");

            Assert.AreEqual("Missing property. Did you mean 'product_id'?", template.Render(Hash.FromAnonymousObject(new
            {
                value = new CamelCaseDrop()
            })));
            Template.NamingConvention = savedNamingConvention;
        }
コード例 #25
0
 public void TestNullCatchAll()
 {
     Assert.AreEqual("", Template.Parse("{{ nulldrop.a_method }}").Render(Hash.FromAnonymousObject(new { nulldrop = new NullDrop() })));
 }
コード例 #26
0
ファイル: Program.cs プロジェクト: AlexBroecker/WIP_PC
    public static void Main()
    {
        try
        {
            // preparation for use with Fody.Costura:
            DotLiquid.Hash h = new DotLiquid.Hash();
            Nancy.ViewEngines.DotLiquid.DotLiquidRegistrations r = new Nancy.ViewEngines.DotLiquid.DotLiquidRegistrations();

            Nancy.Json.JsonSettings.MaxJsonLength = Int32.MaxValue;


            string cwd = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
            System.IO.Directory.SetCurrentDirectory(cwd ?? ".");

            log.InfoFormat("{0} started.", Environment.GetCommandLineArgs()[0]);
        }
        catch (Exception)
        {
        }

        ip_address = Registry.PlcAddress;


        //var gel_plc_status_timer = new System.Timers.Timer(5000);
        //gel_plc_status_timer.Elapsed += (s, e) =>
        //{
        //    var plc = 0; // BauerPLC.SingleCommands.com(Program.ip_address);
        //    int stat = 0; // BauerPLC.SingleCommands.GetStatusWord(plc);
        //    int cnt = 1; // BauerPLC.SingleCommands.GetCounter(plc);
        //    lock (StatusController.status_lock)
        //    {
        //        if (stat > 0 && cnt>0)
        //        {
        //            StatusController.last_status = stat;
        //            BauerWIPService.RfzCounter = cnt;
        //            StatusController.last_status_get = DateTime.Now;
        //        }
        //    }
        //};


        HostFactory.Run(x =>
        {
            try
            {
                var log4net_config = new System.IO.FileInfo("log4net.xml");
                log4net.Config.XmlConfigurator.ConfigureAndWatch(log4net_config);

                BauerLib.log4netAdoProviderHelper.ConfigureConnectionStringToAllLoggers();
                BauerLib.MemoryAppenderWithEvents.RemoveAppender("HttpAppender"); // prevent recursion
                BauerLib.MemoryAppenderWithEvents.AddAppenderToAllLoggersEvent(HandleLogEvent);

                log4net.LogManager.GetRepository().ConfigurationChanged += (s, e) =>
                {
                    try
                    {
                        BauerLib.log4netAdoProviderHelper.ConfigureConnectionStringToAllLoggers();
                        BauerLib.MemoryAppenderWithEvents.RemoveAppender("HttpAppender"); // prevent recursion
                        BauerLib.MemoryAppenderWithEvents.AddAppenderToAllLoggersEvent(HandleLogEvent);
                    }
                    catch
                    {
                    }
                };
            }
            catch
            {
            }

            x.UseLog4Net();
            x.RunAsLocalSystem();
            x.SetDescription("Bauer Logistics WIP Storage Site");
            x.SetDisplayName("WIP Site");
            x.SetServiceName("WIP Site");

            x.Service <BauerWIPService>(s =>
            {
                s.ConstructUsing(name => new BauerWIPService());
                s.WhenStarted(tc => { tc.Start(); /*gel_plc_status_timer.Start();*/ });
                s.WhenStopped(tc => { tc.Stop(); /*gel_plc_status_timer.Stop();*/ });
            });
        });
    }
コード例 #27
0
 public void TestEnumerableDrop()
 {
     Assert.AreEqual("123", Template.Parse("{% for c in collection %}{{c}}{% endfor %}").Render(Hash.FromAnonymousObject(new { collection = new EnumerableDrop() })));
 }