private void button2_Click(object sender, EventArgs e) { string formPath = Config.GetValue("FormPath") + "\\Learun.Application.Web\\"; //来源文件目录 string toPath = Config.GetValue("ToPathWeb"); //目标文件目录 textBox1.Clear(); textBox1.AppendText("开始复制文件\r\n"); string[] filePaths = DirFileHelper.GetFileNames(formPath, "*", true); int num = 0; foreach (string filePath in filePaths) { if (filePath.IndexOf("\\bin\\") == -1 && filePath.IndexOf("\\obj\\") == -1 && filePath.IndexOf("Learun.Application.Web.csproj") == -1) { textBox1.AppendText(num + ":" + filePath + "\r\n"); string path = toPath + filePath.Replace(formPath, ""); if (filePath.IndexOf("\\LR_Content\\") != -1) { string content = File.ReadAllText(filePath, Encoding.UTF8); FileInfo fi = new FileInfo(path); if (fi.Extension == ".js") { if (!string.IsNullOrEmpty(content)) { content = javaScriptCompressor.Compress(content); } DirFileHelper.CreateFileContent(path, content); } else if (fi.Extension == ".css") { if (!string.IsNullOrEmpty(content)) { content = cssCompressor.Compress(content); } DirFileHelper.CreateFileContent(path, content); } else { if (!Directory.Exists(fi.DirectoryName)) { Directory.CreateDirectory(fi.DirectoryName); } System.IO.File.Copy(filePath, path, true); } } else { FileInfo fi = new FileInfo(path); if (!Directory.Exists(fi.DirectoryName)) { Directory.CreateDirectory(fi.DirectoryName); } System.IO.File.Copy(filePath, path, true); } num++; } } textBox1.AppendText("结束复制文件\r\n"); }
/// <summary> /// 生成服务文件 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="strCode">生成代码内容</param> public static void CreateServiceExecution(BaseConfigModel baseConfigModel, string strCode) { var strParam = strCode.ToJObject(); #region 实体类 string entityCode = strParam["entityCode"].ToString(); string entityPath = baseConfigModel.OutputEntity + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.EntityClassName + ".cs"; //if (!System.IO.File.Exists(entityPath)) //{ DirFileHelper.CreateFileContent(entityPath, entityCode); //} #endregion #region 射类 string entitymapCode = strParam["entitymapCode"].ToString(); string entitymapPath = baseConfigModel.OutputMap + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.MapClassName + ".cs"; //if (!System.IO.File.Exists(entitymapPath)) //{ DirFileHelper.CreateFileContent(entitymapPath, entitymapCode); //} #endregion #region 务类 string serviceCode = strParam["serviceCode"].ToString(); string servicePath = baseConfigModel.OutputService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.ServiceClassName + ".cs"; //if (!System.IO.File.Exists(servicePath)) //{ DirFileHelper.CreateFileContent(servicePath, serviceCode); //} #endregion #region 接口类 string iserviceCode = strParam["iserviceCode"].ToString(); string iservicePath = baseConfigModel.OutputIService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.IServiceClassName + ".cs"; //if (!System.IO.File.Exists(iservicePath)) //{ DirFileHelper.CreateFileContent(iservicePath, iserviceCode); //} #endregion #region 业务类 string businesCode = strParam["businesCode"].ToString(); string businesPath = baseConfigModel.OutputBusines + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.BusinesClassName + ".cs"; //if (!System.IO.File.Exists(businesPath)) //{ DirFileHelper.CreateFileContent(businesPath, businesCode); //} #endregion }
public ActionResult CreateCode() { string strcode = ""; string strvalue = ""; string OutputDirectory = Server.MapPath("~/Web.config"); ; for (int i = 0; i < 2; i++) { OutputDirectory = OutputDirectory.Substring(0, OutputDirectory.LastIndexOf('\\')); } GetDataItemConst(out strcode, out strvalue); string codePath = OutputDirectory + "\\LeaRun.Application.Entity\\SystemManage\\ViewModel\\DataItemCodes.cs"; DirFileHelper.CreateFileContent(codePath, strcode); string valuePath = OutputDirectory + "\\LeaRun.Application.Entity\\SystemManage\\ViewModel\\DataItemValues.cs"; DirFileHelper.CreateFileContent(valuePath, strvalue); return(Success("恭喜您,创建成功!")); }
/// <summary> /// 执行创建文件 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="strCode">生成代码内容</param> public static void CreateExecution(BaseConfigModel baseConfigModel, string strCode) { var strParam = strCode.ToJObject(); #region 实体类 string entityCode = strParam["entityCode"].ToString(); string entityPath = baseConfigModel.OutputEntity + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.EntityClassName + ".cs"; //if (!System.IO.File.Exists(entityPath)) //{ DirFileHelper.CreateFileContent(entityPath, entityCode); //} #endregion #region 射类 string entitymapCode = strParam["entitymapCode"].ToString(); string entitymapPath = baseConfigModel.OutputMap + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.MapClassName + ".cs"; //if (!System.IO.File.Exists(entitymapPath)) //{ DirFileHelper.CreateFileContent(entitymapPath, entitymapCode); //} #endregion #region 务类 string serviceCode = strParam["serviceCode"].ToString(); string servicePath = baseConfigModel.OutputService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.ServiceClassName + ".cs"; //if (!System.IO.File.Exists(servicePath)) //{ DirFileHelper.CreateFileContent(servicePath, serviceCode); //} #endregion #region 接口类 string iserviceCode = strParam["iserviceCode"].ToString(); string iservicePath = baseConfigModel.OutputIService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.IServiceClassName + ".cs"; //if (!System.IO.File.Exists(iservicePath)) //{ DirFileHelper.CreateFileContent(iservicePath, iserviceCode); //} #endregion #region 业务类 string businesCode = strParam["businesCode"].ToString(); string businesPath = baseConfigModel.OutputBusines + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.BusinesClassName + ".cs"; //if (!System.IO.File.Exists(businesPath)) //{ DirFileHelper.CreateFileContent(businesPath, businesCode); //} #endregion #region 控制器 string controllerCode = strParam["controllerCode"].ToString(); string controllerPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Controllers\\" + baseConfigModel.ControllerName + ".cs"; //if (!System.IO.File.Exists(controllerPath)) //{ DirFileHelper.CreateFileContent(controllerPath, controllerCode); //} #endregion #region 列表页 string indexCode = strParam["indexCode"].ToString(); string indexPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.IndexPageName + ".cshtml"; //if (!System.IO.File.Exists(indexPath)) //{ DirFileHelper.CreateFileContent(indexPath, indexCode.Replace("★", " ")); //} #endregion #region 表单页 string formCode = strParam["formCode"].ToString(); string formPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.FormPageName + ".cshtml"; //if (!System.IO.File.Exists(formPath)) //{ DirFileHelper.CreateFileContent(formPath, formCode.Replace("★", " ")); //} #endregion }
/// <summary> /// 执行创建文件 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="strCode">生成代码内容</param> public static void CreateExecution(BaseConfigModel baseConfigModel, string strCode) { var strParam = strCode.ToJObject(); #region 实体类 string entityCode = strParam["entityCode"].ToString(); string entityPath = baseConfigModel.OutputEntity + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.EntityClassName + ".cs"; if (!System.IO.File.Exists(entityPath)) { DirFileHelper.CreateFileContent(entityPath, entityCode); } #endregion #region 射类 string entitymapCode = strParam["entitymapCode"].ToString(); string entitymapPath = baseConfigModel.OutputMap + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.MapClassName + ".cs"; if (!System.IO.File.Exists(entitymapPath)) { DirFileHelper.CreateFileContent(entitymapPath, entitymapCode); } #endregion #region 务类 string serviceCode = strParam["serviceCode"].ToString(); string servicePath = baseConfigModel.OutputService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.ServiceClassName + ".cs"; if (!System.IO.File.Exists(servicePath)) { DirFileHelper.CreateFileContent(servicePath, serviceCode); } #endregion #region 接口类 string iserviceCode = strParam["iserviceCode"].ToString(); string iservicePath = baseConfigModel.OutputIService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.IServiceClassName + ".cs"; if (!System.IO.File.Exists(iservicePath)) { DirFileHelper.CreateFileContent(iservicePath, iserviceCode); } #endregion #region 业务类 string businesCode = strParam["businesCode"].ToString(); string businesPath = baseConfigModel.OutputBusines + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.BusinesClassName + ".cs"; if (!System.IO.File.Exists(businesPath)) { DirFileHelper.CreateFileContent(businesPath, businesCode); } #endregion #region 控制器 string controllerCode = strParam["controllerCode"].ToString(); string controllerPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Controllers\\" + baseConfigModel.ControllerName + ".cs"; if (!System.IO.File.Exists(controllerPath)) { DirFileHelper.CreateFileContent(controllerPath, controllerCode); } #endregion #region 列表页 string indexCode = strParam["indexCode"].ToString(); string indexPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.IndexPageName + ".cshtml"; if (!System.IO.File.Exists(indexPath)) { DirFileHelper.CreateFileContent(indexPath, indexCode.Replace("★", " ")); } #endregion #region 表单页 string formCode = strParam["formCode"].ToString(); string formPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.FormPageName + ".cshtml"; if (!System.IO.File.Exists(formPath)) { DirFileHelper.CreateFileContent(formPath, formCode.Replace("★", " ")); } #endregion #region web.config ,Registration.cs 文件 2017-4-1 lijun string configPath = "Areas\\" + baseConfigModel.OutputAreas + "\\Views\\Web.config"; if (!System.IO.File.Exists(baseConfigModel.OutputController + "\\" + configPath)) { // 读取 SystemManager 的配置文件,复制到新文件中 string systemconfigPath = "Areas\\SystemManage\\Views\\Web.config"; DirFileHelper.CopyFile(systemconfigPath, configPath); } string registrationPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.OutputAreas + "AreaRegistration.cs"; if (!System.IO.File.Exists(registrationPath)) { // 读取 SystemManager 的Registration文件,修改后复制到新文件中 string sysRegistrationPath = baseConfigModel.OutputController + "\\Areas\\SystemManage\\SystemManageAreaRegistration.cs"; string text = DirFileHelper.ReadFile(sysRegistrationPath); if (!string.IsNullOrEmpty(text)) { DirFileHelper.CreateFileContent(registrationPath, text.Replace("SystemManage", baseConfigModel.OutputAreas)); } } #endregion }
/// <summary> /// 产生html页面 /// </summary> /// <param name="lists"></param> /// <returns></returns> public string AppBuilder(List <AppTemplatesEntity> lists, AppProjectEntity projectEntity, string outputDirectory) { string path = ""; Dictionary <string, AppTemplatesEntity> pageEntitys = new Dictionary <string, AppTemplatesEntity>(); Dictionary <string, List <AppTemplatesEntity> > componentEntitys = new Dictionary <string, List <AppTemplatesEntity> >(); List <AppTemplatesEntity> tabsEntitys = new List <AppTemplatesEntity>(); AppTemplatesEntity tabEntity = null; try { //将数据做分类处理 foreach (var item in lists) { if (item.F_Value == "lrTabs") { tabEntity = item; } else if (item.F_Value == "lrTab") { tabsEntitys.Add(item); } if (item.F_Type == "Page" && item.F_Value != "lrTabs") { pageEntitys.Add(item.F_Id, item); } else if (item.F_Type == "Component") { if (componentEntitys.ContainsKey(item.F_Parent)) { componentEntitys[item.F_Parent].Add(item); } else { List <AppTemplatesEntity> componentlists = new List <AppTemplatesEntity>(); componentlists.Add(item); componentEntitys.Add(item.F_Parent, componentlists); } } } //JS文件 string jsPath = outputDirectory + "\\js"; #region 创建appJs文件 string appJsPath = jsPath + "\\learun-app.js"; if (!System.IO.File.Exists(appJsPath)) { DirFileHelper.CreateFileContent(appJsPath, JSApp()); } #endregion #region 创建路由文件 string routerJsPath = jsPath + "\\learun-uirouter.js"; if (!System.IO.File.Exists(routerJsPath)) { DirFileHelper.CreateFileContent(routerJsPath, JSRouter(pageEntitys, tabsEntitys, projectEntity)); } #endregion #region 创建controllers文件 string controllersJsPath = jsPath + "\\learun-controllers.js"; if (!System.IO.File.Exists(controllersJsPath)) { DirFileHelper.CreateFileContent(controllersJsPath, JSControllers(pageEntitys)); } #endregion //html文件 string htmlPath = outputDirectory + "\\templates"; #region 创建页面 foreach (var item in pageEntitys) { string htmlPagePath = htmlPath + "\\page" + item.Value.F_Id.Replace("-", "") + ".html"; if (!System.IO.File.Exists(htmlPagePath)) { DirFileHelper.CreateFileContent(htmlPagePath, PageBuilder(item.Value, componentEntitys[item.Key])); } } #endregion #region 创建tabs页 string htmlTabsPath = htmlPath + "\\tabs.html"; if (!System.IO.File.Exists(htmlTabsPath)) { DirFileHelper.CreateFileContent(htmlTabsPath, TabBuilder(tabEntity, tabsEntitys)); } #endregion ZipHelper.CreateZip(outputDirectory, outputDirectory + ".zip"); return(outputDirectory + ".zip"); } catch { throw; } }