protected override void ProcessRecordCore() { var startTime = DateTimeOffset.Now; // start timer for telemetry event TelemetryServiceUtility.StartOrResumeTimer(); // Run Preprocess outside of JTF Preprocess(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await _lockService.ExecuteNuGetOperationAsync(() => { SubscribeToProgressEvents(); WarnIfParametersAreNotSupported(); if (!_readFromPackagesConfig && !_readFromDirectPackagePath && _nugetVersion == null) { Task.Run(InstallPackageByIdAsync); } else { var identities = GetPackageIdentities(); Task.Run(() => InstallPackagesAsync(identities)); } WaitAndLogPackageActions(); UnsubscribeFromProgressEvents(); return(Task.FromResult(true)); }, Token); }); // stop timer for telemetry event and create action telemetry event instance TelemetryServiceUtility.StopTimer(); var isPackageSourceMappingEnabled = PackageSourceMappingUtility.IsMappingEnabled(ConfigSettings); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( OperationId.ToString(), new[] { Project }, NuGetOperationType.Install, OperationSource.PMC, startTime, _status, _packageCount, TelemetryServiceUtility.GetTimerElapsedTimeInSeconds(), isPackageSourceMappingEnabled: isPackageSourceMappingEnabled); // emit telemetry event along with granular level events TelemetryActivity.EmitTelemetryEvent(actionTelemetryEvent); }
protected override void ProcessRecordCore() { var startTime = DateTimeOffset.Now; // Set to log telemetry granular events for this update operation TelemetryService = new NuGetVSActionTelemetryService(); // start timer for telemetry event TelemetryServiceUtility.StartOrResumeTimer(); // Run Preprocess outside of JTF Preprocess(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await _lockService.ExecuteNuGetOperationAsync(() => { SubscribeToProgressEvents(); WarnIfParametersAreNotSupported(); // Update-Package without ID specified if (!_idSpecified) { Task.Run(UpdateOrReinstallAllPackagesAsync); } // Update-Package with Id specified else { Task.Run(UpdateOrReinstallSinglePackageAsync); } WaitAndLogPackageActions(); UnsubscribeFromProgressEvents(); return(Task.FromResult(true)); }, Token); }); // stop timer for telemetry event and create action telemetry event instance TelemetryServiceUtility.StopTimer(); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( new[] { Project }, NuGetOperationType.Update, OperationSource.PMC, startTime, _status, _packageCount, TelemetryServiceUtility.GetTimerElapsedTimeInSeconds()); // emit telemetry event along with granular level for update operation TelemetryService.EmitTelemetryEvent(actionTelemetryEvent); }
protected override void ProcessRecordCore() { var startTime = DateTimeOffset.Now; _packageCount = 1; var stopWatch = Stopwatch.StartNew(); // Run Preprocess outside of JTF Preprocess(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await _lockService.ExecuteNuGetOperationAsync(() => { SubscribeToProgressEvents(); Task.Run(UninstallPackageAsync); WaitAndLogPackageActions(); UnsubscribeFromProgressEvents(); return(Task.FromResult(true)); }, Token); }); stopWatch.Stop(); var isPackageSourceMappingEnabled = PackageSourceMappingUtility.IsMappingEnabled(ConfigSettings); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( OperationId.ToString(), new[] { Project }, NuGetOperationType.Uninstall, OperationSource.PMC, startTime, _status, _packageCount, stopWatch.Elapsed.TotalSeconds, isPackageSourceMappingEnabled: isPackageSourceMappingEnabled); // emit telemetry event along with granular level events TelemetryActivity.EmitTelemetryEvent(actionTelemetryEvent); }
protected override void ProcessRecordCore() { var startTime = DateTimeOffset.Now; _packageCount = 1; // Enable granular level events for this uninstall operation TelemetryService = new NuGetVSActionTelemetryService(); TelemetryServiceUtility.StartOrResumeTimer(); // Run Preprocess outside of JTF Preprocess(); NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await _lockService.ExecuteNuGetOperationAsync(() => { SubscribeToProgressEvents(); Task.Run(UninstallPackageAsync); WaitAndLogPackageActions(); UnsubscribeFromProgressEvents(); return(Task.FromResult(true)); }, Token); }); TelemetryServiceUtility.StopTimer(); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( new[] { Project }, NuGetOperationType.Uninstall, OperationSource.PMC, startTime, _status, _packageCount, TelemetryServiceUtility.GetTimerElapsedTimeInSeconds()); // emit telemetry event with granular level events TelemetryService.EmitTelemetryEvent(actionTelemetryEvent); }
/// <summary> /// The internal implementation to perform user action. /// </summary> /// <param name="resolveActionsAsync">A function that returns a task that resolves the user /// action into project actions.</param> /// <param name="executeActionsAsync">A function that returns a task that executes /// the project actions.</param> private async Task PerformActionImplAsync( INuGetUI uiService, Func <SourceCacheContext, Task <IReadOnlyList <ResolvedAction> > > resolveActionsAsync, Func <IReadOnlyList <ResolvedAction>, SourceCacheContext, Task> executeActionsAsync, NuGetOperationType operationType, CancellationToken token) { var status = NuGetOperationStatus.Succeeded; var startTime = DateTimeOffset.Now; var packageCount = 0; // Enable granular level telemetry events for nuget ui operation uiService.ProjectContext.OperationId = Guid.NewGuid(); await _lockService.ExecuteNuGetOperationAsync(async() => { try { uiService.BeginOperation(); var acceptedFormat = await CheckPackageManagementFormat(uiService, token); if (!acceptedFormat) { return; } TelemetryServiceUtility.StartOrResumeTimer(); using (var sourceCacheContext = new SourceCacheContext()) { var actions = await resolveActionsAsync(sourceCacheContext); var results = GetPreviewResults(actions); if (operationType == NuGetOperationType.Uninstall) { packageCount = results.SelectMany(result => result.Deleted). Select(package => package.Id).Distinct().Count(); } else { var addCount = results.SelectMany(result => result.Added). Select(package => package.Id).Distinct().Count(); var updateCount = results.SelectMany(result => result.Updated). Select(result => result.New.Id).Distinct().Count(); // update packages count packageCount = addCount + updateCount; if (updateCount > 0) { // set operation type to update when there are packages being updated operationType = NuGetOperationType.Update; } } TelemetryServiceUtility.StopTimer(); // Show the preview window. if (uiService.DisplayPreviewWindow) { var shouldContinue = uiService.PromptForPreviewAcceptance(results); if (!shouldContinue) { return; } } TelemetryServiceUtility.StartOrResumeTimer(); // Show the license acceptance window. var accepted = await CheckLicenseAcceptanceAsync(uiService, results, token); TelemetryServiceUtility.StartOrResumeTimer(); if (!accepted) { return; } // Warn about the fact that the "dotnet" TFM is deprecated. if (uiService.DisplayDeprecatedFrameworkWindow) { var shouldContinue = ShouldContinueDueToDotnetDeprecation(uiService, actions, token); TelemetryServiceUtility.StartOrResumeTimer(); if (!shouldContinue) { return; } } if (!token.IsCancellationRequested) { // execute the actions await executeActionsAsync(actions, sourceCacheContext); // fires ActionsExecuted event to update the UI uiService.OnActionsExecuted(actions); } } } catch (System.Net.Http.HttpRequestException ex) { status = NuGetOperationStatus.Failed; if (ex.InnerException != null) { uiService.ShowError(ex.InnerException); } else { uiService.ShowError(ex); } } catch (Exception ex) { status = NuGetOperationStatus.Failed; uiService.ShowError(ex); } finally { TelemetryServiceUtility.StopTimer(); var duration = TelemetryServiceUtility.GetTimerElapsedTime(); uiService.ProjectContext.Log(MessageLevel.Info, string.Format(CultureInfo.CurrentCulture, Resources.Operation_TotalTime, duration)); uiService.EndOperation(); var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( uiService.ProjectContext.OperationId.ToString(), uiService.Projects, operationType, OperationSource.UI, startTime, status, packageCount, duration.TotalSeconds); TelemetryActivity.EmitTelemetryEvent(actionTelemetryEvent); } }, token); }
/// <summary> /// The internal implementation to perform user action. /// </summary> /// <param name="resolveActionsAsync">A function that returns a task that resolves the user /// action into project actions.</param> /// <param name="executeActionsAsync">A function that returns a task that executes /// the project actions.</param> private async Task PerformActionImplAsync( INuGetUI uiService, Func <SourceCacheContext, Task <IReadOnlyList <ResolvedAction> > > resolveActionsAsync, Func <IReadOnlyList <ResolvedAction>, SourceCacheContext, Task> executeActionsAsync, NuGetOperationType operationType, UserAction userAction, CancellationToken token) { var status = NuGetOperationStatus.Succeeded; var startTime = DateTimeOffset.Now; var packageCount = 0; bool continueAfterPreview = true; bool acceptedLicense = true; List <string> removedPackages = null; HashSet <Tuple <string, string> > existingPackages = new HashSet <Tuple <string, string> >(); List <Tuple <string, string> > addedPackages = null; List <Tuple <string, string> > updatedPackagesOld = null; List <Tuple <string, string> > updatedPackagesNew = null; // Enable granular level telemetry events for nuget ui operation uiService.ProjectContext.OperationId = Guid.NewGuid(); Stopwatch packageEnumerationTime = new Stopwatch(); packageEnumerationTime.Start(); try { // collect the install state of the existing packages foreach (var project in uiService.Projects) { var result = await project.GetInstalledPackagesAsync(token); foreach (var package in result) { Tuple <string, string> packageInfo = new Tuple <string, string>(package.PackageIdentity.Id, (package.PackageIdentity.Version == null ? "" : package.PackageIdentity.Version.ToNormalizedString())); if (!existingPackages.Contains(packageInfo)) { existingPackages.Add(packageInfo); } } } } catch (Exception) { // don't teardown the process if we have a telemetry failure } packageEnumerationTime.Stop(); await _lockService.ExecuteNuGetOperationAsync(async() => { try { uiService.BeginOperation(); var acceptedFormat = await CheckPackageManagementFormat(uiService, token); if (!acceptedFormat) { return; } TelemetryServiceUtility.StartOrResumeTimer(); using (var sourceCacheContext = new SourceCacheContext()) { var actions = await resolveActionsAsync(sourceCacheContext); var results = GetPreviewResults(actions); if (operationType == NuGetOperationType.Uninstall) { // removed packages don't have version info removedPackages = results.SelectMany(result => result.Deleted) .Select(package => package.Id) .Distinct() .ToList(); packageCount = removedPackages.Count; } else { // log rich info about added packages addedPackages = results.SelectMany(result => result.Added) .Select(package => new Tuple <string, string>(package.Id, (package.Version == null ? "" : package.Version.ToNormalizedString()))) .Distinct() .ToList(); var addCount = addedPackages.Count; //updated packages can have an old and a new id. updatedPackagesOld = results.SelectMany(result => result.Updated) .Select(package => new Tuple <string, string>(package.Old.Id, (package.Old.Version == null ? "" : package.Old.Version.ToNormalizedString()))) .Distinct() .ToList(); updatedPackagesNew = results.SelectMany(result => result.Updated) .Select(package => new Tuple <string, string>(package.New.Id, (package.New.Version == null ? "" : package.New.Version.ToNormalizedString()))) .Distinct() .ToList(); var updateCount = updatedPackagesNew.Count; // update packages count packageCount = addCount + updateCount; if (updateCount > 0) { // set operation type to update when there are packages being updated operationType = NuGetOperationType.Update; } } TelemetryServiceUtility.StopTimer(); // Show the preview window. if (uiService.DisplayPreviewWindow) { var shouldContinue = uiService.PromptForPreviewAcceptance(results); if (!shouldContinue) { continueAfterPreview = false; return; } } TelemetryServiceUtility.StartOrResumeTimer(); // Show the license acceptance window. var accepted = await CheckLicenseAcceptanceAsync(uiService, results, token); TelemetryServiceUtility.StartOrResumeTimer(); if (!accepted) { acceptedLicense = false; return; } // Warn about the fact that the "dotnet" TFM is deprecated. if (uiService.DisplayDeprecatedFrameworkWindow) { var shouldContinue = ShouldContinueDueToDotnetDeprecation(uiService, actions, token); TelemetryServiceUtility.StartOrResumeTimer(); if (!shouldContinue) { return; } } if (!token.IsCancellationRequested) { // execute the actions await executeActionsAsync(actions, sourceCacheContext); // fires ActionsExecuted event to update the UI uiService.OnActionsExecuted(actions); } else { status = NuGetOperationStatus.Cancelled; } } } catch (System.Net.Http.HttpRequestException ex) { status = NuGetOperationStatus.Failed; if (ex.InnerException != null) { uiService.ShowError(ex.InnerException); } else { uiService.ShowError(ex); } } catch (Exception ex) { status = NuGetOperationStatus.Failed; uiService.ShowError(ex); } finally { TelemetryServiceUtility.StopTimer(); var duration = TelemetryServiceUtility.GetTimerElapsedTime(); uiService.ProjectContext.Log(MessageLevel.Info, string.Format(CultureInfo.CurrentCulture, Resources.Operation_TotalTime, duration)); uiService.EndOperation(); // don't show "Succeeded" if we actually cancelled... if ((!continueAfterPreview) || (!acceptedLicense)) { if (status == NuGetOperationStatus.Succeeded) { status = NuGetOperationStatus.Cancelled; } } var actionTelemetryEvent = VSTelemetryServiceUtility.GetActionTelemetryEvent( uiService.ProjectContext.OperationId.ToString(), uiService.Projects, operationType, OperationSource.UI, startTime, status, packageCount, duration.TotalSeconds); AddUiActionEngineTelemetryProperties(actionTelemetryEvent, continueAfterPreview, acceptedLicense, userAction, existingPackages, addedPackages, removedPackages, updatedPackagesOld, updatedPackagesNew); actionTelemetryEvent["InstalledPackageEnumerationTimeInMilliseconds"] = packageEnumerationTime.ElapsedMilliseconds; TelemetryActivity.EmitTelemetryEvent(actionTelemetryEvent); } }, token); }