Exemplo n.º 1
0
        public void Increment()
        {
            var countdownDisposable = new CountdownDisposable(() => { });

            countdownDisposable.Count.Should().Be(0);

            var disposable1 = countdownDisposable.Increment();

            countdownDisposable.Count.Should().Be(1);

            var disposable2 = countdownDisposable.Increment();

            countdownDisposable.Count.Should().Be(2);

            disposable2.Dispose();
            countdownDisposable.Count.Should().Be(1);

            disposable2.Dispose();
            countdownDisposable.Count.Should().Be(1);

            disposable2 = countdownDisposable.Increment();
            countdownDisposable.Count.Should().Be(2);

            disposable1.Dispose();
            countdownDisposable.Count.Should().Be(1);

            disposable2.Dispose();
            countdownDisposable.Count.Should().Be(0);
        }
Exemplo n.º 2
0
        private IDisposable EditTextBuffer()
        {
            if (_readOnlyRegion != null)
            {
                using (var edit = _historyTextBuffer.CreateReadOnlyRegionEdit()) {
                    edit.RemoveReadOnlyRegion(_readOnlyRegion);
                    _readOnlyRegion = null;
                    edit.Apply();
                }
            }

            HistoryChanging?.Invoke(this, new EventArgs());
            return(_textBufferIsEditable.Increment());
        }
Exemplo n.º 3
0
        public async Task <ExecutionResult> ExecuteCodeAsync(string text)
        {
            var start = 0;
            var end   = text.IndexOf('\n');

            if (end == -1)
            {
                return(ExecutionResult.Success);
            }

            try {
                using (Session.DisableMutatedOnReadConsole()) {
                    while (end != -1)
                    {
                        var line = text.Substring(start, end - start + 1);
                        start = end + 1;
                        end   = text.IndexOf('\n', start);

                        using (var request = await Session.BeginInteractionAsync()) {
                            using (_evaluatorRequest.Increment()) {
                                if (line.Length >= request.MaxLength)
                                {
                                    CurrentWindow.WriteErrorLine(string.Format(Resources.InputIsTooLong, request.MaxLength));
                                    return(ExecutionResult.Failure);
                                }

                                await request.RespondAsync(line);
                            }
                        }
                    }
                }

                return(ExecutionResult.Success);
            } catch (RHostDisconnectedException rhdex) {
                WriteError(rhdex.Message);
                return(ExecutionResult.Success);
            } catch (OperationCanceledException) {
                // Cancellation reason was already reported via RSession.Error and printed out;
                // Return success cause connection lost doesn't mean that RHost died
                return(ExecutionResult.Success);
            } catch (Exception ex) {
                await _coreShell.ShowErrorMessageAsync(ex.ToString());

                return(ExecutionResult.Failure);
            } finally {
                History.AddToHistory(text);
            }
        }
Exemplo n.º 4
0
        public void Create()
        {
            var    callCount = 0;
            Action callback  = () => callCount++;

            var countdownDisposable = new CountdownDisposable(callback);

            countdownDisposable.Count.Should().Be(0);
            callCount.Should().Be(0);

            var disposable = countdownDisposable.Increment();

            countdownDisposable.Count.Should().Be(1);
            callCount.Should().Be(0);

            disposable.Dispose();
            countdownDisposable.Count.Should().Be(0);
            callCount.Should().Be(1);
        }
Exemplo n.º 5
0
 public IDisposable DisableMutatedOnReadConsole()
 {
     return(_disableMutatingOnReadConsole.Increment());
 }
 public IDisposable StartBatchUpdate() => _batchUpdate.Increment();