コード例 #1
0
 public void EmitProjectDependencyStatistics(ProjectDependencyStatistics projectDependencyStatistics)
 {
     EmitEvent(
         ProjectDependencyStatisticsEventName,
         projectDependencyStatistics,
         new Dictionary <string, object>
     {
         { InstalledPackageCountPropertyName, projectDependencyStatistics.InstalledPackageCount }
     });
 }
コード例 #2
0
        private async Task EmitNuGetProjectAsync(EnvDTEProject vsProject, NuGetProject nuGetProject)
        {
            // Get the project details.
            var projectUniqueName = nuGetProject.GetMetadata <string>(NuGetProjectMetadataKeys.UniqueName);
            var projectId         = Guid.Empty;

            try
            {
                projectId = await ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    // Get the project ID.
                    var vsHierarchyItem = VsHierarchyUtility.GetHierarchyItemForProject(vsProject);
                    Guid id;
                    if (!vsHierarchyItem.TryGetProjectId(out id))
                    {
                        id = Guid.Empty;
                    }

                    return(id);
                });
            }
            catch (Exception ex)
            {
                var message =
                    $"Failed to get project name or project ID. Exception:" +
                    Environment.NewLine +
                    ex.ToString();

                ActivityLog.LogWarning(ExceptionHelper.LogEntrySource, message);
                Debug.Fail(message);

                return;
            }

            // Emit the project information.
            try
            {
                var projectType = NuGetProjectType.Unknown;
                if (nuGetProject is MSBuildNuGetProject)
                {
                    projectType = NuGetProjectType.PackagesConfig;
                }
                else if (nuGetProject is BuildIntegratedNuGetProject)
                {
                    projectType = NuGetProjectType.UwpProjectJson;
                }
                else if (nuGetProject is ProjectKNuGetProjectBase)
                {
                    projectType = NuGetProjectType.XProjProjectJson;
                }

                var projectInformation = new ProjectInformation(
                    NuGetVersion.Value,
                    projectId,
                    projectType);

                _nuGetTelemetryService.EmitProjectInformation(projectInformation);
            }
            catch (Exception ex)
            {
                var message =
                    $"Failed to emit project information for project '{projectUniqueName}'. Exception:" +
                    Environment.NewLine +
                    ex.ToString();

                ActivityLog.LogWarning(ExceptionHelper.LogEntrySource, message);
                Debug.Fail(message);
            }

            // Emit the project dependency statistics.
            try
            {
                var installedPackages = await nuGetProject.GetInstalledPackagesAsync(CancellationToken.None);

                var installedPackagesCount = installedPackages.Count();

                var projectDependencyStatistics = new ProjectDependencyStatistics(
                    NuGetVersion.Value,
                    projectId,
                    installedPackagesCount);

                _nuGetTelemetryService.EmitProjectDependencyStatistics(projectDependencyStatistics);
            }
            catch (Exception ex)
            {
                var message =
                    $"Failed to emit project dependency statistics for project '{projectUniqueName}'. Exception:" +
                    Environment.NewLine +
                    ex.ToString();

                ActivityLog.LogWarning(message, ExceptionHelper.LogEntrySource);
                Debug.Fail(message);
            }
        }