Ejemplo n.º 1
0
        private void ExportMessageParser(string outputDir, MessageGroup encodeGroup, MessageGroup decodeGroup, StringContext context)
        {
            context.Add(CONTEXT_ENCODE_MESSAGE_GROUP_KEY, encodeGroup);
            context.Add(CONTEXT_DECODE_MESSAGE_GROUP_KEY, decodeGroup);

            string outputFilePath = $"{outputDir}/{context.Get<string>(CONTEXT_PLATFORM_KEY)}MessageParser{GetExtension()}";
            string outputContent  = TemplateEngine.Execute(context, exportData.parserTemplateContent, new string[] {
                typeof(MessageConfig).Assembly.Location
            });

            if (!string.IsNullOrEmpty(outputContent))
            {
                File.WriteAllText(outputFilePath, outputContent);
            }

            context.Remove(CONTEXT_ENCODE_MESSAGE_GROUP_KEY);
            context.Remove(CONTEXT_DECODE_MESSAGE_GROUP_KEY);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string templateContent =
                @"using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
<%
string spaceName = context.Get<string>(""spaceName"");
string className = context.Get<string>(""className"");
List<int> list = context.Get<List<int>>(""values"");
%>

<%+using System.Collections.Generic;%>
namespace <%=spaceName%>
{
    public class <%=className%>
    {
        public void Print()
        {
            int[] values = {<%foreach(var value in list){%><%=value%>,<%}%>};
            foreach(var value in values)
            {
                Console.WriteLine(value);
            }
        }
    }
}
";
            StringContext context = new StringContext();

            context.Add("spaceName", "Com.Test");
            context.Add("className", "TestClass");
            context.Add("values", new List <int>()
            {
                1, 2, 3, 4, 5, 6
            });

            string output = TemplateEngine.Execute(context, templateContent, null);

            File.WriteAllText("D:/t.cs", output);
        }
Ejemplo n.º 3
0
        private void ExportMessageID(string outputDir)
        {
            StringContext context = new StringContext();

            context.Add(CONTEXT_SPACE_KEY, exportData.messageConfig.Space);

            ExportMessageID(outputDir, exportData.messageConfig.C2SGroup, context);
            ExportMessageID(outputDir, exportData.messageConfig.S2CGroup, context);

            context.Clear();
        }
Ejemplo n.º 4
0
        private void ExportMessageParser(string outputDir)
        {
            StringContext context = new StringContext();

            context.Add(CONTEXT_SPACE_KEY, exportData.messageConfig.Space);

            if (exportData.platformType == OutputPlatformType.All || exportData.platformType == OutputPlatformType.Client)
            {
                context.Add(CONTEXT_PLATFORM_KEY, "Client");
                ExportMessageParser(outputDir, exportData.messageConfig.C2SGroup, exportData.messageConfig.S2CGroup, context);
                context.Remove(CONTEXT_PLATFORM_KEY);
            }

            if (exportData.platformType == OutputPlatformType.All || exportData.platformType == OutputPlatformType.Server)
            {
                context.Add(CONTEXT_PLATFORM_KEY, "Server");
                ExportMessageParser(outputDir, exportData.messageConfig.S2CGroup, exportData.messageConfig.C2SGroup, context);
                context.Remove(CONTEXT_PLATFORM_KEY);
            }

            context.Clear();
        }
Ejemplo n.º 5
0
        private void ExportMessageID(string outputDir, MessageGroup group, StringContext context)
        {
            context.Add(CONTEXT_MESSAGE_GROUP_KEY, group);

            string outputFilePath = $"{outputDir}/{group.Name}_ID{GetExtension()}";
            string outputContent  = TemplateEngine.Execute(context, exportData.idTemplateContent, new string[] {
                typeof(MessageGroup).Assembly.Location
            });

            if (!string.IsNullOrEmpty(outputContent))
            {
                File.WriteAllText(outputFilePath, outputContent);
            }

            context.Remove(CONTEXT_MESSAGE_GROUP_KEY);
        }