コード例 #1
0
            public CloseAsyncResult(SingletonDictionaryManager <TKey, TInstance> owner, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
            {
                List <TKey> tKeys;

                this.owner         = owner;
                this.syncRoot      = new object();
                this.timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                lock (this.owner.ThisLock)
                {
                    tKeys = new List <TKey>(this.owner.instances.Keys);
                }
                this.IncreaseWaitCount();
                foreach (TKey tKey in tKeys)
                {
                    try
                    {
                        this.IncreaseWaitCount();
                        (new SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult(this.owner, tKey, null, false, this.timeoutHelper.RemainingTime(), SingletonDictionaryManager <TKey, TInstance> .CloseAsyncResult.OnUnloadCompletedCallback, this)).Start();
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        this.DecreaseWaitCount(exception, true);
                    }
                }
                this.DecreaseWaitCount(null, true);
            }
コード例 #2
0
        protected TInstance GetInstance(TKey key, TimeSpan timeout)
        {
            SingletonDictionaryManager <TKey, TInstance> .GetInstanceAsyncResult getInstanceAsyncResult = new SingletonDictionaryManager <TKey, TInstance> .GetInstanceAsyncResult(this, key, timeout, null, null);

            getInstanceAsyncResult.RunSynchronously();
            return(getInstanceAsyncResult.Instance);
        }
コード例 #3
0
        protected TInstance LoadInstance(TKey key, object loadingContext, TimeSpan timeout)
        {
            SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult = new SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult(this, key, loadingContext, timeout, null, null);

            loadInstanceAsyncResult.RunSynchronously();
            return(loadInstanceAsyncResult.Instance);
        }
コード例 #4
0
 private void IncreaseWaitCount()
 {
     lock (this.syncRoot)
     {
         SingletonDictionaryManager <TKey, TInstance> .CloseAsyncResult closeAsyncResult = this;
         closeAsyncResult.waitCount = closeAsyncResult.waitCount + 1;
     }
 }
コード例 #5
0
 public LoadInstanceAsyncResult(SingletonDictionaryManager <TKey, TInstance> owner, TKey key, object loadingContext, TimeSpan timeout, AsyncCallback callback, object state) : base(timeout, callback, state)
 {
     this.owner          = owner;
     this.key            = key;
     this.loadingContext = loadingContext;
     SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult loadInstanceAsyncResult = this;
     loadInstanceAsyncResult.OnCompleting = (Action <AsyncResult, Exception>)Delegate.Combine(loadInstanceAsyncResult.OnCompleting, SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult.CompletingDelegate);
 }
コード例 #6
0
 public UnloadInstanceAsyncResult(SingletonDictionaryManager <TKey, TInstance> owner, TKey key, object unloadingContext, bool shouldAbort, TimeSpan timeout, AsyncCallback callback, object state) : base(TimeSpan.MaxValue, callback, state)
 {
     this.owner            = owner;
     this.key              = key;
     this.unloadingContext = unloadingContext;
     this.shouldAbort      = shouldAbort;
     this.closeTimeout     = timeout;
     SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult = this;
     unloadInstanceAsyncResult.OnCompleting = (Action <AsyncResult, Exception>)Delegate.Combine(unloadInstanceAsyncResult.OnCompleting, SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult.CompletingDelegate);
 }
コード例 #7
0
        protected bool TryGetSingletonContext(TKey key, out SingletonDictionaryManager <TKey, TInstance> .SingletonContext singletonContext)
        {
            bool flag;

            lock (base.ThisLock)
            {
                flag = this.instances.TryGetValue(key, out singletonContext);
            }
            return(flag);
        }
コード例 #8
0
 protected override void OnAbort()
 {
     lock (base.ThisLock)
     {
         foreach (TKey list in this.instances.Keys.ToList <TKey>())
         {
             SingletonDictionaryManager <TKey, TInstance> .SingletonContext item = this.instances[list];
             if (item.State != SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loaded)
             {
                 continue;
             }
             this.instances.Remove(list);
             this.OnAbortInstance(item, list, item.Instance, null);
         }
     }
 }
コード例 #9
0
            private static void OnUnloadCompleted(IAsyncResult result)
            {
                SingletonDictionaryManager <TKey, TInstance> .CloseAsyncResult asyncState = (SingletonDictionaryManager <TKey, TInstance> .CloseAsyncResult)result.AsyncState;
                try
                {
                    SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult.End(result);

                    asyncState.DecreaseWaitCount(null, result.CompletedSynchronously);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    asyncState.DecreaseWaitCount(exception, result.CompletedSynchronously);
                }
            }
コード例 #10
0
            private void DecreaseWaitCount(Exception exception, bool isCompletedSynchronously)
            {
                bool flag = false;

                lock (this.syncRoot)
                {
                    if (this.firstException == null)
                    {
                        this.firstException = exception;
                    }
                    SingletonDictionaryManager <TKey, TInstance> .CloseAsyncResult closeAsyncResult = this;
                    int num  = closeAsyncResult.waitCount - 1;
                    int num1 = num;
                    closeAsyncResult.waitCount = num;
                    if (num1 == 0)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    base.Complete(isCompletedSynchronously, this.firstException);
                }
            }
コード例 #11
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));
         }
     }
 }
コード例 #12
0
 private static void OnFinally(AsyncResult result, Exception exception)
 {
     SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult = (SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult)result;
     if (unloadInstanceAsyncResult.ownsUnloading)
     {
         try
         {
             if (exception != null || unloadInstanceAsyncResult.shouldAbort)
             {
                 unloadInstanceAsyncResult.owner.OnAbortInstance(unloadInstanceAsyncResult.singletonContext, unloadInstanceAsyncResult.key, unloadInstanceAsyncResult.instance, unloadInstanceAsyncResult.unloadingContext);
             }
         }
         finally
         {
             lock (unloadInstanceAsyncResult.owner.ThisLock)
             {
                 unloadInstanceAsyncResult.owner.instances.Remove(unloadInstanceAsyncResult.key);
             }
             unloadInstanceAsyncResult.owner.SignalPendingOperations(unloadInstanceAsyncResult.key);
         }
     }
 }
コード例 #13
0
 public SingletonContext(SingletonDictionaryManager <TKey, TInstance> .SingletonState initialState)
 {
     this.State = initialState;
 }
コード例 #14
0
 protected abstract IAsyncResult OnBeginOpenInstance(SingletonDictionaryManager <TKey, TInstance> .SingletonContext singletonContext, TKey key, TInstance instance, TimeSpan timeout, AsyncCallback callback, object state);
コード例 #15
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;
            }
コード例 #16
0
 private static void OnFinally(AsyncResult result, Exception exception)
 {
     SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult instance = (SingletonDictionaryManager <TKey, TInstance> .LoadInstanceAsyncResult)result;
     if (instance.ownsLoading)
     {
         if (exception != null || instance.owner.State != CommunicationState.Opened)
         {
             try
             {
                 if (instance.created)
                 {
                     instance.owner.OnAbortInstance(instance.singletonContext, instance.key, instance.singletonContext.Instance, null);
                 }
             }
             finally
             {
                 lock (instance.owner.ThisLock)
                 {
                     instance.owner.instances.Remove(instance.key);
                 }
                 instance.owner.SignalPendingOperations(instance.key);
             }
         }
         else
         {
             lock (instance.owner.ThisLock)
             {
                 instance.Instance = instance.singletonContext.Instance;
                 instance.singletonContext.State = SingletonDictionaryManager <TKey, TInstance> .SingletonState.Loaded;
             }
             instance.owner.SignalPendingOperations(instance.key);
             MessagingClientEtwProvider.TraceClient(() => MessagingClientEtwProvider.Provider.EventWriteSingletonManagerLoadSucceeded(instance.key.ToString()));
         }
     }
 }
コード例 #17
0
 public GetInstanceAsyncResult(SingletonDictionaryManager <TKey, TInstance> owner, TKey key, TimeSpan timeout, AsyncCallback callback, object state) : base(timeout, callback, state)
 {
     this.owner    = owner;
     this.key      = key;
     this.Instance = default(TInstance);
 }
コード例 #18
0
 protected abstract void OnCloseInstance(SingletonDictionaryManager <TKey, TInstance> .SingletonContext singletonContext, TKey key, TInstance instance, object unloadingContext, TimeSpan timeout);
コード例 #19
0
 protected abstract TInstance OnCreateInstance(SingletonDictionaryManager <TKey, TInstance> .SingletonContext singletonContext, TKey key, object loadingContext, TimeSpan timeout);
コード例 #20
0
 protected virtual void OnGetInstance(SingletonDictionaryManager <TKey, TInstance> .SingletonContext singletonContext, TKey key, TInstance instance, object loadingContext)
 {
 }
コード例 #21
0
 protected abstract void OnAbortInstance(SingletonDictionaryManager <TKey, TInstance> .SingletonContext singletonContext, TKey key, TInstance instance, object unloadingContext);
コード例 #22
0
 protected abstract void OnOpenInstance(SingletonDictionaryManager <TKey, TInstance> .SingletonContext singletonContext, TKey key, TInstance instance, TimeSpan timeout);
コード例 #23
0
        protected void UnloadInstance(TKey key, object unloadingContext, bool shouldAbort, TimeSpan timeout)
        {
            SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult unloadInstanceAsyncResult = new SingletonDictionaryManager <TKey, TInstance> .UnloadInstanceAsyncResult(this, key, unloadingContext, shouldAbort, timeout, null, null);

            unloadInstanceAsyncResult.RunSynchronously();
        }