public void RegisterGettingBookmark(string bookmarkName)
        {
            if (this.ActionInvoker == null)
            {
                throw new InvalidOperationException();
            }

            GettingEventHandler handler = delegate(object sender, GettingEventArgs e)
            {
                this.ActionInvoker.ScheduleAction(bookmarkName, sender, e);
            };

            this.GettingHandlers.Add(new Tuple <string, GettingEventHandler>(bookmarkName, handler));
            this.Server.Getting += handler;
        }
Beispiel #2
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;
            }));
        }