From 5a4bba604d58b6cdca2b971e3cdfe8dc4f4f3270 Mon Sep 17 00:00:00 2001 From: "Leo.Wan" <1830802211@qq.com> Date: Fri, 27 May 2022 11:44:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(ProjectController=5FCommon)=20=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=A1=B9=E7=9B=AE=E6=96=87=E4=BB=B6=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 生成业务文件时,JSON串的顺序必须和选择加载的库顺序一致。同时这个位置有一个循环,如果加了比如Response这种文件时就有可能出再把Response的JSON拿去当csproj的的JSON解析。所以增加一个判断来过滤一下。 --- .../ProjectApp/ProjectController_Common.cs | 104 +++++++++--------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/SoEasyPlatform/Apis/ProjectApp/ProjectController_Common.cs b/SoEasyPlatform/Apis/ProjectApp/ProjectController_Common.cs index f9ab431..154777d 100644 --- a/SoEasyPlatform/Apis/ProjectApp/ProjectController_Common.cs +++ b/SoEasyPlatform/Apis/ProjectApp/ProjectController_Common.cs @@ -35,69 +35,75 @@ namespace SoEasyPlatform for (int i = 0; i < idsArray.Count(); i++) { ExpandoObject jsonItem = GetJsonItem(obj[i]); - var fileId = ids[i].ToString(); - var fileInfo = DbScoped.Sugar.Queryable().InSingle(idsArray[i]); - if (dbid > 0&&fileInfo.Content.Contains("[请设置ConStr]")) - { - var db = DbScoped.Sugar.Queryable().InSingle(dbid); - fileInfo.Content = fileInfo.Content.Replace("[请设置DbType]","SqlSugar.DbType."+db.DbType+"").Replace("[请设置ConStr]", "@@\""+db.Connection.Replace("@","@@")+"\""); - } - var context = fileInfo.Content; - if (!string.IsNullOrEmpty(project.Reference)) + + if ((jsonItem as IDictionary).ContainsKey("nuget")) { - StringBuilder sb = new StringBuilder(); - sb.AppendLine(""); - //< ProjectReference Include = "..\Entites\WebFirst.Entities.csproj" /> - foreach (var item in project.Reference.Split(',')) + var fileId = ids[i].ToString(); + var fileInfo = DbScoped.Sugar.Queryable().InSingle(idsArray[i]); + if (dbid > 0 && fileInfo.Content.Contains("[请设置ConStr]")) { - var data = DbScoped.Sugar.Queryable().InSingle(item); - var itemName = (dynamic)Newtonsoft.Json.JsonConvert.DeserializeObject(data.FileModel); - sb.AppendLine(""); + var db = DbScoped.Sugar.Queryable().InSingle(dbid); + fileInfo.Content = fileInfo.Content.Replace("[请设置DbType]", "SqlSugar.DbType." + db.DbType + "").Replace("[请设置ConStr]", "@@\"" + db.Connection.Replace("@", "@@") + "\""); } - sb.AppendLine(""); - (jsonItem as IDictionary).Add("reference", sb.ToString()); - } - else - { - (jsonItem as IDictionary).Add("reference", null); - } - var html = TemplateHelper.GetTemplateValue(context, context, jsonItem); - var name = (jsonItem as IDictionary)["name"]; - var fileName = FileSugar.MergeUrl(project.Path, name + "." + fileInfo.Suffix.TrimStart('.')); - if (!FileSugar.IsExistFile(fileName)) - FileSugar.CreateFile(fileName, html); - if (fileName.EndsWith(".csproj")) - { - var root= new DirectoryInfo(fileName).Parent.Parent.FullName; - var files=FileSugar.GetFileNames(root).Where(it=>it.EndsWith(".sln")).ToList(); - var directory =FileSugar.MergeUrl( Directory.GetCurrentDirectory(),"wwwroot\\template\\sln.txt"); - if (files.Count == 0) + var context = fileInfo.Content; + if (!string.IsNullOrEmpty(project.Reference)) { - var text = FileSugar.FileToString(directory); - text=text.Replace("{0}", name+""); - text=text.Replace("{1}", new DirectoryInfo(project.Path).Name+"\\"+name+".csproj" ); - FileSugar.CreateFile(root+"\\WebFirst.sln", text); + StringBuilder sb = new StringBuilder(); + sb.AppendLine(""); + //< ProjectReference Include = "..\Entites\WebFirst.Entities.csproj" /> + foreach (var item in project.Reference.Split(',')) + { + var data = DbScoped.Sugar.Queryable().InSingle(item); + var itemName = (dynamic)Newtonsoft.Json.JsonConvert.DeserializeObject(data.FileModel); + sb.AppendLine(""); + } + sb.AppendLine(""); + (jsonItem as IDictionary).Add("reference", sb.ToString()); + } + else + { + (jsonItem as IDictionary).Add("reference", null); } - else if (files.Count > 0) + var html = TemplateHelper.GetTemplateValue(context, context, jsonItem); + var name = (jsonItem as IDictionary)["name"]; + var fileName = FileSugar.MergeUrl(project.Path, name + "." + fileInfo.Suffix.TrimStart('.')); + if (!FileSugar.IsExistFile(fileName)) + FileSugar.CreateFile(fileName, html); + if (fileName.EndsWith(".csproj")) { - foreach (var item in files) + var root = new DirectoryInfo(fileName).Parent.Parent.FullName; + var files = FileSugar.GetFileNames(root).Where(it => it.EndsWith(".sln")).ToList(); + var directory = FileSugar.MergeUrl(Directory.GetCurrentDirectory(), "wwwroot\\template\\sln.txt"); + if (files.Count == 0) { - var text = FileSugar.FileToString(item); - if (!text.ToLower().Contains(name.ToString().ToLower())) + var text = FileSugar.FileToString(directory); + text = text.Replace("{0}", name + ""); + text = text.Replace("{1}", new DirectoryInfo(project.Path).Name + "\\" + name + ".csproj"); + FileSugar.CreateFile(root + "\\WebFirst.sln", text); + } + else if (files.Count > 0) + { + foreach (var item in files) { - StringBuilder sb = new StringBuilder(); - sb.AppendLine("EndProject"); - sb.AppendLine("Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \""+name+"\", \""+ new DirectoryInfo(project.Path).Name + "\\" + name + ".csproj" + "\", \"{"+Guid.NewGuid()+"}\""); - sb.AppendLine(@"EndProject + var text = FileSugar.FileToString(item); + if (!text.ToLower().Contains(name.ToString().ToLower())) + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("EndProject"); + sb.AppendLine("Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \"" + name + "\", \"" + new DirectoryInfo(project.Path).Name + "\\" + name + ".csproj" + "\", \"{" + Guid.NewGuid() + "}\""); + sb.AppendLine(@"EndProject Global"); - text = text.Replace(@"EndProject + text = text.Replace(@"EndProject Global", sb.ToString()); - FileSugar.DeleteFile(item); - FileSugar.CreateFile(item, text); + FileSugar.DeleteFile(item); + FileSugar.CreateFile(item, text); + } } } } } + + } } else -- Gitee