Exemple #1
0
        /// <summary>
        /// Checks if the attributes of a determinate class are visible according to the agent connected
        /// </summary>
        /// <param name="typeInstance">Type fo the class to check the visibility</param>
        /// <param name="attributeVisibility">Attribute to be checked, it is not owned to the class that is being checked</param>
        /// <param name="onContext">Request context </param>
        public static bool IsVisibleInv(Type typeInstance, ONPath attributeVisibility, ONContext onContext)
        {
            if (attributeVisibility.Count == 0)
            {
                return(true);
            }

            ONPath lAttributeVisibility = new ONPath(attributeVisibility);
            string lRol = lAttributeVisibility.RemoveHead();

            // Attributes
            if (lAttributeVisibility.Count == 0)
            {
                ONAttributeAttribute lAttributeAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONAttributeAttribute), "<Attribute>" + lRol + "</Attribute>") as ONAttributeAttribute;
                if (lAttributeAttribute != null)
                {
                    return(lAttributeAttribute.IsVisible(onContext));
                }
            }

            // Roles
            ONRoleAttribute lRoleAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONRoleAttribute), "<Role>" + lRol + "</Role>") as ONRoleAttribute;

            if (lRoleAttribute != null)
            {
                Type lTypeInstanceInv = ONContext.GetType_Instance(lRoleAttribute.Domain);
                return(IsVisible(lTypeInstanceInv, lRoleAttribute.RoleInv, onContext) && IsVisibleInv(lTypeInstanceInv, lAttributeVisibility, onContext));
            }

            return(false);
        }
Exemple #2
0
        public ONDisplaySetItem(string className, string path, StringCollection activeAgentFacets)
        {
            Path = path;

            Type lInstanceType = ONContext.GetType_Instance(className);

            if (!ONInstance.IsOptimized(lInstanceType, Path))
            {
                InMemory = true;
            }
            else
            {
                if (ONInstance.IsLocal(lInstanceType, Path))
                {
                    InData = true;
                }

                if (ONInstance.IsLegacy(lInstanceType, Path))
                {
                    InLegacy = true;
                }
            }

            if (Path.Contains("."))
            {
                HasHV = ONInstance.HasHorizontalVisibility(lInstanceType, Path, activeAgentFacets);
            }
        }
Exemple #3
0
        /// <summary>
        /// Obtains by reflection the name of an attribute in the database
        /// </summary>
        /// <param name="typeInstance">Type of the class</param>
        /// <param name="attributeInDisplay">Attribute to be checked</param>
        public static string GetFieldNameOfAttribute(Type typeInstance, ONPath attributeInDisplay)
        {
            string lRol = attributeInDisplay.RemoveHead();

            // Attributes
            if (attributeInDisplay.Count == 0)
            {
                ONAttributeAttribute lAttributeAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONAttributeAttribute), "<Attribute>" + lRol + "</Attribute>") as ONAttributeAttribute;
                if (lAttributeAttribute != null)
                {
                    return(lAttributeAttribute.FieldName);
                }
            }

            // Roles
            ONRoleAttribute lRoleAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONRoleAttribute), "<Role>" + lRol + "</Role>") as ONRoleAttribute;

            if (lRoleAttribute != null)
            {
                if (attributeInDisplay.Count == 0)
                {
                    return("");
                }
                else
                {
                    return(GetFieldNameOfAttribute(ONContext.GetType_Instance(lRoleAttribute.Domain), attributeInDisplay));
                }
            }
            return("");
        }
Exemple #4
0
        public static string InversePath(Type typeInstance, ONPath rolePath)
        {
            ONPath          lRolePath      = new ONPath(rolePath);
            string          lRol           = lRolePath.RemoveHead();
            ONRoleAttribute lRoleAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONRoleAttribute), "<Role>" + lRol + "</Role>") as ONRoleAttribute;

            if (lRoleAttribute != null)
            {
                if (lRolePath.Count == 0)
                {
                    return(lRoleAttribute.RoleInv);
                }
                else
                {
                    return((InversePath(ONContext.GetType_Instance(lRoleAttribute.Domain), lRolePath)) + "." + (lRoleAttribute.RoleInv));
                }
            }
            return("");
        }
Exemple #5
0
        /// <summary>
        /// Obtains by reflection if an attribute is optimized
        /// </summary>
        /// <param name="typeInstance">Type of the class</param>
        /// <param name="attributeInDisplay">Attribute to be checked</param>
        public static bool IsOptimized(Type typeInstance, ONPath path)
        {
            if (path == null)
            {
                return(true);
            }

            if (path.Count == 0)
            {
                return(true);
            }

            ONPath lPath = new ONPath(path);
            string lRol  = lPath.RemoveHead();

            // Attributes
            if (lPath.Count == 0)
            {
                ONAttributeAttribute lAttributeAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONAttributeAttribute), "<Attribute>" + lRol + "</Attribute>") as ONAttributeAttribute;
                if (lAttributeAttribute != null)
                {
                    return(lAttributeAttribute.IsOptimized);
                }
            }

            // Roles
            ONRoleAttribute lRoleAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONRoleAttribute), "<Role>" + lRol + "</Role>") as ONRoleAttribute;

            if (lRoleAttribute != null)
            {
                if (lPath.Count == 0)
                {
                    return(!lRoleAttribute.IsLegacy);
                }
                else if (!lRoleAttribute.IsLegacy)
                {
                    return(IsOptimized(ONContext.GetType_Instance(lRoleAttribute.Domain), lPath));
                }
            }

            return(false);
        }
Exemple #6
0
        /// <summary>
        /// Fix related instance
        /// </summary>
        /// <param name="onSql">Sentence SQL to be executed</param>
        /// <param name="linkedTo">List to reach the class to retrieve the related instance</param>
        protected bool AddLinkedTo(ONSqlSelect onSql, ONLinkedToList linkedTo)
        {
            // Fix related instance
            foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in linkedTo)
            {
                ONPath lPath = lDictionaryEntry.Key as ONPath;
                ONOid  lOID  = lDictionaryEntry.Value as ONOid;

                string lAliasRelated = InhAddPath(onSql, lOID.ClassName, lPath, "", true);

                // Check Visibility
                if (!ONInstance.IsVisibleInv(ONContext.GetType_Instance(ClassName), lPath, OnContext))
                {
                    return(false);
                }

                ONDBData lData = ONContext.GetComponent_Data(lOID.ClassName, OnContext) as ONDBData;
                lData.InhFixInstance(onSql, null, lPath, lOID, true);
            }

            return(true);
        }
Exemple #7
0
        public static string GetTargetClass(ONContext onContext, Type typeInstance, ONPath path)
        {
            foreach (string lRole in path.Roles)
            {
                // Attributes
                ONAttributeAttribute lAttributeAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONAttributeAttribute), "<Attribute>" + lRole + "</Attribute>") as ONAttributeAttribute;

                if (lAttributeAttribute != null)
                {
                    return(lAttributeAttribute.FacetOfField);
                }

                // Roles
                ONRoleAttribute lRoleAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONRoleAttribute), "<Role>" + lRole + "</Role>") as ONRoleAttribute;

                if (lRoleAttribute != null)
                {
                    typeInstance = ONContext.GetType_Instance(lRoleAttribute.Domain);
                }
                else
                {
                    break;
                }
            }

            if (typeInstance != null)
            {
                object[] lParameters = new object[1];
                lParameters[0] = onContext;

                ONInstance lInstance = Activator.CreateInstance(typeInstance, lParameters) as ONInstance;
                return(lInstance.ClassName);
            }
            else
            {
                return("");
            }
        }
Exemple #8
0
        public static bool HasHorizontalVisibility(Type typeInstance, ONPath rolePath, StringCollection activeAgentFacets)
        {
            ONPath lRolePath = new ONPath(rolePath);
            string lRol      = lRolePath.RemoveHead();

            // Attributes
            if (lRolePath.Count == 0)
            {
                ONAttributeAttribute lAttributeAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONAttributeAttribute), "<Attribute>" + lRol + "</Attribute>") as ONAttributeAttribute;
                if (lAttributeAttribute != null)
                {
                    return(false);
                }
            }

            ONRoleAttribute lRoleAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONRoleAttribute), "<Role>" + lRol + "</Role>") as ONRoleAttribute;

            if (lRoleAttribute != null)
            {
                if (lRoleAttribute.HasHorizontalVisibility(activeAgentFacets))
                {
                    return(true);
                }

                if (lRolePath.Count == 0)
                {
                    return(false);
                }
                else
                {
                    return(HasHorizontalVisibility(ONContext.GetType_Instance(lRoleAttribute.Domain), lRolePath, activeAgentFacets));
                }
            }

            return(false);
        }
Exemple #9
0
        public static bool IsLocal(Type typeInstance, ONPath rolePath)
        {
            if (rolePath.Count == 0)
            {
                return(true);
            }

            ONPath lRolePath = new ONPath(rolePath);
            string lRol      = lRolePath.RemoveHead();

            // Attributes
            if (lRolePath.Count == 0)
            {
                ONAttributeAttribute lAttributeAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONAttributeAttribute), "<Attribute>" + lRol + "</Attribute>") as ONAttributeAttribute;
                if (lAttributeAttribute != null)
                {
                    return(!lAttributeAttribute.IsLegacy);
                }
            }

            ONRoleAttribute lRoleAttribute = ONContext.GetAttributeInProperty(typeInstance, typeof(ONRoleAttribute), "<Role>" + lRol + "</Role>") as ONRoleAttribute;

            if (lRoleAttribute != null)
            {
                if (lRolePath.Count == 0)
                {
                    return(!lRoleAttribute.IsLegacy);
                }
                else
                {
                    return((!lRoleAttribute.IsLegacy) && (IsLocal(ONContext.GetType_Instance(lRoleAttribute.Domain), lRolePath)));
                }
            }

            return(false);
        }
Exemple #10
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);
            }
        }
Exemple #11
0
        public override ONCollection ExecuteQuery(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize)
        {
            ONCollection lInstances    = null;
            Type         lTypeInstance = ONContext.GetType_Instance(ClassName);

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

            if (linkedTo == null)
            {
                linkedTo = new ONLinkedToList();
            }

            if (filters == null)
            {
                filters = new ONFilterList();
            }

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

                if (ONInstance.IsLegacy(lTypeInstance, lPath))
                {
                    lLinkedToLegacy.mLinkedToList.Add(lPath, lOid);
                }
                else
                {
                    lLinkedToLocal.mLinkedToList.Add(lPath, lOid);
                }
            }
            #endregion Treatment of LinkedTo

            ONFilterList lFiltersToLegacy = new ONFilterList();
            ONFilterList lFiltersToLocal  = new ONFilterList();

            #region Treatment of Filters
            ONFilterList lFiltersToMixed = new ONFilterList();
            foreach (ONFilter lFilter in filters.Values)
            {
                if (lFilter.InLegacy)
                {
                    lFiltersToLegacy.Add(lFilter.FilterName, lFilter);
                }
                else
                {
                    lFiltersToLocal.Add(lFilter.FilterName, lFilter);
                }
            }
            #endregion Treatment of Filters

            if ((lFiltersToLegacy.Count <= 1) && (lFiltersToLocal.Count == 0) && (lLinkedToLocal.mLinkedToList.Count == 0))
            {
                #region No leged filters
                if (lFiltersToLegacy.Count == 0)
                {
                    QueryByRelatedFilter lFilter = new QueryByRelatedFilter(ClassName, null, null);
                    lInstances = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, startRowOid, (blockSize == 0 ? 0 : blockSize + 1));
                }
                #endregion No leged filters

                #region Solve leged filters
                foreach (ONFilter lFilter in lFiltersToLegacy.Values)
                {
                    ONCollection lInstancesAux = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, startRowOid, (blockSize == 0 ? 0 : blockSize + 1));

                    if (lInstances == null)
                    {
                        lInstances = lInstancesAux;
                    }
                    else
                    {
                        lInstances.Intersection(lInstancesAux);
                    }
                }
                #endregion Solve leged filters

                if ((lInstances.totalNumInstances == -1) && (lInstances.Count <= blockSize) && ((startRowOid == null).TypedValue))
                {
                    lInstances.totalNumInstances = lInstances.Count;
                }
            }
            else
            {
                #region Solve leged filters
                foreach (ONFilter lFilter in lFiltersToLegacy.Values)
                {
                    ONCollection lInstancesAux = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, null, 0);

                    if (lInstances == null)
                    {
                        lInstances = lInstancesAux;
                    }
                    else
                    {
                        lInstances.Intersection(lInstancesAux);
                    }
                }
                #endregion Solve leged filters

                #region Solve local filters in data
                if ((lFiltersToLocal.InData) || (lLinkedToLocal.mLinkedToList.Count > 0))
                {
                    ONCollection lInstancesAux = base.ExecuteQuery(lLinkedToLocal, lFiltersToLocal, displaySet, null, null, 0);

                    if (lInstances == null)
                    {
                        lInstances = lInstancesAux;
                    }
                    else
                    {
                        lInstances.Intersection(lInstancesAux);
                    }
                }
                #endregion Solve local filters in data

                #region No leged filters
                if (lFiltersToLegacy.Count == 0)
                {
                    int maxNumberQueries = Convert.ToInt32(ONContext.GetType_LV(ClassName).GetField("maxNumberQueries").GetValue(null));

                    if ((lInstances == null || lInstances.Count > maxNumberQueries) || (lLinkedToLegacy.mLinkedToList.Count > 0) || (comparer != null))
                    {
                        ONCollection         lInstancesAux = lInstances;
                        QueryByRelatedFilter lFilter       = new QueryByRelatedFilter(ClassName, null, null);
                        lInstances = lFilter.FilterInLegacy(OnContext, lLinkedToLegacy, comparer, null, 0);

                        if (lInstancesAux != null)
                        {
                            lInstances.Intersection(lInstancesAux);
                        }
                    }
                    else
                    {
                        ONCollection lInstancesAux = ONContext.GetComponent_Collection(ClassName, OnContext);
                        foreach (object lobject in lInstances)
                        {
                            ONInstance       lInstance = lobject as ONInstance;
                            QueryByOidFilter lFilter   = new QueryByOidFilter(lInstance.Oid);
                            lInstancesAux.AddRange(lFilter.FilterInLegacy(OnContext, null, null, null, 0));
                        }
                        lInstances = lInstancesAux.Clone() as ONCollection;
                    }
                }
                #endregion No leged filters

                #region Solve local filters in memory
                if ((lInstances != null) && (lFiltersToLocal.InMemory))
                {
                    ONCollection lInstancesAux = lInstances;
                    lInstances = ONContext.GetComponent_Collection(ClassName, OnContext);

                    foreach (ONInstance lInstance in lInstancesAux)
                    {
                        if (lFiltersToLocal.FilterInMemory(lInstance))
                        {
                            lInstances.Add(lInstance);
                        }
                    }
                }
                #endregion Solve local filters in memory

                lInstances.totalNumInstances = lInstances.Count;
            }

            return(lInstances);
        }