Пример #1
0
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="message">fault message</param>
        /// <param name="eventType">Logging level for this fault TraceEventType.Stop == No logging</param>
        protected FaultBase(string message, TraceEventType eventType)
        {
            this.Message = message;

            switch (eventType)
            {
            case TraceEventType.Error:
            case TraceEventType.Information:
            case TraceEventType.Warning:
                break;

            default:
                return;
            }

            string stackTrace = UnhandledExceptionHelper.GetStackString();

            string logString = string.Format("{0}\r\n{1}\r\n{2}", this.GetType().Name, message, stackTrace);

            switch (eventType)
            {
            case TraceEventType.Error:
                EventLog.Error(logString);
                break;

            case TraceEventType.Information:
                EventLog.Information(logString);
                break;

            case TraceEventType.Warning:
                EventLog.Warning(logString);
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Acquires a writer lock.
        /// </summary>
        /// <param name="transactionId">A token used to identify the holder of the lock.</param>
        /// <param name="timeSpan">The time that the thread will wait for the lock.</param>
        //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual void AcquireWriterLock(global::System.Guid transactionId, global::System.TimeSpan timeSpan)
        {
            try
            {
                global::System.Threading.Monitor.Enter(this.rowRoot);
                this.writerWaiters = (this.writerWaiters + 1);
                if ((this.writer != transactionId))
                {
                    int index = this._readers.BinarySearch(transactionId);
                    if ((index >= 0))
                    {
                        this._readers.RemoveAt(index);
                        if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
                        {
                            this._readersStackTrace.RemoveAt(index);
                        }
                    }
                    for (
                        ; ((this.writer != global::System.Guid.Empty) ||
                           (this._readers.Count != 0));
                        )
                    {
                        try
                        {
                            try
                            {
                                global::System.Threading.Monitor.Enter(this.writerRoot);
                                global::System.Threading.Monitor.Exit(this.rowRoot);
                                if (false == global::System.Threading.Monitor.Wait(this.writerRoot, timeSpan))
                                {
                                    try
                                    {
                                        EventLog.Information("AcquireWriterLock TIMEOUT\r\n {0} Current Stack: {1} \r\n{2}", this.GetRowDebugDescription(), UnhandledExceptionHelper.GetStackString(), this.GetCurrentLockStacks(false));
                                    }
                                    catch
                                    {
                                    }

                                    throw new FluidTrade.Core.Utilities.DeadlockException("AcquireWriterLock TIMEOUT", null);
                                }
                            }
                            finally
                            {
                                global::System.Threading.Monitor.Exit(this.writerRoot);
                            }
                        }
                        finally
                        {
                            global::System.Threading.Monitor.Enter(this.rowRoot);
                        }
                    }
                    this.writer = transactionId;
                }
            }
            finally
            {
                this.writerWaiters = (this.writerWaiters - 1);
                global::System.Threading.Monitor.Exit(this.rowRoot);
            }
        }
Пример #3
0
 /// <summary>
 /// Acquires a reader lock for this record.
 /// </summary>
 /// <param name="dataModelTransaction">The transaction context for this operation.</param>
 //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 public virtual void AcquireReaderLock(IDataModelTransaction dataModelTransaction)
 {
     global::System.Guid transactionId = dataModelTransaction.TransactionId;
     try
     {
         global::System.Threading.Monitor.Enter(this.rowRoot);
         this.readerWaiters = (this.readerWaiters + 1);
         if ((this.writer != transactionId))
         {
             for (
                 ; (this.writer != global::System.Guid.Empty);
                 )
             {
                 if (false == global::System.Threading.Monitor.Wait(this.rowRoot, this.LockTimeout))
                 {
                     try
                     {
                         EventLog.Information("AcquireReaderLock DEGRADE from TIMEOUT\r\n {0} Current Stack: {1} \r\n{2}", this.GetRowDebugDescription(), UnhandledExceptionHelper.GetStackString(), this.GetCurrentLockStacks(false));
                     }
                     catch
                     {
                     }
                     break;
                 }
             }
             int index = this._readers.BinarySearch(transactionId);
             if ((index < 0))
             {
                 InsertToReaderList(transactionId, index);
             }
         }
     }
     finally
     {
         this.readerWaiters = (this.readerWaiters - 1);
         global::System.Threading.Monitor.Exit(this.rowRoot);
     }
     dataModelTransaction.AddLock(this);
     if ((this.RowState == global::System.Data.DataRowState.Detached))
     {
         throw new global::System.Exception("The " + this.GetType().FullName + " record was deleted after it was locked");
     }
 }
Пример #4
0
        /// <summary>
        /// Acquires a reader lock.
        /// </summary>
        /// <param name="transactionId">A token used to identify the holder of the lock.</param>
        /// <param name="timeSpan">The time that the thread will wait for the lock.</param>
        ///[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual void AcquireReaderLock(global::System.Guid transactionId, global::System.TimeSpan timeSpan)
        {
            try
            {
                global::System.Threading.Monitor.Enter(this.rowRoot);
                this.readerWaiters = (this.readerWaiters + 1);
                if ((this.writer != transactionId))               //no-op if there is a writer lock
                {
                    for (
                        ; (this.writer != global::System.Guid.Empty);
                        )
                    {
                        if (false == global::System.Threading.Monitor.Wait(this.rowRoot, timeSpan))
                        {
                            try
                            {
                                EventLog.Information("AcquireReaderLock DEGRADE from TIMEOUT\r\n {0} Current Stack: {1} \r\n{2}", this.GetRowDebugDescription(), UnhandledExceptionHelper.GetStackString(), this.GetCurrentLockStacks(false));
                            }
                            catch
                            {
                            }

                            break;
                        }
                    }
                    int index = this._readers.BinarySearch(transactionId);
                    if ((index < 0))
                    {
                        InsertToReaderList(transactionId, index);
                    }
                }
            }
            finally
            {
                this.readerWaiters = (this.readerWaiters - 1);
                global::System.Threading.Monitor.Exit(this.rowRoot);
            }
        }
Пример #5
0
        /// <summary>
        /// Acquires a writer lock for this record.
        /// </summary>
        /// <param name="dataModelTransaction">The transaction context for this operation.</param>
        //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual void AcquireWriterLock(IDataModelTransaction dataModelTransaction)
        {
            global::System.Guid transactionId = dataModelTransaction.TransactionId;
            try
            {
                global::System.Threading.Monitor.Enter(this.rowRoot);
                this.writerWaiters = (this.writerWaiters + 1);
                if ((this.writer != transactionId))
                {
                    int index = this._readers.BinarySearch(transactionId);
                    if ((index >= 0))
                    {
                        this._readers.RemoveAt(index);
                        if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
                        {
                            this._readersStackTrace.RemoveAt(index);
                        }
                    }
                    for (
                        ; ((this.writer != global::System.Guid.Empty) ||
                           (this._readers.Count != 0));
                        )
                    {
                        try
                        {
                            try
                            {
                                global::System.Threading.Monitor.Enter(this.writerRoot);
                                global::System.Threading.Monitor.Exit(this.rowRoot);
                                if (false == global::System.Threading.Monitor.Wait(this.writerRoot, this.LockTimeout))
                                {
                                    try
                                    {
                                        EventLog.Information("AcquireWriterLock TIMEOUT\r\n {0} Current Stack: {1} \r\n{2}", this.GetRowDebugDescription(), UnhandledExceptionHelper.GetStackString(), this.GetCurrentLockStacks(false));
                                    }
                                    catch
                                    {
                                    }

                                    throw new FluidTrade.Core.Utilities.DeadlockException("AcquireWriterLock TIMEOUT", null);
                                }
                            }
                            finally
                            {
                                global::System.Threading.Monitor.Exit(this.writerRoot);
                            }
                        }
                        finally
                        {
                            global::System.Threading.Monitor.Enter(this.rowRoot);
                        }
                    }
                    this.writer = transactionId;
                }
            }
            finally
            {
                this.writerWaiters = (this.writerWaiters - 1);
                global::System.Threading.Monitor.Exit(this.rowRoot);
            }
            dataModelTransaction.AddLock(this);
            if ((this.RowState == global::System.Data.DataRowState.Detached))
            {
                throw new global::System.Exception("The " + this.GetType().FullName + " record was deleted after it was locked");
            }
        }