/// <summary> /// Makes sure <paramref name="eventArgs"/> is not null /// and logs the event to <see cref="_log"/> /// </summary> /// <returns><c>False</c> if <paramref name="eventArgs"/> is <c>null</c>, <c>True</c> otherwise.</returns> private void QueueVisualStudioEvent(object sender, VisualStudioEventArgs eventArgs) { #region Null Guard Check and Logging if (null == eventArgs) { _log.Error("Received a [null] event in OnVisualStudioEvents"); return; } var senderId = (null == sender) ? "<null sender>" : sender.GetType().Name; _log.InfoFormat("[{0}] sent event: {1}", senderId, eventArgs.GetDebugString()); #endregion if (eventArgs is VisualStudioClassEventArgs && !(eventArgs as VisualStudioClassEventArgs).IsCSharpFile()) { return; } lock (EventQueueLock) { _pendingVisualStudioEvents.Add(eventArgs); } }
/// <summary> /// Makes sure <paramref name="eventArgs"/> is not null /// and logs the event to <see cref="_log"/> /// </summary> /// <returns><c>False</c> if <paramref name="eventArgs"/> is <c>null</c>, <c>True</c> otherwise.</returns> private void QueueVisualStudioEvent(object sender, VisualStudioEventArgs eventArgs) { #region Null Guard Check and Logging if (null == eventArgs) { _log.Error("Received a [null] event in OnVisualStudioEvents"); return; } var senderId = (null == sender) ? "<null sender>" : sender.GetType().Name; _log.InfoFormat("[{0}] sent event: {1}", senderId, eventArgs.GetDebugString()); #endregion if (eventArgs is VisualStudioClassEventArgs && !(eventArgs as VisualStudioClassEventArgs).IsCSharpFile()) return; lock (EventQueueLock) { _pendingVisualStudioEvents.Add(eventArgs); } }
private void ProcessEventSafe(VisualStudioEventArgs vsEvent) { if (vsEvent is VisualStudioBuildEventArgs) { return; } if (vsEvent is ProjectAddedEventArgs || vsEvent is ProjectReferenceAddedEventArgs || vsEvent is ProjectReferenceRemovedEventArgs) { SolutionExtender.AddOrUpdateProject(vsEvent.ProjectFullPath); return; } if (vsEvent is ProjectRemovedEventArgs) { SolutionExtender.RemoveProject(SolutionExtender.GetProjectByFilePath(vsEvent.ProjectFullPath)); return; } if (vsEvent is VisualStudioClassEventArgs) { var classEvent = vsEvent as VisualStudioClassEventArgs; if (!classEvent.IsCSharpFile()) { return; } if (classEvent is ProjectItemAddedEventArgs) { SolutionExtender.AddFileToProject(classEvent.ProjectFullPath, classEvent.ClassFullPath); return; } if (classEvent is ProjectItemRemovedEventArgs) { SolutionExtender.RemoveCSharpFileFromProject( SolutionExtender.GetProjectByFilePath(vsEvent.ProjectFullPath), classEvent.ClassFullPath); return; } if (classEvent is ProjectItemRenamedEventArgs) { var origFileName = ((ProjectItemRenamedEventArgs)classEvent).OldClassFileName; var project = SolutionExtender.GetProjectByFilePath(classEvent.ProjectFullPath); if (null == project) { throw new Exception(string.Format(Strings.ExceptionCouldNotFindProjectWithFullName, classEvent.ProjectFullPath)); } SolutionExtender.RemoveCSharpFileFromProject(project, origFileName); SolutionExtender.AddFileToProject(classEvent.ProjectFullPath, classEvent.ClassFullPath); return; } if (classEvent is ProjectItemSavedEventArgs) { var project = SolutionExtender.GetProjectByFilePath(classEvent.ProjectFullPath); if (null == project) { throw new Exception(string.Format(Strings.ExceptionCouldNotFindProjectWithFullName, classEvent.ProjectFullPath)); } SolutionExtender.RemoveCSharpFileFromProject(project, classEvent.ClassFullPath); SolutionExtender.AddFileToProject(classEvent.ProjectFullPath, classEvent.ClassFullPath); } } //If we made it this far we don't know how to handle this type of event. throw new Exception( string.Format( "ProcessEventSafe() does not know how to handle event of type [{0}]. This is a bug and the method should be updated.", vsEvent.GetType())); }
private void ProcessEventSafe(VisualStudioEventArgs vsEvent) { if (vsEvent is VisualStudioBuildEventArgs) return; if (vsEvent is ProjectAddedEventArgs || vsEvent is ProjectReferenceAddedEventArgs || vsEvent is ProjectReferenceRemovedEventArgs) { SolutionExtender.AddOrUpdateProject(vsEvent.ProjectFullPath); return; } if (vsEvent is ProjectRemovedEventArgs) { SolutionExtender.RemoveProject(SolutionExtender.GetProjectByFilePath(vsEvent.ProjectFullPath)); return; } if (vsEvent is VisualStudioClassEventArgs) { var classEvent = vsEvent as VisualStudioClassEventArgs; if (!classEvent.IsCSharpFile()) return; if (classEvent is ProjectItemAddedEventArgs) { SolutionExtender.AddFileToProject(classEvent.ProjectFullPath, classEvent.ClassFullPath); return; } if (classEvent is ProjectItemRemovedEventArgs) { SolutionExtender.RemoveCSharpFileFromProject( SolutionExtender.GetProjectByFilePath(vsEvent.ProjectFullPath), classEvent.ClassFullPath); return; } if (classEvent is ProjectItemRenamedEventArgs) { var origFileName = ((ProjectItemRenamedEventArgs) classEvent).OldClassFileName; var project = SolutionExtender.GetProjectByFilePath(classEvent.ProjectFullPath); if (null == project) throw new Exception(string.Format(Strings.ExceptionCouldNotFindProjectWithFullName, classEvent.ProjectFullPath)); SolutionExtender.RemoveCSharpFileFromProject(project, origFileName); SolutionExtender.AddFileToProject(classEvent.ProjectFullPath, classEvent.ClassFullPath); return; } if (classEvent is ProjectItemSavedEventArgs) { var project = SolutionExtender.GetProjectByFilePath(classEvent.ProjectFullPath); if (null == project) throw new Exception(string.Format(Strings.ExceptionCouldNotFindProjectWithFullName, classEvent.ProjectFullPath)); SolutionExtender.RemoveCSharpFileFromProject(project, classEvent.ClassFullPath); SolutionExtender.AddFileToProject(classEvent.ProjectFullPath, classEvent.ClassFullPath); } } //If we made it this far we don't know how to handle this type of event. throw new Exception( string.Format( "ProcessEventSafe() does not know how to handle event of type [{0}]. This is a bug and the method should be updated.", vsEvent.GetType())); }