Exemple #1
0
        private void ProcessNextSponsor()
        {
            object   sponsorId = (object)null;
            TimeSpan timeSpan  = TimeSpan.Zero;

            lock (this.sponsorTable)
            {
                IDictionaryEnumerator local_4 = this.sponsorTable.GetEnumerator();
                while (local_4.MoveNext())
                {
                    object local_5 = local_4.Key;
                    Lease.SponsorStateInfo local_6 = (Lease.SponsorStateInfo)local_4.Value;
                    if (local_6.sponsorState == Lease.SponsorState.Initial && timeSpan == TimeSpan.Zero)
                    {
                        timeSpan  = local_6.renewalTime;
                        sponsorId = local_5;
                    }
                    else if (local_6.renewalTime > timeSpan)
                    {
                        timeSpan  = local_6.renewalTime;
                        sponsorId = local_5;
                    }
                }
            }
            if (sponsorId != null)
            {
                this.SponsorCall(this.GetSponsorFromId(sponsorId));
            }
            else
            {
                this.Cancel();
            }
        }
Exemple #2
0
        private void ProcessNextSponsor()
        {
            object    obj      = null;
            TimeSpan  timeSpan = TimeSpan.Zero;
            Hashtable obj2     = this.sponsorTable;

            lock (obj2)
            {
                IDictionaryEnumerator enumerator = this.sponsorTable.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    object key = enumerator.Key;
                    Lease.SponsorStateInfo sponsorStateInfo = (Lease.SponsorStateInfo)enumerator.Value;
                    if (sponsorStateInfo.sponsorState == Lease.SponsorState.Initial && timeSpan == TimeSpan.Zero)
                    {
                        timeSpan = sponsorStateInfo.renewalTime;
                        obj      = key;
                    }
                    else if (sponsorStateInfo.renewalTime > timeSpan)
                    {
                        timeSpan = sponsorStateInfo.renewalTime;
                        obj      = key;
                    }
                }
            }
            if (obj != null)
            {
                this.SponsorCall(this.GetSponsorFromId(obj));
                return;
            }
            this.Cancel();
        }
Exemple #3
0
 internal void SponsorTimeout(object sponsorId)
 {
     lock (this)
     {
         if (this.sponsorTable.ContainsKey(sponsorId))
         {
             Hashtable obj = this.sponsorTable;
             lock (obj)
             {
                 Lease.SponsorStateInfo sponsorStateInfo = (Lease.SponsorStateInfo) this.sponsorTable[sponsorId];
                 if (sponsorStateInfo.sponsorState == Lease.SponsorState.Waiting)
                 {
                     this.Unregister(this.GetSponsorFromId(sponsorId));
                     this.ProcessNextSponsor();
                 }
             }
         }
     }
 }
Exemple #4
0
 public void Unregister(ISponsor sponsor)
 {
     lock (this)
     {
         if (this.state != LeaseState.Expired)
         {
             object    sponsorId = this.GetSponsorId(sponsor);
             Hashtable obj       = this.sponsorTable;
             lock (obj)
             {
                 if (sponsorId != null)
                 {
                     this.leaseManager.DeleteSponsor(sponsorId);
                     Lease.SponsorStateInfo sponsorStateInfo = (Lease.SponsorStateInfo) this.sponsorTable[sponsorId];
                     this.sponsorTable.Remove(sponsorId);
                 }
             }
         }
     }
 }
Exemple #5
0
 public void Unregister(ISponsor sponsor)
 {
     lock (this)
     {
         if (this.state == LeaseState.Expired)
         {
             return;
         }
         object local_2 = this.GetSponsorId(sponsor);
         lock (this.sponsorTable)
         {
             if (local_2 == null)
             {
                 return;
             }
             this.leaseManager.DeleteSponsor(local_2);
             Lease.SponsorStateInfo temp_27 = (Lease.SponsorStateInfo) this.sponsorTable[local_2];
             this.sponsorTable.Remove(local_2);
         }
     }
 }
Exemple #6
0
        internal void SponsorCall(ISponsor sponsor)
        {
            bool flag = false;

            if (this.state == LeaseState.Expired)
            {
                return;
            }
            lock (this.sponsorTable)
            {
                try
                {
                    object local_3 = this.GetSponsorId(sponsor);
                    this.sponsorCallThread = Thread.CurrentThread.GetHashCode();
                    Lease.AsyncRenewal     local_4 = new Lease.AsyncRenewal(sponsor.Renewal);
                    Lease.SponsorStateInfo temp_22 = (Lease.SponsorStateInfo) this.sponsorTable[local_3];
                    int temp_23 = 1;
                    temp_22.sponsorState = (Lease.SponsorState)temp_23;
                    local_4.BeginInvoke((ILease)this, new AsyncCallback(this.SponsorCallback), (object)null);
                    if (temp_22.sponsorState == Lease.SponsorState.Waiting && this.state != LeaseState.Expired)
                    {
                        this.leaseManager.RegisterSponsorCall(this, local_3, this.sponsorshipTimeout);
                    }
                    this.sponsorCallThread = 0;
                }
                catch (Exception exception_0)
                {
                    flag = true;
                    this.sponsorCallThread = 0;
                }
            }
            if (!flag)
            {
                return;
            }
            this.Unregister(sponsor);
            this.ProcessNextSponsor();
        }
Exemple #7
0
        internal void SponsorCall(ISponsor sponsor)
        {
            bool flag = false;

            if (this.state == LeaseState.Expired)
            {
                return;
            }
            Hashtable obj = this.sponsorTable;

            lock (obj)
            {
                try
                {
                    object sponsorId = this.GetSponsorId(sponsor);
                    this.sponsorCallThread = Thread.CurrentThread.GetHashCode();
                    Lease.AsyncRenewal     asyncRenewal     = new Lease.AsyncRenewal(sponsor.Renewal);
                    Lease.SponsorStateInfo sponsorStateInfo = (Lease.SponsorStateInfo) this.sponsorTable[sponsorId];
                    sponsorStateInfo.sponsorState = Lease.SponsorState.Waiting;
                    IAsyncResult asyncResult = asyncRenewal.BeginInvoke(this, new AsyncCallback(this.SponsorCallback), null);
                    if (sponsorStateInfo.sponsorState == Lease.SponsorState.Waiting && this.state != LeaseState.Expired)
                    {
                        this.leaseManager.RegisterSponsorCall(this, sponsorId, this.sponsorshipTimeout);
                    }
                    this.sponsorCallThread = 0;
                }
                catch (Exception)
                {
                    flag = true;
                    this.sponsorCallThread = 0;
                }
            }
            if (flag)
            {
                this.Unregister(sponsor);
                this.ProcessNextSponsor();
            }
        }
Exemple #8
0
 internal void SponsorCallback(IAsyncResult iar)
 {
     if (this.state == LeaseState.Expired)
     {
         return;
     }
     if (Thread.CurrentThread.GetHashCode() == this.sponsorCallThread)
     {
         ThreadPool.QueueUserWorkItem(new WaitCallback(this.SponsorCallback), (object)iar);
     }
     else
     {
         Lease.AsyncRenewal     asyncRenewal     = (Lease.AsyncRenewal)((AsyncResult)iar).AsyncDelegate;
         ISponsor               sponsor          = (ISponsor)asyncRenewal.Target;
         Lease.SponsorStateInfo sponsorStateInfo = (Lease.SponsorStateInfo)null;
         if (iar.IsCompleted)
         {
             bool     flag     = false;
             TimeSpan timeSpan = TimeSpan.Zero;
             try
             {
                 timeSpan = asyncRenewal.EndInvoke(iar);
             }
             catch (Exception ex)
             {
                 flag = true;
             }
             if (flag)
             {
                 this.Unregister(sponsor);
                 this.ProcessNextSponsor();
             }
             else
             {
                 object sponsorId = this.GetSponsorId(sponsor);
                 lock (this.sponsorTable)
                 {
                     if (this.sponsorTable.ContainsKey(sponsorId))
                     {
                         sponsorStateInfo = (Lease.SponsorStateInfo) this.sponsorTable[sponsorId];
                         sponsorStateInfo.sponsorState = Lease.SponsorState.Completed;
                         sponsorStateInfo.renewalTime  = timeSpan;
                     }
                 }
                 if (sponsorStateInfo == null)
                 {
                     this.ProcessNextSponsor();
                 }
                 else if (sponsorStateInfo.renewalTime == TimeSpan.Zero)
                 {
                     this.Unregister(sponsor);
                     this.ProcessNextSponsor();
                 }
                 else
                 {
                     this.RenewInternal(sponsorStateInfo.renewalTime);
                 }
             }
         }
         else
         {
             this.Unregister(sponsor);
             this.ProcessNextSponsor();
         }
     }
 }
Exemple #9
0
        internal void SponsorCallback(IAsyncResult iar)
        {
            if (this.state == LeaseState.Expired)
            {
                return;
            }
            int hashCode = Thread.CurrentThread.GetHashCode();

            if (hashCode == this.sponsorCallThread)
            {
                WaitCallback callBack = new WaitCallback(this.SponsorCallback);
                ThreadPool.QueueUserWorkItem(callBack, iar);
                return;
            }
            AsyncResult asyncResult = (AsyncResult)iar;

            Lease.AsyncRenewal asyncRenewal = (Lease.AsyncRenewal)asyncResult.AsyncDelegate;
            ISponsor           sponsor      = (ISponsor)asyncRenewal.Target;

            Lease.SponsorStateInfo sponsorStateInfo = null;
            if (!iar.IsCompleted)
            {
                this.Unregister(sponsor);
                this.ProcessNextSponsor();
                return;
            }
            bool     flag        = false;
            TimeSpan renewalTime = TimeSpan.Zero;

            try
            {
                renewalTime = asyncRenewal.EndInvoke(iar);
            }
            catch (Exception)
            {
                flag = true;
            }
            if (flag)
            {
                this.Unregister(sponsor);
                this.ProcessNextSponsor();
                return;
            }
            object    sponsorId = this.GetSponsorId(sponsor);
            Hashtable obj       = this.sponsorTable;

            lock (obj)
            {
                if (this.sponsorTable.ContainsKey(sponsorId))
                {
                    sponsorStateInfo = (Lease.SponsorStateInfo) this.sponsorTable[sponsorId];
                    sponsorStateInfo.sponsorState = Lease.SponsorState.Completed;
                    sponsorStateInfo.renewalTime  = renewalTime;
                }
            }
            if (sponsorStateInfo == null)
            {
                this.ProcessNextSponsor();
                return;
            }
            if (sponsorStateInfo.renewalTime == TimeSpan.Zero)
            {
                this.Unregister(sponsor);
                this.ProcessNextSponsor();
                return;
            }
            this.RenewInternal(sponsorStateInfo.renewalTime);
        }