private static SourceFile GetSourceFile(EnvDTE.ProjectItem projectItem)
 {
     return CodeRush.Source.ActiveSolution.FindSourceFile(projectItem.get_FileNames(0));
 }
        private void ProjectItemRenamed(EnvDTE.ProjectItem projectItem, string oldName)
        {
            try
            {
                string originalPath = Path.GetDirectoryName(projectItem.get_FileNames(0)) + Path.DirectorySeparatorChar + oldName;
                foreach (CodeIssueFile codeIssue in CodeIssues)
                {
                    if (codeIssue.file.Name == originalPath)
                        codeIssue.file = GetSourceFile(projectItem);
                }
            }
            catch (Exception err)
            {
                Debug.Assert(false, "Error renaming code issues", err.Message);
            }

            OnResults(null);
        }
示例#3
0
		/// <summary>
		/// Ensure that the current project item has the required extensions loaded.
		/// This is only called after verifying that the current project item does
		/// not satisfy the requirements.
		/// </summary>
		/// <param name="projectItem">The <see cref="EnvDTE.ProjectItem"/> to modify</param>
		/// <param name="serviceProvider">The <see cref="IServiceProvider"/> for document tracking.</param>
		/// <param name="extensions">An <see cref="T:ICollection{System.String}"/> of additional required extensions</param>
		public static bool EnsureExtensions(EnvDTE.ProjectItem projectItem, IServiceProvider serviceProvider, ICollection<string> extensions)
		{
			ServiceProvider provider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)projectItem.DTE);
			// UNDONE: Localize message strings in here
			if ((int)DialogResult.No == VsShellUtilities.ShowMessageBox(
				provider,
				"Additional extensions are required to support the chosen generators. Would you like to load the required extensions now?",
				"ORM Generator Selection",
				OLEMSGICON.OLEMSGICON_QUERY,
				OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
				OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST))
			{
				return false;
			}
			EnvDTE.Document document = projectItem.Document;
			bool secondPass = false;
			bool tryDocument = true;
			string itemPath = null;
			while (tryDocument)
			{
				object documentExtensionManager;
				MethodInfo methodInfo;
				if (null != document &&
					null != (documentExtensionManager = ORMCustomToolUtility.GetDocumentExtension<object>(document, "ORMExtensionManager", itemPath ?? (itemPath = projectItem.get_FileNames(0)), serviceProvider)) &&
					null != (methodInfo = documentExtensionManager.GetType().GetMethod("EnsureExtensions", new Type[] { typeof(string[]) })))
				{
					string[] extensionsArray = new string[extensions.Count];
					extensions.CopyTo(extensionsArray, 0);
					methodInfo.Invoke(documentExtensionManager, new object[] { extensionsArray });
					return true;
				}

				if (secondPass)
				{
					return false;
				}
				tryDocument = false;
				secondPass = true;

				// UNDONE: Localize message strings in here
				if ((int)DialogResult.No == VsShellUtilities.ShowMessageBox(
					provider,
					"The .ORM file must be open in the default designer to add extensions. Would you like to open or reopen the document now?",
					"ORM Generator Selection",
					OLEMSGICON.OLEMSGICON_QUERY,
					OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
					OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST))
				{
					return false;
				}

				if (document != null)
				{
					document.Close(EnvDTE.vsSaveChanges.vsSaveChangesPrompt);
					document = projectItem.Document;
				}
				if (document == null)
				{
					projectItem.Open(Guid.Empty.ToString("B")).Visible = true;
					document = projectItem.Document;
					tryDocument = true;
				}
			}
			return false;
		}
        private void ProjectItemRemoved(EnvDTE.ProjectItem projectItem)
        {
            try
            {
                CodeIssues.RemoveAll(new CodeIssueMatch(projectItem.get_FileNames(0)).FilePathMatch);
            }
            catch (Exception err)
            {
                Debug.Assert(false, "Error removing code issues", err.Message);
            }

            OnResults(null);
        }
        /// <summary>
        /// Runs custom wizard logic when a project item has finished generating.
        /// </summary>
        /// <param name="projectItem">The project item that finished generating.</param>
        public override void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
        {
            base.ProjectItemFinishedGenerating(projectItem);

            if (this.projectItemCreated == null)
            {
                this.projectItemCreated = projectItem.get_FileNames(1);
            }
        }