public void SaveFile(string _jsonPath, string templatePath, int _headNum, TemplateType _type, string _fileName, Action <string> callback) { if (Directory.Exists(_jsonPath)) { if (JsonData.ContainsKey(_fileName)) { string fileName = _jsonPath + "\\" + _fileName + ".json"; ; string jsonData = JsonData[_fileName]; if (CanEncryption) { jsonData = DesEncrypt(Key, IV, jsonData, Mode, Padding); } using (FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { using (TextWriter writer = new StreamWriter(file, new UTF8Encoding(false))) { writer.Write(jsonData); } file.Close(); callback?.Invoke(_fileName + ".json"); } } } if (Directory.Exists(templatePath) && _headNum > 1 && _type != TemplateType.MIN) { if (TemplateData.ContainsKey(_fileName)) { string suffix = ""; switch (_type) { case TemplateType.CS: suffix = ".cs"; break; case TemplateType.TS: suffix = ".ts"; break; default: break; } string fileName = templatePath + "\\" + _fileName + suffix; string templateData = TemplateData[_fileName]; //if (CanEncryption) // templateData = DesEncrypt(Key, IV, templateData, Mode, Padding); using (FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { using (TextWriter writer = new StreamWriter(file, new UTF8Encoding(false))) { writer.Write(templateData); } file.Close(); callback?.Invoke(_fileName + suffix); } } } }
public void ExportTemplate(FileInfo _file, int _headNum, bool _isMutiple, TemplateType _template, string _sheetSign = "") { string name = _file.Name.Split('.')[0]; if (!ExcelData.ContainsKey(name)) { return; } DataSet excelData = ExcelData[name]; if (excelData == null) { return; } if (!_isMutiple) { DataTable dataTabale = excelData.Tables[0]; if (dataTabale.Rows.Count > 0 && dataTabale.Columns.Count > 0) { string tmp = ""; switch (_template) { case TemplateType.CS: tmp = (new CSDefineGenerator().CSGenerator(name, _headNum, dataTabale)); break; case TemplateType.TS: tmp = (new TypeScriptGenerator().TSGenerator(name, _headNum, dataTabale)); break; } if (!TemplateData.ContainsKey(name)) { TemplateData.Add(name, tmp); } } } else { Dictionary <string, string> data = new Dictionary <string, string>(); foreach (DataTable item in excelData.Tables) { if (!string.IsNullOrEmpty(_sheetSign) && item.TableName.Contains(_sheetSign)) { continue; } if (item.Rows.Count > 0 && item.Columns.Count > 0) { string tmp = ""; switch (_template) { case TemplateType.CS: tmp = (new CSDefineGenerator().CSGenerator(item.TableName, _headNum, item)); break; case TemplateType.TS: tmp = (new TypeScriptGenerator().TSGenerator(item.TableName, _headNum, item)); break; } if (!MultipleTemplateData.ContainsKey(name)) { MultipleTemplateData.Add(name, data); } data.Add(item.TableName, tmp); } } } }