public void Preprocess(MarshalByRefObject inst, IMessage msg)
        {
            if (mServiceCacheItem == null)
            {
                mServiceCacheItem = ONServiceCacheItem.Get("Action", ClassName, ServiceName);
            }

            IMethodCallMessage lMsg = msg as IMethodCallMessage;
            int lIndex = 0;

            // Extract Action
            ONAction lAction = inst as ONAction;

            // Shared Event Control
            if (lAction.OnContext.InSharedContext == true) // No-Principal Shared Event
            {
                return;
            }
            lAction.OnContext.InSharedContext = true;
            mReflexivePrincipal = true;

            // Shared Event Arguments (in Shared Event order)
            HybridDictionary lReflexiveEventArguments     = new HybridDictionary(true);
            HybridDictionary lReflexiveEventArgumentsInfo = new HybridDictionary(true);
            int i = 0;

            foreach (ParameterInfo lArgument in lMsg.MethodBase.GetParameters())
            {
                ONSharedArgumentAttribute[] lReflexiveArgumentsInfo = lArgument.GetCustomAttributes(typeof(ONSharedArgumentAttribute), false) as ONSharedArgumentAttribute[];
                foreach (ONSharedArgumentAttribute lReflexiveArgumentInfo in lReflexiveArgumentsInfo)
                {
                    lReflexiveEventArgumentsInfo[lArgument.Name] = lReflexiveArgumentInfo;
                    break;
                }

                lReflexiveEventArguments[lArgument.Name] = lMsg.Args[i];
                i++;
            }

            // Shared Event Arguments for each Class (in Shared Event order)
            mServiceCacheItems = new List <ONServiceCacheItem>();
            foreach (DictionaryEntry lEntry in lReflexiveEventArgumentsInfo)
            {
                string lReflexiveArgumentName = lEntry.Key as String;
                ONSharedArgumentAttribute lReflexiveArgumentInfo = lEntry.Value as ONSharedArgumentAttribute;

                // Create Instance
                ONInstance lInstance = (lReflexiveEventArguments[lReflexiveArgumentName] as ONOid).GetInstance(lAction.OnContext);

                if (lInstance == null)
                {
                    throw new ONInstanceNotExistException(null, "", (lReflexiveEventArguments[lReflexiveArgumentName] as ONOid).ClassName);
                }

                // Create Action
                ONAction lReflexiveAction = ONContext.GetComponent_Action(lReflexiveArgumentInfo.ClassName, lAction.OnContext);
                //lSharedAction.Instance
                lReflexiveAction.Instance = lInstance;

                // Copy arguments
                MethodInfo lMethodInfo = ONContext.GetMethods(lReflexiveAction.GetType(), ToStringPartial());
                lIndex = 0;
                object[] lArguments = new object[lReflexiveEventArguments.Count];
                foreach (ParameterInfo lParameterInfo in lMethodInfo.GetParameters())
                {
                    // Normal Argument
                    lArguments[lIndex++] = lReflexiveEventArguments[lParameterInfo.Name];
                }
                mReflexiveClass = new KeyValuePair <ONAction, object[]>(lReflexiveAction, lArguments);
                mServiceCacheItems.Add(ONServiceCacheItem.Get("Action", lReflexiveArgumentInfo.ClassName, ServiceName + "_Partial"));
                object[] lObject = new object[mReflexiveClass.Value.Length];
                lObject[0] = mReflexiveClass.Value[1];
                lObject[1] = mReflexiveClass.Value[0];
                mReflexiveClass.Value[0] = lObject[0];
                mReflexiveClass.Value[1] = lObject[1];
            }

            // Take the active Instance
            lIndex = 0;
            bool lSharedFind = false;

            foreach (ONInstance lInstance in lAction.OnContext.TransactionStack)
            {
                if (lInstance == mReflexiveClass.Key.Instance)
                {
                    mReflexiveClass.Key.Instance = lInstance.GetFacet(mReflexiveClass.Key.Instance.ClassName);
                    lSharedFind = true;
                    break;
                }
            }
            if (!lSharedFind)
            {
                foreach (ONInstance lInstance in lAction.OnContext.OperationStack)
                {
                    if (lInstance == mReflexiveClass.Key.Instance)
                    {
                        mReflexiveClass.Key.Instance           = lInstance.GetFacet(mReflexiveClass.Key.Instance.ClassName);
                        mReflexiveClass.Key.Instance.OnContext = mReflexiveClass.Key.OnContext;

                        break;
                    }
                }
            }

            // Check State Changes
            if (lAction.OnContext.NeedsVerification)
            {
                mServiceCacheItem.InvoqueCheckState(lAction, lMsg.Args);
                lAction.OnContext.NeedsVerification = false;
            }


            // Push OID to Class Stack
            mReflexiveClass.Key.OnContext.TransactionStack.Push(mReflexiveClass.Key.Instance);

            // Check Shared STD
            if (!lSharedFind)
            {
                mServiceCacheItem.InvoqueSTD(mReflexiveClass.Key, mReflexiveClass.Value);
            }

            // Take the active Instance
            bool lFind = false;

            foreach (ONInstance lInstance in lAction.OnContext.TransactionStack)
            {
                if (lInstance == lAction.Instance)
                {
                    lAction.Instance = lInstance.GetFacet(lAction.Instance.ClassName);
                    lFind            = true;
                    break;
                }
            }
            if (!lFind)
            {
                foreach (ONInstance lInstance in lAction.OnContext.OperationStack)
                {
                    if (lInstance == lAction.Instance)
                    {
                        // Saving the old context of the This instance
                        lAction.Instance           = lInstance.GetFacet(lAction.Instance.ClassName);
                        mThisOnContext             = lAction.Instance.OnContext;
                        lAction.Instance.OnContext = lAction.OnContext;

                        break;
                    }
                }
            }

            // Push OID to Class Stack
            lAction.OnContext.TransactionStack.Push(lAction.Instance);
            mInStack = true;

            // Check STD
            if (!lFind)
            {
                mServiceCacheItem.InvoqueSTD(lAction, lMsg.Args);
            }

            // Check Shared Precondition
            lIndex = 0;
            mServiceCacheItem.InvoquePrecondition(mReflexiveClass.Key, mReflexiveClass.Value);

            // Check Precondition
            mServiceCacheItem.InvoquePrecondition(lAction, lMsg.Args);

            // Get Initial Values of the instances
            lAction.OnContext.GetInitialValues(lAction, lMsg.Args);

            // Throw Check Shared Partials
            lIndex = 0;
            if (mReflexiveClass.Key.Instance != lAction.Instance)
            {
                ONContext.InvoqueMethod(mReflexiveClass.Key, "_" + ServiceName + "_Partial", mReflexiveClass.Value);
            }
        }
예제 #2
0
        public void Preprocess(MarshalByRefObject inst, IMessage msg)
        {
            if (mServiceCacheItem == null)
            {
                mServiceCacheItem = ONServiceCacheItem.Get("Action", ClassName, ServiceName);
            }

            IMethodCallMessage lMsg = msg as IMethodCallMessage;
            int lIndex = 0;

            // Extract Action
            ONAction lAction = inst as ONAction;

            // Shared Event Control
            if (lAction.OnContext.InSharedContext == true)             // No-Principal Shared Event
            {
                return;
            }
            lAction.OnContext.InSharedContext = true;
            mSharedPrincipal = true;

            // Shared Event Arguments (in Shared Event order)
            HybridDictionary lSharedEventArguments     = new HybridDictionary(true);
            HybridDictionary lSharedEventArgumentsInfo = new HybridDictionary(true);
            int i = 0;

            foreach (ParameterInfo lArgument in lMsg.MethodBase.GetParameters())
            {
                ONSharedArgumentAttribute[] lSharedArgumentsInfo = lArgument.GetCustomAttributes(typeof(ONSharedArgumentAttribute), false) as ONSharedArgumentAttribute[];
                foreach (ONSharedArgumentAttribute lSharedArgumentInfo in lSharedArgumentsInfo)
                {
                    lSharedEventArgumentsInfo[lArgument.Name] = lSharedArgumentInfo;
                    break;
                }

                lSharedEventArguments[lArgument.Name] = lMsg.Args[i];
                i++;
            }

            // Shared Event Arguments for each Class (in Shared Event order)
            mServiceCacheItems = new List <ONServiceCacheItem>();
            foreach (DictionaryEntry lEntry in lSharedEventArgumentsInfo)
            {
                string lSharedArgumentName = lEntry.Key as String;
                ONSharedArgumentAttribute lSharedArgumentInfo = lEntry.Value as ONSharedArgumentAttribute;

                // Create Instance
                ONInstance lInstance = (lSharedEventArguments[lSharedArgumentName] as ONOid).GetInstance(lAction.OnContext);

                if (lInstance == null)
                {
                    throw new ONInstanceNotExistException(null, "", (lSharedEventArguments[lSharedArgumentName] as ONOid).ClassName);
                }

                // Create Action
                ONAction lSharedAction = ONContext.GetComponent_Action(lSharedArgumentInfo.ClassName, lAction.OnContext);
                lSharedAction.Instance = lInstance;

                // Reorder arguments
                lIndex = 0;
                object[] lArguments = new object[lSharedEventArguments.Count];
                foreach (MethodInfo lMethodInfo in ONContext.GetMethods(lSharedAction.GetType(), typeof(ONServiceAttribute), ToString(lSharedAction.ClassName)))
                {
                    foreach (ParameterInfo lParameterInfo in lMethodInfo.GetParameters())
                    {
                        if (lSharedEventArguments.Contains(lParameterInfo.Name))
                        {
                            // Normal Argument
                            lArguments[lIndex++] = lSharedEventArguments[lParameterInfo.Name];
                        }
                        else
                        {
                            ONSharedArgumentAttribute[] lSharedArgumentsInfo = lParameterInfo.GetCustomAttributes(typeof(ONSharedArgumentAttribute), false) as ONSharedArgumentAttribute[];
                            if (lSharedArgumentsInfo.Length == 0)
                            {
                                // Target Oid
                                lArguments[lIndex++] = lInstance.Oid;
                            }
                            else if (string.Compare(lSharedArgumentsInfo[0].ClassName, lAction.ClassName, true) == 0)
                            {
                                // Source Oid
                                lArguments[lIndex++] = lAction.Instance.Oid;
                            }
                            else
                            {
                                lArguments[lIndex++] = null;
                            }
                        }
                    }
                }

                mSharedClasses.Add(new KeyValuePair <ONAction, object[]>(lSharedAction, lArguments));
                mServiceCacheItems.Add(ONServiceCacheItem.Get("Action", lSharedArgumentInfo.ClassName, ServiceName));
            }

            // Check State Changes
            if (lAction.OnContext.NeedsVerification)
            {
                mServiceCacheItem.InvoqueCheckState(lAction, lMsg.Args);
                lAction.OnContext.NeedsVerification = false;
            }

            // Check Shared STD
            lIndex = 0;
            foreach (KeyValuePair <ONAction, object[]> lShared in mSharedClasses)
            {
                // Take the active Instance
                bool lSharedFind = false;
                foreach (ONInstance lInstance in lAction.OnContext.TransactionStack)
                {
                    if (lInstance == lShared.Key.Instance)
                    {
                        lShared.Key.Instance = lInstance.GetFacet(lShared.Key.Instance.ClassName);
                        lSharedFind          = true;
                        break;
                    }
                }
                if (!lSharedFind)
                {
                    foreach (ONInstance lInstance in lAction.OnContext.OperationStack)
                    {
                        if (lInstance == lShared.Key.Instance)
                        {
                            lShared.Key.Instance           = lInstance.GetFacet(lShared.Key.Instance.ClassName);
                            lShared.Key.Instance.OnContext = lShared.Key.OnContext;

                            break;
                        }
                    }
                }

                // Push OID to Class Stack
                lShared.Key.OnContext.TransactionStack.Push(lShared.Key.Instance);

                // Check STD
                if (!lSharedFind)
                {
                    mServiceCacheItems[lIndex++].InvoqueSTD(lShared.Key, lShared.Value);
                }
            }

            // Take the active Instance
            bool lFind = false;

            foreach (ONInstance lInstance in lAction.OnContext.TransactionStack)
            {
                if (lInstance == lAction.Instance)
                {
                    lAction.Instance = lInstance.GetFacet(lAction.Instance.ClassName);
                    lFind            = true;
                    break;
                }
            }
            if (!lFind)
            {
                foreach (ONInstance lInstance in lAction.OnContext.OperationStack)
                {
                    if (lInstance == lAction.Instance)
                    {
                        // Saving the old context of the This instance
                        lAction.Instance           = lInstance.GetFacet(lAction.Instance.ClassName);
                        mThisOnContext             = lAction.Instance.OnContext;
                        lAction.Instance.OnContext = lAction.OnContext;

                        break;
                    }
                }
            }


            // Push OID to Class Stack
            lAction.OnContext.TransactionStack.Push(lAction.Instance);
            mInStack = true;

            // Check STD
            if (!lFind)
            {
                mServiceCacheItem.InvoqueSTD(lAction, lMsg.Args);
            }

            // Check Shared Precondition
            lIndex = 0;
            foreach (KeyValuePair <ONAction, object[]> lShared in mSharedClasses)
            {
                mServiceCacheItems[lIndex++].InvoquePrecondition(lShared.Key, lShared.Value);
            }

            // Check Precondition
            mServiceCacheItem.InvoquePrecondition(lAction, lMsg.Args);

            // Get Initial Values of the instances
            lAction.OnContext.GetInitialValues(lAction, lMsg.Args);

            // Throw Check Shared Partials
            lIndex = 0;
            foreach (KeyValuePair <ONAction, object[]> lShared in mSharedClasses)
            {
                if ((string.Compare(lAction.ClassName, lShared.Key.ClassName, true) != 0) || (lAction.Instance != lShared.Key.Instance))
                {
                    mServiceCacheItems[lIndex++].InvoqueService(lShared.Key, lShared.Value);
                }
            }
        }