Update Demo

This commit is contained in:
sunkaixuan
2019-01-17 18:10:19 +08:00
parent 43fc184e2f
commit 8752a59ff3
6 changed files with 180 additions and 83 deletions

View File

@@ -35,25 +35,27 @@ namespace SugarCodeGeneration.Codes
public static void AddCsproj(string classPath, string projectName)
{
var classDirectory = Methods.GetSlnPath + "\\" +projectName+"\\"+ classPath.TrimStart('\\');
if (FileHelper.IsExistDirectory(classDirectory) == false) {
var classDirectory = Methods.GetSlnPath + "\\" + projectName + "\\" + classPath.TrimStart('\\');
if (FileHelper.IsExistDirectory(classDirectory) == false)
{
FileHelper.CreateDirectory(classDirectory);
}
var files = Directory.GetFiles(classDirectory).ToList().Select(it=>classPath+"\\"+Path.GetFileName(it));
var xmlPath = GetSlnPath + @"\" + projectName + @"\"+projectName+".csproj";
var files = Directory.GetFiles(classDirectory).ToList().Select(it => classPath + "\\" + Path.GetFileName(it));
var xmlPath = GetSlnPath + @"\" + projectName + @"\" + projectName + ".csproj";
var xml = File.ReadAllText(xmlPath, System.Text.Encoding.UTF8);
var firstLine = System.IO.File.ReadLines(xmlPath, System.Text.Encoding.UTF8).First();
var newXml = xml.Replace(firstLine, "").TrimStart('\r').TrimStart('\n');
XDocument xe = XDocument.Load(xmlPath);
var itemGroup=xe.Root.Elements().Where(it=>it.Name.LocalName== "ItemGroup"&&it.Elements().Any(y=>y.Name.LocalName== "Compile")).First();
var compieList=itemGroup.Elements().ToList();
var itemGroup = xe.Root.Elements().Where(it => it.Name.LocalName == "ItemGroup" && it.Elements().Any(y => y.Name.LocalName == "Compile")).First();
var compieList = itemGroup.Elements().ToList();
var noAddFiles = files.Where(it => !compieList.Any(f => it.Equals(f.Attribute("Include").Value, StringComparison.CurrentCultureIgnoreCase))).ToList();
if (noAddFiles.Any()) {
if (noAddFiles.Any())
{
foreach (var item in noAddFiles)
{
var addItem = new XElement("Compile", new XAttribute("Include",item));
itemGroup.AddFirst(addItem) ;
var addItem = new XElement("Compile", new XAttribute("Include", item));
itemGroup.AddFirst(addItem);
}
}
newXml = xe.ToString().Replace("xmlns=\"\"", "");
@@ -61,7 +63,7 @@ namespace SugarCodeGeneration.Codes
xe.Save(xmlPath);
}
public static void CreateBLL(string templatePath, string savePath,List<string> tables)
public static void CreateBLL(string templatePath, string savePath, List<string> tables)
{
string template = System.IO.File.ReadAllText(templatePath); //从文件中读出模板内容
@@ -70,18 +72,29 @@ namespace SugarCodeGeneration.Codes
{
BLLParameter model = new BLLParameter()
{
Name=item
Name = item
};
var result = Engine.Razor.RunCompile(template, templateKey, model.GetType(), model);
FileHelper.CreateFile(savePath+"\\"+item+ "Manager.cs", result, System.Text.Encoding.UTF8);
var cp = savePath + "\\" + item + "Manager.cs";
if (FileHelper.IsExistFile(cp) == false)
FileHelper.CreateFile(cp, result, System.Text.Encoding.UTF8);
}
}
public static void CreateDbContext(string templatePath, string savePath, object model) {
public static void CreateDbContext(string templatePath, string savePath, object model)
{
string template = System.IO.File.ReadAllText(templatePath); //从文件中读出模板内容
string templateKey ="dbcontext"; //取个名字
var result =Engine.Razor.RunCompile(template, templateKey, model.GetType(), model);
string templateKey = "dbcontext"; //取个名字
var result = Engine.Razor.RunCompile(template, templateKey, model.GetType(), model);
FileHelper.CreateFile(savePath, result, System.Text.Encoding.UTF8);
}
public static void CreateProject(string name) {
var templatePath = GetCurrentProjectPath + "/Template/Project.txt";
string project = System.IO.File.ReadAllText(templatePath).Replace("@pid",Guid.NewGuid().ToString()); //从文件中读出模板内容
//FileHelper
}
}
}