Esempio n. 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);
        }
Esempio n. 2
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("");
        }
Esempio n. 3
0
        public static string GetTargetClassName(ONPath onPath)
        {
            ONPath lOnPath = new ONPath(onPath);

            if (lOnPath.Count == 0)
            {
                return("Administrador");
            }

            string lRol = lOnPath.RemoveHead();

            return("");
        }
        /// <summary>This method adds to the SQL statement any path that appears in a formula</summary>
        /// <param name="onSql">This parameter has the current SQL statement</param>
        /// <param name="joinType">This parameter has the type of join</param>
        /// <param name="facet">First class, the beginning of the path</param>
        /// <param name="onPath">Path to add to SQL statement</param>
        /// <param name="processedOnPath">Path pocessed until the call of this method</param>
        /// <param name="initialClass">Domain of the object valued argument, object valued filter variables or AGENT when it should be necessary</param>
        /// <param name="forceLastAlias">Create almost the last alias in the sql</param>
        public static string AddPath(ONSqlSelect onSql, JoinType joinType, string facet, ONPath onPath, ONPath processedOnPath, string initialClass, bool forceLastAlias)
        {
            // initialClass is used for Object-valued arguments, object-valued filter variables, agent instance, ...
            ONPath lProcessedOnPath = new ONPath(processedOnPath);
            ONPath lOnPath = new ONPath(onPath);

            // Calculate processed path
            string lRole = lOnPath.RemoveHead() as string;
            lProcessedOnPath += lRole;

            // Search Path
            if (lOnPath.Count == 0)
            {
                string lAlias = onSql.GetAlias(facet, lProcessedOnPath);
                if ((lAlias != "") && (!forceLastAlias))
                    return (lAlias);
            }
             			// Create path
            if (initialClass == "") // Simple paths
            {
                if (string.Compare(lRole, "NaveNodriza", true) == 0)
                    return NaveNodrizaData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias);
                if (string.Compare(lRole, "Aeronave", true) == 0)
                    return AeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias);
                if (string.Compare(lRole, "Pasajero", true) == 0)
                    return PasajeroData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias);
                if (string.Compare(lRole, "PasajeroAeronave", true) == 0)
                    return PasajeroAeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias);
                if (string.Compare(lRole, "Revision", true) == 0)
                    return RevisionData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias);
                if (string.Compare(lRole, "RevisionPasajero", true) == 0)
                    return RevisionPasajeroData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias);
                if (string.Compare(lRole, "Administrador", true) == 0)
                    return AdministradorData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias);
            }

            // Solve path with initialPath
            object[] lParameters = new object[6];
            lParameters[0] = onSql;
            lParameters[1] = facet;
            lParameters[2] = lOnPath;
            lParameters[3] = lProcessedOnPath;
            lParameters[4] = "";
            lParameters[5] = forceLastAlias;

            return ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string;
        }
Esempio n. 5
0
        public object this [ONPath onPath]
        {
            get
            {
                if ((onPath == null) || (onPath.Count == 0))
                {
                    return(this);
                }

                // Search in preloaded related attributes
                if (RelatedValues.ContainsKey(onPath.Path))
                {
                    return(RelatedValues[onPath.Path]);
                }

                string       lRol      = onPath.RemoveHead();
                PropertyInfo lProperty = null;

                // Last unique role (like attributes)
                if (onPath.Count == 0)
                {
                    lProperty = ONContext.GetPropertyInfoWithAttribute(GetType(), typeof(ONAttributeAttribute), "<Attribute>" + lRol + "</Attribute>");
                    if (lProperty != null)
                    {
                        return(lProperty.GetValue(this, null));
                    }
                }

                // Roles
                lProperty = ONContext.GetPropertyInfoWithAttribute(GetType(), typeof(ONRoleAttribute), "<Role>" + lRol + "</Role>");
                if (lProperty != null)
                {
                    if (onPath.Count == 0)
                    {
                        return(lProperty.GetValue(this, null));
                    }
                    else
                    {
                        return((lProperty.GetValue(this, null) as ONCollection)[onPath]);
                    }
                }

                return(null);
            }
        }
Esempio n. 6
0
        public static string GetTargetClassName(ONPath onPath)
        {
            ONPath lOnPath = new ONPath(onPath);

            if (lOnPath.Count == 0)
            {
                return("Aeronave");
            }

            string lRol = lOnPath.RemoveHead();

            if (string.Compare(lRol, "PasajeroAeronave", true) == 0)
            {
                return(PasajeroAeronaveData.GetTargetClassName(lOnPath));
            }

            return("");
        }
Esempio n. 7
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("");
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public ONSimpleType DisplaysetItemValue(ONPath displaysetItem)
        {
            if ((displaysetItem == null) || (displaysetItem.Count == 0))
            {
                return(null);
            }

            ONPath       lDisplaysetItem = new ONPath(displaysetItem);
            string       lRol            = lDisplaysetItem.RemoveHead();
            PropertyInfo lProperty       = null;
            MethodInfo   lMethod         = null;
            string       methodName      = lRol + "RoleHV";

            // Last unique role (like attributes)
            if (lDisplaysetItem.Count == 0)
            {
                lProperty = ONContext.GetPropertyInfoWithAttribute(GetType(), typeof(ONAttributeAttribute), "<Attribute>" + lRol + "</Attribute>");
                if (lProperty != null)
                {
                    return((lProperty.GetValue(this, null)) as ONSimpleType);
                }
            }

            // Roles
            lMethod = GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
            if (lMethod != null)
            {
                ONCollection lCollection = lMethod.Invoke(this, null) as ONCollection;
                if (lCollection.Count <= 0)
                {
                    return(ONSimpleType.Null(ONInstance.GetTypeOfAttribute(GetType(), displaysetItem)));
                }

                ONInstance lInstance = lCollection[0];

                return(lInstance.DisplaysetItemValue(lDisplaysetItem));
            }

            return(null);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public static string GetTargetClassName(ONPath onPath)
        {
            ONPath lOnPath = new ONPath(onPath);

            if (lOnPath.Count == 0)
                return "NaveNodriza";

            string lRol = lOnPath.RemoveHead();

            return "";
        }
Esempio n. 13
0
        /// <summary>This method adds to the SQL statement any path that appears in a formula</summary>
        /// <param name="onSql">This parameter has the current SQL statement</param>
        /// <param name="joinType">This parameter has the type of join</param>
        /// <param name="facet">First class, the beginning of the path</param>
        /// <param name="onPath">Path to add to SQL statement</param>
        /// <param name="processedOnPath">Path pocessed until the call of this method</param>
        /// <param name="initialClass">Domain of the object valued argument, object valued filter variables or AGENT when it should be necessary</param>
        /// <param name="forceLastAlias">Create almost the last alias in the sql</param>
        /// <param name="isLinkedTo">The alias belongs to a role in a linked To element</param>
        public static string AddPath(ONSqlSelect onSql, JoinType joinType, string facet, ONPath onPath, ONPath processedOnPath, string initialClass, bool forceLastAlias, bool isLinkedTo)
        {
            // initialClass is used for Object-valued arguments, object-valued filter variables, agent instance, ...
            ONPath lProcessedOnPath = new ONPath(processedOnPath);
            ONPath lOnPath          = new ONPath(onPath);
            bool   lOnPathExist     = true;

            object[] lParameters = new object[8];

            if (initialClass != "")
            {
                string lRol = lOnPath.RemoveHead();
                lProcessedOnPath += lRol;
                // Solve path with initialPath
                lParameters[0] = onSql;
                lParameters[1] = joinType;
                lParameters[2] = facet;
                lParameters[3] = lOnPath;
                lParameters[4] = lProcessedOnPath;
                lParameters[5] = "";
                lParameters[6] = forceLastAlias;
                lParameters[7] = isLinkedTo;

                return(ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string);
            }

            // Search max solved path
            ONPath lMaxSolvedPath       = new ONPath(onPath);
            string lMaxSolvedPathDomain = facet;

            while ((lMaxSolvedPath.Count > 0) && (onSql.GetAlias(lMaxSolvedPathDomain, lProcessedOnPath + lMaxSolvedPath, isLinkedTo) == ""))
            {
                lMaxSolvedPath.RemoveTail();
                lMaxSolvedPathDomain = GetTargetClassName(lMaxSolvedPath);
            }
            if (lMaxSolvedPath.Count > 0)
            {
                lProcessedOnPath += lMaxSolvedPath;
                for (int i = 0; i < lMaxSolvedPath.Count; i++)
                {
                    lOnPath.RemoveHead();
                }

                lParameters[0] = onSql;
                lParameters[1] = joinType;
                lParameters[2] = facet;
                lParameters[3] = lOnPath;
                lParameters[4] = lProcessedOnPath;
                lParameters[5] = "";
                lParameters[6] = forceLastAlias;
                lParameters[7] = isLinkedTo;

                return(ONContext.InvoqueMethod(ONContext.GetType_Data(lMaxSolvedPathDomain), "AddPath", lParameters) as string);
            }

            // Create inheritance path
            if ((onPath == null) || (onPath.Count == 0))
            {
                if (forceLastAlias)
                {
                    return(AeronaveFacetAddSql(joinType, onSql, processedOnPath, forceLastAlias, isLinkedTo));
                }

                if ((processedOnPath == null) || (processedOnPath.Count == 0))
                {
                    return(onSql.CreateAlias(joinType, "", CtesBD.TBL_AERONAVE, null, "Aeronave", false, isLinkedTo));
                }
                else
                {
                    return(onSql.CreateAlias(joinType, "", CtesBD.TBL_AERONAVE, processedOnPath, "Aeronave", false, isLinkedTo));
                }
            }

            // Calculate processed path
            string lRole = lOnPath.RemoveHead() as string;

            lProcessedOnPath += lRole;

            // Search Path
            if (lOnPath.Count == 0)
            {
                string lAlias = onSql.GetAlias(facet, lProcessedOnPath, isLinkedTo);
                if ((lAlias != "") && (!forceLastAlias))
                {
                    return(lAlias);
                }
                else
                {
                    lOnPathExist = false;
                }
            }
            else
            {
                string lTargetClass = GetTargetClassName(new ONPath(lRole));

                // Agent & OV Argument Control
                if ((lTargetClass == "") && (initialClass != ""))
                {
                    lTargetClass = initialClass;
                }

                string lAlias = onSql.GetAlias(lTargetClass, lProcessedOnPath, isLinkedTo);
                if (lAlias == "")
                {
                    lOnPathExist = false;
                }
            }

            // Create path
            if (string.Compare(lRole, "PasajeroAeronave", true) == 0)
            {
                if (lOnPathExist)
                {
                    return(PasajeroAeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias, isLinkedTo));
                }
                else
                {
                    return(PasajeroAeronaveRoleAddSql(onSql, joinType, facet, lOnPath, processedOnPath, lRole, forceLastAlias, isLinkedTo));
                }
            }

            initialClass = "Aeronave";

            // Solve path with initialPath
            lParameters[0] = onSql;
            lParameters[1] = joinType;
            lParameters[2] = facet;
            lParameters[3] = lOnPath;
            lParameters[4] = lProcessedOnPath;
            lParameters[5] = "";
            lParameters[6] = forceLastAlias;
            lParameters[7] = isLinkedTo;

            return(ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string);
        }
Esempio n. 14
0
        public static string GetTargetClassName(ONPath onPath)
        {
            ONPath lOnPath = new ONPath(onPath);

            if (lOnPath.Count == 0)
                return "Aeronave";

            string lRol = lOnPath.RemoveHead();
            if (string.Compare(lRol, "PasajeroAeronave", true) == 0)
                return PasajeroAeronaveData.GetTargetClassName(lOnPath);

            return "";
        }
Esempio n. 15
0
        /// <summary>This method adds to the SQL statement any path that appears in a formula</summary>
        /// <param name="onSql">This parameter has the current SQL statement</param>
        /// <param name="joinType">This parameter has the type of join</param>
        /// <param name="facet">First class, the beginning of the path</param>
        /// <param name="onPath">Path to add to SQL statement</param>
        /// <param name="processedOnPath">Path pocessed until the call of this method</param>
        /// <param name="initialClass">Domain of the object valued argument, object valued filter variables or AGENT when it should be necessary</param>
        /// <param name="forceLastAlias">Create almost the last alias in the sql</param>
        /// <param name="isLinkedTo">The alias belongs to a role in a linked To element</param>
        public static string AddPath(ONSqlSelect onSql, JoinType joinType, string facet, ONPath onPath, ONPath processedOnPath, string initialClass, bool forceLastAlias, bool isLinkedTo)
        {
            // initialClass is used for Object-valued arguments, object-valued filter variables, agent instance, ...
            ONPath lProcessedOnPath = new ONPath(processedOnPath);
            ONPath lOnPath = new ONPath(onPath);
            bool lOnPathExist = true;
            object[] lParameters = new object[8];

            if (initialClass != "")
            {
                string lRol = lOnPath.RemoveHead();
                lProcessedOnPath += lRol;
                // Solve path with initialPath
                lParameters[0] = onSql;
                lParameters[1] = joinType;
                lParameters[2] = facet;
                lParameters[3] = lOnPath;
                lParameters[4] = lProcessedOnPath;
                lParameters[5] = "";
                lParameters[6] = forceLastAlias;
                lParameters[7] = isLinkedTo;

                return ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string;

            }

            // Search max solved path
            ONPath lMaxSolvedPath = new ONPath(onPath);
            string lMaxSolvedPathDomain = facet;
            while ((lMaxSolvedPath.Count > 0) && (onSql.GetAlias(lMaxSolvedPathDomain, lProcessedOnPath + lMaxSolvedPath, isLinkedTo) == ""))
            {
                lMaxSolvedPath.RemoveTail();
                lMaxSolvedPathDomain = GetTargetClassName(lMaxSolvedPath);
            }
            if (lMaxSolvedPath.Count > 0)
            {
                lProcessedOnPath += lMaxSolvedPath;
                for (int i = 0; i < lMaxSolvedPath.Count; i++)
                    lOnPath.RemoveHead();

                lParameters[0] = onSql;
                lParameters[1] = joinType;
                lParameters[2] = facet;
                lParameters[3] = lOnPath;
                lParameters[4] = lProcessedOnPath;
                lParameters[5] = "";
                lParameters[6] = forceLastAlias;
                lParameters[7] = isLinkedTo;

                return ONContext.InvoqueMethod(ONContext.GetType_Data(lMaxSolvedPathDomain), "AddPath", lParameters) as string;
            }

            // Create inheritance path
            if ((onPath == null) || (onPath.Count == 0))
            {
                if (forceLastAlias)
                    return AeronaveFacetAddSql(joinType, onSql, processedOnPath, forceLastAlias, isLinkedTo);

                if ((processedOnPath == null) || (processedOnPath.Count == 0))
                    return (onSql.CreateAlias(joinType, "", CtesBD.TBL_AERONAVE, null, "Aeronave", false, isLinkedTo));
                else
                    return (onSql.CreateAlias(joinType, "", CtesBD.TBL_AERONAVE, processedOnPath, "Aeronave", false, isLinkedTo));
            }

            // Calculate processed path
            string lRole = lOnPath.RemoveHead() as string;
            lProcessedOnPath += lRole;

            // Search Path
            if (lOnPath.Count == 0)
            {
                string lAlias = onSql.GetAlias(facet, lProcessedOnPath, isLinkedTo);
                if ((lAlias != "") && (!forceLastAlias))
                    return (lAlias);
                else
                    lOnPathExist = false;
            }
            else
            {
                string lTargetClass = GetTargetClassName(new ONPath(lRole));

                // Agent & OV Argument Control
                if ((lTargetClass == "") && (initialClass != ""))
                    lTargetClass = initialClass;

                string lAlias = onSql.GetAlias(lTargetClass, lProcessedOnPath, isLinkedTo);
                if (lAlias == "")
                    lOnPathExist = false;
            }

            // Create path
            if (string.Compare(lRole, "PasajeroAeronave", true) == 0)
            {
                if (lOnPathExist)
                    return PasajeroAeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias, isLinkedTo);
                else
                    return PasajeroAeronaveRoleAddSql(onSql, joinType, facet, lOnPath, processedOnPath, lRole, forceLastAlias, isLinkedTo);
            }

            initialClass = "Aeronave";

            // Solve path with initialPath
            lParameters[0] = onSql;
            lParameters[1] = joinType;
            lParameters[2] = facet;
            lParameters[3] = lOnPath;
            lParameters[4] = lProcessedOnPath;
            lParameters[5] = "";
            lParameters[6] = forceLastAlias;
            lParameters[7] = isLinkedTo;

            return ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string;
        }
Esempio n. 16
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);
              		}
        }
Esempio n. 17
0
        /// <summary>This method adds to the SQL statement any path that appears in a formula</summary>
        /// <param name="onSql">This parameter has the current SQL statement</param>
        /// <param name="joinType">This parameter has the type of join</param>
        /// <param name="facet">First class, the beginning of the path</param>
        /// <param name="onPath">Path to add to SQL statement</param>
        /// <param name="processedOnPath">Path pocessed until the call of this method</param>
        /// <param name="initialClass">Domain of the object valued argument, object valued filter variables or AGENT when it should be necessary</param>
        /// <param name="forceLastAlias">Create almost the last alias in the sql</param>
        public static string AddPath(ONSqlSelect onSql, JoinType joinType, string facet, ONPath onPath, ONPath processedOnPath, string initialClass, bool forceLastAlias)
        {
            // initialClass is used for Object-valued arguments, object-valued filter variables, agent instance, ...
            ONPath lProcessedOnPath = new ONPath(processedOnPath);
            ONPath lOnPath          = new ONPath(onPath);

            // Calculate processed path
            string lRole = lOnPath.RemoveHead() as string;

            lProcessedOnPath += lRole;

            // Search Path
            if (lOnPath.Count == 0)
            {
                string lAlias = onSql.GetAlias(facet, lProcessedOnPath);
                if ((lAlias != "") && (!forceLastAlias))
                {
                    return(lAlias);
                }
            }
            // Create path
            if (initialClass == "")             // Simple paths
            {
                if (string.Compare(lRole, "NaveNodriza", true) == 0)
                {
                    return(NaveNodrizaData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias));
                }
                if (string.Compare(lRole, "Aeronave", true) == 0)
                {
                    return(AeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias));
                }
                if (string.Compare(lRole, "Pasajero", true) == 0)
                {
                    return(PasajeroData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias));
                }
                if (string.Compare(lRole, "PasajeroAeronave", true) == 0)
                {
                    return(PasajeroAeronaveData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias));
                }
                if (string.Compare(lRole, "Revision", true) == 0)
                {
                    return(RevisionData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias));
                }
                if (string.Compare(lRole, "RevisionPasajero", true) == 0)
                {
                    return(RevisionPasajeroData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias));
                }
                if (string.Compare(lRole, "Administrador", true) == 0)
                {
                    return(AdministradorData.AddPath(onSql, joinType, facet, lOnPath, lProcessedOnPath, "", forceLastAlias));
                }
            }

            // Solve path with initialPath
            object[] lParameters = new object[6];
            lParameters[0] = onSql;
            lParameters[1] = facet;
            lParameters[2] = lOnPath;
            lParameters[3] = lProcessedOnPath;
            lParameters[4] = "";
            lParameters[5] = forceLastAlias;

            return(ONContext.InvoqueMethod(ONContext.GetType_Data(initialClass), "AddPath", lParameters) as string);
        }
Esempio n. 18
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);
            }
        }