Example #1
0
        private static async Task RestoreAsync(IDictionary <string, Manifest> manifests, CancellationToken cancellationToken = default(CancellationToken))
        {
            Logger.LogEvent(LibraryManager.Resources.Text.RestoringLibraries, LogLevel.Status);

            var sw = new Stopwatch();

            sw.Start();
            int  resultCount = 0;
            bool hasErrors   = false;
            var  telResult   = new Dictionary <string, double>();

            foreach (KeyValuePair <string, Manifest> manifest in manifests)
            {
                IEnumerable <ILibraryInstallationResult> results = await RestoreLibrariesAsync(manifest.Value, cancellationToken).ConfigureAwait(false);

                Project project = VsHelpers.DTE.Solution?.FindProjectItem(manifest.Key)?.ContainingProject;
                AddFilesToProject(manifest.Key, project, results);

                var errorList = new ErrorList(project?.Name, manifest.Key);
                hasErrors |= errorList.HandleErrors(results);

                resultCount += results.Count();

                foreach (ILibraryInstallationResult result in results.Where(r => r.Success))
                {
                    if (result.InstallationState.ProviderId != null)
                    {
                        telResult.TryGetValue(result.InstallationState.ProviderId, out double count);
                        telResult[result.InstallationState.ProviderId] = count + 1;
                    }
                }
            }

            sw.Stop();

            telResult.Add("time", sw.Elapsed.TotalMilliseconds);
            Telemetry.TrackUserTask("restore", TelemetryResult.None, telResult.Select(i => new KeyValuePair <string, object>(i.Key, i.Value)).ToArray());

            if (resultCount > 0)
            {
                string text = hasErrors ?
                              LibraryManager.Resources.Text.RestoreHasErrors :
                              string.Format(LibraryManager.Resources.Text.LibrariesRestored, resultCount, Math.Round(sw.Elapsed.TotalSeconds, 2));

                Logger.LogEvent(Environment.NewLine + text + Environment.NewLine, LogLevel.Task);
            }
            else
            {
                Logger.LogEvent(Environment.NewLine + Resources.Text.LibraryRestoredNoChange + Environment.NewLine, LogLevel.Task);
            }
        }
        private void AddErrorsToErrorList(string projectName, string configFile, IEnumerable <ILibraryOperationResult> results)
        {
            var errorList = new ErrorList(projectName, configFile);

            errorList.HandleErrors(results);
        }