private void ResolvePrefix(ref Attribute attribute)
 {
     if (attribute.prefixLength != 0)
     {
         ResolvePrefix(attribute.prefixOffset, attribute.prefixLength, out attribute.nsOffset, out attribute.nsLength);
     }
     else
     {
         // These should've been set when we added the prefix
         Fx.Assert(attribute.nsOffset == 0 && attribute.nsLength == 0, "");
     }
 }
 public override byte[] TakeBuffer(int bufferSize)
 {
     return(Fx.AllocateByteArray(bufferSize));
 }
示例#3
0
 public void MakePendingItemAvailable()
 {
     Fx.AssertAndThrow(_pendingCount != 0, "ItemQueue does not contain any pending items");
     _pendingCount--;
 }
示例#4
0
 public Item DequeueAvailableItem()
 {
     Fx.AssertAndThrow(_totalCount != _pendingCount, "ItemQueue does not contain any available items");
     return(DequeueItemCore());
 }
示例#5
0
 public InputQueue(Func <Action <AsyncCallback, IAsyncResult> > asyncCallbackGenerator)
     : this()
 {
     Fx.Assert(asyncCallbackGenerator != null, "use default ctor if you don't have a generator");
     AsyncCallbackGenerator = asyncCallbackGenerator;
 }
示例#6
0
 public bool EnqueueWithoutDispatch(Exception exception, Action dequeuedCallback)
 {
     Fx.Assert(exception != null, "EnqueueWithoutDispatch: exception parameter should not be null");
     return(EnqueueWithoutDispatch(new Item(exception, dequeuedCallback)));
 }
示例#7
0
 public bool EnqueueWithoutDispatch(T item, Action dequeuedCallback)
 {
     Fx.Assert(item != null, "EnqueueWithoutDispatch: item parameter should not be null");
     return(EnqueueWithoutDispatch(new Item(item, dequeuedCallback)));
 }
示例#8
0
 public static Exception AssertAndThrowFatal(string description)
 {
     Fx.Assert(description);
     TraceCore.ShipAssertExceptionMessage(Trace, description);
     throw new FatalInternalException(description);
 }
示例#9
0
 public void EnqueueAndDispatch(Exception exception, Action dequeuedCallback, bool canDispatchOnThisThread)
 {
     Fx.Assert(exception != null, "EnqueueAndDispatch: exception parameter should not be null");
     EnqueueAndDispatch(new Item(exception, dequeuedCallback), canDispatchOnThisThread);
 }
示例#10
0
        protected void Complete(bool completedSynchronously)
        {
            if (this.isCompleted)
            {
                throw Fx.Exception.AsError(new InvalidOperationException(InternalSR.AsyncResultCompletedTwice(GetType())));
            }

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

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

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

            if (this.callback != null)
            {
                try
                {
                    if (VirtualCallback != null)
                    {
                        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(InternalSR.AsyncCallbackThrewException, e));
                }
#pragma warning restore 1634
            }
        }
示例#11
0
 private static void UpdateLevel()
 {
     Fx.UpdateLevel(Fx.Trace);
 }
示例#12
0
        private static EtwDiagnosticTrace InitializeTracing()
        {
            EtwDiagnosticTrace etwDiagnosticTrace = new EtwDiagnosticTrace("System.Runtime", EtwDiagnosticTrace.DefaultEtwProviderId);

            if (etwDiagnosticTrace.EtwProvider != null)
            {
                EtwDiagnosticTrace etwDiagnosticTrace1 = etwDiagnosticTrace;
                Action             refreshState        = etwDiagnosticTrace1.RefreshState;
                etwDiagnosticTrace1.RefreshState = (Action)Delegate.Combine(refreshState, () => Fx.UpdateLevel());
            }
            Fx.UpdateLevel(etwDiagnosticTrace);
            return(etwDiagnosticTrace);
        }
 public ThreadNeutralSemaphore(int maxCount, Func <Exception> abortedExceptionGenerator)
 {
     Fx.Assert(maxCount > 0, "maxCount must be positive");
     this.maxCount = maxCount;
     this.abortedExceptionGenerator = abortedExceptionGenerator;
 }
 public TransactionSignalScope(TransactedAsyncResult result, Transaction transaction)
 {
     Fx.Assert(transaction != null, "Null Transaction provided to AsyncResult.TransactionSignalScope.");
     this.parent           = result;
     this.transactionScope = TransactionHelper.CreateTransactionScope(transaction);
 }
示例#15
0
 public ScheduledOverlapped()
 {
     unsafe {
         this.nativeOverlapped = (new Overlapped()).UnsafePack(Fx.ThunkCallback(new IOCompletionCallback(this.IOCallback)), null);
     }
 }
 public FatalException(string message, Exception innerException) : base(message, innerException)
 {
     // This can't throw something like ArgumentException because that would be worse than
     // throwing the fatal exception that was requested.
     Fx.Assert(innerException == null || !Fx.IsFatal(innerException), "FatalException can't be used to wrap fatal exceptions.");
 }
示例#17
0
 public void EnqueueAndDispatch(T item, Action dequeuedCallback, bool canDispatchOnThisThread)
 {
     Fx.Assert(item != null, "EnqueueAndDispatch: item parameter should not be null");
     EnqueueAndDispatch(new Item(item, dequeuedCallback), canDispatchOnThisThread);
 }
示例#18
0
        static bool TryNumericConversion <T>(object source, out T result)
        {
            Fx.Assert(source != null, "caller must verify");
            TypeCode sourceTypeCode      = Type.GetTypeCode(source.GetType());
            TypeCode destinationTypeCode = Type.GetTypeCode(typeof(T));

            switch (sourceTypeCode)
            {
            case TypeCode.SByte:
            {
                SByte sbyteSource = (SByte)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int16:
                    result = (T)(object)(Int16)sbyteSource;
                    return(true);

                case TypeCode.Int32:
                    result = (T)(object)(Int32)sbyteSource;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)sbyteSource;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)sbyteSource;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)sbyteSource;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)sbyteSource;
                    return(true);
                }
                break;
            }

            case TypeCode.Byte:
            {
                Byte byteSource = (Byte)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int16:
                    result = (T)(object)(Int16)byteSource;
                    return(true);

                case TypeCode.UInt16:
                    result = (T)(object)(UInt16)byteSource;
                    return(true);

                case TypeCode.Int32:
                    result = (T)(object)(Int32)byteSource;
                    return(true);

                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)byteSource;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)byteSource;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)byteSource;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)byteSource;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)byteSource;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)byteSource;
                    return(true);
                }
                break;
            }

            case TypeCode.Int16:
            {
                Int16 int16Source = (Int16)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int32:
                    result = (T)(object)(Int32)int16Source;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)int16Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)int16Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)int16Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)int16Source;
                    return(true);
                }
                break;
            }

            case TypeCode.UInt16:
            {
                UInt16 uint16Source = (UInt16)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int32:
                    result = (T)(object)(Int32)uint16Source;
                    return(true);

                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)uint16Source;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)uint16Source;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)uint16Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)uint16Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)uint16Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)uint16Source;
                    return(true);
                }
                break;
            }

            case TypeCode.Int32:
            {
                Int32 int32Source = (Int32)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Int64:
                    result = (T)(object)(Int64)int32Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)int32Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)int32Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)int32Source;
                    return(true);
                }
                break;
            }

            case TypeCode.UInt32:
            {
                UInt32 uint32Source = (UInt32)source;
                switch (destinationTypeCode)
                {
                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)uint32Source;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)uint32Source;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)uint32Source;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)uint32Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)uint32Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)uint32Source;
                    return(true);
                }
                break;
            }

            case TypeCode.Int64:
            {
                Int64 int64Source = (Int64)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Single:
                    result = (T)(object)(Single)int64Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)int64Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)int64Source;
                    return(true);
                }
                break;
            }

            case TypeCode.UInt64:
            {
                UInt64 uint64Source = (UInt64)source;
                switch (destinationTypeCode)
                {
                case TypeCode.Single:
                    result = (T)(object)(Single)uint64Source;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)uint64Source;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)uint64Source;
                    return(true);
                }
                break;
            }

            case TypeCode.Char:
            {
                Char charSource = (Char)source;
                switch (destinationTypeCode)
                {
                case TypeCode.UInt16:
                    result = (T)(object)(UInt16)charSource;
                    return(true);

                case TypeCode.Int32:
                    result = (T)(object)(Int32)charSource;
                    return(true);

                case TypeCode.UInt32:
                    result = (T)(object)(UInt32)charSource;
                    return(true);

                case TypeCode.Int64:
                    result = (T)(object)(Int64)charSource;
                    return(true);

                case TypeCode.UInt64:
                    result = (T)(object)(UInt64)charSource;
                    return(true);

                case TypeCode.Single:
                    result = (T)(object)(Single)charSource;
                    return(true);

                case TypeCode.Double:
                    result = (T)(object)(Double)charSource;
                    return(true);

                case TypeCode.Decimal:
                    result = (T)(object)(Decimal)charSource;
                    return(true);
                }
                break;
            }

            case TypeCode.Single:
            {
                if (destinationTypeCode == TypeCode.Double)
                {
                    result = (T)(object)(Double)(Single)source;
                    return(true);
                }
                break;
            }
            }

            result = default(T);
            return(false);
        }