Ejemplo n.º 1
0
        public void TestClear()
        {
            StringTemplate st = "[#{item}]";

            st.Assign("item", "v");
            Assert.AreEqual("[v]", st.Render());

            st.Clear();
            Assert.AreEqual("[#{item}]", st.Render(true));
        }
Ejemplo n.º 2
0
        public void NameResetBuild()
        {
            StringTemplate st = "Let name = #{name};";

            st.Assign("name", "R");
            string result1 = st.Render();

            Assert.AreEqual("Let name = R;", result1);

            st.Assign("name", "X");
            string result2 = st.Render();

            Assert.AreEqual("Let name = X;", result2);
        }
Ejemplo n.º 3
0
        static void Basic()
        {
            StringTemplate stringTemplate = new StringTemplate("hello <data>");
            stringTemplate.Add("data", "world");

            Console.WriteLine(stringTemplate.Render());
        }
Ejemplo n.º 4
0
        public void EnsureFluentConfigurationRenders(object input, StringTemplateConfiguration cfg, string template, string expected)
        {
            Assert.Equal(expected, StringTemplate.Render(template, input, cfg));
            dynamic dyn = input.ToDynamic();

            Assert.Equal(expected, StringTemplate.Render(template, dyn, cfg));
        }
Ejemplo n.º 5
0
        public void TestEscape()
        {
            StringTemplate st = "##{test}#{case}";

            st.Assign("case", "1");
            Assert.AreEqual("#{test}1", st.Render());
        }
Ejemplo n.º 6
0
        public void EnsureIfTestRenders(object input, string template, string expected)
        {
            Assert.Equal(expected, StringTemplate.Render(template, input));
            dynamic dyn = input.ToDynamic();

            Assert.Equal(expected, StringTemplate.Render(template, dyn));
        }
Ejemplo n.º 7
0
        string WriteTextures(ShaderOutputContext ctx, TemplateGroup group)
        {
            List <Texture> textures = ctx.Textures;

            if (textures.Count == 0)
            {
                return("");
            }

            StringBuilder result = new StringBuilder();

            result.Append("///////////////// TEXTURES /////////////////// ");
            result.Append('\n');

            foreach (var texture in textures)
            {
                StringTemplate textureTemplate = group.GetInstanceOf("tex2d");
                textureTemplate.Add("name", texture.Name);
                textureTemplate.Add("reg", texture.Bindpoint.Reg);
                textureTemplate.Add("space", texture.Bindpoint.Space);
                result.Append(textureTemplate.Render() + '\n');
            }

            result.Append('\n');
            result.Append('\n');

            return(result.ToString());
        }
Ejemplo n.º 8
0
        string WriteSamplers(ShaderOutputContext ctx, TemplateGroup group)
        {
            List <Sampler> samplers = ctx.Samplers;

            if (samplers.Count == 0)
            {
                return("");
            }

            StringBuilder result = new StringBuilder();

            result.Append("///////////////// SAMPLERS /////////////////// ");
            result.Append('\n');

            foreach (var sampler in samplers)
            {
                StringTemplate samplerTemplate = group.GetInstanceOf("sampler");
                samplerTemplate.Add("name", sampler.Name);
                samplerTemplate.Add("reg", sampler.Bindpoint.Reg);
                samplerTemplate.Add("space", sampler.Bindpoint.Space);
                result.Append(samplerTemplate.Render() + '\n');
            }

            result.Append('\n');
            result.Append('\n');

            return(result.ToString());
        }
Ejemplo n.º 9
0
        string WriteVertexLayout(ShaderOutputContext ctx, TemplateGroup group)
        {
            VertexLayout vLayout = ctx.VertLayout;

            StringBuilder result = new StringBuilder();

            result.Append("///////////////// VERTEX LAYOUT /////////////////// ");
            result.Append('\n');

            StringBuilder members = new StringBuilder();

            foreach (var member in vLayout.Members)
            {
                StringTemplate memberTemplate = group.GetInstanceOf("vlayoutvar");
                memberTemplate.Add("type", Variable.ConvertHlslType(member.Type));
                memberTemplate.Add("name", member.Name);
                string index = "";
                if (member.Semantic == "TEXCOORD" || member.Semantic == "COLOR")
                {
                    index = member.SemanticIndex.ToString();
                }
                memberTemplate.Add("semantic", member.Semantic + index);
                members.Append(memberTemplate.Render() + '\n');
            }
            StringTemplate structTemplate = group.GetInstanceOf("struct");

            structTemplate.Add("name", "vIn");
            structTemplate.Add("members", members);
            result.Append(structTemplate.Render() + '\n' + '\n');

            result.Append('\n');
            result.Append('\n');

            return(result.ToString());
        }
Ejemplo n.º 10
0
        public void WriteFactory(string[] files)
        {
            TemplateGroup cppGroup = new Antlr4.StringTemplate.TemplateGroupFile(Program.TemplatesDir + "/factoryTemplateCpp.stg");

            StringBuilder mapping  = new StringBuilder();
            StringBuilder includes = new StringBuilder();

            foreach (var filepath in files)
            {
                string         filenameWithoutExt = Path.GetFileNameWithoutExtension(filepath);
                StringTemplate mapTemplate        = cppGroup.GetInstanceOf("shaderMap");
                mapTemplate.Add("key", filenameWithoutExt);
                mapping.Append(mapTemplate.Render() + '\n');

                StringTemplate inclTemplate = cppGroup.GetInstanceOf("include");
                inclTemplate.Add("filename", filenameWithoutExt);
                includes.Append(inclTemplate.Render() + '\n');
            }
            StringTemplate factoryCppTemplate = cppGroup.GetInstanceOf("factory");

            factoryCppTemplate.Add("includes", includes.ToString());
            factoryCppTemplate.Add("mapping", mapping.ToString());

            string filename = Program.CppOutputDir + "/KiotoShaders";

            System.IO.File.WriteAllText(filename + ".cpp", factoryCppTemplate.Render());

            TemplateGroup  hGroup           = new Antlr4.StringTemplate.TemplateGroupFile(Program.TemplatesDir + "/factoryTemplateH.stg");
            StringTemplate factoryHTemplate = hGroup.GetInstanceOf("factory");

            System.IO.File.WriteAllText(filename + ".h", factoryHTemplate.Render());
        }
Ejemplo n.º 11
0
        public void TestMissingNotAllow()
        {
            StringTemplate st = "[#{item1},#{item2}]";

            st.Assign("item1", "v1");
            string r = st.Render();
        }
Ejemplo n.º 12
0
        string WriteRootConstants(ShaderOutputContext ctx, TemplateGroup group)
        {
            List <UniformConstant> rootConstants = ctx.UniformConstants;

            if (rootConstants.Count == 0)
            {
                return("");
            }

            StringBuilder result = new StringBuilder();

            result.Append("///////////////// ROOT CONSANTS /////////////////// ");
            result.Append('\n');

            foreach (var rootConstant in rootConstants)
            {
                StringTemplate cbufferTemplate = group.GetInstanceOf("cbuffer");
                cbufferTemplate.Add("name", "cb_" + rootConstant.Name);
                string member = rootConstant.Type + " " + rootConstant.Name + ";";
                cbufferTemplate.Add("members", member);
                cbufferTemplate.Add("reg", rootConstant.Bindpoint.Reg);
                cbufferTemplate.Add("space", rootConstant.Bindpoint.Space);
                result.Append(cbufferTemplate.Render() + '\n' + '\n');
            }

            result.Append('\n');
            result.Append('\n');

            return(result.ToString());
        }
Ejemplo n.º 13
0
        public void WriteHeaders(ShaderOutputContext ctx, string filename)
        {
            TemplateGroup group = new Antlr4.StringTemplate.TemplateGroupFile(Program.TemplatesDir + "/cppTemplate.stg");

            string constantBuffers     = WriteConstantBuffers(ctx, group);
            string constantBufferNames = WriteConstantBuffersNames(ctx, group);
            string constants           = WriteRootConstants(ctx, group);
            string textureSets         = WriteTextureSets(ctx, group);
            string bindings            = WriteBindings(ctx, group);
            string vertexLayouts       = WriteVertexLayouts(ctx, group);
            string programNames        = WriteProgramNames(ctx, group);
            string structs             = WriteStructures(group, ctx.Structures);

            structs += WriteStructures(group, ctx.ConstantBuffers);

            StringTemplate headerTemplate = group.GetInstanceOf("header");

            headerTemplate.Add("name", filename);
            headerTemplate.Add("structs", structs);
            headerTemplate.Add("cbuffers", constantBuffers);
            headerTemplate.Add("cbNames", constantBufferNames);
            headerTemplate.Add("constants", constants);
            headerTemplate.Add("texSets", textureSets);
            headerTemplate.Add("shaderProgs", bindings);
            headerTemplate.Add("vertexLayout", vertexLayouts);
            headerTemplate.Add("shaderProgNames", programNames);
            headerTemplate.Add("shaderPath", "Shaders/" + filename + ".hlsl");

            string outDirHlsl  = Program.CppOutputDir + "/sInp/";
            string filenameOut = outDirHlsl + filename + ".h";

            System.IO.File.WriteAllText(filenameOut, headerTemplate.Render());
        }
        public void StringTemplateRenderWhitespaceTemplateTest()
        {
            String excepted = " ";

            target = new StringTemplate(excepted);

            Assert.AreEqual(excepted, target.Render());
        }
        public void StringTemplateRenderOneElementRepeatedTemplateTest()
        {
            target = new StringTemplate("one <test> <test>");

            target.Add("test", "two");

            Assert.AreEqual("one two two", target.Render());
        }
        public void StringTemplateRenderNoElementTemplateTest()
        {
            String excepted = "testing";

            target = new StringTemplate(excepted);

            Assert.AreEqual(excepted, target.Render());
        }
Ejemplo n.º 17
0
        static void Basic()
        {
            StringTemplate stringTemplate = new StringTemplate("hello <data>");

            stringTemplate.Add("data", "world");

            Console.WriteLine(stringTemplate.Render());
        }
        public void StringTemplateRenderEmptyTemplateTest()
        {
            String excepted = String.Empty;

            target = new StringTemplate(excepted);

            Assert.AreEqual(excepted, target.Render());
        }
        public void StringTemplateRenderNoDataForElementTest()
        {
            target = new StringTemplate("<test> two two");

            target.Add("testing", "one");

            Assert.AreEqual("<test> two two", target.Render());
        }
        public void StringTemplateRenderCaseInsensitiveTest2()
        {
            target = new StringTemplate("<TEST> two two");

            target.Add("test", "one");

            Assert.AreEqual("one two two", target.Render());
        }
Ejemplo n.º 21
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var variableValues = new Dictionary <string, object>
            {
                ["LogLevel"]      = logLevel,
                ["LogLevelSmall"] = GetLogLevelString(logLevel),
                ["DateTime"]      = DateTime.Now.ToString(_config.TimeStampFormat),
                ["EventId"]       = eventId.Id,
                ["Name"]          = _name,
                ["State"]         = formatter(state, exception),
                ["Exception"]     = exception?.ToString() ?? string.Empty
            };

            string message = StringTemplate.Render(
                logLevel < _config.LogToStandardErrorThreshold ? _config.LogFormat : _config.LogErrorFormat,
                variableValues);


            if (_config.Async)
            {
                _telegramMessageService.QueueMessage(new LogMessageEntry
                {
                    ChatId  = _config.ChatId,
                    Message = message.ToString()
                });

                if (logLevel >= _config.LogToStandardErrorThreshold && _config.LogErrorChatId != 0)
                {
                    _telegramMessageService.QueueMessage(new LogMessageEntry
                    {
                        ChatId  = _config.LogErrorChatId,
                        Message = message.ToString()
                    });
                }
            }
            else
            {
                _telegramMessageService.SendMessage(new LogMessageEntry
                {
                    ChatId  = _config.ChatId,
                    Message = message.ToString()
                }).GetAwaiter().GetResult();

                if (logLevel >= _config.LogToStandardErrorThreshold && _config.LogErrorChatId != 0)
                {
                    _telegramMessageService.SendMessage(new LogMessageEntry
                    {
                        ChatId  = _config.LogErrorChatId,
                        Message = message.ToString()
                    }).GetAwaiter().GetResult();
                }
            }
        }
        public void StringTemplateRenderExtraElementDataTest()
        {
            target = new StringTemplate("<test> two two");

            target.Add("test", "one");
            target.Add("testing", "two");

            Assert.AreEqual("one two two", target.Render());
        }
Ejemplo n.º 23
0
        public void NormalBuild()
        {
            StringTemplate st = "Let name = #{name};";

            st.Assign("name", "R");
            string result = st.Render();

            Assert.AreEqual("Let name = R;", result);
        }
Ejemplo n.º 24
0
        public void TestMissingAllow()
        {
            StringTemplate st = "[#{item1},#{item2}]";

            st.Assign("item1", "v1");
            string r = st.Render(true);

            Assert.AreEqual("[v1,#{item2}]", r);
        }
        public void StringTemplateRenderTwoElementTemplateTest()
        {
            target = new StringTemplate("<test1> <test2> two");

            target.Add("test1", "one");
            target.Add("test2", "two");

            Assert.AreEqual("one two two", target.Render());
        }
Ejemplo n.º 26
0
        public void EnsureDefaultConfigurationRenders(object input, string template, string expected, bool isDynamic)
        {
            var props = StringTemplate.BuildPropertyDictionary(input);

            Assert.Equal(expected, StringTemplate.Render(template, input));
            if (isDynamic)
            {
                var dyn      = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(input));
                var rendered = StringTemplate.Render(template, dyn);
                Assert.Equal(expected, rendered);
            }
        }
Ejemplo n.º 27
0
        string WriteConstantBuffersNames(ShaderOutputContext ctx, TemplateGroup group)
        {
            StringBuilder         res = new StringBuilder();
            List <ConstantBuffer> cbs = ctx.ConstantBuffers;

            foreach (var cb in cbs)
            {
                StringTemplate cBufferTemplate = group.GetInstanceOf("cbName");
                cBufferTemplate.Add("name", cb.Name);
                res.Append(cBufferTemplate.Render() + '\n');
            }
            return(res.ToString());
        }
        public void StringTemplatStringAngleBracketsTest()
        {
            target = new StringTemplate("<hello> <world>");
            target.Add("hello", "hello");
            target.Add("<world>", "world");

            Assert.AreEqual(2, target.ElementData.Count);
            Assert.IsTrue(target.ElementData.ContainsKey("hello"));
            Assert.AreEqual("hello", target.ElementData["hello"]);
            Assert.IsTrue(target.ElementData.ContainsKey("world"));
            Assert.AreEqual("world", target.ElementData["world"]);

            Assert.AreEqual("hello world", target.Render());
        }
Ejemplo n.º 29
0
        string WriteProgramNames(ShaderOutputContext ctx, TemplateGroup group)
        {
            StringBuilder        res         = new StringBuilder();
            List <ShaderBinding> shaderBinds = ctx.ShaderBinding.Bindings;

            for (int i = 0; i < shaderBinds.Count; ++i)
            {
                StringTemplate nameTemplate = group.GetInstanceOf("programNamePair");
                nameTemplate.Add("shaderProg", m_shaderStagesToKioto[shaderBinds[i].ShaderType]);
                nameTemplate.Add("name", shaderBinds[i].EntryPointName);
                res.Append(nameTemplate.Render() + '\n');
            }
            return(res.ToString());
        }
Ejemplo n.º 30
0
        string WriteRootConstants(ShaderOutputContext ctx, TemplateGroup group)
        {
            StringBuilder          res    = new StringBuilder();
            List <UniformConstant> consts = ctx.UniformConstants;

            foreach (var c in consts)
            {
                StringTemplate cBufferTemplate = group.GetInstanceOf("uniformConstant");
                cBufferTemplate.Add("name", c.Name);
                cBufferTemplate.Add("reg", c.Bindpoint.Reg.ToString());
                cBufferTemplate.Add("space", c.Bindpoint.Space.ToString());
                res.Append(cBufferTemplate.Render() + '\n');
            }
            return(res.ToString());
        }
Ejemplo n.º 31
0
        public void Generate(string database, string table, string className, string rutaDestino, string rutaTemplate)
        {
            StreamReader sr       = new StreamReader(rutaTemplate);
            string       template = sr.ReadToEnd();

            sr.Close();
            TemplateContent content      = GenerateContent(database, table, className);
            string          renderedText = StringTemplate.Render(template, content);

            // Write the string array to a new file
            using (StreamWriter outputFile = new StreamWriter(rutaDestino))
            {
                outputFile.Write(renderedText);
            }
        }
        public void StringTemplatStringAngleBracketsTest()
        {
            target = new StringTemplate("<hello> <world>");
            target.Add("hello", "hello");
            target.Add("<world>", "world");

            Assert.AreEqual(2, target.ElementData.Count);
            Assert.IsTrue(target.ElementData.ContainsKey("hello"));
            Assert.AreEqual("hello", target.ElementData["hello"]);
            Assert.IsTrue(target.ElementData.ContainsKey("world"));
            Assert.AreEqual("world", target.ElementData["world"]);

            Assert.AreEqual("hello world", target.Render());
        }
        public void StringTemplateRenderWhitespaceTemplateTest()
        {
            String excepted = " ";

            target = new StringTemplate(excepted);

            Assert.AreEqual(excepted, target.Render());
        }
        public void StringTemplateRenderTwoElementTemplateTest()
        {
            target = new StringTemplate("<test1> <test2> two");

            target.Add("test1", "one");
            target.Add("test2", "two");

            Assert.AreEqual("one two two", target.Render());
        }
        public void StringTemplateRenderOneElementRepeatedTemplateTest()
        {
            target = new StringTemplate("one <test> <test>");

            target.Add("test", "two");

            Assert.AreEqual("one two two", target.Render());
        }
        public void StringTemplateRenderNoElementTemplateTest()
        {
            String excepted = "testing";

            target = new StringTemplate(excepted);

            Assert.AreEqual(excepted, target.Render());
        }
        public void StringTemplateRenderNoDataForElementTest()
        {
            target = new StringTemplate("<test> two two");

            target.Add("testing", "one");

            Assert.AreEqual("<test> two two", target.Render());
        }
        public void StringTemplateRenderExtraElementDataTest()
        {
            target = new StringTemplate("<test> two two");

            target.Add("test", "one");
            target.Add("testing", "two");

            Assert.AreEqual("one two two", target.Render());
        }
        public void StringTemplateRenderEmptyTemplateTest()
        {
            String excepted = String.Empty;

            target = new StringTemplate(excepted);

            Assert.AreEqual(excepted, target.Render());
        }
        public void StringTemplateRenderCaseInsensitiveTest2()
        {
            target = new StringTemplate("<TEST> two two");

            target.Add("test", "one");

            Assert.AreEqual("one two two", target.Render());
        }