Beispiel #1
0
            public void Dispose()
            {
                ApplicationImpersonationContext context = new ApplicationImpersonationContext();

                try
                {
                    if (this._filestream != null)
                    {
                        this._filestream.Close();
                    }
                    this._tempFiles.Delete();
                    ((IDisposable)this._tempFiles).Dispose();
                }
                catch
                {
                }
                finally
                {
                    if (context != null)
                    {
                        ((IDisposable)context).Dispose();
                    }
                }
            }
        internal void Flush(int max, FlushCallReason reason)
        {
            WebBaseEvent[] events = null;
            DateTime utcNow = DateTime.UtcNow;
            long waitTimeMs = 0L;
            DateTime maxValue = DateTime.MaxValue;
            int eventsDiscardedSinceLastNotification = -1;
            int eventsInBuffer = -1;
            int num4 = 0;
            EventNotificationType regular = EventNotificationType.Regular;
            bool flag = true;
            bool flag2 = false;
            bool flag3 = false;
            lock (this._buffer)
            {
                if (this._buffer.Count == 0)
                {
                    flag = false;
                }
                switch (reason)
                {
                    case FlushCallReason.UrgentFlushThresholdExceeded:
                        if (!this._urgentFlushScheduled)
                        {
                            break;
                        }
                        return;

                    case FlushCallReason.Timer:
                        if (this._regularFlushIntervalMs != Infinite)
                        {
                            flag2 = true;
                            waitTimeMs = this.GetNextRegularFlushDueTimeInMs();
                        }
                        goto Label_00D3;

                    default:
                        goto Label_00D3;
                }
                flag = false;
                flag2 = true;
                flag3 = true;
                if (this.AnticipateBurst(utcNow))
                {
                    waitTimeMs = this._burstWaitTimeMs;
                }
                else
                {
                    waitTimeMs = 0L;
                }
                TimeSpan span = (TimeSpan) (utcNow - this._lastScheduledFlushTime);
                long totalMilliseconds = (long) span.TotalMilliseconds;
                if ((totalMilliseconds + waitTimeMs) < this._urgentFlushIntervalMs)
                {
                    waitTimeMs = this._urgentFlushIntervalMs - totalMilliseconds;
                }
            Label_00D3:
                if (flag)
                {
                    if (this._threadsInFlush >= this._maxBufferThreads)
                    {
                        num4 = 0;
                    }
                    else
                    {
                        num4 = Math.Min(this._buffer.Count, max);
                    }
                }
                if (flag)
                {
                    if (num4 > 0)
                    {
                        events = new WebBaseEvent[num4];
                        for (int i = 0; i < num4; i++)
                        {
                            events[i] = (WebBaseEvent) this._buffer.Dequeue();
                        }
                        maxValue = this._lastFlushTime;
                        this._lastFlushTime = utcNow;
                        if (reason == FlushCallReason.Timer)
                        {
                            this._lastScheduledFlushTime = utcNow;
                        }
                        eventsDiscardedSinceLastNotification = this._discardedSinceLastFlush;
                        this._discardedSinceLastFlush = 0;
                        if (reason == FlushCallReason.StaticFlush)
                        {
                            regular = EventNotificationType.Flush;
                        }
                        else
                        {
                            regular = this._regularTimeoutUsed ? EventNotificationType.Regular : EventNotificationType.Urgent;
                        }
                    }
                    eventsInBuffer = this._buffer.Count;
                    if (eventsInBuffer >= this._urgentFlushThreshold)
                    {
                        flag2 = true;
                        flag3 = true;
                        waitTimeMs = this._urgentFlushIntervalMs;
                    }
                }
                this._urgentFlushScheduled = false;
                if (flag2)
                {
                    if (flag3)
                    {
                        long nextRegularFlushDueTimeInMs = this.GetNextRegularFlushDueTimeInMs();
                        if (nextRegularFlushDueTimeInMs < waitTimeMs)
                        {
                            waitTimeMs = nextRegularFlushDueTimeInMs;
                            this._regularTimeoutUsed = true;
                        }
                        else
                        {
                            this._regularTimeoutUsed = false;
                        }
                    }
                    else
                    {
                        this._regularTimeoutUsed = true;
                    }
                    this.SetTimer(waitTimeMs);
                    this._urgentFlushScheduled = flag3;
                }
                if ((reason == FlushCallReason.Timer) && !flag2)
                {
                    this._timer.Dispose();
                    this._timer = null;
                    this._urgentFlushScheduled = false;
                }
                if (events != null)
                {
                    Interlocked.Increment(ref this._threadsInFlush);
                }
            }
            if (events != null)
            {
                ApplicationImpersonationContext context = new ApplicationImpersonationContext();
                try
                {
                    WebEventBufferFlushInfo flushInfo = new WebEventBufferFlushInfo(new WebBaseEventCollection(events), regular, Interlocked.Increment(ref this._notificationSequence), maxValue, eventsDiscardedSinceLastNotification, eventsInBuffer);
                    this._flushCallback(flushInfo);
                }
                catch (Exception exception)
                {
                    try
                    {
                        this._provider.LogException(exception);
                    }
                    catch
                    {
                    }
                }
                catch
                {
                    try
                    {
                        this._provider.LogException(new Exception(System.Web.SR.GetString("Provider_Error")));
                    }
                    catch
                    {
                    }
                }
                finally
                {
                    if (context != null)
                    {
                        ((IDisposable) context).Dispose();
                    }
                }
                Interlocked.Decrement(ref this._threadsInFlush);
            }
        }
 public void Dispose()
 {
     ApplicationImpersonationContext context = new ApplicationImpersonationContext();
     try
     {
         if (this._filestream != null)
         {
             this._filestream.Close();
         }
         this._tempFiles.Delete();
         ((IDisposable) this._tempFiles).Dispose();
     }
     catch
     {
     }
     finally
     {
         if (context != null)
         {
             ((IDisposable) context).Dispose();
         }
     }
 }