Example #1
0
        public static Boolean PerformPassivation(ref Int32 transitionState, ref InProgressTracker passivationInProgress, InProgressTracker activationInProgress, Int32 waitTime, Action passivationAction)
        {
            Int32   initialState = (Int32)(new InProgressTracker().Equals(activationInProgress) ? ActivationState.DURING_ACTIVATION : ActivationState.ACTIVE);
            Int32   prevState;
            Boolean actionInvoked;
            Boolean tryAgain;

#if SILVERLIGHT
            using (var waitEvt = new ManualResetEvent(false))
#else
            using (var waitEvt = new ManualResetEventSlim(false))
#endif
            {
                do
                {
                    prevState = ApplicationSkeleton.ThreadsafeStateTransition(ref transitionState, initialState, (Int32)ActivationState.DURING_PASSIVATION, (Int32)ActivationState.PASSIVE, false, ref passivationInProgress, waitTime, passivationAction);

                    actionInvoked = prevState == initialState;
                    tryAgain      = !actionInvoked && prevState != (Int32)ActivationState.PASSIVE && prevState != (Int32)ActivationState.DURING_PASSIVATION;
                    if (tryAgain && initialState == (Int32)ActivationState.ACTIVE)
                    {
                        // Wait if we are not inside activation action,
                        // and if transition state change failed because activation is in progress.
#if SILVERLIGHT
                        waitEvt.WaitOne(waitTime);
#else
                        waitEvt.Wait(waitTime);
#endif
                    }
                } while (tryAgain);
            }
            return(actionInvoked);
        }
 public void DisablePrototype(Int32 compositeMethodIndex, MethodGenericArgumentsInfo gArgsInfo, AbstractFragmentMethodModel nextMethod)
 {
     ApplicationSkeleton.ThreadsafeStateTransition(ref this._isPrototype, (Int32)PrototypeState.PROTOTYPE, (Int32)PrototypeState.IN_TRANSITION_RUNNING_ACTION, (Int32)PrototypeState.NOT_PROTOTYPE, true, ref this._isPrototypeTransitionInProgress, ApplicationSkeleton.WAIT_TIME, () =>
     {
         this.RunPrototypeAction(compositeMethodIndex, gArgsInfo, nextMethod);
         Interlocked.Exchange(ref this._isPrototype, (Int32)PrototypeState.IN_TRANSITION_CHECKING_STATE);
         this.CheckCompositeState(compositeMethodIndex, gArgsInfo, nextMethod);
         ((CompositeModelImmutable)this.ModelInfo.Model).InvokeCompositeInstantiated(this);
     });
 }
 internal void RunPassivationActionIfNeeded()
 {
     ApplicationSkeleton.PerformPassivation(ref this._activationState, ref this._passivationInProgress, this._activationInProgress, ApplicationSkeleton.WAIT_TIME, () =>
     {
         try
         {
             if (this._passivationAction != null)
             {
                 this._passivationAction();
             }
         }
         finally
         {
             ((ServiceCompositeModelImmutable)this.ModelInfo.Model).InvokeAfterPassivation(this);
         }
     });
 }
        public void ActivateIfNeeded(Int32 compositeMethodIndex, MethodGenericArgumentsInfo gArgsInfo, AbstractFragmentMethodModel nextFragment)
        {
            if ((Int32)ActivatingAllowed.ALLOWED == this._activatingAllowed)
            {
                ApplicationSkeleton.PerformActivation(ref this._activationState, ref this._activationInProgress, this._passivationInProgress, ApplicationSkeleton.WAIT_TIME, false, () =>
                {
                    CompositePropertySPI idProp = (CompositePropertySPI)this.State.Properties[IDENTITY_QNAME];
                    if (Convert.ToBoolean(this._needToSetIdentity))
                    {
                        idProp.PropertyValueAsObject = this._serviceID;
                        Interlocked.Exchange(ref this._needToSetIdentity, Convert.ToInt32(false));
                    }

                    // Disable prototype
                    this.DisablePrototype(compositeMethodIndex, gArgsInfo, nextFragment);

                    if (this._activationAction != null)
                    {
                        var compositeMethod = this.GetCompositeMethodInfo(compositeMethodIndex, gArgsInfo);

                        if (compositeMethod != null)
                        {
                            this.InvocationInfo = new InvocationInfoImpl(compositeMethod, nextFragment);
                        }
                        try
                        {
                            this._activationAction();
                        }
                        finally
                        {
                            if (compositeMethod != null)
                            {
                                this.InvocationInfo = null;
                            }
                        }
                    }
                    ((ServiceCompositeModelImmutable)this.ModelInfo.Model).InvokeAfterActivation(this);
                });
            }
        }