1+ using System . Collections . Generic ;
12using System . ComponentModel . Design ;
23using System . IO ;
34using System . Windows . Interop ;
45using System . Windows . Threading ;
56using CodingWithCalvin . ProjectRenamifier . Dialogs ;
67using CodingWithCalvin . ProjectRenamifier . Services ;
8+ using CodingWithCalvin . Otel4Vsix ;
79using EnvDTE ;
810using EnvDTE80 ;
911
@@ -44,6 +46,8 @@ private void Execute(object sender, EventArgs e)
4446 {
4547 ThreadHelper . ThrowIfNotOnUIThread ( ) ;
4648
49+ using var activity = VsixTelemetry . StartCommandActivity ( "ProjectRenamifier.Execute" ) ;
50+
4751 if ( ! ( ServiceProvider . GetService ( typeof ( DTE ) ) is DTE2 dte ) )
4852 {
4953 return ;
@@ -63,9 +67,10 @@ private void RenameProject(Project project, DTE2 dte)
6367 {
6468 ThreadHelper . ThrowIfNotOnUIThread ( ) ;
6569
66- var currentName = Path . GetFileNameWithoutExtension ( project . FullName ) ;
70+ using var activity = VsixTelemetry . StartCommandActivity ( "ProjectRenamifier.RenameProject" ) ;
6771
68- var dialog = new RenameProjectDialog ( currentName ) ;
72+ var currentName = Path . GetFileNameWithoutExtension ( project . FullName ) ;
73+ var dialog = new RenameProjectDialog ( currentName ) ;
6974
7075 // Set the owner to the VS main window for proper modal behavior
7176 var helper = new WindowInteropHelper ( dialog )
@@ -75,13 +80,16 @@ private void RenameProject(Project project, DTE2 dte)
7580
7681 if ( dialog . ShowDialog ( ) != true )
7782 {
83+ VsixTelemetry . LogInformation ( "Rename cancelled by user" ) ;
7884 return ;
7985 }
8086
8187 var newName = dialog . NewProjectName ;
8288 var projectFilePath = project . FullName ;
8389 var originalProjectFilePath = projectFilePath ;
8490
91+ VsixTelemetry . LogInformation ( "Renaming project" ) ;
92+
8593 // Show progress dialog
8694 var progressDialog = new RenameProgressDialog ( currentName ) ;
8795 var progressHelper = new WindowInteropHelper ( progressDialog )
@@ -93,7 +101,7 @@ private void RenameProject(Project project, DTE2 dte)
93101 var stepIndex = 0 ;
94102 var projectRemovedFromSolution = false ;
95103 var projectReaddedToSolution = false ;
96- System . Collections . Generic . List < string > referencingProjects = null ;
104+ List < string > referencingProjects = null ;
97105 Project parentSolutionFolder = null ;
98106
99107 try
@@ -172,13 +180,27 @@ private void RenameProject(Project project, DTE2 dte)
172180 DoEvents ( ) ;
173181 System . Threading . Thread . Sleep ( 500 ) ;
174182 progressDialog . Close ( ) ;
183+
184+ activity ? . SetTag ( "rename.success" , true ) ;
185+ activity ? . SetTag ( "rename.steps_completed" , stepIndex ) ;
186+ VsixTelemetry . LogInformation ( "Successfully renamed project" ) ;
175187 }
176188 catch ( Exception ex )
177189 {
178190 // Mark the current step as failed
179191 progressDialog . FailStep ( stepIndex , ex . Message ) ;
180192 DoEvents ( ) ;
181193
194+ activity ? . RecordError ( ex ) ;
195+ activity ? . SetTag ( "rename.success" , false ) ;
196+ activity ? . SetTag ( "rename.failed_step" , stepIndex ) ;
197+
198+ VsixTelemetry . TrackException ( ex , new Dictionary < string , object >
199+ {
200+ { "operation.name" , "RenameProject" } ,
201+ { "step.index" , stepIndex }
202+ } ) ;
203+
182204 // Attempt rollback if project was removed but not re-added
183205 if ( projectRemovedFromSolution && ! projectReaddedToSolution )
184206 {
@@ -187,13 +209,16 @@ private void RenameProject(Project project, DTE2 dte)
187209 // Try to re-add the project at its current location
188210 var currentProjectPath = File . Exists ( projectFilePath ) ? projectFilePath : originalProjectFilePath ;
189211 if ( File . Exists ( currentProjectPath ) )
190- {
191- SolutionFolderService . AddProjectToSolution ( dte . Solution , currentProjectPath , parentSolutionFolder ) ;
212+ { SolutionFolderService . AddProjectToSolution ( dte . Solution , currentProjectPath , parentSolutionFolder ) ;
213+ VsixTelemetry . LogInformation ( "Rollback: Re-added project" ) ;
192214 }
193215 }
194- catch
216+ catch ( Exception rollbackEx )
195217 {
196- // Rollback failed, nothing more we can do
218+ VsixTelemetry . TrackException ( rollbackEx , new Dictionary < string , object >
219+ {
220+ { "operation.name" , "RenameProject.Rollback" }
221+ } ) ;
197222 }
198223 }
199224
0 commit comments