Exemple #1
0
 public static void ThrowIfNonPositiveArgument(TimeSpan timeout, string argumentName)
 {
     if (timeout <= TimeSpan.Zero)
     {
         throw Fx.Exception.ArgumentOutOfRange(argumentName, timeout, SRCore.TimeoutMustBePositive(argumentName, timeout));
     }
 }
Exemple #2
0
        public static System.Exception AssertAndFailFastService(string description)
        {
            string str = SRCore.FailFastMessage(description);

            try
            {
                try
                {
                    MessagingClientEtwProvider.Provider.EventWriteFailFastOccurred(description);
                    Fx.Exception.TraceFailFast(str);
                    Fx.FailFastInProgress = true;
                    Thread.Sleep(TimeSpan.FromSeconds(15));
                }
                finally
                {
                    Thread thread = new Thread(() => throw new FatalException(str));
                    thread.Start();
                    thread.Join();
                }
            }
            catch
            {
                throw;
            }
            return(null);
        }
Exemple #3
0
 protected void Complete(bool didCompleteSynchronously, Exception e)
 {
     if (!this.TryComplete(didCompleteSynchronously, e))
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.AsyncResultCompletedTwice(this.GetType())), null);
     }
 }
Exemple #4
0
        public T Dequeue(TimeSpan timeout)
        {
            T t;

            if (!this.Dequeue(timeout, out t))
            {
                throw Fx.Exception.AsInformation(new TimeoutException(SRCore.TimeoutInputQueueDequeue(timeout)), null);
            }
            return(t);
        }
Exemple #5
0
        public T Dequeue(TimeSpan timeout)
        {
            T value;

            if (!this.Dequeue(timeout, out value))
            {
                throw Fx.Exception.AsError(new TimeoutException(SRCore.TimeoutInputQueueDequeue(timeout)));
            }

            return(value);
        }
Exemple #6
0
            private static void OnWaiterCompleted(IAsyncResult result)
            {
                PendingOperationTracker.WaitPendingOperationsAsyncResult asyncState = (PendingOperationTracker.WaitPendingOperationsAsyncResult)result.AsyncState;
                if (AsyncWaiter.End(result))
                {
                    asyncState.Complete(result.CompletedSynchronously);
                    return;
                }
                TimeoutException timeoutException = new TimeoutException(SRCore.TimeoutOnOperation(asyncState.timeout));

                asyncState.Complete(result.CompletedSynchronously, timeoutException);
            }
Exemple #7
0
        private void AddUpdateOrRemoveCore(TKey key, TValue value, bool delete, bool throwNotFound = true)
        {
            ConcurrentTransactionalDictionary <TKey, TValue> .TransactionInformation transactionInformation;
            TValue      tValue;
            string      localIdentifier;
            Transaction current = Transaction.Current;

            if (current != null)
            {
                localIdentifier = current.TransactionInformation.LocalIdentifier;
            }
            else
            {
                localIdentifier = null;
            }
            string str = localIdentifier;

            lock (this.syncLock)
            {
                bool flag = !this.internalDictionary.TryGetValue(key, out tValue);
                if (!delete || !flag)
                {
                    if (this.pendingTransactions.TryGetValue(key, out transactionInformation))
                    {
                        if (!string.Equals(transactionInformation.TransactionId, str, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new InvalidOperationException(SRCore.DictionaryKeyIsModified(key));
                        }
                    }
                    else if (str != null)
                    {
                        this.pendingTransactions[key] = new ConcurrentTransactionalDictionary <TKey, TValue> .TransactionInformation(current, key, tValue, flag, this);
                    }
                    if (!delete)
                    {
                        this.internalDictionary[key] = value;
                    }
                    else
                    {
                        this.internalDictionary.Remove(key);
                    }
                }
                else if (throwNotFound)
                {
                    throw new InvalidOperationException(SRCore.DictionaryKeyNotExist(key));
                }
            }
        }
Exemple #8
0
            protected override void Invoke()
            {
                TimeoutException timeoutException;
                Action <object, TimeoutException> action = this.callback;
                object obj = this.state;

                if (this.TimedOut)
                {
                    timeoutException = new TimeoutException(SRCore.TimeoutOnOperation(this.originalTimeout));
                }
                else
                {
                    timeoutException = null;
                }
                action(obj, timeoutException);
            }
 public AssertionFailedException(string description) : base(SRCore.ShipAssertExceptionMessage(description))
 {
 }
Exemple #10
0
 public ArgumentException ArgumentNullOrEmpty(string paramName)
 {
     return(this.Argument(paramName, SRCore.ArgumentNullOrEmpty(paramName)));
 }
Exemple #11
0
 static void ThrowInvalidAsyncResult(IAsyncResult result)
 {
     throw Fx.Exception.AsError(new InvalidOperationException(SRCore.InvalidAsyncResultImplementation(result.GetType())));
 }
Exemple #12
0
        protected void Complete(bool didCompleteSynchronously)
        {
            if (this.isCompleted)
            {
#if DEBUG
                throw Fx.Exception.AsError(new InvalidOperationException(SRCore.AsyncResultCompletedTwice(this.GetType() + "\r\n First Complete Call Stack: \r\n" + this.completeStack + "\r\n")));
#else
                throw Fx.Exception.AsError(new InvalidOperationException(SRCore.AsyncResultCompletedTwice(this.GetType())));
#endif
            }

#if DEBUG
            this.marker.AsyncResult = null;
            this.marker             = null;
            if (completeStack == null)
            {
                this.completeStack = new StackTrace();
            }
#endif

            this.completedSynchronously = didCompleteSynchronously;
            if (this.OnCompleting != null)
            {
                // Allow exception replacement, like a catch/throw pattern.
                try
                {
                    this.OnCompleting(this, this.exception);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    this.exception = e;
                }
            }

            if (didCompleteSynchronously)
            {
                // If we completedSynchronously, then there's no chance that the manualResetEvent was created so
                // we don't need to worry about a race
                Fx.Assert(this.manualResetEvent == null, "No ManualResetEvent should be created for a synchronous AsyncResult.");
                this.isCompleted = true;
            }
            else
            {
                lock (this.ThisLock)
                {
                    this.isCompleted = true;
                    if (this.manualResetEvent != null)
                    {
                        this.manualResetEvent.Set();
                    }
                }
            }

            if (this.Callback != null)
            {
                try
                {
                    if (this.VirtualCallback != null)
                    {
                        this.VirtualCallback(this.Callback, this);
                    }
                    else
                    {
                        this.Callback(this);
                    }
                }
#pragma warning disable 1634
#pragma warning suppress 56500 // transferring exception to another thread
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    throw Fx.Exception.AsError(new CallbackException(SRCore.AsyncCallbackThrewException, e));
                }
#pragma warning restore 1634
            }
        }
 public ArgumentException ArgumentNullOrWhiteSpace(string paramName)
 {
     return(this.Argument(paramName, SRCore.ArgumentNullOrWhiteSpace(paramName)));
 }