Example #1
0
        private IDisposable TrackProgress(ISolutionProjectModel projectViewModel, out GetFilterCallback filterCallback,
                                          CancellationToken cancellationToken = default(CancellationToken))
        {
            filterCallback = (workspace, operations, data) => {};
            if (cancellationToken.IsCancellationRequested || projectViewModel == null)
            {
                return(new DisposableCookie(() => { }));
            }

            double total    = 0;
            double progress = 0;

            var server = tfsContext.VersionControlServer;

            projectViewModel.ResetProgress();
            filterCallback = (workspace, operations, data) =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                total = operations.Length + 4;
            };

            var projectBaseServerPath   = Path.GetDirectoryName(projectViewModel.ServerItem).Replace(@"\", "/");
            GettingEventHandler handler = (sender, e) =>
            {
                var model = projectViewModel;
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }
                if (e.SourceServerItem == projectBaseServerPath || e.SourceServerItem.StartsWith(projectBaseServerPath))
                {
                    model.CurrentOperation?.SetProgress(total, (++progress));
                    Output.WriteLine(e.Status + " " + e.ServerItem);
                }
            };

            cancellationToken.Register(() => server.Getting -= handler);
            server.Getting += handler;

            return(new DisposableCookie(() =>
            {
                server.Getting -= handler;
            }));
        }
Example #2
0
        public async Task CleanSolutionAsync(ISolutionProjectModel projectViewModel, IServiceSettings settings,
                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!IsCancelled(projectViewModel, cancellationToken))
            {
                await cancellationToken.WaitWhenPaused();

                using (new PauseCheckedActionScope(() => projectViewModel.CurrentOperation = Operations.Clean, () => projectViewModel.CurrentOperation = Operations.None, cancellationToken))
                {
                    var externalActionService = serviceProvider.Get <ExternalActionService>();
                    await externalActionService.RunExternalPreActions(projectViewModel, this, cancellationToken : cancellationToken);

                    await Task.Run(async() =>
                    {
                        if (!File.Exists(projectViewModel.ItemPath))
                        {
                            return;
                        }
                        projectViewModel.ResetProgress();

                        foreach (var outputPath in GetOutputPathes(new[] { projectViewModel }, settings, (model, project) => model.IncrementProgress()))
                        {
                            await cancellationToken.WaitWhenPaused();
                            if (cancellationToken.IsCancellationRequested)
                            {
                                return;
                            }
                            TryDelete(outputPath);
                        }
                    }, cancellationToken);

                    await externalActionService.RunExternalPostActions(projectViewModel, this, true, cancellationToken : cancellationToken);

                    await cancellationToken.WaitWhenPaused();

                    statusService.IncrementStep();
                }
            }
        }