Пример #1
0
        public async void Refresh()
        {
            var data = new GitData();

            var oldData = DataContext as GitData;

            if (oldData != null)
            {
                data = oldData;
            }

            data.Syncing = true;
            DataContext  = data;

            try
            {
                if (MainWindow.Instance == null)
                {
                    return;
                }

                var repo = new Repository(MainWindow.Instance.RepoDir);
                await RefreshView(data, repo);

                await Task.Run(delegate
                {
                    var author = Author.Load();
                    repo.Fetch("origin", new FetchOptions
                    {
                        CredentialsProvider = (a, b, c) => author.Credentials
                    });
                });

                var newrepo = new Repository(MainWindow.Instance.RepoDir);
                await RefreshView(data, newrepo);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                data.Syncing = false;
            }
        }
Пример #2
0
        private Task RefreshView(GitData data, Repository repo)
        {
            return(Task.Run(delegate
            {
                var status = repo.RetrieveStatus();
                var master = repo.Branches[repo.Head.TrackedBranch.UpstreamBranchCanonicalName];
                var details = master.TrackingDetails;
                var uptodate = details.AheadBy == 0 && details.BehindBy == 0;
                var ahead = details.AheadBy;
                var behind = details.BehindBy;

                Dispatcher.Invoke(delegate
                {
                    data.Status = status;
                    data.MasterBranch = master;
                    data.UpToDate = uptodate;
                    data.Ahead = ahead;
                    data.Behind = behind;
                    data.Dirty = status.IsDirty;
                });
            }));
        }