public int OnBeforeUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy) { var handler = BeforeCloseProject; if (handler != null) { var args = new ModelChangeEventArgs(); try { args.ProjectObj = VSHelpers.GetProject(pRealHierarchy); } catch (ArgumentException) { return(VSConstants.E_NOTIMPL); } if (args.ProjectObj == null) { return(VSConstants.E_NOTIMPL); } return(handler(this, args)); } return(VSConstants.S_OK); }
public int OnQueryRemoveFiles( IVsProject pProject, int cFiles, string[] rgpszMkDocuments, VSQUERYREMOVEFILEFLAGS[] rgFlags, VSQUERYREMOVEFILERESULTS[] pSummaryResult, VSQUERYREMOVEFILERESULTS[] rgResults) { var hr = VSConstants.S_OK; var handler = QueryRemoveFile; if (handler != null) { if (cFiles <= rgpszMkDocuments.Length) { for (var fileCount = 0; fileCount < cFiles; fileCount++) { var args = new ModelChangeEventArgs(); args.OldFileName = rgpszMkDocuments[fileCount]; args.ProjectObj = VSHelpers.GetProject(pProject as IVsHierarchy); if (args.ProjectObj == null) { continue; } hr = handler(this, args); } } } return(hr); }
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); } } } } }
private bool IsDependentTTFile(VSFileFinder.VSFileInfo fileInfo) { string contents = null; var docData = VSHelpers.GetDocData(ServiceProvider, fileInfo.Path); if (docData == null) { // load file from disk try { contents = File.ReadAllText(fileInfo.Path); } catch (Exception e) { var errorMsg = String.Format(CultureInfo.CurrentCulture, Resources.ErrorOccurredLoadingFile, fileInfo.Path, e.Message); VsUtils.LogOutputWindowPaneMessage(VSHelpers.GetProject(Hierarchy), errorMsg); contents = null; } } else { // read buffer contents var tl = VSHelpers.GetVsTextLinesFromDocData(docData); Debug.Assert(tl != null, "Couldn't get text lines from doc data for .tt file"); if (tl != null) { contents = VSHelpers.GetTextFromVsTextLines(tl); } } // // BUGBUG 592011: replace this with something smarter. Use T4 parser to identify all input files. // if (contents != null) { var fi = new FileInfo(FileName); return(contents.Contains(fi.Name)); } else { return(false); } }
public int OnAfterSave(uint docCookie) { var hr = VSConstants.S_OK; if (AfterSaveFile != null) { var docTable = Services.IVsRunningDocumentTable; uint rdtFlags, readLocks, editLocks, itemId; string fileName; IVsHierarchy hierarchy; var docData = IntPtr.Zero; try { hr = docTable.GetDocumentInfo( docCookie, out rdtFlags, out readLocks, out editLocks, out fileName, out hierarchy, out itemId, out docData); } finally { if (docData != IntPtr.Zero) { Marshal.Release(docData); } } if (hr == VSConstants.S_OK && hierarchy != null) { var projectObj = VSHelpers.GetProject(hierarchy); if (projectObj != null) { var args = new ModelChangeEventArgs(); args.DocCookie = docCookie; args.Artifact = PackageManager.Package.ModelManager.GetArtifact(Utils.FileName2Uri(fileName)); args.ProjectObj = projectObj; hr = AfterSaveFile(this, args); } } } return(hr); }
public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded) { if (AfterOpenProject != null) { var args = new ModelChangeEventArgs(); try { args.ProjectObj = VSHelpers.GetProject(pHierarchy); } catch (ArgumentException) { return(VSConstants.E_NOTIMPL); } if (args.ProjectObj == null) { return(VSConstants.E_NOTIMPL); } return(AfterOpenProject(this, args)); } return(VSConstants.S_OK); }
private static Project GetProjectFromArray(int cProjects, int fileIndex, IVsProject[] rgpProjects, int[] rgFirstIndices) { if (cProjects == 0) { return(null); } var projIndex = 0; for (; projIndex + 1 < cProjects; projIndex++) { if (fileIndex > rgFirstIndices[projIndex] && fileIndex < rgFirstIndices[projIndex + 1]) { break; } } var hierarchy = rgpProjects[projIndex] as IVsHierarchy; if (hierarchy == null) { return(null); } return(VSHelpers.GetProject(hierarchy)); }