Beispiel #1
0
        public void ExportConfigReaderStruct()
        {
            List <object[]> dicts  = new List <object[]>();
            List <object[]> fields = new List <object[]>();

            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.fieldNameIsEnable)
                {
                    object[] lines = new object[] { dataField.field, GetParseTxt(dataField) };
                    fields.Add(lines);
                }
                else
                {
                    object[] lines = new object[] { dataField.field, GetParseTxt(dataField) };
                    dicts.Add(lines);
                }
            }


            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigReaderStructTemplate));

            template.AddVariable("classNameConfig", classNameConfig);
            template.AddVariable("classNameConfigReaderStruct", classNameConfigReaderStruct);
            template.AddVariable("tableName", tableName);
            template.AddVariable("fields", fields.ToArray());
            template.AddVariable("dicts", dicts.ToArray());
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigReaderStructTemplate, classNameConfigReaderStruct);

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #2
0
        public void ExportConfig()
        {
            List <object[]> langs = new List <object[]>();


            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.field.StartsWith("zh_cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("zh_cn_", ""), dataField.field };
                    langs.Add(lines);
                }
                else if (dataField.field.StartsWith("cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("cn_", ""), dataField.field };
                    langs.Add(lines);
                }
            }


            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigTemplate));

            template.AddVariable("classNameConfig", classNameConfig);
            template.AddVariable("classNameConfigStruct", classNameConfigStruct);
            template.AddVariable("langs", langs.ToArray());
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigTemplate, classNameConfig);


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
        public void SaveCode()
        {
            List <object[]> fields = new List <object[]>();


            // 0 KeyField
            // 1 KeyValue
            // 2 ID
            // 3 ModuleName
            // 4 Name
            for (int i = 0; i < dataList.Count; i++)
            {
                Dictionary <string, string> rowData = dataList[i];

                object[] lines = new object[5];
                lines[0] = rowData[option.keyField].Replace("-", "_").Replace(" ", "");
                lines[1] = rowData[option.keyField];
                lines[2] = rowData[option.idField];
                lines[3] = string.IsNullOrEmpty(option.txtModuleField) ? string.Empty : rowData[option.txtModuleField];
                lines[4] = rowData[option.txtNameField];

                fields.Add(lines);
            }


            TemplateSystem template = new TemplateSystem(File.ReadAllText(option.tplPath));

            template.AddVariable("className", option.codeClassname);
            template.AddVariable("fields", fields.ToArray());
            string content = template.Parse();
            string path    = option.codePath;

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #4
0
        public static void Export(TableReader table, XlsxManager xlsxManager)
        {
            Log.Info("ExportJson:" + table.path);
            string uidKey = table.fieldDictByIndex[1].field;


            JsonData jd = new JsonData();

            foreach (Dictionary <string, string> line in table.dataList)
            {
                JsonData lineJD = new JsonData();
                foreach (var kvp in table.fieldDictByIndex)
                {
                    DataField dataField = kvp.Value;
                    string    field     = dataField.field;
                    string    valueTxt  = string.Empty;
                    if (line.ContainsKey(field))
                    {
                        valueTxt = line[field];
                    }

                    Parse(dataField, valueTxt, lineJD, xlsxManager);
                }
                string uid = line[uidKey];
                jd[uid] = lineJD;
            }

            string jsonData = JsonMapper.ToJson(jd).ConvertJsonString();


            string path = Setting.JsonRoot + "/" + string.Format(Setting.Options.jsonNameFormat, table.tableName);

            PathHelper.CheckPath(path);
            File.WriteAllText(path, jsonData, Encoding.UTF8);
        }
Beispiel #5
0
        public void ExportConfigReader()
        {
            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigReaderTemplate));

            template.AddVariable("classNameConfigReader", classNameConfigReader);
            template.AddVariable("classNameConfigReaderStruct", classNameConfigReaderStruct);
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigReaderTemplate, classNameConfigReader);


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #6
0
        public static void Export(TableReader table)
        {
            string csvSeparator = Setting.Options.csvSeparator;


            StringWriter sw = new StringWriter();

            List <string> headTypes  = new List <string>();
            List <string> headCns    = new List <string>();
            List <string> headFields = new List <string>();

            foreach (var kvp in  table.fieldDictByIndex)
            {
                headTypes.Add(kvp.Value.typeName);
                headCns.Add(ReplaceSpearator(kvp.Value.cn));
                headFields.Add(kvp.Value.field);
            }

            sw.WriteLine(string.Join(csvSeparator, headTypes));
            sw.WriteLine(string.Join(csvSeparator, headCns));
            sw.WriteLine(string.Join(csvSeparator, headFields));


            foreach (Dictionary <string, string> line in table.dataList)
            {
                List <string> strList = new List <string>();
                foreach (var kvp in table.fieldDictByIndex)
                {
                    if (line.ContainsKey(kvp.Value.field))
                    {
                        strList.Add(ReplaceSpearator(line[kvp.Value.field]));
                    }
                    else
                    {
                        strList.Add("-");
                    }
                }
                sw.WriteLine(string.Join(csvSeparator, strList));
            }



            string path = Setting.CsvRoot + "/" + table.tableName + ".csv";

            PathHelper.CheckPath(path);
            File.WriteAllText(path, sw.ToString(), Encoding.UTF8);
        }
Beispiel #7
0
        public static void ExportConfigIncludes(List <ExportClientTS> list)
        {
            List <object[]> lines = new List <object[]>();

            foreach (ExportClientTS item in list)
            {
                lines.Add(new object[] { item.classNameConfig });
            }
            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigIncludesTemplate));

            template.AddVariable("list", lines.ToArray());
            string content = template.Parse();
            string path    = OutPaths.Client.ConfigIncludesTemplate;


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #8
0
        public static void ExportConfigManagerList(List <ExportClientTS> list)
        {
            List <object[]> lines = new List <object[]>();

            foreach (ExportClientTS item in list)
            {
                if (item.isExtend)
                {
                    continue;
                }

                lines.Add(new object[] { item.fieldName, item.classNameConfigReader });
            }
            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigManagerListTemplate));

            template.AddVariable("tables", lines.ToArray());
            string content = template.Parse();
            string path    = OutPaths.Client.ConfigManagerListTemplate;


            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #9
0
        public void ExportDT()
        {
            List <object[]> fields = new List <object[]>();

            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                object[] lines = new object[] { dataField.field, dataField.GetTsTypeName() };
                fields.Add(lines);
            }



            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Server.DTTemplate));

            template.AddVariable("classNameConfig", classNameConfig);
            template.AddVariable("fields", fields.ToArray());
            string content = template.Parse();
            string path    = string.Format(OutPaths.Server.DTTemplate, classNameConfig);

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }
Beispiel #10
0
        public void ExportConfigStruct()
        {
            List <object[]> dicts  = new List <object[]>();
            List <object[]> fields = new List <object[]>();


            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.fieldNameIsEnable)
                {
                    object[] lines = new object[] { dataField.field, dataField.GetTsTypeName() };
                    fields.Add(lines);
                }
                else
                {
                    object[] lines = new object[] { dataField.field, dataField.GetTsTypeName(), Regex.Replace(dataField.field, @"[^A-Za-z0-9_]", @"_") };
                    dicts.Add(lines);
                }
            }


            List <object[]> langs = new List <object[]>();


            for (int i = 0; i < dataStruct.fields.Count; i++)
            {
                DataField dataField = dataStruct.fields[i];

                if (dataField.field.StartsWith("zh_cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("zh_cn_", ""), dataField.field, fieldName };
                    langs.Add(lines);
                }
                else if (dataField.field.StartsWith("cn_"))
                {
                    object[] lines = new object[] { dataField.field.Replace("cn_", ""), dataField.field, fieldName };
                    langs.Add(lines);
                }
            }



            string parse      = "";
            string parseArray = "";

            if (isExtend)
            {
                StringWriter sw = new StringWriter();
                sw.WriteLine($"  static parse(txt: string): {classNameConfig} ");
                sw.WriteLine("      {");

                sw.WriteLine($"          let csv = toStringArray(txt);");
                sw.WriteLine($"          let config = new {classNameConfig}();");


                for (int i = 0; i < dataStruct.fields.Count; i++)
                {
                    DataField dataField = dataStruct.fields[i];
                    sw.WriteLine($"          config.{dataField.field} = {GetParseCsvTxt(dataField, i)};");
                }

                sw.WriteLine("          return config;");
                sw.WriteLine("      }");

                parse = sw.ToString();



                // parseArray
                sw = new StringWriter();
                sw.WriteLine($"  static parseArray(txt: string): {classNameConfig}[] ");
                sw.WriteLine("      {");
                sw.WriteLine($"          let csv = toStringArray(txt, /[;]/);");
                sw.WriteLine($"          let list:{classNameConfig}[] = [];");
                sw.WriteLine($"          for(let i = 0; i < csv.length; i ++)");
                sw.WriteLine("          {");
                sw.WriteLine($"              list.push(      {classNameConfig}.parse(csv[i])          );");
                sw.WriteLine("           }");

                sw.WriteLine("          return list;");
                sw.WriteLine("      }");

                parseArray = sw.ToString();
            }



            TemplateSystem template = new TemplateSystem(File.ReadAllText(TemplatingFiles.Client.ConfigStructTemplates));

            template.AddVariable("classNameConfigStruct", classNameConfigStruct);
            template.AddVariable("fields", fields.ToArray());
            template.AddVariable("dicts", dicts.ToArray());
            template.AddVariable("langs", langs.ToArray());
            template.AddVariable("parse", parse);
            template.AddVariable("parseArray", parseArray);
            string content = template.Parse();
            string path    = string.Format(OutPaths.Client.ConfigStructTeamplate, classNameConfigStruct);

            PathHelper.CheckPath(path);
            File.WriteAllText(path, content);
        }