Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
.vscode
node_modules
dist
build
*.db-journal
package-lock.json
DatabaseUtils\bin
DatabaseUtils\obj
DatabaseUtils/bin
DatabaseUtils/obj
build
./src/assets/dbUtil
.vs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PluginCollection } from "./PluginCollection";

const fs = require("fs");
export class CreateProjectParameters {

public TemplatesDirectory: string;
Expand Down Expand Up @@ -44,7 +43,7 @@ export class CreateProjectParameters {
msgPrefix: "DatabaseMustBeOneOf",
args: this.AvailableDatabases[this.ORM].join(","),
};
} else if (this.Database === "InMemory" && !this.ConnectionString) {
} else if (this.Database !== "InMemory" && !this.ConnectionString) {
return {
isSuccess: false,
msgPrefix: "ConnectionStringCantBeEmpty",
Expand All @@ -56,8 +55,15 @@ export class CreateProjectParameters {
};
}
if (this.UseDefaultPlugins) {
const pluginCollection = PluginCollection.FromFile(this.UseDefaultPlugins);
if (!fs.existsSync(this.UseDefaultPlugins)) {
return {
isSuccess: false,
msgPrefix: "DefaultPluginsFileNotFound",
};
}

const json = fs.readFileSync(this.UseDefaultPlugins, "utf8");
const pluginCollection = JSON.parse(json);
let isOrmExit = false;

for (const orm of pluginCollection.SupportedORM) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
const fs = require("fs");
export class PluginCollection {

public PrependPlugins: string[];
public AppendPlugins: string[];
public SupportedORM: string[];

public static FromFile(path: string): PluginCollection {
const json = fs.readFileSync(path, "utf8");
return JSON.parse(json);
}

public PluginCollection() {
this.PrependPlugins = [];
this.AppendPlugins = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@

<div class="row form-group">
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="NHibernate" (ngModelChange)="changeOrm('NHibernate')"
<input class="form-check-input" Id="NHibernateOrm" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="NHibernate" (ngModelChange)="changeOrm('NHibernate')"
/>
<label for="NHibernate">NHibernate</label>
<label for="NHibernateOrm">NHibernate</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="EFCore" (ngModelChange)="changeOrm('EFCore')"
<input class="form-check-input" Id="EFCoreOrm" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="EFCore" (ngModelChange)="changeOrm('EFCore')"
/>
<label for="EFCore">EntityFramework Core</label>
<label for="EFCoreOrm">EntityFramework Core</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="Dapper" (ngModelChange)="changeOrm('Dapper')"
<input class="form-check-input" Id="DapperOrm" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="Dapper" (ngModelChange)="changeOrm('Dapper')"
/>
<label for="Dapper">Dapper</label>
<label for="DapperOrm">Dapper</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="MongoDB" (ngModelChange)="changeOrm('MongoDB')"
<input class="form-check-input" Id="MongoDBOrm" type="radio" [(ngModel)]='parameters.ORM' name="ORM" value="MongoDB" (ngModelChange)="changeOrm('MongoDB')"
/>
<label for="MongoDB">MongoDB</label>
<label for="MongoDBOrm">MongoDB</label>
</div>
</div>

Expand All @@ -96,32 +96,32 @@
<div class="row form-group">
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.Database' [attr.disabled]="!enableDatabase.MSSQL?'':null"
name="Database" value="MSSQL" />
name="Database" value="MSSQL" Id="MSSQL" (ngModelChange)="changeDataBase('MSSQL')"/>
<label for="MSSQL">MSSQL</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.Database' [attr.disabled]="!enableDatabase.MySQL?'':null"
name="Database" value="MySQL" />
name="Database" value="MySQL" Id="MySQL" (ngModelChange)="changeDataBase('MySQL')"/>
<label for="MySQL">MySQL</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.Database' [attr.disabled]="!enableDatabase.SQLite?'':null"
name="Database" value="SQLite" />
name="Database" value="SQLite" Id="SQLite" (ngModelChange)="changeDataBase('SQLite')"/>
<label for="SQLite">SQLite</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.Database' [attr.disabled]="!enableDatabase.PostgreSQL?'':null"
name="Database" value="PostgreSQL" />
name="Database" value="PostgreSQL" Id="PostgreSQL" (ngModelChange)="changeDataBase('PostgreSQL')"/>
<label for="PostgreSQL">PostgreSQL</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.Database' [attr.disabled]="!enableDatabase.InMemory?'':null"
name="Database" value="InMemory" />
name="Database" value="InMemory" Id="InMemory" (ngModelChange)="changeDataBase('InMemory')"/>
<label for="InMemory">InMemory</label>
</div>
<div class="col-sm">
<input class="form-check-input" type="radio" [(ngModel)]='parameters.Database' [attr.disabled]="!enableDatabase.MongoDB?'':null"
name="Database" value="MongoDB" />
name="Database" value="MongoDB" Id="MongoDB" (ngModelChange)="changeDataBase('MongoDB')" />
<label for="MongoDB">MongoDB</label>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class AppComponent {
public parameters: CreateProjectParameters;
@Input()
public enableDatabase: any;
public defaultConnetionstring: any;
private language: string;
private eventEmitter: MessageEmitter;
private rootPath: string;
Expand All @@ -31,20 +32,33 @@ export class AppComponent {
constructor(public translateService: TranslateService) {
this.language = app.getLocale();
this.rootPath = app.getAppPath();
this.parameters = new CreateProjectParameters();
this.parameters.ProjectType = "AspNetCore";
this.parameters.ORM = "NHibernate";
this.parameters.Database = "MSSQL";
this.isDataBaseChecking = false;
this.eventEmitter = new MessageEmitter();

this.enableDatabase = {
MSSQL: true,
MySQL: true,
SQLite: true,
PostgreSQL: true,
InMemory: true,
MongoDB: true,
InMemory: false,
MongoDB: false
};

this.defaultConnetionstring = {
MSSQL: "Server=127.0.0.1;Database=test_db;User Id=test_user;Password=123456;",
MySQL: "Server=127.0.0.1;Port=3306;Database=test_db;User Id=test_user;Password=123456;",
SQLite: "Data Source={{App_Data}}/test.db;",
PostgreSQL: "Server=127.0.0.1;Port=5432;Database=test_db;User Id=test_user;Password=123456;",
InMemory: "",
MongoDB: "mongodb://test_user:[email protected]:27017/test_db",
};

this.parameters = new CreateProjectParameters();
this.parameters.ProjectName = "Hello.World";
this.parameters.ProjectType = "AspNetCore";
this.parameters.ORM = "NHibernate";
this.parameters.Database = "MSSQL";
this.parameters.ConnectionString = this.defaultConnetionstring[this.parameters.Database];
this.isDataBaseChecking = false;
this.eventEmitter = new MessageEmitter();
}

ngOnInit() {
Expand Down Expand Up @@ -143,6 +157,14 @@ export class AppComponent {
});
}

public changeDataBase(dataBase: string): void {
if (this.defaultConnetionstring[dataBase]) {
this.parameters.ConnectionString = this.defaultConnetionstring[dataBase];
} else {
this.parameters.ConnectionString = "";
}
}

public pluginSelect(): void {
const selectFile = remote.dialog.showOpenDialog({ properties: ["openFile"] });
if (selectFile && selectFile.length > 0) {
Expand All @@ -160,22 +182,22 @@ export class AppComponent {
private createCommand(toolPath: string): string {
let parametersStr = [
"--t=" + this.parameters.ProjectType,
"--n=" + this.parameters.ProjectName,
"--n=\"" + this.parameters.ProjectName + "\"",
"--m=" + this.parameters.ORM,
"--b=" + this.parameters.Database,
"--c=" + "\"this.parameters.ConnectionString" + "\"",
"--o=" + this.parameters.OutputDirectory,
"--c=\"" + this.parameters.ConnectionString + "\"",
"--o=\"" + this.parameters.OutputDirectory + "\"",
].join(" ");
if (this.parameters.ProjectDescription) {
parametersStr += " " + "--d=" + this.parameters.ProjectDescription;
parametersStr += " " + "--d=\"" + this.parameters.ProjectDescription + "\"";
}
if (this.parameters.ProjectDescription) {
parametersStr += " " + "--u=" + this.parameters.UseDefaultPlugins;
if (this.parameters.UseDefaultPlugins) {
parametersStr += " " + "--u=\"" + this.parameters.UseDefaultPlugins + "\"";
}

toolPath = path.join(toolPath, "ProjectCreator.Cmd.NetCore", "ZKWeb.Toolkits.ProjectCreator.Cmd.dll");
return "dotnet " + toolPath + " " + parametersStr;

return "dotnet " + toolPath + " " + parametersStr;
}

private findTools(): string {
Expand All @@ -186,5 +208,4 @@ export class AppComponent {
}
return "";
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"ThisPluginCollectionOnlySupportTheseORM": "This plugin collection only support these ORM:",
"dataBaseTestFail":"fail to connect dataBase",
"ToolsFoderFail":"unable to find Tools foder",
"notValidConnectionString":"Invalid ConnectionString"
"notValidConnectionString":"Invalid ConnectionString",
"DefaultPluginsFileNotFound":"Plugin file not found"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
"ThisPluginCollectionOnlySupportTheseORM": "这个插件集只支持这些ORM:" ,
"dataBaseTestFail":"数据库连接失败",
"ToolsFoderFail":"无法探测到Tools文件夹",
"notValidConnectionString":"连接字符串错误"
"notValidConnectionString":"连接字符串错误",
"DefaultPluginsFileNotFound":"插件文件不存在"
}