Exemplo n.º 1
0
            public override void Handle(RHost host, Message response)
            {
                response.ExpectArguments(1, 3);
                var firstArg = response[0] as JValue;

                if (firstArg != null && firstArg.Value == null)
                {
                    CompletionSource.TrySetCanceled();
                    return;
                }

                response.ExpectArguments(3);
                var parseStatus = response.GetEnum <RParseStatus>(0, "parseStatus", parseStatusNames);
                var error       = response.GetString(1, "error", allowNull: true);

                REvaluationResult result;

                if (Kind.HasFlag(REvaluationKind.NoResult))
                {
                    result = new REvaluationResult(error, parseStatus);
                }
                else if (Kind.HasFlag(REvaluationKind.RawResult))
                {
                    result = new REvaluationResult(response.Blob, error, parseStatus);
                }
                else
                {
                    result = new REvaluationResult(response[2], error, parseStatus);
                }

                CompletionSource.TrySetResult(result);
            }
Exemplo n.º 2
0
            public async Task <IssuedToken> GetTokenAsync(VssTraceActivity traceActivity)
            {
                IssuedToken token = null;

                try
                {
                    VssHttpEventSource.Log.IssuedTokenAcquiring(traceActivity, this.Provider);
                    if (this.Provider.InvokeRequired)
                    {
                        // Post to the UI thread using the scheduler. This may return a new task object which needs
                        // to be awaited, since once we get to the UI thread there may be nothing to do if someone else
                        // preempts us.

                        // The cancellation token source is used to handle race conditions between scheduling and
                        // waiting for the UI task to begin execution. The callback is responsible for disposing of
                        // the token source, since the thought here is that the callback will run eventually as the
                        // typical reason for not starting execution within the timeout is due to a deadlock with
                        // the scheduler being used.
                        var timerTask          = new TaskCompletionSource <Object>();
                        var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3));
                        timeoutTokenSource.Token.Register(() => timerTask.SetResult(null), false);

                        var uiTask = Task.Factory.StartNew((state) => PostCallback(state, timeoutTokenSource),
                                                           this,
                                                           this.CancellationToken,
                                                           TaskCreationOptions.None,
                                                           this.Provider.Credential.Scheduler).Unwrap();

                        var completedTask = await Task.WhenAny(timerTask.Task, uiTask).ConfigureAwait(false);

                        if (completedTask == uiTask)
                        {
                            token = uiTask.Result;
                        }
                    }
                    else
                    {
                        token = await this.Provider.OnGetTokenAsync(this.FailedToken, this.CancellationToken).ConfigureAwait(false);
                    }

                    CompletionSource.TrySetResult(token);
                    return(token);
                }
                catch (Exception exception)
                {
                    // Mark our completion source as failed so other waiters will get notified in all cases
                    CompletionSource.TrySetException(exception);
                    throw;
                }
                finally
                {
                    this.Provider.CurrentToken = token ?? this.FailedToken;
                    VssHttpEventSource.Log.IssuedTokenAcquired(traceActivity, this.Provider, token);
                }
            }
Exemplo n.º 3
0
        /// <summary>
        /// Completes the block.  This must only be called once, and only once all of the completion conditions are met.
        /// </summary>
        private void CompleteBlockOncePossible()
        {
            Debug.Assert(_completionReserved, "Should only invoke once completion has been reserved.");

            // Dump any messages that might remain in the queue, which could happen if we completed due to exceptions.
            TInput dumpedMessage;

            while (_messages.TryDequeue(out dumpedMessage))
            {
                ;
            }

            // Complete the completion task
            bool result;

            if (_exceptions != null)
            {
                Exception[] exceptions;
                lock (_exceptions) exceptions = _exceptions.ToArray();
                result = CompletionSource.TrySetException(exceptions);
            }
            else
            {
                result = CompletionSource.TrySetResult(default(VoidResult));
            }
            Debug.Assert(result, "Expected completion task to not yet be completed");
            // We explicitly do not set the _activeTask to null here, as that would
            // allow for races where a producer calling OfferMessage could end up
            // seeing _activeTask as null and queueing a new consumer task even
            // though the block has completed.

#if FEATURE_TRACING
            DataflowEtwProvider etwLog = DataflowEtwProvider.Log;
            if (etwLog.IsEnabled())
            {
                etwLog.DataflowBlockCompleted(_owningTarget);
            }
#endif
        }
Exemplo n.º 4
0
            public override void Handle(RHost host, Message response)
            {
                long size = response.GetInt64(0, "blob_size");

                CompletionSource.TrySetResult(size);
            }
Exemplo n.º 5
0
 public override void Handle(RHost host, Message response)
 {
     CompletionSource.TrySetResult(response.Blob);
 }
Exemplo n.º 6
0
            public override void Handle(RHost host, Message response)
            {
                ulong id = response.GetUInt64(0, "blob_id");

                CompletionSource.TrySetResult(id);
            }
Exemplo n.º 7
0
 public void SetResult(byte[] fileData)
 {
     CompletionSource.TrySetResult(fileData);
 }