Esempio n. 1
0
        /// <summary>
        /// Converts an OID into XML in order to put it in XML message response
        /// </summary>
        /// <param name="xmlWriter">XML with the response message</param>
        /// <param name="oid">OID that will be insert into XML message</param>
        /// <param name="dtdVersion">Version of DTD that follows the XML message</param>
        /// <param name="xmlElement">Element in the XML message in order to convert in the right form of the XML</param>
        public static void ON2XML(XmlWriter xmlWriter, PasajeroOid oid, double dtdVersion, string xmlElement)
        {
            if (oid == null)
            {
                xmlWriter.WriteElementString(ONXml.XMLTAG_NULL, null);
            }
            else
            {
                xmlWriter.WriteStartElement(ONXml.XMLTAG_OID);
                xmlWriter.WriteAttributeString(ONXml.XMLATT_CLASS, "Pasajero");
                ONXmlAutonumeric.ON2XML(xmlWriter, oid.Id_PasajeroAttr, dtdVersion, xmlElement);

                xmlWriter.WriteEndElement();                 // OID
            }
        }
Esempio n. 2
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
        }