Update Demo

This commit is contained in:
sunkaixuan
2019-01-16 22:03:41 +08:00
parent 800f1d0810
commit 2f38dc4750
4 changed files with 36 additions and 16 deletions

View File

@@ -28,15 +28,29 @@ namespace SugarCodeGeneration.Codes
} }
} }
public static void AddCsproj(string fileDirectory, string projectName) public static void AddCsproj(string classPath, string projectName)
{ {
var files = Directory.GetFiles(fileDirectory).ToList(); var classDirectory = Methods.GetSlnPath + "\\" +projectName+"\\"+ classPath.TrimStart('\\');
var files = Directory.GetFiles(classDirectory).ToList().Select(it=>classPath+"\\"+Path.GetFileName(it));
var xmlPath = GetSlnPath + @"\" + projectName + @"\SugarCodeGeneration.csproj"; var xmlPath = GetSlnPath + @"\" + projectName + @"\SugarCodeGeneration.csproj";
var xml = File.ReadAllText(xmlPath,Encoding.UTF8); var xml = File.ReadAllText(xmlPath,Encoding.UTF8);
var firstLine = System.IO.File.ReadLines(xmlPath, Encoding.UTF8).First(); var firstLine = System.IO.File.ReadLines(xmlPath, Encoding.UTF8).First();
var newXml = xml.Replace(firstLine, "").TrimStart('\r').TrimStart('\n'); var newXml = xml.Replace(firstLine, "").TrimStart('\r').TrimStart('\n');
XElement xe = XElement.Parse(newXml); 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 noAddFiles = files.Where(it => !compieList.Any(f => it.Equals(f.Attribute("Include").Value, StringComparison.CurrentCultureIgnoreCase))).ToList();
if (noAddFiles.Any()) {
foreach (var item in noAddFiles)
{
var addItem = new XElement("Compile", new XAttribute("Include",item));
itemGroup.AddFirst(addItem) ;
}
}
newXml = xe.ToString().Replace("xmlns=\"\"", "");
xe = XDocument.Parse(newXml);
xe.Save(xmlPath);
} }
} }
} }

View File

@@ -22,14 +22,14 @@ namespace MyTest
/// <summary> /// <summary>
/// Desc: /// Desc:
/// Default: /// Default:1
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public int? SchoolId {get;set;} public int? SchoolId {get;set;}
/// <summary> /// <summary>
/// Desc:Student Name /// Desc:Student Name
/// Default:default name /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public string Name {get;set;} public string Name {get;set;}
@@ -46,14 +46,21 @@ namespace MyTest
/// Default: /// Default:
/// Nullable:True /// Nullable:True
/// </summary> /// </summary>
public double? float {get;set;} public byte[] Timestamp {get;set;}
/// <summary> /// <summary>
/// Desc: /// Desc:
/// Default: /// Default:
/// Nullable:False /// Nullable:True
/// </summary> /// </summary>
public byte[] Timestamp {get;set;} public DateTimeOffset? Datetimeoffset {get;set;}
/// <summary>
/// Desc:
/// Default:
/// Nullable:True
/// </summary>
public double? Float {get;set;}
} }
} }

View File

@@ -13,7 +13,7 @@ namespace SugarCodeGeneration
{ {
private const SqlSugar.DbType sqlServer = SqlSugar.DbType.SqlServer; private const SqlSugar.DbType sqlServer = SqlSugar.DbType.SqlServer;
private const string projectName = "SugarCodeGeneration"; private const string projectName = "SugarCodeGeneration";
private const string classPath= projectName + @"\Models"; private const string classPath= "Models";
private const string classNamespace = "MyTest"; private const string classNamespace = "MyTest";
private const string connectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest"; private const string connectionString = "server=.;uid=sa;pwd=@jhl85661501;database=SqlSugar4XTest";
@@ -25,12 +25,12 @@ namespace SugarCodeGeneration
ConnectionString = connectionString, ConnectionString = connectionString,
IsAutoCloseConnection = true IsAutoCloseConnection = true
}); });
var classDirectory = Methods.GetSlnPath +"\\"+ classPath.TrimStart('\\'); var classDirectory = Methods.GetSlnPath +"\\"+projectName+"\\"+ classPath.TrimStart('\\');
//if all then remove .Where //if all then remove .Where
db.DbFirst.Where("Student","School").CreateClassFile(classDirectory, classNamespace); db.DbFirst.Where("Student","School").CreateClassFile(classDirectory, classNamespace);
//Methods.AddCsproj(classDirectory, projectName); Methods.AddCsproj(classPath, projectName);
//Generation DbContext //Generation DbContext
} }

View File

@@ -11,8 +11,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<NuGetPackageImportStamp> <NuGetPackageImportStamp></NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@@ -73,7 +72,9 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Models\Student.cs" />
<Compile Include="Codes\Methods.cs" /> <Compile Include="Codes\Methods.cs" />
<Compile Include="Models\School.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
@@ -81,9 +82,7 @@
<None Include="app.config" /> <None Include="app.config" />
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup />
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="x64\SQLite.Interop.dll"> <Content Include="x64\SQLite.Interop.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>