示例#1
0
        private void DoRun(IEnumerable <DbSchema.Table> tables, IEnumerable <string> files)
        {
            const string FILE_NAME_KEY = "FILE_NAME";
            var          engine        = new Engine();
            var          host          = new CustomHost();

            var basePath = OUTPUT_DIR;

            foreach (var path in files)
            {
                var content      = File.ReadAllText(path);
                var templateName = Path.GetFileName(path);
                Trace.WriteLine(Localization.Template + templateName);

                foreach (var table in tables)
                {
                    host.TemplateFile = path;
                    host.Table        = table;

                    var outputPath = GetOutputPath(table, basePath);
                    host.SetValue("OutputPath", outputPath);

                    Trace.WriteLine(String.Format(Localization.Generate_Table, host.Table.Name, templateName, outputPath));
                    var result = engine.ProcessTemplate(content, host);

                    if (string.IsNullOrWhiteSpace(result))
                    {
                        Trace.WriteLine(String.Format(Localization.Finish_Generate_Empty, host.Table.DisplayName));
                        continue;
                    }

                    var fileName = host.GetValue(FILE_NAME_KEY) as String;

                    if (string.IsNullOrWhiteSpace(fileName))
                    {
                        fileName = host.Table.DisplayName;
                    }
                    else
                    {
                        host.SetValue(FILE_NAME_KEY, null);
                    }

                    var targetPath = Path.Combine(outputPath, fileName + host.FileExtension);

                    File.WriteAllText(targetPath, result, new UTF8Encoding(true));
                    Trace.WriteLine(String.Format(Localization.Finish_Generate, host.Table.DisplayName));
                }
            }

            var outputBasePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, basePath);

            Trace.WriteLine(Localization.Finished);
            //BuildThriftCodeAsync(outputBasePath);
        }