// <summary> // This will do analysis to determine if a document should be opened // only in the XmlEditor. // </summary> internal override void DetermineIfArtifactIsDesignerSafe() { VsUtils.EnsureProvider(this); base.DetermineIfArtifactIsDesignerSafe(); // // TODO: we need to figure out how to deal with errors from the wizard. // when we clear the error list below, we lose errors that we put into the error // list when running the wizard. // // // Now update the VS error list with all of the errors we want to display, which are now in the EFArtifactSet. // var errorInfos = ArtifactSet.GetAllErrors(); if (errorInfos.Count > 0) { var currentProject = VSHelpers.GetProjectForDocument(Uri.LocalPath, PackageManager.Package); if (currentProject != null) { var hierarchy = VsUtils.GetVsHierarchy(currentProject, Services.ServiceProvider); if (hierarchy != null) { var fileFinder = new VSFileFinder(Uri.LocalPath); fileFinder.FindInProject(hierarchy); Debug.Assert(fileFinder.MatchingFiles.Count <= 1, "Unexpected count of matching files in project"); // if the EDMX file is not part of the project. if (fileFinder.MatchingFiles.Count == 0) { var docData = VSHelpers.GetDocData(PackageManager.Package, Uri.LocalPath) as IEntityDesignDocData; ErrorListHelper.AddErrorInfosToErrorList(errorInfos, docData.Hierarchy, docData.ItemId); } else { foreach (var vsFileInfo in fileFinder.MatchingFiles) { if (vsFileInfo.Hierarchy == VsUtils.GetVsHierarchy(currentProject, Services.ServiceProvider)) { var errorList = ErrorListHelper.GetSingleDocErrorList(vsFileInfo.Hierarchy, vsFileInfo.ItemId); if (errorList != null) { errorList.Clear(); ErrorListHelper.AddErrorInfosToErrorList(errorInfos, vsFileInfo.Hierarchy, vsFileInfo.ItemId); } else { Debug.Fail("errorList is null!"); } } } } } } } }
private void ProcessDependentTTFiles() { // check if template processing was turned off via designer options var processTemplates = true; var artifact = PackageManager.Package.ModelManager.GetArtifact(Utils.FileName2Uri(FileName)); if (artifact != null) { DesignerInfo designerInfo; if (artifact.DesignerInfo().TryGetDesignerInfo(OptionsDesignerInfo.ElementName, out designerInfo)) { var optionsDesignerInfo = designerInfo as OptionsDesignerInfo; Debug.Assert( optionsDesignerInfo != null, "DesignerInfo associated with " + OptionsDesignerInfo.ElementName + "must be of type OptionsDesignerInfo"); if (optionsDesignerInfo != null && optionsDesignerInfo.ProcessDependentTemplatesOnSave != null && optionsDesignerInfo.ProcessDependentTemplatesOnSave.ValueAttr != null) { bool.TryParse(optionsDesignerInfo.ProcessDependentTemplatesOnSave.ValueAttr.Value, out processTemplates); } } } // if template processing was turned off, return if (processTemplates == false) { return; } // Find all .tt files in the project and invoke custom Tool var fileFinder = new VSFileFinder(".tt"); fileFinder.FindInProject(Hierarchy); foreach (var vsFileInfo in fileFinder.MatchingFiles) { if (IsDependentTTFile(vsFileInfo)) { var pi = VsUtils.GetProjectItem(vsFileInfo.Hierarchy, vsFileInfo.ItemId); Debug.Assert(pi != null, "Couldn't find project item, but file was discovered by VSFileFinder"); if (pi != null) { try { VsUtils.RunCustomTool(pi); } catch (Exception e) { // Swallow exceptions here, since we don't want a custom tool to interfere with the file save. var errorMsg = String.Format( CultureInfo.CurrentCulture, Resources.ErrorOccurredRunningCustomTool, vsFileInfo.Path, e.Message); VsUtils.LogOutputWindowPaneMessage(VSHelpers.GetProject(Hierarchy), errorMsg); } } } } }
internal static HashSet <string> InitializeExistingNamespaces(Project project) { var existingNamespaces = new HashSet <string>(); if (project != null) { // find the namespace used in the CSDL section of each existing edmx file in the project var vsHierarchy = VsUtils.GetVsHierarchy(project, Services.ServiceProvider); var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx); fileFinder.FindInProject(vsHierarchy); foreach (var fileInfo in fileFinder.MatchingFiles) { try { var xmlDocument = EdmUtils.SafeLoadXmlFromPath(fileInfo.Path); foreach (var schemaVersion in EntityFrameworkVersion.GetAllVersions()) { var nsMgr = SchemaManager.GetEdmxNamespaceManager(xmlDocument.NameTable, schemaVersion); foreach ( XmlElement e in xmlDocument.SelectNodes("/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/csdl:Schema", nsMgr)) { var namespaceValue = e.GetAttribute("Namespace"); if (!string.IsNullOrEmpty(namespaceValue)) { existingNamespaces.Add(namespaceValue); } } } } // swallow various exceptions that come from reading the file or parsing xml // We just skip this document in the event of an exception. catch (IOException) { } catch (UnauthorizedAccessException) { } catch (NotSupportedException) { } catch (SecurityException) { } catch (XmlException) { } } } return(existingNamespaces); }
private static bool ShouldLoadEDMPackage(IVsHierarchy project) { var shouldLoadEDMPackage = false; try { if (BootstrapUtils.IsEDMSupportedInProject(project)) { // Check if project is a website project. If yes, search for edmx files under the app_code folder. // Note that website project doesn't have project file and to exclude files from project you append ".exclude" in file name. var dteProject = BootstrapUtils.GetProject(project); if (dteProject != null && BootstrapUtils.IsWebProject(dteProject)) { var projectFullPathProperty = dteProject.Properties.Item("FullPath"); var projectFullPath = projectFullPathProperty.Value as string; Debug.Assert(String.IsNullOrWhiteSpace(projectFullPath) == false, "Unable to get project full path"); if (String.IsNullOrWhiteSpace(projectFullPath) == false) { // App_Code is a special folder that will not be localized should always be under root folder. var appCodePath = Path.Combine(projectFullPath, "App_Code"); if (Directory.Exists(appCodePath)) { // Directory.GetFiles could potentially be an expensive operation. // If the performance is not acceptable, we should look into calling Win32 API to search for files. shouldLoadEDMPackage = Directory.GetFiles(appCodePath, "*" + ExtensionEdmx, SearchOption.AllDirectories).Any(); } } } else { var fileFinder = new VSFileFinder(ExtensionEdmx); shouldLoadEDMPackage = fileFinder.ExistInProject(project); } } } catch (Exception ex) { Debug.Fail("Caught exception in BootstrapPackage's ShouldLoadEDMPackage method. Message: " + ex.Message); // We want to continue loading the package if the exception is not critical. // Do not do Debug.Assert here because it could cause a lot of DDBasic failures in CHK build. if (VSErrorHandler.IsCriticalException(ex)) { throw; } } return(shouldLoadEDMPackage); }
internal static HashSet<string> InitializeExistingNamespaces(Project project) { var existingNamespaces = new HashSet<string>(); if (project != null) { // find the namespace used in the CSDL section of each existing edmx file in the project var vsHierarchy = VsUtils.GetVsHierarchy(project, Services.ServiceProvider); var fileFinder = new VSFileFinder(EntityDesignArtifact.ExtensionEdmx); fileFinder.FindInProject(vsHierarchy); foreach (var fileInfo in fileFinder.MatchingFiles) { try { var xmlDocument = EdmUtils.SafeLoadXmlFromPath(fileInfo.Path); foreach (var schemaVersion in EntityFrameworkVersion.GetAllVersions()) { var nsMgr = SchemaManager.GetEdmxNamespaceManager(xmlDocument.NameTable, schemaVersion); foreach ( XmlElement e in xmlDocument.SelectNodes("/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/csdl:Schema", nsMgr)) { var namespaceValue = e.GetAttribute("Namespace"); if (!string.IsNullOrEmpty(namespaceValue)) { existingNamespaces.Add(namespaceValue); } } } } // swallow various exceptions that come from reading the file or parsing xml // We just skip this document in the event of an exception. catch (IOException) { } catch (UnauthorizedAccessException) { } catch (NotSupportedException) { } catch (SecurityException) { } catch (XmlException) { } } } return existingNamespaces; }
private static bool ShouldLoadEDMPackage(IVsHierarchy project) { var shouldLoadEDMPackage = false; try { if (BootstrapUtils.IsEDMSupportedInProject(project)) { // Check if project is a website project. If yes, search for edmx files under the app_code folder. // Note that website project doesn't have project file and to exclude files from project you append ".exclude" in file name. var dteProject = BootstrapUtils.GetProject(project); if (dteProject != null && BootstrapUtils.IsWebProject(dteProject)) { var projectFullPathProperty = dteProject.Properties.Item("FullPath"); var projectFullPath = projectFullPathProperty.Value as string; Debug.Assert(String.IsNullOrWhiteSpace(projectFullPath) == false, "Unable to get project full path"); if (String.IsNullOrWhiteSpace(projectFullPath) == false) { // App_Code is a special folder that will not be localized should always be under root folder. var appCodePath = Path.Combine(projectFullPath, "App_Code"); if (Directory.Exists(appCodePath)) { // Directory.GetFiles could potentially be an expensive operation. // If the performance is not acceptable, we should look into calling Win32 API to search for files. shouldLoadEDMPackage = Directory.GetFiles(appCodePath, "*" + ExtensionEdmx, SearchOption.AllDirectories).Any(); } } } else { var fileFinder = new VSFileFinder(ExtensionEdmx); shouldLoadEDMPackage = fileFinder.ExistInProject(project); } } } catch (Exception ex) { Debug.Fail("Caught exception in BootstrapPackage's ShouldLoadEDMPackage method. Message: " + ex.Message); // We want to continue loading the package if the exception is not critical. // Do not do Debug.Assert here because it could cause a lot of DDBasic failures in CHK build. if (VSErrorHandler.IsCriticalException(ex)) { throw; } } return shouldLoadEDMPackage; }