private void Finish() { WebConfig w = new WebConfig(webConfigFileName); //If Membership is selected then save Simple Membership first, because these providers are in the same section, //so if any is removed but called second place it will remove the entire section if (IsMembershipSelected()) { pages[SimpleMembershipIndex].ProviderConfig.Save(w); pages[MEMBERSHIP_INDEX].ProviderConfig.Save(w); } else { pages[MEMBERSHIP_INDEX].ProviderConfig.Save(w); pages[SimpleMembershipIndex].ProviderConfig.Save(w); } pages[ROLES_INDEX].ProviderConfig.Save(w); pages[PROFILES_INDEX].ProviderConfig.Save(w); pages[SESSION_INDEX].ProviderConfig.Save(w); pages[SITEMAP_INDEX].ProviderConfig.Save(w); pages[PERSONALIZATION_INDEX].ProviderConfig.Save(w); w.Save(); WebConfig webConfig = new WebConfig(webConfigFileName); pages[ENTITYFRAMEWORK_INDEX].ProviderConfig.Save(webConfig); project.DTE.Solution.SolutionBuild.Build(true); Close(); }
private void Finish() { WebConfig w = new WebConfig(webConfigFileName); pages[0].ProviderConfig.Save(w); pages[1].ProviderConfig.Save(w); pages[2].ProviderConfig.Save(w); pages[3].ProviderConfig.Save(w); w.Save(); Close(); }
public override void ProjectFinishedGenerating(Project project) { if (project != null) { VSProject vsProj = project.Object as VSProject; var tables = new List <string>(); Settings.Default.MVCWizardConnection = WizardForm.ServerExplorerConnectionSelected; Settings.Default.Save(); if (_generalPane != null) { _generalPane.Activate(); } SendToGeneralOutputWindow("Starting project generation..."); //Updating project references try { vsProj.References.Add("MySql.Data"); } catch { var infoResult = InfoDialog.ShowDialog( InfoDialogProperties.GetOkCancelDialogProperties( InfoDialog.InfoType.Warning, Resources.MySqlDataProviderPackage_ConnectorNetNotFoundError, @"To use it you must download and install the MySQL Connector/Net package from http://dev.mysql.com/downloads/connector/net/", Resources.MySqlDataProviderPackage_ClickOkOrCancel)); if (infoResult.DialogResult == DialogResult.OK) { ProcessStartInfo browserInfo = new ProcessStartInfo("http://dev.mysql.com/downloads/connector/net/"); System.Diagnostics.Process.Start(browserInfo); } } double version = double.Parse(WizardForm.Wizard.GetVisualStudioVersion()); if (version >= 12.0) { References refs = vsProj.References; foreach (Reference item in refs) { switch (item.Name) { case "System.Web.Razor": if (item.Version.Equals("1.0.0.0")) { vsProj.References.Find("System.Web.Razor").Remove(); } break; case "System.Web.WebPages": vsProj.References.Find("System.Web.WebPages").Remove(); break; case "System.Web.Mvc": vsProj.References.Find("System.Web.Mvc").Remove(); break; case "System.Web.Helpers": vsProj.References.Find("System.Web.Helpers").Remove(); break; } } vsProj.References.Add("System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"); vsProj.References.Add("System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"); vsProj.References.Add("System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"); vsProj.References.Add("System.Web.Razor"); #if NET_40_OR_GREATER vsProj.Project.Save(); #endif } AddNugetPackage(vsProj, JQUERY_PKG_NAME, JQUERY_VERSION, false); var packagesPath = Path.Combine(Path.GetDirectoryName(ProjectPath), @"Packages\jQuery." + JQUERY_VERSION + @"\Content\Scripts"); CopyPackageToProject(vsProj, ProjectPath, packagesPath, "Scripts"); if (WizardForm.SelectedTables != null && WizardForm.DEVersion != DataEntityVersion.None) { WizardForm.SelectedTables.ForEach(t => tables.Add(t.Name)); SendToGeneralOutputWindow("Generating Entity Framework model..."); if (tables.Count > 0) { if (WizardForm.DEVersion == DataEntityVersion.EntityFramework5) { CurrentEntityFrameworkVersion = ENTITY_FRAMEWORK_VERSION_5; } else if (WizardForm.DEVersion == DataEntityVersion.EntityFramework6) { CurrentEntityFrameworkVersion = ENTITY_FRAMEWORK_VERSION_6; } AddNugetPackage(vsProj, ENTITY_FRAMEWORK_PCK_NAME, CurrentEntityFrameworkVersion, true); string modelPath = Path.Combine(ProjectPath, "Models"); GenerateEntityFrameworkModel(project, vsProj, new MySqlConnection(WizardForm.ConnectionStringForModel), WizardForm.ModelName, tables, modelPath); GenerateMVCItems(vsProj); if (WizardForm.DEVersion == DataEntityVersion.EntityFramework6) { project.DTE.SuppressUI = true; project.Properties.Item("TargetFrameworkMoniker").Value = ".NETFramework,Version=v4.5"; } } } else { string indexPath = Language == LanguageGenerator.CSharp ? (string)(FindProjectItem(FindProjectItem(FindProjectItem(vsProj.Project.ProjectItems, "Views").ProjectItems, "Home").ProjectItems, "Index.cshtml").Properties.Item("FullPath").Value) : (string)(FindProjectItem(FindProjectItem(FindProjectItem(vsProj.Project.ProjectItems, "Views").ProjectItems, "Home").ProjectItems, "Index.vbhtml").Properties.Item("FullPath").Value); string contents = File.ReadAllText(indexPath); contents = contents.Replace("$catalogList$", String.Empty); File.WriteAllText(indexPath, contents); } var webConfig = new MySql.Data.VisualStudio.WebConfig.WebConfig(ProjectPath + @"\web.config"); SendToGeneralOutputWindow("Starting provider configuration..."); try { try { string configPath = ProjectPath + @"\web.config"; if (WizardForm.CreateAdministratorUser) { SendToGeneralOutputWindow("Creating administrator user..."); using (AppConfig.Load(configPath)) { var configFile = new FileInfo(configPath); var vdm = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name); var wcfm = new WebConfigurationFileMap(); wcfm.VirtualDirectories.Add("/", vdm); System.Configuration.Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/"); try { if (!WizardForm.IncludeSensitiveInformation) { ConnectionStringsSection connectionStringsection = config.GetSection("connectionStrings") as ConnectionStringsSection; if (connectionStringsection != null) { connectionStringsection.ConnectionStrings[WizardForm.ConnectionStringNameForAspNetTables].ConnectionString = _fullconnectionstring; config.Save(); } } } catch { } MembershipSection section = (MembershipSection)config.GetSection("system.web/membership"); ProviderSettingsCollection settings = section.Providers; NameValueCollection membershipParams = settings[section.DefaultProvider].Parameters; var provider = new MySQLMembershipProvider(); provider.Initialize(section.DefaultProvider, membershipParams); //create the user MembershipCreateStatus status; if (!WizardForm.RequireQuestionAndAnswer) { provider.CreateUser(WizardForm.AdminName, WizardForm.AdminPassword, "*****@*****.**", null, null, true, null, out status); } else { provider.CreateUser(WizardForm.AdminName, WizardForm.AdminPassword, "*****@*****.**", WizardForm.UserQuestion, WizardForm.UserAnswer, true, null, out status); } } } // add creation of providers tables if (WizardForm.IncludeProfilesProvider) { var profileConfig = new ProfileConfig(); profileConfig.Initialize(webConfig); profileConfig.Enabled = true; profileConfig.DefaultProvider = "MySQLProfileProvider"; var options = new Options(); options.AppName = @"\"; options.AutoGenSchema = true; options.ConnectionStringName = WizardForm.ConnectionStringNameForAspNetTables; options.ConnectionString = WizardForm.ConnectionStringForAspNetTables; options.EnableExpireCallback = false; options.ProviderName = "MySQLProfileProvider"; options.WriteExceptionToLog = WizardForm.WriteExceptionsToLog; profileConfig.GenericOptions = options; profileConfig.DefaultProvider = "MySQLProfileProvider"; profileConfig.Save(webConfig); } if (WizardForm.IncludeRoleProvider) { var roleConfig = new RoleConfig(); roleConfig.Initialize(webConfig); roleConfig.Enabled = true; roleConfig.DefaultProvider = "MySQLRoleProvider"; var options = new Options(); options.AppName = @"\"; options.AutoGenSchema = true; options.ConnectionStringName = WizardForm.ConnectionStringNameForAspNetTables; options.ConnectionString = WizardForm.ConnectionStringForAspNetTables; options.EnableExpireCallback = false; options.ProviderName = "MySQLRoleProvider"; options.WriteExceptionToLog = WizardForm.WriteExceptionsToLog; roleConfig.GenericOptions = options; roleConfig.DefaultProvider = "MySQLRoleProvider"; roleConfig.Save(webConfig); } webConfig.Save(); } catch (Exception ex) { MySqlSourceTrace.WriteAppErrorToLog(ex, null, Resources.WebWizard_UserCreationError, true); } } catch (Exception ex) { MySqlSourceTrace.WriteAppErrorToLog(ex, true); } } SendToGeneralOutputWindow("Finished project generation."); WizardForm.Dispose(); }