Exemplo n.º 1
0
        private void Report(string message, Exception e)
        {
            message = message + ": " + e.Message;
            var exception = new Exception(message, e);

            _protectedOperations.Report(exception);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The clipboard is a shared resource across all applications.  It can only be used
        /// by one application at a time and has no mechanism for synchronizing access.
        ///
        /// Use of the clipboard should be short lived though so most applications guard
        /// against races by simply retrying the access a number of times.  This is how
        /// WinForms handles the race.  WPF does not do this hence we have to implement it
        /// manually here.
        /// </summary>
        private bool TryAccessClipboard(Action action, int retryCount = 5, int pauseMilliseconds = 100)
        {
            var i = retryCount;

            do
            {
                try
                {
                    action();
                    return(true);
                }
                catch (Exception ex)
                {
                    i--;
                    if (i == 0)
                    {
                        _protectedOperations.Report(ex);
                        _useTextMethods = true;
                        return(false);
                    }
                }

                Thread.Sleep(TimeSpan.FromMilliseconds(pauseMilliseconds));
            } while (true);
        }
Exemplo n.º 3
0
        private string GetText()
        {
            try
            {
                var text = _useTextMethods
                    ? Clipboard.GetText()
                    : (string)Clipboard.GetData(DataFormats.UnicodeText);

                return(text ?? string.Empty);
            }
            catch (Exception ex)
            {
                _protectedOperations.Report(ex);
                _useTextMethods = false;
                return(string.Empty);
            }
        }
Exemplo n.º 4
0
        private void OnTimer(object sender, EventArgs e)
        {
            try
            {
                Debug.Assert(!_vimApplicationSettings.UseEditorCommandMargin);

                var vimBuffer = _vim.FocusedBuffer.SomeOrDefault(null);
                var status    = vimBuffer != null
                    ? _commandMarginUtil.GetStatus(vimBuffer)
                    : "";

                if (status.Length == 0)
                {
                    status = " ";
                }

                _vsStatusbar.SetText(status);
            }
            catch (Exception ex)
            {
                _vimProtectedOperations.Report(ex);
            }
        }