/// <summary> /// Set properties such as "Custom Tool" and "Item Type" /// </summary> internal static void SetProjectItemProperties(ProjectItem projectItem, VisualStudioProjectSystem applicationType) { // set the CustomTool property for the SingleFileGenerator EdmUtils.ToggleEdmxItemCustomToolProperty(projectItem, true); // set the ItemType property to "EntityDeploy". This is the "build action" of the item. if (applicationType != VisualStudioProjectSystem.Website) { var prop = projectItem.Properties.Item(ModelObjectItemWizard.ItemTypePropertyName); if (prop != null) { prop.Value = ModelObjectItemWizard.EntityDeployBuildActionName; } } }
public ConfigFileUtils(Project project, IServiceProvider serviceProvider, VisualStudioProjectSystem?applicationType = null, IVsUtils vsUtils = null, IVsHelpers vsHelpers = null) { Debug.Assert(project != null, "project is null"); Debug.Assert(serviceProvider != null, "serviceProvider is null"); _vsUtils = vsUtils ?? new VsUtilsWrapper(); _vsHelpers = vsHelpers ?? new VsHelpersWrapper(); _project = project; _serviceProvider = serviceProvider; _applicationType = applicationType ?? _vsUtils.GetApplicationType(_serviceProvider, _project); _configFileName = VsUtils.IsWebProject(_applicationType) ? VsUtils.WebConfigFileName : VsUtils.AppConfigFileName; }
private static Mock <IVsUtils> CreateMockVsUtils(LangEnum projectLanguage, VisualStudioProjectSystem applicationType) { var mockVsUtils = new Mock <IVsUtils>(); mockVsUtils .Setup(u => u.GetApplicationType(It.IsAny <IServiceProvider>(), It.IsAny <Project>())) .Returns(applicationType); mockVsUtils .Setup(u => u.GetLanguageForProject(It.IsAny <Project>())) .Returns(projectLanguage); mockVsUtils .Setup(u => u.GetProjectRoot(It.IsAny <Project>(), It.IsAny <IServiceProvider>())) .Returns(new DirectoryInfo(Directory.GetCurrentDirectory())); return(mockVsUtils); }
/// <summary> /// Set properties such as "Custom Tool" and "Item Type" /// </summary> internal static void SetProjectItemProperties(ProjectItem projectItem, VisualStudioProjectSystem applicationType) { // set the CustomTool property for the SingleFileGenerator EdmUtils.ToggleEdmxItemCustomToolProperty(projectItem, true); // set the ItemType property to "EntityDeploy". This is the "build action" of the item. if (applicationType != VisualStudioProjectSystem.Website) { var prop = projectItem.Properties.Item(ModelObjectItemWizard.ItemTypePropertyName); if (prop != null) { prop.Value = ModelObjectItemWizard.EntityDeployBuildActionName; } } }
public ConfigFileUtils(Project project, IServiceProvider serviceProvider, VisualStudioProjectSystem? applicationType = null, IVsUtils vsUtils = null, IVsHelpers vsHelpers = null) { Debug.Assert(project != null, "project is null"); Debug.Assert(serviceProvider != null, "serviceProvider is null"); _vsUtils = vsUtils ?? new VsUtilsWrapper(); _vsHelpers = vsHelpers ?? new VsHelpersWrapper(); _project = project; _serviceProvider = serviceProvider; _applicationType = applicationType ?? _vsUtils.GetApplicationType(_serviceProvider, _project); _configFileName = VsUtils.IsWebProject(_applicationType) ? VsUtils.WebConfigFileName : VsUtils.AppConfigFileName; }
private static string GetOutputPath(Project project, VisualStudioProjectSystem applicationType) { return (VisualStudioProjectSystem.WebApplication == applicationType) ? project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value as string : string.Empty; }
internal static ConnectionString CreateEntityConnectionString( Project project, VisualStudioProjectSystem applicationType, IEnumerable<string> metadataFiles, string configFileConnectionStringValue, string providerInvariantName) { // note that this connection string may not have credentials if the user chose to not store sensitive info return ConstructConnectionStringObject( InjectEFAttributesIntoConnectionString(configFileConnectionStringValue, providerInvariantName), providerInvariantName, metadataFiles, project, applicationType); }
// <summary> // Construct a connection string and add it to the hash, pushing the update to the .config file // </summary> internal void AddConnectionString(Project project, VisualStudioProjectSystem applicationType, ICollection<string> metadataFiles, string connectionStringName, string configFileConnectionStringValue, string providerInvariantName) { if (null == project) { throw new ArgumentNullException("project"); } if (project.UniqueName.Equals(Constants.vsMiscFilesProjectUniqueName, StringComparison.Ordinal)) { return; } if (String.IsNullOrEmpty(connectionStringName)) { throw new ArgumentNullException("connectionStringName"); } if (String.IsNullOrEmpty(configFileConnectionStringValue)) { throw new ArgumentNullException("configFileConnectionStringValue"); } var newConfigFileConnString = CreateEntityConnectionString( project, applicationType, metadataFiles, configFileConnectionStringValue, providerInvariantName); // add the connection string to the hash and update the .config file AddConnectionString(project, connectionStringName, newConfigFileConnString); }
// <summary> // Helper to wrap the given sql connection string with a entity client connection string and return it // </summary> // <param name="sqlConnectionString">sql connection string</param> // <returns>map connection string containing the sql connection string</returns> internal static ConnectionString ConstructConnectionStringObject( string sqlConnectionString, string providerInvariantName, IEnumerable<string> metadataFiles, Project project, VisualStudioProjectSystem applicationType) { if (null == sqlConnectionString) { throw new ArgumentNullException("sqlConnectionString"); } if (String.IsNullOrEmpty(providerInvariantName)) { throw new ArgumentNullException("providerInvariantName"); } if (project == null) { throw new ArgumentNullException("project"); } // Wrap the given sql connection string in a map connection string var builder = new EntityConnectionStringBuilder { Provider = providerInvariantName, ProviderConnectionString = sqlConnectionString, // we don't want to mess with the model when we are in the process of adding it, so just feed in the default value for metadata artifact processing Metadata = GetConnectionStringMetadata( metadataFiles, project, applicationType, GetMetadataArtifactProcessingDefault()) }; return new ConnectionString(builder); }
// <summary> // Helper function to construct the metadata, depending on what type of application and output path // </summary> private static string GetConnectionStringMetadata( IEnumerable<string> metadataFiles, Project project, VisualStudioProjectSystem applicationType, string metadataProcessingType) { var outputPath = GetOutputPath(project, applicationType); // fix up outputPath if (null == outputPath) { outputPath = String.Empty; } else if (!outputPath.EndsWith("\\", StringComparison.OrdinalIgnoreCase)) { outputPath += "\\"; } outputPath = outputPath.Replace("\\", "/"); // construct metadata portion of connection string if (metadataFiles == null || !metadataFiles.Any()) { if (metadataProcessingType == ConnectionDesignerInfo.MAP_EmbedInOutputAssembly || applicationType == VisualStudioProjectSystem.Website) { return EmbedAsResourcePrefix; } if (applicationType == VisualStudioProjectSystem.WebApplication) { // web-app's need to have the outputPath (usually "bin") appended return "~/" + outputPath; } else { return "."; } } else { var md = new StringBuilder(); var i = 0; var metadataFileCount = metadataFiles.Count(); foreach (var f in metadataFiles) { // if this is a web app, then change relative path to virtual path if (applicationType == VisualStudioProjectSystem.WebApplication && metadataProcessingType == ConnectionDesignerInfo.MAP_CopyToOutputDirectory) { md.Append(f.Replace(".\\", "~/" + outputPath)); } else if (applicationType == VisualStudioProjectSystem.Website) { // // The 3.5 runtime's Build Provider will include the web site's virtual root in the resource name. This can change when // a web app is deployed, so we must use res:\\* for the connection string when targeting netfx 3.5. // if (NetFrameworkVersioningHelper.TargetNetFrameworkVersion(project, PackageManager.Package) == NetFrameworkVersioningHelper.NetFrameworkVersion3_5) { return EmbedAsResourcePrefix; } else { md.Append(EmbedAsResourcePrefix); md.Append("/"); if (f[0] == '.' && f[1] == Path.DirectorySeparatorChar) { var folderAndFile = f.Substring(2); md.Append(folderAndFile.Replace(Path.DirectorySeparatorChar, '.')); } else { Debug.Fail("Unexpected start characters in metadata file"); return EmbedAsResourcePrefix; } } } else { if (metadataProcessingType == ConnectionDesignerInfo.MAP_EmbedInOutputAssembly) { md.Append(EmbedAsResourcePrefix); md.Append("/"); md.Append(f.Replace(Path.DirectorySeparatorChar, '.').TrimStart('.')); } else if (metadataProcessingType == ConnectionDesignerInfo.MAP_CopyToOutputDirectory) { md.Append(f); } } if (i++ < metadataFileCount - 1) { // Character used by framework to separate paths to artifacts in the Entity Connection String md.Append("|"); } } return md.ToString(); } }
public CodeIdentifierUtils(VisualStudioProjectSystem applicationType, LangEnum projectLanguage) { _applicationType = applicationType; _projectLanguage = projectLanguage; }
public CodeIdentifierUtils(VisualStudioProjectSystem applicationType, LangEnum projectLanguage) { _applicationType = applicationType; _projectLanguage = projectLanguage; }
private static Mock<IVsUtils> CreateMockVsUtils(LangEnum projectLanguage, VisualStudioProjectSystem applicationType) { var mockVsUtils = new Mock<IVsUtils>(); mockVsUtils .Setup(u => u.GetApplicationType(It.IsAny<IServiceProvider>(), It.IsAny<Project>())) .Returns(applicationType); mockVsUtils .Setup(u => u.GetLanguageForProject(It.IsAny<Project>())) .Returns(projectLanguage); mockVsUtils .Setup(u => u.GetProjectRoot(It.IsAny<Project>(), It.IsAny<IServiceProvider>())) .Returns(new DirectoryInfo(Directory.GetCurrentDirectory())); return mockVsUtils; }