예제 #1
0
        private async Task EmitNuGetProjectAsync(NuGetProject nuGetProject)
        {
            // Get the project details.
            var projectUniqueName = nuGetProject.GetMetadata <string>(NuGetProjectMetadataKeys.UniqueName);

            // Emit the project information.
            try
            {
                var projectId = nuGetProject.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId);

                // Get project type.
                var projectType = NuGetProjectType.Unknown;
                if (nuGetProject is MSBuildNuGetProject)
                {
                    projectType = NuGetProjectType.PackagesConfig;
                }
#if VS15
                else if (nuGetProject is NetCorePackageReferenceProject)
                {
                    projectType = NuGetProjectType.CPSBasedPackageRefs;
                }
                else if (nuGetProject is LegacyPackageReferenceProject)
                {
                    projectType = NuGetProjectType.LegacyProjectSystemWithPackageRefs;
                }
#endif
                else if (nuGetProject is ProjectJsonNuGetProject)
                {
                    projectType = NuGetProjectType.UwpProjectJson;
                }
                else if (nuGetProject is ProjectKNuGetProjectBase)
                {
                    projectType = NuGetProjectType.XProjProjectJson;
                }

                // Get package count.
                var installedPackages = await nuGetProject.GetInstalledPackagesAsync(CancellationToken.None);

                var installedPackagesCount = installedPackages.Count();

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

                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);
            }
        }
예제 #2
0
        public void EmitProjectInformation(ProjectTelemetryEvent projectInformation)
        {
            var telemetryEvent = new TelemetryEvent(
                TelemetryConstants.ProjectInformationEventName,
                new Dictionary <string, object>
            {
                { TelemetryConstants.InstalledPackageCountPropertyName, projectInformation.InstalledPackageCount },
                { TelemetryConstants.NuGetProjectTypePropertyName, projectInformation.NuGetProjectType },
                { TelemetryConstants.NuGetVersionPropertyName, projectInformation.NuGetVersion },
                { TelemetryConstants.ProjectIdPropertyName, projectInformation.ProjectId.ToString() }
            });

            telemetrySession.PostEvent(telemetryEvent);
        }
예제 #3
0
        private void EmitEvent(string eventName, ProjectTelemetryEvent projectTelemetryEvent, Dictionary <string, object> properties)
        {
            var telemetryEvent = new TelemetryEvent(eventName);

            foreach (var pair in properties)
            {
                telemetryEvent.Properties[pair.Key] = pair.Value;
            }

            telemetryEvent.Properties[NuGetVersionPropertyName] = projectTelemetryEvent.NuGetVersion;
            telemetryEvent.Properties[ProjectIdPropertyName]    = projectTelemetryEvent.ProjectId.ToString();

            _telemetrySession.PostEvent(telemetryEvent);
        }
예제 #4
0
        public static async Task <ProjectTelemetryEvent> GetProjectTelemetryEventAsync(NuGetProject nuGetProject)
        {
            if (nuGetProject == null)
            {
                throw new ArgumentNullException(nameof(nuGetProject));
            }
            string projectUniqueName          = string.Empty;
            ProjectTelemetryEvent returnValue = null;

            try
            {
                // Get the project details.
                projectUniqueName = nuGetProject.GetMetadata <string>(NuGetProjectMetadataKeys.UniqueName);
                string           projectId    = nuGetProject.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId);
                NuGetProjectType projectType  = GetProjectType(nuGetProject);
                bool             isUpgradable = await NuGetProjectUpgradeUtility.IsNuGetProjectUpgradeableAsync(nuGetProject);

                string fullPath = nuGetProject.GetMetadata <string>(NuGetProjectMetadataKeys.FullPath);

                returnValue = new ProjectTelemetryEvent(
                    NuGetVersion.Value,
                    projectId,
                    projectType,
                    isUpgradable,
                    fullPath);
            }
            catch (Exception ex)
            {
                // ArgumentException means project metadata is empty
                // DTE exceptions could mean VS process has a severe failure
                string message =
                    $"Failed to emit project information for project '{projectUniqueName}'. Exception:" +
                    Environment.NewLine +
                    ex.ToString();

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

                await TelemetryUtility.PostFaultAsync(ex, nameof(VSTelemetryServiceUtility), nameof(GetProjectTelemetryEventAsync));
            }

            return(returnValue);
        }
예제 #5
0
 public void EmitProjectInformation(ProjectTelemetryEvent projectInformation)
 {
     _telemetrySession.PostEvent(projectInformation);
 }