Exemplo n.º 1
0
 protected override IEnumerator <IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .AsyncStep> GetAsyncSteps()
 {
     while (true)
     {
         Monitor.Enter(this.owner.ThisLock);
         this.shouldReleaseLock = true;
         try
         {
             if (!this.owner.instances.TryGetValue(this.key, out this.singletonContext))
             {
                 break;
             }
             if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loaded)
             {
                 this.singletonContext.State = SingletonDictionaryManager <TKey, TInstance> .SingletonState.Unloading;
                 this.instance      = this.singletonContext.Instance;
                 this.ownsUnloading = true;
                 break;
             }
             else if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loading || this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Unloading)
             {
                 SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult = this;
                 IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .BeginCall beginCall = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => {
                     IAsyncResult asyncResult;
                     try
                     {
                         thisPtr.shouldReleaseLock = false;
                         asyncResult = thisPtr.owner.BeginWaitPendingOperation(thisPtr.key, t, c, s);
                     }
                     finally
                     {
                         Monitor.Exit(thisPtr.owner.ThisLock);
                     }
                     return(asyncResult);
                 };
                 yield return(unloadInstanceAsyncResult.CallAsync(beginCall, (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.EndWaitPendingOperation(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
             }
             else
             {
                 CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                 object[]    state            = new object[] { this.singletonContext.State, typeof(SingletonDictionaryManager <TKey, TInstance>).Name };
                 string      str = string.Format(invariantCulture, "{0} was not recognized. This is likely a bug in {1}.", state);
                 Fx.AssertAndFailFastService(str);
                 break;
             }
         }
         finally
         {
             if (this.shouldReleaseLock)
             {
                 Monitor.Exit(this.owner.ThisLock);
             }
         }
     }
     if (this.ownsUnloading)
     {
         if (!this.waitPendingOperationsCalled)
         {
             this.waitPendingOperationsCalled = true;
             SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult1 = this;
             IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .BeginCall beginCall1 = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginWaitPendingOperations(thisPtr.instance, thisPtr.closeTimeout, c, s);
             yield return(unloadInstanceAsyncResult1.CallAsync(beginCall1, (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.OnEndWaitPendingOperations(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
         }
         if (!this.shouldAbort)
         {
             SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult2 = this;
             IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .BeginCall beginCall2 = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginCloseInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.instance, thisPtr.unloadingContext, thisPtr.closeTimeout, c, s);
             IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult> .EndCall   endCall    = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.OnEndCloseInstance(r);
             yield return(unloadInstanceAsyncResult2.CallAsync(beginCall2, endCall, (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult thisPtr, TimeSpan t) => thisPtr.owner.OnCloseInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.instance, thisPtr.unloadingContext, thisPtr.closeTimeout), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
         }
     }
 }
Exemplo n.º 2
0
            protected override IEnumerator <IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .AsyncStep> GetAsyncSteps()
            {
                while (true)
                {
                    Monitor.Enter(this.owner.ThisLock);
                    this.shouldReleaseLock = true;
                    try
                    {
                        this.owner.ThrowIfDisposedOrNotOpen();
                        if (!this.owner.instances.TryGetValue(this.key, out this.singletonContext))
                        {
                            this.singletonContext = new SingletonDictionaryManager <TKey, TInstance> .SingletonContext(SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loading);

                            this.owner.instances.Add(this.key, this.singletonContext);
                            this.ownsLoading = true;
                            break;
                        }
                        else if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loaded)
                        {
                            this.Instance = this.singletonContext.Instance;
                            break;
                        }
                        else if (base.RemainingTime() <= TimeSpan.Zero)
                        {
                            base.Complete(new TimeoutException(SRCore.TimeoutOnOperation(base.OriginalTimeout)));
                            goto Label0;
                        }
                        else if (this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loading || this.singletonContext.State == SingletonDictionaryManager <TKey, TInstance> .SingletonState.Unloading)
                        {
                            SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult = this;
                            IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .BeginCall beginCall = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => {
                                IAsyncResult asyncResult;
                                try
                                {
                                    thisPtr.shouldReleaseLock = false;
                                    asyncResult = thisPtr.owner.BeginWaitPendingOperation(thisPtr.key, t, c, s);
                                }
                                finally
                                {
                                    Monitor.Exit(thisPtr.owner.ThisLock);
                                }
                                return(asyncResult);
                            };
                            yield return(loadInstanceAsyncResult.CallAsync(beginCall, (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.EndWaitPendingOperation(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
                        }
                        else
                        {
                            CultureInfo invariantCulture = CultureInfo.InvariantCulture;
                            object[]    state            = new object[] { this.singletonContext.State, typeof(SingletonDictionaryManager <TKey, TInstance>).Name };
                            string      str = string.Format(invariantCulture, "{0} was not recognized. This is likely a bug in {1}.", state);
                            Fx.AssertAndFailFastService(str);
                            break;
                        }
                    }
                    finally
                    {
                        if (this.shouldReleaseLock)
                        {
                            Monitor.Exit(this.owner.ThisLock);
                        }
                    }
                }
                if (!this.ownsLoading)
                {
                    this.owner.OnGetInstance(this.singletonContext, this.key, this.singletonContext.Instance, this.loadingContext);
                }
                else
                {
                    SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult1 = this;
                    IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .BeginCall beginCall1 = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginCreateInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.loadingContext, t, c, s);
                    IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .EndCall   instance   = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.singletonContext.Instance = thisPtr.owner.OnEndCreateInstance(r);
                    yield return(loadInstanceAsyncResult1.CallAsync(beginCall1, instance, (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t) => thisPtr.singletonContext.Instance = thisPtr.owner.OnCreateInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.loadingContext, t), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));

                    this.created = true;
                    SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult2 = this;
                    IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .BeginCall beginCall2 = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => thisPtr.owner.OnBeginOpenInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.singletonContext.Instance, t, c, s);
                    IteratorAsyncResult <SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult> .EndCall   endCall    = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, IAsyncResult r) => thisPtr.owner.OnEndOpenInstance(r);
                    yield return(loadInstanceAsyncResult2.CallAsync(beginCall2, endCall, (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult thisPtr, TimeSpan t) => thisPtr.owner.OnOpenInstance(thisPtr.singletonContext, thisPtr.key, thisPtr.singletonContext.Instance, t), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer));
                }
Label0:
                yield break;
            }