예제 #1
0
        public void Preprocess(MarshalByRefObject inst, IMessage msg)
        {
            if (mServiceCacheItem == null)
            {
                mServiceCacheItem = ONServiceCacheItem.Get("Server", ClassName, ServiceName);
            }

            IMethodCallMessage lMsgIn = msg as IMethodCallMessage;

            // Extract Server
            ONServer lServer = inst as ONServer;

            // Take the active Instance
            bool lFind = false;

            foreach (ONInstance lInstance in lServer.OnContext.OperationStack)
            {
                if (((object)lInstance != null) && (lInstance == lServer.Instance))
                {
                    lServer.Instance = lInstance.GetFacet(lServer.Instance.ClassName);
                    lFind            = true;

                    break;
                }
            }

            // Push OID to Class Stack
            lServer.OnContext.OperationStack.Push(lServer.Instance);
            mInStack = true;

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

            // Search all facets
            foreach (IONType lArgument in lMsgIn.InArgs)
            {
                ONOid lOidArgument = lArgument as ONOid;
                if (lOidArgument != null)
                {
                    if (!lOidArgument.Exist(lServer.OnContext, null))
                    {
                        throw new ONInstanceNotExistException(null, ONContext.GetComponent_Instance(lOidArgument.ClassName, lServer.OnContext).IdClass, lOidArgument.ClassName);
                    }
                }
            }

            // Check Precondition
            mServiceCacheItem.InvoquePrecondition(lServer, lMsgIn.Args);
        }
예제 #2
0
        public void Preprocess(MarshalByRefObject inst, IMessage msg)
        {
            IMethodCallMessage lMsgIn = msg as IMethodCallMessage;

            // Extract Server
            ONServer lServer = inst as ONServer;

            // Take the active Instance
            bool lFind = false;

            foreach (ONInstance lInstance in lServer.OnContext.TransactionStack)
            {
                if (((object)lInstance != null) && (lInstance == lServer.Instance))
                {
                    lServer.Instance = lInstance.GetFacet(lServer.Instance.ClassName);
                    lFind            = true;

                    break;
                }
            }
            if (!lFind)
            {
                foreach (ONInstance lInstance in lServer.OnContext.OperationStack)
                {
                    if (((object)lInstance != null) && (lInstance == lServer.Instance))
                    {
                        lServer.Instance = lInstance.GetFacet(lServer.Instance.ClassName);
                        lFind            = true;

                        break;
                    }
                }
            }

            // Push OID to Class Stack
            lServer.OnContext.OperationStack.Push(lServer.Instance);
            mInStack = true;

            // Search all facets
            foreach (IONType lArgument in lMsgIn.InArgs)
            {
                ONOid lOidArgument = lArgument as ONOid;
                if (lOidArgument != null)
                {
                    if (!lOidArgument.Exist(lServer.OnContext, null))
                    {
                        throw new ONInstanceNotExistException(null, ONContext.GetComponent_Instance(lOidArgument.ClassName, lServer.OnContext).IdClass, lOidArgument.ClassName);
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Retrieve all the instances of a determinate class that fulfil a determinate formula of searching
        /// </summary>
        /// <param name="linkedTo">List to reach the class to retrieve the related instance</param>
        /// <param name="filters">Formula to search concrete instances</param>
        /// <param name="comparer">Order Criteria that must be followed by the query</param>
        /// <param name="startRowOID">OID frontier</param>
        /// <param name="blockSize">Number of instances to be returned</param>
        public override ONCollection ExecuteQuery(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize)
        {
            try
            {
                ONCollection lInstances    = null;
                Type         lTypeInstance = ONContext.GetType_Instance(ClassName);
                Type         lTypeQuery    = ONContext.GetType_Query(ClassName);

                // Initialize the list of related queries
                if (linkedTo == null)
                {
                    linkedTo = new ONLinkedToList();
                }

                // Initialize the filter list
                if (filters == null)
                {
                    filters = new ONFilterList();
                }

                ONLinkedToList lLinkedToLegacy = new ONLinkedToList();
                ONLinkedToList lLinkedToLocal  = new ONLinkedToList();
                ONLinkedToList lLinkedToMixed  = new ONLinkedToList();

                #region Treatment of LinkedTo
                foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in linkedTo)
                {
                    ONPath lPath = lDictionaryEntry.Key as ONPath;
                    ONOid  lOid  = lDictionaryEntry.Value as ONOid;

                    ONPath lInversePath             = new ONPath(ONInstance.InversePath(lTypeInstance, lPath));
                    Type   lTypeTargetClassInstance = ONContext.GetType_Instance(ONInstance.GetTargetClass(OnContext, lTypeInstance, lPath));
                    if ((lInversePath.Count == 0) || (!ONInstance.IsVisible(lTypeTargetClassInstance, lInversePath, OnContext)))
                    {
                        return(ONContext.GetComponent_Collection(ClassName, OnContext));
                    }

                    bool   lexistLV = false;
                    ONData lData    = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext);

                    if (lData.GetType().BaseType == typeof(ONLVData))
                    {
                        if (!lOid.Exist(OnContext, null))
                        {
                            return(ONContext.GetComponent_Collection(ClassName, OnContext));
                        }
                    }

                    foreach (string lRole in lInversePath.Roles)
                    {
                        lData = ONContext.GetComponent_Data(lData.InhGetTargetClassName(new ONPath(lRole)), OnContext);
                        if (lData.GetType().BaseType == typeof(ONLVData))
                        {
                            lexistLV = true;
                        }
                    }
                    if (!lexistLV)
                    {
                        lLinkedToLocal.mLinkedToList.Add(lPath, lOid);
                    }
                    else
                    {
                        lLinkedToMixed.mLinkedToList.Add(lPath, lOid);
                    }
                }
                #endregion

                #region displaySet
                if (!filters.PreloadRelatedAttributes)
                {
                    displaySet = null;
                }
                #endregion displaySet

                #region No link item
                if ((linkedTo.mLinkedToList.Count == 0) || (lLinkedToMixed.mLinkedToList.Count > 0))
                {
                    if ((GetType().BaseType != typeof(ONLVData)) || (filters.InData))
                    {
                        lInstances = SolveQuery(new ONLinkedToList(), filters, displaySet, comparer, startRowOid, blockSize);
                    }
                }
                #endregion

                #region Local Link
                if (lLinkedToLocal.mLinkedToList.Count > 0)
                {
                    ONCollection lInstancesAux = SolveQuery(lLinkedToLocal, filters, displaySet, comparer, startRowOid, blockSize);
                    if (lInstances != null)
                    {
                        lInstances.Intersection(lInstancesAux);
                    }
                    else
                    {
                        lInstances = lInstancesAux;
                    }
                }
                #endregion

                #region Hybrid Link
                if (lLinkedToMixed.mLinkedToList.Count > 0)
                {
                    ONCollection lInstancesAux = null;

                    foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in lLinkedToMixed)
                    {
                        ONPath lPath = lDictionaryEntry.Key as ONPath;
                        ONOid  lOid  = lDictionaryEntry.Value as ONOid;

                        if (lPath.Roles.Count == 1)
                        {
                            ONLinkedToList lLinked = new ONLinkedToList();
                            lLinked[lPath] = lOid;
                            ONCollection lInstanceColl = SolveQuery(lLinked, filters, displaySet, comparer, startRowOid, blockSize);
                            if (lInstances != null)
                            {
                                lInstances.Intersection(lInstanceColl);
                            }
                            else
                            {
                                lInstances = lInstanceColl;
                            }
                            continue;
                        }

                        #region Optimized Path
                        ONLinkedToList linkedToOptimized    = new ONLinkedToList();
                        ONPath         lInversePath         = new ONPath(ONInstance.InversePath(lTypeInstance, lPath));
                        ONPath         lOptimizedRole       = new ONPath(lInversePath.RemoveHead() as string);
                        Type           lTypeInstanceDestiny = ONContext.GetType_Instance(InhGetTargetClassName(lPath));

                        bool   lBeginIsLegacy = (ONInstance.IsLegacy(lTypeInstanceDestiny, lOptimizedRole));
                        bool   lEnterLoop     = true;
                        ONData lData          = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext);
                        if (lData.GetType().BaseType != typeof(ONLVData))
                        {
                            if (ONContext.GetType_Data(lData.InhGetTargetClassName(lOptimizedRole)).BaseType == typeof(ONLVData))
                            {
                                lEnterLoop = false;
                            }
                        }

                        lPath.RemoveTail();
                        if (lEnterLoop)
                        {
                            while (lInversePath.Roles.Count > 0)
                            {
                                lData = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext);
                                if ((!lBeginIsLegacy) && (ONContext.GetType_Data(lData.InhGetTargetClassName(new ONPath(lInversePath.Roles[0]))).BaseType == typeof(ONLVData)))
                                {
                                    break;
                                }
                                if ((lBeginIsLegacy) && (ONContext.GetType_Data(lData.InhGetTargetClassName(new ONPath(lInversePath.Roles[0]))).BaseType != typeof(ONLVData)))
                                {
                                    break;
                                }

                                lOptimizedRole.Roles.Add(lInversePath.RemoveHead());
                                lPath.RemoveTail();
                            }
                        }

                        linkedToOptimized[ONInstance.InversePath(lTypeInstanceDestiny, lOptimizedRole)] = lOid;
                        if ((lPath.Count > 0) || (lBeginIsLegacy))
                        {
                            // It is not the last role or it is leged
                            lInstancesAux = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext).ExecuteQuery(linkedToOptimized, null, null, comparer, startRowOid, blockSize);
                        }
                        else
                        {
                            // It is the last role and it is local
                            lInstancesAux = ONContext.GetComponent_Data(InhGetTargetClassName(lPath), OnContext).ExecuteQuery(linkedToOptimized, null, displaySet, comparer, startRowOid, blockSize);
                        }
                        #endregion

                        #region Rest of the path
                        lInstancesAux = lInstancesAux[lInversePath] as ONCollection;
                        #endregion

                        if (lInstances != null)
                        {
                            lInstances.Intersection(lInstancesAux);
                        }
                        else
                        {
                            lInstances = lInstancesAux;
                        }
                    }
                }
                #endregion

                return(lInstances);
            }
            catch (Exception e)
            {
                string ltraceItem = "Method: SolveQuery, Component: ONDBData";
                if (e is ONSystemException)
                {
                    ONSystemException lException = e as ONSystemException;
                    lException.addTraceInformation(ltraceItem);
                    throw lException;
                }
                throw new ONSystemException(e, ltraceItem);
            }
        }