示例#1
0
        /// <summary>
        /// Returns the instance with the Oid
        /// </summary>
        /// <param name="oid">OID to search the instance</param>
        /// <param name="onFilterList">Filters to theck</param>
        /// <returns>The instance searched</returns>
        public override ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet)
        {
            ONSqlSelect lOnSql = new ONSqlSelect();

            // Create select and first table
            InhRetrieveInstances(lOnSql, displaySet, null, OnContext);

            // Fix instance
            InhFixInstance(lOnSql, null, null, oid);

            // Add filter formula
            onFilterList.FilterInData(lOnSql, this);

            // Execute
            ONCollection lCollection = ExecuteSql(lOnSql, onFilterList, displaySet, null, null, 0);

            if (lCollection.Count > 0)
            {
                return(lCollection[0] as ONInstance);
            }
            else
            {
                return(null);
            }
        }
示例#2
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>
        /// <returns>Instances that check the filter list</returns>
        protected virtual ONCollection SolveQuery(ONLinkedToList linkedTo, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOid, int blockSize)
        {
            ONSqlSelect lOnSql = new ONSqlSelect();

            try
            {
                // Create select and first table
                InhRetrieveInstances(lOnSql, displaySet, null, OnContext);

                // Fix related instance
                if (!AddLinkedTo(lOnSql, linkedTo))
                {
                    return(ONContext.GetComponent_Collection(ClassName, OnContext));
                }

                // Add filter formula
                if (onFilterList != null)
                {
                    onFilterList.FilterInData(lOnSql, this);
                }

                // Retrieve query instance number
                int lTotalNumInstances = -1;
                if (OnContext.CalculateQueryInstancesNumber)
                {
                    if ((onFilterList == null) || (!onFilterList.InMemory))
                    {
                        ArrayList lSqlParameters;
                        string    lNumInstancesSqlSentence = ONSqlSelect.GenerateSQLAsCount(lOnSql, out lSqlParameters);
                        lTotalNumInstances = Convert.ToInt32(ExecuteScalar(lNumInstancesSqlSentence, lSqlParameters));
                    }
                    OnContext.CalculateQueryInstancesNumber = false;
                }

                // OrderCriteria
                AddOrderCriteria(lOnSql, comparer, startRowOid, blockSize);

                // Execute
                ONCollection lONCollection = ExecuteSql(lOnSql, onFilterList, displaySet, comparer, startRowOid, blockSize);

                // Set Query instance number
                if (lTotalNumInstances > -1)
                {
                    lONCollection.totalNumInstances = lTotalNumInstances;
                }

                return(lONCollection);
            }
            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);
            }
        }
示例#3
0
 /// <summary>
 /// Puts each instance of the collection in the modified class list to check integrity constraints and trigger conditions
 /// The instances are added thought they are not marked as modified
 /// </summary>
 /// <param name="collection">Oid that represents the instance to be added</param>
 public void AddUnmodifiedClass(ONCollection collection)
 {
     foreach (ONInstance lInstance in collection)
     {
         AddUnmodifiedClass(lInstance.Oid);
     }
 }
示例#4
0
        /// <summary>
        /// Searchs a determinate instance
        /// </summary>
        /// <param name="oid">OID to search the instance</param>
        /// <param name="onFilterList">Filter list</param>
        public override ONInstance Search(ONOid oid, ONFilterList onFilterList, ONDisplaySet displaySet)
        {
            ONFilterList lOnFilterList = null;

            if (onFilterList != null)
            {
                lOnFilterList = new ONFilterList(onFilterList);
            }
            else
            {
                lOnFilterList = new ONFilterList();
            }
            lOnFilterList.Add("QueryByOid", new QueryByOidFilter(oid));

            ONCollection lCollection = ExecuteQuery(new ONLinkedToList(), lOnFilterList, displaySet, null, null, 0);

            if (lCollection.Count > 0)
            {
                return(lCollection[0] as ONInstance);
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        public ONCollection QueryByFilter_FUM(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, out ONOid startRowOID, out int blockSize, double dtdVersion, string clientName)
        {
            ONLinkedToList lLinkedTo = null;
            ONFilterList   lFilters  = new ONFilterList();

            // Read Request
            blockSize = int.Parse(xmlReader.GetAttribute("BlockSize"));
            if (!xmlReader.IsEmptyElement)
            {
                xmlReader.ReadStartElement("Query.Filter");
                if (xmlReader.IsStartElement("StartRow"))
                {
                    xmlReader.ReadStartElement("StartRow");
                    startRowOID = XML2ON(xmlReader, dtdVersion);
                    xmlReader.ReadEndElement();                     // StartRow
                }
                else
                {
                    startRowOID = null;
                }

                // Fill relations
                lLinkedTo = GetLinkedTo(xmlReader, dtdVersion);

                // Fill filter variables
                lFilters["FUM"] = GetFilter_FUM(xmlReader, dtdVersion);

                // Read Request
                xmlReader.ReadEndElement();                 // Query.Filter
            }
            else
            {
                xmlReader.ReadStartElement("Query.Filter");
                lLinkedTo   = new ONLinkedToList();
                startRowOID = null;
            }

            // Read Order Criteria
            string lOrderCriteria = "";

            if (xmlReader.IsStartElement("Sort"))
            {
                lOrderCriteria = xmlReader.GetAttribute("Criterium");
                xmlReader.Skip();                 // Sort
            }

            // Create Context
            ONContext lOnContext = new ONContext();

            lOnContext.OidAgent = agentOid;

            // Execute
            PasajeroQuery lQuery      = new PasajeroQuery(lOnContext);
            ONCollection  lCollection = lQuery.QueryByFilter(lLinkedTo, lFilters, displaySet, lOrderCriteria, startRowOID, blockSize);

            ticket = lOnContext.GetTicket(dtdVersion, clientName);

            return(lCollection);
        }
示例#6
0
        ///<summary> This method adds the order criteria to the SQL statement </summary>
        ///<param name = "onSql"> This parameter represents the SQL component </param>
        ///<param name = "comparer"> This parameter has all the information refering to the order criteria to add to SQL statement</param>
        /// <param name="startRowOid">This parameter has the OID necessary to start the search</param>
        /// <param name="blockSize">This parameter represents the number of instances to be returned</param>
        protected override void AddOrderCriteria(ONSqlSelect onSql, ONOrderCriteria comparer, ONOid startRowOid, int blockSize, ONPath initialPath)
        {
            //Initilizate StartRow
            AeronaveInstance lInstance = null;

            if (startRowOid != null)
            {
                lInstance     = new AeronaveInstance(OnContext);
                lInstance.Oid = startRowOid as AeronaveOid;
            }

            //Default OrderCriteria
            if (comparer == null)
            {
                string lAlias = onSql.GetAlias("Aeronave", initialPath);
                if (lInstance != null)
                {
                    onSql.AddOrderBy(lAlias, CtesBD.FLD_AERONAVE_ID_AERONAVE, OrderByTypeEnumerator.Asc, lInstance.Oid.Id_AeronaveAttr);
                }
                else
                {
                    onSql.AddOrderBy(lAlias, CtesBD.FLD_AERONAVE_ID_AERONAVE, OrderByTypeEnumerator.Asc, null);
                }
                return;
            }

            //Add OrderCriteria
            bool lUseStartRow = (!comparer.InMemory);

            foreach (ONOrderCriteriaItem lOrderCriteriaItem in comparer.OrderCriteriaSqlItem)
            {
                ONPath lPath = new ONPath(lOrderCriteriaItem.OnPath);
                if ((lInstance != null) && (lUseStartRow))
                {
                    ONSimpleType lAttrStartRow = null;

                    if (lPath.Path == "")
                    {
                        lAttrStartRow = lInstance[lOrderCriteriaItem.Attribute] as ONSimpleType;
                    }
                    else
                    {
                        ONCollection lCollection = (lInstance[lPath.Path] as ONCollection);
                        if ((lCollection != null) && (lCollection.Count > 0))
                        {
                            lAttrStartRow = lCollection[0][lOrderCriteriaItem.Attribute] as ONSimpleType;
                        }
                    }
                    onSql.AddOrderBy(AeronaveData.AddPath(onSql, JoinType.LeftJoin, lOrderCriteriaItem.Facet, lPath, null, lOrderCriteriaItem.DomainArgument, false), lOrderCriteriaItem.Attribute, lOrderCriteriaItem.Type, lAttrStartRow);
                    lUseStartRow = (lAttrStartRow != null);
                }
                else
                {
                    onSql.AddOrderBy(AeronaveData.AddPath(onSql, JoinType.LeftJoin, lOrderCriteriaItem.Facet, lPath, null, lOrderCriteriaItem.DomainArgument, false), lOrderCriteriaItem.Attribute, lOrderCriteriaItem.Type, null);
                }
            }
            return;
        }
        /// <summary>Solves the filters defined in this class</summary>
        /// <param name="linkedTo">This parameter has the related instance to retrieve the requested instances</param>
        /// <param name="filters">This parameter has all the filters defined with this class</param>
        /// <param name="orderCriteria">This parameter has the name of the order criteria to add to SQL statement</param>
        /// <param name="startRowOID">This parameter has the OID necessary to start the search</param>
        /// <param name="blockSize">This parameter represents the number of instances to be returned</param>
        public override ONCollection QueryByFilter(ONLinkedToList linkedTo, ONFilterList filters, ONDisplaySet displaySet, string orderCriteria, ONOid startRowOID, int blockSize)
        {
            // OrderCriteria
            ONOrderCriteria lComparer = GetOrderCriteria(orderCriteria);

            // Horizontal visibility
            if (filters == null)
            {
                filters = new ONFilterList();
            }
            filters.Add("HorizontalVisibility", new NaveNodrizaHorizontalVisibility());

            // Linked To List
            if (linkedTo == null)
            {
                linkedTo = new ONLinkedToList();
            }

            // Call Data
            try
            {
                NaveNodrizaData lData       = new NaveNodrizaData(OnContext);
                ONCollection    lCollection = lData.ExecuteQuery(linkedTo, filters, displaySet, lComparer, startRowOID, blockSize);

                // OrderCriteria
                if (lComparer != null)
                {
                    lCollection.Sort(lComparer);
                }

                return(lCollection);
            }
            catch (Exception e)
            {
                if (e is ONException)
                {
                    throw e;
                }
                else
                {
                    string ltraceItem = "Error in query, Method: ExecuteQuery, Component: NaveNodrizaQuery";
                    if (e is ONSystemException)
                    {
                        ONSystemException lException = e as ONSystemException;
                        lException.addTraceInformation(ltraceItem);
                        throw lException;
                    }
                    throw new ONSystemException(e, ltraceItem);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Finds the instance that represents this object in persistance tier. For this reaseon it is used the data component
        /// </summary>
        public ONInstance Find(ONFilterList onFilterList)
        {
            ONData       lData       = ONContext.GetComponent_Data(ClassName, OnContext);
            ONCollection lCollection = lData.ExecuteQuery(new ONLinkedToList(), onFilterList, null, null, null, 0);

            ONInstance lInstance = null;

            if (lCollection.Count > 0)
            {
                lInstance = lCollection[0];
                Copy(lInstance);
            }
            return(lInstance);
        }
        /// <summary>
        /// This method recovers an instance with the OID
        /// </summary>
        /// <param name="onContext">Recovers the context of the execution of the service</param>
        /// <param name="linkedTo">List to reach the class to retrieve the related instance</param>
        /// <param name="comparer">Order Criteria that must be followed</param>
        /// <param name="${startRowOid}">OID frontier</param>
        /// <param name="blockSize">Number of instances to be returned</param>
        /// <returns>The instance</returns>
        public override ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList linkedTo, ONOrderCriteria comparer, ONOid startRowOID, int blockSize)
        {
            if (InData)
            {
                return(null);
            }

            // Add parameters
            object[] lParameters = new object[2];
            lParameters[0] = onContext;
            lParameters[1] = mOid;
            ONCollection lCollection = ONContext.GetComponent_Collection(mOid.ClassName, onContext);
            ONInstance   lInstance   = ONContext.InvoqueMethod(ONContext.GetType_LV(mOid.ClassName), "QueryByOid", lParameters) as ONInstance;

            if (lInstance != null)
            {
                lCollection.Add(lInstance);
            }
            return(lCollection);
        }
示例#10
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);
        }
示例#11
0
        public ONInstance LocalSearch(ONInstance instance)
        {
            ONSqlSelect onSql = new ONSqlSelect();

            // Create select and first table
            InhRetrieveInstances(onSql, null, null, OnContext);

            // Fix instance
            InhFixInstance(onSql, null, null, instance.Oid);

            // Execute
            ONCollection lCollection = ExecuteQuery(onSql, instance);

            if (lCollection.Count > 0)
            {
                return(lCollection[0]);
            }
            else
            {
                return(null);
            }
        }
示例#12
0
        /// <summary>
        /// Process the request dedicated to loof for an instance with an OID given
        /// </summary>
        /// <param name="agentOid">OID with the agent connected to the system</param>
        /// <param name="xmlReader">XML with the request message</param>
        /// <param name="dtdVersion">Version of DTD that follows the XML message</param>
        public override ONCollection QueryByOid(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, double dtdVersion, string clientName)
        {
            // Get OID class
            string lClass = xmlReader.GetAttribute("Class");

            // Set OID parameter
            ONOid lOID = XML2ON(xmlReader, dtdVersion);

            // Read Request
            xmlReader.ReadEndElement();             // Query.Instance

            // Read Order Criteria
            if (xmlReader.IsStartElement("Sort"))             // Sort
            {
                xmlReader.Skip();
            }

            //Read Filter Navigation
            if (xmlReader.IsStartElement("NavFilt"))
            {
                xmlReader.Skip();
            }

            // Create Context
            ONContext lOnContext = new ONContext();

            lOnContext.OidAgent = agentOid;

            // Execute
            PasajeroQuery lQuery      = new PasajeroQuery(lOnContext);
            ONCollection  lCollection = lQuery.QueryByOid(lOID, displaySet);

            ticket = lOnContext.GetTicket(dtdVersion, clientName);

            return(lCollection);
        }
示例#13
0
 /// <summary>
 /// Method to convert the data providen by the system to a message with XML format.Is empty, it implementation is done in child classes
 /// </summary>
 /// <param name="agentOID">OID of the agent connected to the system</param>
 /// <param name="xmlWriter">Variable with the message XML to be treated</param>
 /// <param name="val">Variable with the message XML to be treated</param>
 /// <param name="startRowOID">OID to start the searching</param>
 /// <param name="blockSize">Number of instance to be retrieved for the query</param>
 /// <param name="dtdVersion">Version of the DTD that follows the XML message</param>
 public virtual void ONQuery2XML(ONOid agentOID, XmlWriter xmlWriter, ONCollection val, ONOid startRowOID, int blockSize, ONDisplaySet displaySet, double dtdVersion)
 {
 }
示例#14
0
        /// <summary>
        /// Converts the instances returned by a query in XML format in order to put it in XML message response
        /// </summary>
        /// <param name="agentOid">OID with the agent connected to the system</param>
        /// <param name="xmlWriter">This parameter has the response message XML</param>
        /// <param name="val">Instances that fullfils with the query request</param>
        /// <param name="startRowOID">OID necessary to start the search</param>
        /// <param name="blockSize">Represents the number of instances to be returned</param>
        /// <param name="displaySet">Attributes to be returned in the response</param>
        /// <param name="dtdVersion">Version of DTD that follows the XML message</param>
        public override void ONQuery2XML(ONOid agentOid, XmlWriter xmlWriter, ONCollection val, ONOid startRowOID, int blockSize, ONDisplaySet displaySet, double dtdVersion)
        {
            xmlWriter.WriteStartElement("Head");
            xmlWriter.WriteStartElement("Head.OID");
            xmlWriter.WriteAttributeString("Class", "Pasajero");
            xmlWriter.WriteStartElement("Head.OID.Field");
            xmlWriter.WriteAttributeString("Name", "id_Pasajero");
            xmlWriter.WriteAttributeString("Type", "autonumeric");
            xmlWriter.WriteEndElement(); // Head.OID.Field

            xmlWriter.WriteEndElement(); // Head.OID

            xmlWriter.WriteStartElement("Head.Cols");
            foreach (ONDisplaySetItem lDisplaySetItem in displaySet)
            {
                xmlWriter.WriteStartElement("Head.Col");
                xmlWriter.WriteAttributeString("Name", lDisplaySetItem.Path);
                string lType = ONInstance.GetTypeOfAttribute(typeof(PasajeroInstance), new ONPath(lDisplaySetItem.Path));
                if(lType == "")
                    lType = "string";
                xmlWriter.WriteAttributeString("Type", lType);
                xmlWriter.WriteEndElement(); // Head.Col
            }
            xmlWriter.WriteEndElement(); // Head.Cols
            xmlWriter.WriteEndElement(); // Head

            // Search StartRow
            int i = 0;
            if (startRowOID != null)
                i = val.IndexOf(startRowOID) + 1;

            // Instance count
            int lInstances = 0;
            int lNumInstances = 0;
            string lLastBlock = "True";
            if (i >= 0)
            {
                lNumInstances = val.Count - i;
                if ((blockSize > 0) && (lNumInstances > blockSize))
                {
                    lNumInstances = blockSize;
                    lLastBlock = "False";
                }
            }

            xmlWriter.WriteStartElement("Data");
            xmlWriter.WriteAttributeString("Rows", lNumInstances.ToString());
            xmlWriter.WriteAttributeString("LastBlock", lLastBlock);
            xmlWriter.WriteAttributeString("TotalRows", val.totalNumInstances.ToString());
            while ((lInstances++ < lNumInstances) && (i < val.Count))
            {
                PasajeroInstance lInstance = val[i++] as PasajeroInstance;

                xmlWriter.WriteStartElement("R");
                ONXmlAutonumeric.ON2XML(xmlWriter, lInstance.Oid.Id_PasajeroAttr, dtdVersion, ONXml.XMLTAG_O);

                foreach (ONDisplaySetItem lDisplaySetItem in displaySet)
                {
                    if (lDisplaySetItem.Visibility == VisibilityState.NotChecked)
                    {
                        if (ONInstance.IsVisible(lInstance.GetType(), lDisplaySetItem.Path, lInstance.OnContext))
                            lDisplaySetItem.Visibility = VisibilityState.Visible;
                        else
                            lDisplaySetItem.Visibility = VisibilityState.NotVisible;
                    }
                    if (lDisplaySetItem.Visibility == VisibilityState.NotVisible) // No Visibility
                        xmlWriter.WriteElementString("V", null);
                    else
                    {
                        ONSimpleType lAttribute;
                        if(lDisplaySetItem.HasHV)
                            lAttribute = lInstance.DisplaysetItemValue(lDisplaySetItem.Path);
                        else
                            lAttribute = lInstance[lDisplaySetItem.Path] as ONSimpleType;

                        if (lAttribute is ONInt)
                            ONXmlInt.ON2XML(xmlWriter, lAttribute as ONInt, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONString)
                            ONXmlString.ON2XML(xmlWriter, lAttribute as ONString, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONBlob)
                            ONXmlBlob.ON2XML(xmlWriter, lAttribute as ONBlob, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONBool)
                            ONXmlBool.ON2XML(xmlWriter, lAttribute as ONBool, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONReal)
                            ONXmlReal.ON2XML(xmlWriter, lAttribute as ONReal, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONInt)
                            ONXmlAutonumeric.ON2XML(xmlWriter, lAttribute as ONInt, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONDate)
                            ONXmlDate.ON2XML(xmlWriter, lAttribute as ONDate, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONDateTime)
                            ONXmlDateTime.ON2XML(xmlWriter, lAttribute as ONDateTime, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONTime)
                            ONXmlTime.ON2XML(xmlWriter, lAttribute as ONTime, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONNat)
                            ONXmlNat.ON2XML(xmlWriter, lAttribute as ONNat, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONText)
                            ONXmlText.ON2XML(xmlWriter, lAttribute as ONText, dtdVersion, ONXml.XMLTAG_V);
                        else if (lAttribute is ONString)
                            ONXmlPassword.ON2XML(xmlWriter, lAttribute as ONString, dtdVersion, ONXml.XMLTAG_V);
                    }
                }
                xmlWriter.WriteEndElement(); // R
            }
            xmlWriter.WriteEndElement(); // Data
        }
示例#15
0
 /// <summary>
 /// Method to convert the data providen by the system to a message with XML format.Is empty, it implementation is done in child classes
 /// </summary>
 /// <param name="agentOID">OID of the agent connected to the system</param>
 /// <param name="xmlWriter">Variable with the message XML to be treated</param>
 /// <param name="val">Variable with the message XML to be treated</param>
 /// <param name="startRowOID">OID to start the searching</param>
 /// <param name="blockSize">Number of instance to be retrieved for the query</param>
 /// <param name="dtdVersion">Version of the DTD that follows the XML message</param>
 public virtual void ONQuery2XML(ONOid agentOID, XmlWriter xmlWriter, ONCollection val, ONOid startRowOID, int blockSize, ONDisplaySet displaySet, double dtdVersion)
 {
 }
示例#16
0
        /// <summary>
        /// Treatment of the XML message that has a query request
        /// </summary>
        /// <param name="agentOID">OID of the agent connected to the system</param>
        /// <param name="xmlReader">Variable with the message XML to be treated</param>
        /// <param name="xmlWriter">Variable with the message XML to response</param>
        /// <param name="dtdVersion">Version of the DTD that follows the XML message</param>
        public void XMLRequestQuery(ref string ticket, ONOid agentOID, XmlTextReader xmlReader, out XmlTextWriter xmlWriter, double dtdVersion, string clientName)
        {
            try
            {
                // Read Request
                ONDisplaySet lDisplaySet;
                using (ONContext lOnContext = new ONContext())
                {
                    lOnContext.OidAgent = agentOID;
                    lDisplaySet         = new ONDisplaySet(ClassName, xmlReader.GetAttribute("DisplaySet"), lOnContext.LeafActiveAgentFacets);
                }
                ONDisplaySet lDSRequested = new ONDisplaySet(lDisplaySet);
                xmlReader.ReadStartElement("Query.Request");

                // Create XMLWriterRequest
                MemoryStream lXMLMemoryStream = new MemoryStream();
                xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding());

                // Write Response
                xmlWriter.WriteStartElement("Query.Response");

                // Get start row & block size
                ONCollection lCollection  = null;
                ONOid        lStartRowOID = null;
                int          lBlockSize   = 1;

                // Execute
                if (xmlReader.IsStartElement("Query.Instance"))                 // QueryByOID
                {
                    // Read Request
                    xmlReader.ReadStartElement("Query.Instance");
                    if (xmlReader.IsStartElement(ONXml.XMLTAG_ALTERNATEKEY))
                    {
                        lCollection = QueryByAlternateKey(ref ticket, ref agentOID, xmlReader, lDisplaySet, dtdVersion, clientName);
                    }
                    else
                    {
                        lCollection = QueryByOid(ref ticket, ref agentOID, xmlReader, lDisplaySet, dtdVersion, clientName);
                    }
                }
                else if (xmlReader.IsStartElement("Query.Related"))                 // QueryByRelated
                {
                    lCollection = QueryByRelated(ref ticket, ref agentOID, xmlReader, lDisplaySet, out lStartRowOID, out lBlockSize, dtdVersion, clientName);
                }
                else if (xmlReader.IsStartElement("Query.Filter"))                 // QueryByFilter
                {
                    // Read Request
                    string lFilterName = xmlReader.GetAttribute("Name");

                    object[] ParametersList = new object[8];
                    ParametersList[0] = ticket;
                    ParametersList[1] = agentOID;
                    ParametersList[2] = xmlReader;
                    ParametersList[3] = lDisplaySet;
                    ParametersList[4] = lStartRowOID;
                    ParametersList[5] = lBlockSize;
                    ParametersList[6] = dtdVersion;
                    ParametersList[7] = clientName;
                    // Execute
                    lCollection  = ONContext.InvoqueMethod(this, typeof(ONFilterXMLAttribute), "<Filter>" + lFilterName + "</Filter>", ParametersList) as ONCollection;
                    ticket       = ParametersList[0] as string;
                    agentOID     = ParametersList[1] as ONOid;
                    lStartRowOID = ParametersList[4] as ONOid;
                    lBlockSize   = (int)ParametersList[5];
                }

                // Generate response
                ONQuery2XML(agentOID, xmlWriter, lCollection, lStartRowOID, lBlockSize, lDSRequested, dtdVersion);
                lCollection.Dispose();

                // Read Request
                xmlReader.ReadEndElement();                 // Query.Request

                // Write Response
                xmlWriter.WriteEndElement();                 // Query.Response
            }
            catch (ONException e)
            {
                MemoryStream lXMLMemoryStream = new MemoryStream();
                xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding());

                // Write Response
                xmlWriter.WriteStartElement("Query.Response");
                CreateXMLError(xmlWriter, e, dtdVersion);
                xmlWriter.WriteEndElement();                 // Query.Response

                return;
            }
            catch (Exception e)
            {
                string message = e.Message;

                MemoryStream lXMLMemoryStream = new MemoryStream();
                xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding());

                // Write Response
                xmlWriter.WriteStartElement("Query.Response");
                xmlWriter.WriteStartElement("Error");
                xmlWriter.WriteAttributeString("Type", "External");
                xmlWriter.WriteAttributeString("Number", "999");
                if (dtdVersion <= 2)
                {
                    xmlWriter.WriteString(e.Message);
                }
                else
                {
                    if ((e is ONSystemException) || (e.InnerException is ONSystemException))
                    {
                        ONSystemException lException = null;
                        if (e is ONSystemException)
                        {
                            lException = e as ONSystemException;
                        }
                        else
                        {
                            lException = e.InnerException as ONSystemException;
                        }
                        ArrayList trace = lException.mTraceInformation;
                        xmlWriter.WriteElementString("Error.Message", message);
                        xmlWriter.WriteElementString("Error.Params", "");
                        xmlWriter.WriteStartElement("Error.Trace");
                        int length = trace.Count;
                        int i      = 0;
                        while (length > 0)
                        {
                            string mensaje = (string)trace[length - 1];
                            xmlWriter.WriteStartElement("Error.TraceItem");
                            xmlWriter.WriteAttributeString("Type", "External");
                            xmlWriter.WriteAttributeString("Number", i.ToString());
                            xmlWriter.WriteStartElement("Error.Message");
                            xmlWriter.WriteString(mensaje);
                            xmlWriter.WriteEndElement(); // Error.Message
                            xmlWriter.WriteElementString("Error.Params", "");
                            xmlWriter.WriteEndElement(); // Error.TraceItem
                            i      += 1;
                            length -= 1;
                        }
                        xmlWriter.WriteEndElement(); // Error.Trace
                    }
                    else
                    {
                        xmlWriter.WriteElementString("Error.Message", message);
                        xmlWriter.WriteElementString("Error.Params", "");
                        xmlWriter.WriteElementString("Error.Trace", "");
                    }
                }

                xmlWriter.WriteEndElement();                 // Error
                xmlWriter.WriteEndElement();                 // Query.Response

                return;
            }
        }
示例#17
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);
        }
示例#18
0
        public override ONCollection QueryByRelated(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, out ONOid startRowOID, out int blockSize, double dtdVersion, string clientName)
        {
            ONLinkedToList lLinkedTo = null;
            ONFilterList   lFilters  = new ONFilterList();

            // Read Request
            blockSize = int.Parse(xmlReader.GetAttribute("BlockSize"));
            if (!xmlReader.IsEmptyElement)
            {
                xmlReader.ReadStartElement("Query.Related");
                if (xmlReader.IsStartElement("StartRow"))
                {
                    xmlReader.ReadStartElement("StartRow");
                    startRowOID = XML2ON(xmlReader, dtdVersion);
                    xmlReader.ReadEndElement();                     // StartRow
                }
                else
                {
                    startRowOID = null;
                }

                // Fill relations
                lLinkedTo = GetLinkedTo(xmlReader, dtdVersion);

                // Read Request
                xmlReader.ReadEndElement();                 // Query.Related
            }
            else
            {
                xmlReader.ReadStartElement("Query.Related");
                lLinkedTo   = new ONLinkedToList();
                startRowOID = null;
            }

            // Read Order Criteria
            string lOrderCriteria = "";

            if (xmlReader.IsStartElement("Sort"))
            {
                lOrderCriteria = xmlReader.GetAttribute("Criterium");
                xmlReader.Skip();                 // Sort
            }

            //Read Navigational Filter
            string lNavFilterId    = "";
            ONOid  lSelectedObject = null;

            if (xmlReader.IsStartElement("NavFilt"))
            {
                xmlReader.ReadStartElement("NavFilt");
                if (xmlReader.IsStartElement("NavFilt.SelectedObject"))
                {
                    lNavFilterId = xmlReader.GetAttribute("NavFilterID");
                    xmlReader.ReadStartElement("NavFilt.SelectedObject");
                    string lClassName = xmlReader.GetAttribute("Class");
                    if (lClassName == "")
                    {
                        lClassName = "GlobalTransaction";
                    }
                    object[] lArgs = new object[2];
                    lArgs[0]        = xmlReader;
                    lArgs[1]        = dtdVersion;
                    lSelectedObject = ONContext.InvoqueMethod(ONContext.GetType_XML(lClassName), "XML2ON", lArgs) as ONOid;

                    lArgs    = new Object[1];
                    lArgs[0] = lSelectedObject;

                    lFilters.Add(lNavFilterId, ONContext.GetComponent_NavigationalFilter(lNavFilterId, lArgs) as ONFilter);
                }
                else if (xmlReader.IsStartElement("NavFilt.Argument"))
                {
                    string lClassName = xmlReader.GetAttribute("Class");
                    if (lClassName == "")
                    {
                        lClassName = "GlobalTransaction";
                    }
                    string lServiceName  = xmlReader.GetAttribute("Service");
                    string lArgumentName = xmlReader.GetAttribute("Argument");
                    xmlReader.ReadStartElement("NavFilt.Argument");

                    string lFilterName = lClassName + "_" + lServiceName + "Service_" + lArgumentName + "_NavigationalFilter";
                    if (xmlReader.IsStartElement("Arguments"))
                    {
                        object[] lArgs = new object[3];
                        lArgs[0] = xmlReader;
                        lArgs[1] = dtdVersion;
                        lArgs[2] = lArgumentName;

                        lFilters.Add(lFilterName, ONContext.InvoqueMethod(ONContext.GetComponent_XML(lClassName), typeof(ONNavigationalFilterXMLAttribute), "<Filter>" + lServiceName + "</Filter>", lArgs) as ONFilter);
                    }
                    else
                    {
                        lFilters.Add(lFilterName, ONContext.GetComponent_Filter(lFilterName, null) as ONFilter);
                    }

                    xmlReader.ReadEndElement();                     //NavFilt.Argument
                }
                else if (xmlReader.IsStartElement("NavFilt.ServiceIU"))
                {
                    lNavFilterId = xmlReader.GetAttribute("NavFilterID");
                    xmlReader.ReadStartElement("NavFilt.ServiceIU");

                    if (xmlReader.IsStartElement("Arguments"))
                    {
                        object[] lArgs = new object[2];
                        lArgs[0] = xmlReader;
                        lArgs[1] = dtdVersion;

                        ONServiceInfo lSInfo = new ONServiceInfo("", "", "", "");
                        lSInfo.XML2ON(xmlReader, dtdVersion, false);

                        HybridDictionary lArguments = new HybridDictionary(true);
                        foreach (ONArgumentInfo lArgument in lSInfo.mArgumentList.Values)
                        {
                            lArguments.Add(lArgument.Name, lArgument.Value);
                        }
                        lFilters.Add(lNavFilterId, ONContext.GetComponent_NavigationalFilter(lNavFilterId, new object[1] {
                            lArguments
                        }) as ONFilter);
                    }
                    else
                    {
                        lFilters.Add(lNavFilterId, ONContext.GetComponent_NavigationalFilter(lNavFilterId, null) as ONFilter);
                    }

                    xmlReader.ReadEndElement();                     //NavFilt.ServiceIU
                }
                else if (xmlReader.IsStartElement("NavFilt.Variable"))
                {
                    string lClassName        = xmlReader.GetAttribute("Class");
                    string lSourceFilterName = xmlReader.GetAttribute("Filter");
                    string lVariableName     = xmlReader.GetAttribute("Variable");

                    xmlReader.ReadStartElement("NavFilt.Variable");
                    string lFilterName = lClassName + "_" + lSourceFilterName + "Filter_" + lVariableName + "_NavigationalFilter";
                    if (xmlReader.IsStartElement("Filter.Variables"))
                    {
                        object[] lArgs = new object[3];
                        lArgs[0] = xmlReader;
                        lArgs[1] = dtdVersion;
                        lArgs[2] = lVariableName;

                        lFilters.Add(lFilterName, ONContext.InvoqueMethod(ONContext.GetComponent_XML(lClassName), typeof(ONNavigationalFilterXMLAttribute), "<Filter>" + lSourceFilterName + "</Filter>", lArgs) as ONFilter);
                    }
                    else
                    {
                        lFilters.Add(lFilterName, ONContext.GetComponent_Filter(lFilterName, null) as ONFilter);
                    }

                    xmlReader.ReadEndElement();                     //NavFilt.Variable
                }
            }

            // Create Context
            ONContext lOnContext = new ONContext();

            lOnContext.OidAgent = agentOid;

            foreach (ONFilter lFilter in lFilters.Values)
            {
                lFilter.CheckFilterVariables(lOnContext);
            }

            // Execute
            lOnContext.CalculateQueryInstancesNumber = true;
            PasajeroQuery lQuery      = new PasajeroQuery(lOnContext);
            ONCollection  lCollection = lQuery.QueryByFilter(lLinkedTo, lFilters, displaySet, lOrderCriteria, startRowOID, blockSize);

            ticket = lOnContext.GetTicket(dtdVersion, clientName);

            return(lCollection);
        }
示例#19
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);
            }
        }
示例#20
0
        /// <summary>
        /// Converts the instances returned by a query in XML format in order to put it in XML message response
        /// </summary>
        /// <param name="agentOid">OID with the agent connected to the system</param>
        /// <param name="xmlWriter">This parameter has the response message XML</param>
        /// <param name="val">Instances that fullfils with the query request</param>
        /// <param name="startRowOID">OID necessary to start the search</param>
        /// <param name="blockSize">Represents the number of instances to be returned</param>
        /// <param name="displaySet">Attributes to be returned in the response</param>
        /// <param name="dtdVersion">Version of DTD that follows the XML message</param>
        public override void ONQuery2XML(ONOid agentOid, XmlWriter xmlWriter, ONCollection val, ONOid startRowOID, int blockSize, ONDisplaySet displaySet, double dtdVersion)
        {
            xmlWriter.WriteStartElement("Head");
            xmlWriter.WriteStartElement("Head.OID");
            xmlWriter.WriteAttributeString("Class", "Pasajero");
            xmlWriter.WriteStartElement("Head.OID.Field");
            xmlWriter.WriteAttributeString("Name", "id_Pasajero");
            xmlWriter.WriteAttributeString("Type", "autonumeric");
            xmlWriter.WriteEndElement();             // Head.OID.Field

            xmlWriter.WriteEndElement();             // Head.OID

            xmlWriter.WriteStartElement("Head.Cols");
            foreach (ONDisplaySetItem lDisplaySetItem in displaySet)
            {
                xmlWriter.WriteStartElement("Head.Col");
                xmlWriter.WriteAttributeString("Name", lDisplaySetItem.Path);
                string lType = ONInstance.GetTypeOfAttribute(typeof(PasajeroInstance), new ONPath(lDisplaySetItem.Path));
                if (lType == "")
                {
                    lType = "string";
                }
                xmlWriter.WriteAttributeString("Type", lType);
                xmlWriter.WriteEndElement();         // Head.Col
            }
            xmlWriter.WriteEndElement();             // Head.Cols
            xmlWriter.WriteEndElement();             // Head

            // Search StartRow
            int i = 0;

            if (startRowOID != null)
            {
                i = val.IndexOf(startRowOID) + 1;
            }

            // Instance count
            int    lInstances    = 0;
            int    lNumInstances = 0;
            string lLastBlock    = "True";

            if (i >= 0)
            {
                lNumInstances = val.Count - i;
                if ((blockSize > 0) && (lNumInstances > blockSize))
                {
                    lNumInstances = blockSize;
                    lLastBlock    = "False";
                }
            }

            xmlWriter.WriteStartElement("Data");
            xmlWriter.WriteAttributeString("Rows", lNumInstances.ToString());
            xmlWriter.WriteAttributeString("LastBlock", lLastBlock);
            xmlWriter.WriteAttributeString("TotalRows", val.totalNumInstances.ToString());
            while ((lInstances++ < lNumInstances) && (i < val.Count))
            {
                PasajeroInstance lInstance = val[i++] as PasajeroInstance;

                xmlWriter.WriteStartElement("R");
                ONXmlAutonumeric.ON2XML(xmlWriter, lInstance.Oid.Id_PasajeroAttr, dtdVersion, ONXml.XMLTAG_O);


                foreach (ONDisplaySetItem lDisplaySetItem in displaySet)
                {
                    if (lDisplaySetItem.Visibility == VisibilityState.NotChecked)
                    {
                        if (ONInstance.IsVisible(lInstance.GetType(), lDisplaySetItem.Path, lInstance.OnContext))
                        {
                            lDisplaySetItem.Visibility = VisibilityState.Visible;
                        }
                        else
                        {
                            lDisplaySetItem.Visibility = VisibilityState.NotVisible;
                        }
                    }
                    if (lDisplaySetItem.Visibility == VisibilityState.NotVisible)                     // No Visibility
                    {
                        xmlWriter.WriteElementString("V", null);
                    }
                    else
                    {
                        ONSimpleType lAttribute;
                        if (lDisplaySetItem.HasHV)
                        {
                            lAttribute = lInstance.DisplaysetItemValue(lDisplaySetItem.Path);
                        }
                        else
                        {
                            lAttribute = lInstance[lDisplaySetItem.Path] as ONSimpleType;
                        }

                        if (lAttribute is ONInt)
                        {
                            ONXmlInt.ON2XML(xmlWriter, lAttribute as ONInt, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONString)
                        {
                            ONXmlString.ON2XML(xmlWriter, lAttribute as ONString, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONBlob)
                        {
                            ONXmlBlob.ON2XML(xmlWriter, lAttribute as ONBlob, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONBool)
                        {
                            ONXmlBool.ON2XML(xmlWriter, lAttribute as ONBool, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONReal)
                        {
                            ONXmlReal.ON2XML(xmlWriter, lAttribute as ONReal, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONInt)
                        {
                            ONXmlAutonumeric.ON2XML(xmlWriter, lAttribute as ONInt, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONDate)
                        {
                            ONXmlDate.ON2XML(xmlWriter, lAttribute as ONDate, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONDateTime)
                        {
                            ONXmlDateTime.ON2XML(xmlWriter, lAttribute as ONDateTime, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONTime)
                        {
                            ONXmlTime.ON2XML(xmlWriter, lAttribute as ONTime, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONNat)
                        {
                            ONXmlNat.ON2XML(xmlWriter, lAttribute as ONNat, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONText)
                        {
                            ONXmlText.ON2XML(xmlWriter, lAttribute as ONText, dtdVersion, ONXml.XMLTAG_V);
                        }
                        else if (lAttribute is ONString)
                        {
                            ONXmlPassword.ON2XML(xmlWriter, lAttribute as ONString, dtdVersion, ONXml.XMLTAG_V);
                        }
                    }
                }
                xmlWriter.WriteEndElement();         // R
            }
            xmlWriter.WriteEndElement();             // Data
        }
示例#21
0
 /// <summary>
 /// Puts each instance of the collection in the modified class list to check integrity constraints and trigger conditions
 /// The instances are added thought they are not marked as modified
 /// </summary>
 /// <param name="collection">Oid that represents the instance to be added</param>
 public void AddUnmodifiedClass(ONCollection collection)
 {
     foreach (ONInstance lInstance in collection)
     AddUnmodifiedClass(lInstance.Oid);
 }