protected override void ExecuteCore() { var projects = this.GetSelectedProjects(); if (projects.Count != 1) { MessageBox.Show("请选择要生成实体的项目,再执行本命令。"); return; } var win = new MigerateDatabaseWizardWindow(); win.txtConnectionString.Text = @"server=.;database=LCL;uid=sa;pwd=123456"; win.txtDomainName.Text = projects[0].Properties.Item("RootNamespace").Value.ToString(); var res = win.ShowDialog(); if (res == true) { var connectionString = win.txtConnectionString.Text; var domainName = win.txtDomainName.Text; //构造实体代码生成器。 var generator = new CodeFileGenerator(); generator.DomainName = domainName; generator.DbSetting = DbSetting.SetSetting( domainName, connectionString, DbSetting.Provider_SqlClient//目前只支持 SqlServer。 ); //设置项目生成文件夹。 var items = projects[0].ProjectItems; generator.Directory = items.FindByName("Entities") ?? items.AddFolder("Entities"); generator.RepoDirectory = items.FindByName("Repository") ?? items.AddFolder("Repository"); generator.EFContexts = items.FindByName("EFContexts") ?? items.AddFolder("EFContexts"); generator.ValidationModel = items.FindByName("ValidationModel") ?? items.AddFolder("ValidationModel"); generator.ViewModels = items.FindByName("ViewModels") ?? items.AddFolder("ViewModels"); generator.Controllers = items.FindByName("Controllers") ?? items.AddFolder("Controllers"); generator.IsMVC = win.txtIsMVC.IsChecked.Value; //开始生成代码。 try { var error = generator.Generate(); var msg = string.Format("生成完毕,本次一共生成了 {0} 张表。", generator.SuccessCount); if (!string.IsNullOrEmpty(error)) { msg += Environment.NewLine + "无法移植的表:" + Environment.NewLine + error; } MessageBox.Show(msg); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
/// <summary> /// 如果配置文件的给connection加密属性设置为ture,那么程序运行会走这个方法 /// 这个方法通过AES加解密来保护connection不被发现,默认的key是DBEN /// </summary> protected virtual void DecryptConnectionString() { if (ConfigurationHelper.GetAppSettingOrDefault("DBEN.DBI.Data.UseEncryptedConnectionString", false)) { var settingName = RBACPlugin.DbSettingName; // VATEnginePlugin.DbSettingName; var settings = DbSetting.FindOrCreate(settingName); var encriptionStr = settings.ConnectionString; //获取connection var decriptionStr = DescriptAES.AESDecrypt(encriptionStr, "DBEN"); //解密后的connection DbSetting.SetSetting(settingName, decriptionStr, settings.ProviderName); } }
protected override void ExecuteOnProject(IList<Project> projects) { var win = new MigerateDatabaseWizardWindow(); win.txtConnectionString.Text = @"server=.\SQLExpress;database=XXX;uid=XXX;pwd=XXX"; win.txtDomainName.Text = projects[0].Properties.Item("RootNamespace").Value.ToString(); var res = win.ShowDialog(); if (res == true) { var connectionString = win.txtConnectionString.Text; var domainName = win.txtDomainName.Text; //构造实体代码生成器。 var generator = new EntityGenerator(); generator.DomainName = domainName; generator.DbSetting = DbSetting.SetSetting( domainName, connectionString, DbSetting.Provider_SqlClient//目前只支持 SqlServer。 ); //默认生成在 Entities 文件夹内。 var items = projects[0].ProjectItems; var item = items.FindByName("Entities"); if (item == null) { item = items.AddFolder("Entities"); } generator.Directory = item; //开始生成代码。 try { var error = generator.Generate(); var msg = string.Format("生成完毕,本次一共生成了 {0} 张表。", generator.SuccessCount); if (!string.IsNullOrEmpty(error)) { msg += Environment.NewLine + "无法移植的表:" + Environment.NewLine + error; } MessageBox.Show(msg); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }