Example #1
0
        public async Task Load_should_execute_async_operation_and_callback()
        {
            var loadSignal = new SemaphoreSlim(0);

            var started   = 0;
            var completed = 0;
            var task      = _loader.Load(
                () =>
            {
                started++;
                loadSignal.Release();
                Thread.Sleep(100);
            },
                () => completed++);

            Assert.True(await loadSignal.WaitAsync(1000));

            Assert.AreEqual(1, started);
            Assert.AreEqual(0, completed);

            await task;

            Assert.AreEqual(1, started);
            Assert.AreEqual(1, completed);

            Assert.AreEqual(TaskStatus.RanToCompletion, task.Status);
        }
Example #2
0
        private void InitializeSoft()
        {
            GitStash gitStash = Stashes.SelectedItem as GitStash;

            Stashed.GitItemStatuses = null;

            Loading.Visible = true;
            Stashes.Enabled = false;
            refreshToolStripButton.Enabled        = false;
            toolStripButton_customMessage.Enabled = false;
            if (gitStash == null)
            {
                Stashed.GitItemStatuses = null;
            }
            else if (gitStash == currentWorkingDirStashItem)
            {
                toolStripButton_customMessage.Enabled = true;
                _asyncLoader.Load(() => Module.GetAllChangedFiles(), LoadGitItemStatuses);
                Clear.Enabled = false; // disallow Drop  (of current working directory)
                Apply.Enabled = false; // disallow Apply (of current working directory)
            }
            else
            {
                _asyncLoader.Load(() => Module.GetStashDiffFiles(gitStash.Name), LoadGitItemStatuses);
                Clear.Enabled = true; // allow Drop
                Apply.Enabled = true; // allow Apply
            }
        }
Example #3
0
        private void LoadBranches()
        {
            string from = _NO_TRANSLATE_From.Text;

            Cursor = Cursors.AppStarting;
            _branchListLoader.Load(() => Module.GetRemoteServerRefs(from, false, true), UpdateBranches);
        }
        private void Init()
        {
            _createBtn.Enabled   = false;
            _yourBranchesCB.Text = _strLoading.Text;
            _hostedRemotes       = _repoHost.GetHostedRemotesForModule(Module);
            this.Mask();
            _remoteLoader.Load(
                () => _hostedRemotes.Where(r => !r.IsOwnedByMe).ToArray(),
                (IHostedRemote[] foreignHostedRemotes) =>
            {
                if (foreignHostedRemotes.Length == 0)
                {
                    MessageBox.Show(this, _strFailedToCreatePullRequest.Text + Environment.NewLine +
                                    _strPleaseCloneGitHubRep.Text, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                    return;
                }

                this.UnMask();

                _currentBranch = Module.IsValidGitWorkingDir() ? Module.GetSelectedBranch() : "";
                LoadRemotes(foreignHostedRemotes);
                LoadMyBranches();
            });
        }
Example #5
0
        private void LoadBranchesAsync()
        {
            var selectedBranch = UICommands.GitModule.GetSelectedBranch();

            ExistingBranches      = Module.GetRefs(false);
            comboBoxBranches.Text = Strings.GetLoadingData();
            _branchesLoader.Load(
                () => ExistingBranches.Where(r => r.Name != selectedBranch).ToList(),
                list =>
            {
                comboBoxBranches.Text          = string.Empty;
                comboBoxBranches.DataSource    = list;
                comboBoxBranches.DisplayMember = "LocalName";
            })
            .ContinueWith(_ =>
            {
                if (comboBoxBranches.Items.Count == 0)
                {
                    radioButtonCreateNewBranch.Checked        = true;
                    radioButtonCheckoutExistingBranch.Enabled = false;
                }
                else
                {
                    radioButtonCheckoutExistingBranch.Checked = true;
                }

                ValidateWorktreeOptions();
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
Example #6
0
        private void Init()
        {
            _isFirstLoad = true;

            this.Mask();
            loader.Load(
                () =>
            {
                var t = _gitHoster.GetHostedRemotesForModule(Module).ToList();
                foreach (var el in t)
                {
                    el.GetHostedRepository();     // We do this now because we want to do it in the async part.
                }
                return(t);
            },
                hostedRemotes =>
            {
                _hostedRemotes = hostedRemotes;
                _selectHostedRepoCB.Items.Clear();
                foreach (var hostedRepo in _hostedRemotes)
                {
                    _selectHostedRepoCB.Items.Add(hostedRepo);
                }

                SelectHostedRepositoryForCurrentRemote();
                this.UnMask();
            });
        }
Example #7
0
        public DashboardItem(Repository repository)
            : this()
        {
            if (repository == null)
                return;

            Bitmap icon = GetRepositoryIcon(repository);


            if (AppSettings.DashboardShowCurrentBranch)
            {
                _branchNameLoader = new AsyncLoader();
                _branchNameLoader.Load(() =>
                {
                    if (!GitCommands.GitModule.IsBareRepository(repository.Path))
                    {
                        return GitModule.GetSelectedBranchFast(repository.Path);
                    }
                    return string.Empty;
                },
                UpdateBranchName);
            }

            Initialize(icon, repository.Path, repository.Title, repository.Description);
        }
Example #8
0
        public void Using_load_or_cancel_after_dispose_throws()
        {
            var loader = new AsyncLoader();

            // Safe to dispose multiple times
            loader.Dispose();
            loader.Dispose();
            loader.Dispose();

            // Any use after dispose should throw
            Assert.Throws <ObjectDisposedException>(() => loader.Load(() => { }, () => { }));
            Assert.Throws <ObjectDisposedException>(() => loader.Load(_ => { }, () => { }));
            Assert.Throws <ObjectDisposedException>(() => loader.Load(() => 1, i => { }));
            Assert.Throws <ObjectDisposedException>(() => loader.Load(_ => 1, i => { }));
            Assert.Throws <ObjectDisposedException>(() => loader.Cancel());
        }
Example #9
0
        public DashboardItem(Repository repository)
            : this()
        {
            if (repository == null)
            {
                return;
            }

            Bitmap icon = GetRepositoryIcon(repository);


            if (AppSettings.DashboardShowCurrentBranch)
            {
                _branchNameLoader = new AsyncLoader();
                _branchNameLoader.Load(() =>
                {
                    if (!GitCommands.GitModule.IsBareRepository(repository.Path))
                    {
                        return(GitModule.GetSelectedBranchFast(repository.Path));
                    }
                    return(string.Empty);
                },
                                       UpdateBranchName);
            }

            Initialize(icon, repository.Path, repository.Title, repository.Description);
        }
Example #10
0
        public void LoadBlame(GitRevision revision, List <string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding, int?initialLine = null, bool force = false)
        {
            //refresh only when something changed
            string guid = revision.Guid;

            if (!force && guid.Equals(_blameHash) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
            {
                return;
            }

            if (controlToMask != null)
            {
                controlToMask.Mask();
            }

            var scrollpos = BlameFile.ScrollPos;

            int line = initialLine.GetValueOrDefault(0);

            if (_clickedBlameLine.CommitGuid == guid)
            {
                line = _clickedBlameLine.OriginLineNumber;
            }
            _revGrid  = revGrid;
            _fileName = fileName;
            _encoding = encoding;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                             () => ProcessBlame(revision, children, controlToMask, line, scrollpos));
        }
Example #11
0
 private void LoadMultiBranchViewData(string remote, IList <GitRef> localHeads)
 {
     _remoteBranchesLoader.Cancel();
     Cursor = Cursors.AppStarting;
     _remoteBranchesLoader.Load(() => Module.GetRemoteRefs(remote, false, true),
                                (remoteHeads) => ProcessHeads(remote, localHeads, remoteHeads));
 }
Example #12
0
        private void LoadBranches()
        {
            Branches.DisplayMember = "LocalName";
            string from = _NO_TRANSLATE_From.Text;

            Cursor = Cursors.AppStarting;
            _branchListLoader.Load(() => Module.GetRemoteRefs(from, false, true), UpdateBranches);
        }
Example #13
0
        private void Branches_DropDown(object sender, EventArgs e)
        {
            Branches.DisplayMember = "LocalName";
            string from = _NO_TRANSLATE_From.Text;

            Cursor = Cursors.AppStarting;
            branchListLoader.Load(() => { return(Module.GetRemoteHeads(from, false, true)); }, UpdateBranches);
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            OnTextChanged(e);
            if (_isUpdatingTextFromCode)
            {
                _isUpdatingTextFromCode = false;
                return;
            }
            string _selectedText = textBox1.Text;

            backgroundLoader.Load(() => getCandidates(_selectedText), SearchForCandidates);
        }
Example #15
0
 private void LoadBranchesAsync()
 {
     comboBoxBranches.Text = Strings.GetLoadingData();
     _branchesLoader.Load(
         () => Module.GetRefs(false).ToList(),
         list =>
     {
         comboBoxBranches.Text = string.Empty;
         GitRefsToDataSource(comboBoxBranches, list);
         comboBoxBranches.DisplayMember = "LocalName";
         SetSelectedRevisionByFocusedControl();
     });
 }
Example #16
0
 private void LoadTagsAsync()
 {
     comboBoxTags.Text = Strings.GetLoadingData();
     _tagsLoader.Load(
         () => Module.GetTagRefs(GitModule.GetTagRefsSortOrder.ByCommitDateDescending).ToList(),
         list =>
     {
         comboBoxTags.Text = string.Empty;
         GitRefsToDataSource(comboBoxTags, list);
         comboBoxTags.DisplayMember = "LocalName";
         SetSelectedRevisionByFocusedControl();
     });
 }
Example #17
0
        private void InitializeLinesOfCode()
        {
            if (initializeLinesOfCodeDone)
            {
                return;
            }

            initializeLinesOfCodeDone = true;

            lineCounter = new LineCounter(WorkingDir);
            lineCounter.LinesOfCodeUpdated += lineCounter_LinesOfCodeUpdated;

            loadThread.Load(LoadLinesOfCode, () => { });
        }
Example #18
0
        private void FilePattern_TextChanged(object sender, EventArgs e)
        {
            _ignoredFilesLoader.Cancel();
            if (_NO_TRANSLATE_Preview.Enabled)
            {
                _ignoredFilesLoader.Delay             = 300;
                _NO_TRANSLATE_filesWillBeIgnored.Text = _updateStatusString.Text;
                _NO_TRANSLATE_Preview.DataSource      = new List <string> {
                    _updateStatusString.Text
                };
                _NO_TRANSLATE_Preview.Enabled = false;
            }

            _ignoredFilesLoader.Load(() => Module.GetIgnoredFiles(GetCurrentPatterns()), UpdatePreviewPanel);
        }
Example #19
0
 private void LoadBranches(string branchType)
 {
     cbManageType.Enabled  = false;
     cbBranches.DataSource = new List <string> {
         _loading.Text
     };
     if (!Branches.ContainsKey(branchType))
     {
         _task.Load(() => GetBranches(branchType), (branches) => { Branches.Add(branchType, branches); DisplayBranchDatas(); });
     }
     else
     {
         DisplayBranchDatas();
     }
 }
Example #20
0
        private void LoadFileHistory()
        {
            FileChanges.Visible = true;

            asyncLoader.Load(() => BuildFilter(FileName), (filter) =>
            {
                if (filter == null)
                {
                    return;
                }
                FileChanges.FixedFilter          = filter;
                FileChanges.AllowGraphWithFilter = true;
                FileChanges.Load();
            });
        }
Example #21
0
 private void comboBoxTags_Enter(object sender, EventArgs e)
 {
     comboBoxTags.Text = Strings.GetLoadingData();
     _tagsLoader.Load(
         () => Module.GetTagHeads(GitModule.GetTagHeadsSortOrder.ByCommitDateDescending).Select(g => new GitHeaderGuiWrapper(g)).ToList(),
         list =>
     {
         comboBoxTags.Text       = string.Empty;
         comboBoxTags.DataSource = list;
         if (!comboBoxTags.Text.IsNullOrEmpty())
         {
             comboBoxTags.Select(0, comboBoxTags.Text.Length);
         }
     }
         );
 }
Example #22
0
 private void comboBoxBranches_Enter(object sender, EventArgs e)
 {
     comboBoxBranches.Text = Strings.GetLoadingData();
     _branchesLoader.Load(
         () => Module.GetHeads(false).Select(g => new GitHeaderGuiWrapper(g)).ToList(),
         list =>
     {
         comboBoxBranches.Text       = string.Empty;
         comboBoxBranches.DataSource = list;
         if (!comboBoxBranches.Text.IsNullOrEmpty())
         {
             comboBoxBranches.Select(0, comboBoxBranches.Text.Length);
         }
     }
         );
 }
Example #23
0
 private void comboBoxTags_Enter(object sender, EventArgs e)
 {
     comboBoxTags.Text = Strings.GetLoadingData();
     _tagsLoader.Load(
         () => Module.GetTagRefs(GitModule.GetTagRefsSortOrder.ByCommitDateDescending).ToList(),
         list =>
     {
         comboBoxTags.Text              = string.Empty;
         comboBoxTags.DataSource        = list;
         comboBoxBranches.DisplayMember = "LocalName";
         if (!comboBoxTags.Text.IsNullOrEmpty())
         {
             comboBoxTags.Select(0, comboBoxTags.Text.Length);
         }
     }
         );
 }
Example #24
0
 private void comboBoxBranches_Enter(object sender, EventArgs e)
 {
     comboBoxBranches.Text = Strings.GetLoadingData();
     _branchesLoader.Load(
         () => Module.GetRefs(false).ToList(),
         list =>
     {
         comboBoxBranches.Text          = string.Empty;
         comboBoxBranches.DataSource    = list;
         comboBoxBranches.DisplayMember = "LocalName";
         if (!comboBoxBranches.Text.IsNullOrEmpty())
         {
             comboBoxBranches.Select(0, comboBoxBranches.Text.Length);
         }
     }
         );
 }
Example #25
0
        public async Task Load_performed_on_thread_pool_and_result_handled_via_callers_context()
        {
            var    callerThread       = Thread.CurrentThread;
            Thread loadThread         = null;
            Thread continuationThread = null;

            Assert.False(callerThread.IsThreadPoolThread);

            using (var scheduler = new SingleThreadTaskScheduler())
                using (var loader = new AsyncLoader(scheduler))
                {
                    await loader.Load(
                        () => loadThread         = Thread.CurrentThread,
                        () => continuationThread = Thread.CurrentThread);
                }

            Assert.True(loadThread.IsThreadPoolThread);
            Assert.AreNotSame(loadThread, callerThread);
            Assert.AreNotSame(loadThread, continuationThread);
        }
Example #26
0
        public void LoadBlame(GitRevision revision, List <string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            //refresh only when something changed
            if (revision.Equals(CommitInfo.Revision) && fileName == _fileName && revGrid == _revGrid && encoding == _encoding)
            {
                return;
            }

            if (controlToMask != null)
            {
                controlToMask.Mask();
            }

            var scrollpos = BlameFile.ScrollPos;

            _revGrid  = revGrid;
            _fileName = fileName;
            _encoding = encoding;
            string guid = revision.Guid;

            blameLoader.Load(() => _blame = Module.Blame(fileName, guid, encoding),
                             () => ProcessBlame(revision, children, controlToMask, scrollpos));
        }
Example #27
0
        private void LoadMultiBranchViewData(string remote, IList <GitRef> localHeads)
        {
            _remoteBranchesLoader.Cancel();
            Cursor = Cursors.AppStarting;
            _remoteBranchesLoader.Load(() => { return(Module.GetRemoteRefs(remote, false, true)); },
                                       (remoteHeads) =>
            {
                Cursor = Cursors.Default;
                if (remoteHeads.HostKeyFail)
                {
                    string remoteUrl;

                    remoteUrl = Module.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote));
                    if (string.IsNullOrEmpty(remoteUrl))
                    {
                        remoteUrl = remote;
                    }

                    if (FormRemoteProcess.AskForCacheHostkey(this, Module, remoteUrl))
                    {
                        LoadMultiBranchViewData(remote, localHeads);
                    }
                }
                else if (remoteHeads.AuthenticationFail)
                {
                    string loadedKey;
                    if (FormPuttyError.AskForKey(this, out loadedKey))
                    {
                        LoadMultiBranchViewData(remote, localHeads);
                    }
                }
                else
                {
                    // Add all the local branches.
                    foreach (var head in localHeads)
                    {
                        DataRow row   = _branchTable.NewRow();
                        row["Force"]  = false;
                        row["Delete"] = false;
                        row["Local"]  = head.Name;

                        string remoteName;
                        if (head.Remote == remote)
                        {
                            remoteName = head.MergeWith ?? head.Name;
                        }
                        else
                        {
                            remoteName = head.Name;
                        }

                        row["Remote"]    = remoteName;
                        bool newAtRemote = remoteHeads.Result.Any(h => h.Name == remoteName);
                        row["New"]       = newAtRemote ? _no.Text : _yes.Text;
                        row["Push"]      = newAtRemote;

                        _branchTable.Rows.Add(row);
                    }

                    // Offer to delete all the left over remote branches.
                    foreach (var remoteHead in remoteHeads.Result)
                    {
                        GitRef head = remoteHead;
                        if (localHeads.All(h => h.Name != head.Name))
                        {
                            DataRow row   = _branchTable.NewRow();
                            row["Local"]  = null;
                            row["Remote"] = remoteHead.Name;
                            row["New"]    = _no.Text;
                            row["Push"]   = false;
                            row["Force"]  = false;
                            row["Delete"] = false;
                            _branchTable.Rows.Add(row);
                        }
                    }
                }
            });
        }
Example #28
0
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string selectedText = textBox1.Text;

            _backgroundLoader.Load(() => _getCandidates(selectedText), SearchForCandidates);
        }
Example #29
0
        public void LoadBlame(GitRevision revision, List <string> children, string fileName, RevisionGrid revGrid, Control controlToMask, Encoding encoding)
        {
            string guid = revision.Guid;

            //refresh only when something changed
            if (guid.Equals(CommitInfo.Revision) && fileName.Equals(fileName) && revGrid == _revGrid && encoding == _encoding)
            {
                return;
            }

            if (controlToMask != null)
            {
                controlToMask.Mask();
            }

            var scrollpos = BlameFile.ScrollPos;

            var blameCommitter = new StringBuilder();
            var blameFile      = new StringBuilder();

            _revGrid  = revGrid;
            _fileName = fileName;
            _encoding = encoding;

            blameLoader.Load(() =>
            {
                _blame = Module.Blame(fileName, guid, encoding);
            },
                             () =>
            {
                for (int i = 0; i < _blame.Lines.Count; i++)
                {
                    GitBlameLine blameLine     = _blame.Lines[i];
                    GitBlameHeader blameHeader = _blame.FindHeaderForCommitGuid(blameLine.CommitGuid);
                    if (i > 0 && _blame.Lines[i - 1].CommitGuid == blameLine.CommitGuid)
                    {
                        blameCommitter.AppendLine(new string(' ', 200));
                    }
                    else
                    {
                        blameCommitter.AppendLine((blameHeader.Author + " - " + blameHeader.AuthorTime + " - " + blameHeader.FileName + new string(' ', 100)).Trim(new[] { '\r', '\n' }));
                    }
                    if (blameLine.LineText == null)
                    {
                        blameFile.AppendLine("");
                    }
                    else
                    {
                        blameFile.AppendLine(blameLine.LineText.Trim(new char[] { '\r', '\n' }));
                    }
                }

                BlameCommitter.ViewText("committer.txt", blameCommitter.ToString());
                BlameFile.ViewText(fileName, blameFile.ToString());
                BlameFile.ScrollPos = scrollpos;

                CommitInfo.SetRevisionWithChildren(revision, children);

                if (controlToMask != null)
                {
                    controlToMask.UnMask();
                }
            });
        }
Example #30
0
 public void Execute()
 {
     backgroundLoader.Load(execute, executed);
 }
 public void LoadAsync(List <GameObject> assetsToLoad, Action <GameObject> cb)
 {
     loader.Load(assetsToLoad, cb);
 }