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); }
/// <summary> /// Point of access to the application. /// </summary> /// <param name="xmlRequest">The message with the request in XML format</param> public string XMLRequest(string xmlRequest) { // Start Time DateTime lStartTime = DateTime.Now; // Response Type string lResponseType = "Service.Response"; // Request Attributes string lSecuence = ""; string lDTDVersionResponse = ""; double lDTDVersion = 0; try { // Create XMLReader XmlTextReader lXMLReader = new XmlTextReader(new StringReader(xmlRequest)); lXMLReader.WhitespaceHandling = WhitespaceHandling.None; lXMLReader.MoveToContent(); // Read Attributes string lApplication = lXMLReader.GetAttribute("Application"); string lIdCnx = lXMLReader.GetAttribute("IdCnx"); lSecuence = lXMLReader.GetAttribute("Sequence"); lDTDVersion = ExtractDTDVersion(lXMLReader.GetAttribute("VersionDTD")); if (lDTDVersion >= 3.0) { lDTDVersionResponse = "CARE.Response v. " + lDTDVersion.ToString("#.00", ONXml.ComXMLFormat); } else { lDTDVersionResponse = "CARE.Response v." + lDTDVersion.ToString("#.0", ONXml.ComXMLFormat); } lXMLReader.ReadStartElement("Request"); // Check Secure server if ((ONSecureControl.SecureServer) && (lDTDVersion < 3.1)) { throw new ONAgentValidationException(null); } // Create XMLWriter MemoryStream lXMLMemoryStream = new MemoryStream(); XmlTextWriter lXMLWriter = new XmlTextWriter(lXMLMemoryStream, new System.Text.UTF8Encoding()); lXMLWriter.WriteStartDocument(); // Create XMLWriterRequest XmlTextWriter lXMLWriterRequest = null; // Load agent ONOid lAgentOID = GetAgent(lXMLReader, lDTDVersion); string lTicket = ""; if (lDTDVersion >= 3.1) { lTicket = GetTicket(lXMLReader, lDTDVersion); } lStartTime = DateTime.Now; if (lXMLReader.IsStartElement("Service.Request")) { string lService = lXMLReader.GetAttribute("Service"); if ((lDTDVersion >= 3.1) && (string.Compare(lService, "MVAgentValidation", true) != 0)) { using (ONContext lOnContext = new ONContext()) { if (((object)lAgentOID == null) || !lAgentOID.IsAnonymousAgent) { ONOid lAgentOid = lOnContext.SetTicket(lDTDVersion, lApplication, lTicket); if (ONSecureControl.SecureServer) { if (lAgentOID != lAgentOid) { throw new ONAgentValidationException(null); } } } } } // Response Type lResponseType = "Service.Response"; // Read Attributes string lClass = lXMLReader.GetAttribute("Class"); // Global services if ((lClass == "") || (lClass == "InteraccionGlobal") || (lClass == "GlobalTransactions")) { lClass = "GlobalTransaction"; } ONXml lComponent = ONContext.GetComponent_XML(lClass); lComponent.XMLRequestService(ref lTicket, lAgentOID, lXMLReader, out lXMLWriterRequest, lDTDVersion, lApplication); } else if (lXMLReader.IsStartElement("Query.Request")) { if (lDTDVersion >= 3.1) { using (ONContext lOnContext = new ONContext()) { if (((object)lAgentOID == null) || !lAgentOID.IsAnonymousAgent) { ONOid lAgentOid = lOnContext.SetTicket(lDTDVersion, lApplication, lTicket); if (ONSecureControl.SecureServer) { if (lAgentOID != lAgentOid) { throw new ONAgentValidationException(null); } } } } } // Response Type lResponseType = "Query.Response"; // Read Attributes string lClass = lXMLReader.GetAttribute("Class"); ONXml lComponent = ONContext.GetComponent_XML(lClass); lComponent.XMLRequestQuery(ref lTicket, lAgentOID, lXMLReader, out lXMLWriterRequest, lDTDVersion, lApplication); } else { throw new ONXMLException(null, "Request type"); } // Get Time DateTime lEndTime = DateTime.Now; double lElapsedTime = (lEndTime.Ticks - lStartTime.Ticks) / 10000; // Write Response lXMLWriter.WriteStartElement("Response"); lXMLWriter.WriteAttributeString("Sequence", lSecuence); lXMLWriter.WriteAttributeString("VersionDTD", lDTDVersionResponse); lXMLWriter.WriteStartElement("Statistics"); lXMLWriter.WriteAttributeString("StartTime", lStartTime.ToString().Trim()); lXMLWriter.WriteAttributeString("EndTime", lEndTime.ToString().Trim()); lXMLWriter.WriteAttributeString("ElapsedTime", lElapsedTime.ToString().Trim()); lXMLWriter.WriteEndElement(); // Statistics if (lDTDVersion >= 3.1) { lXMLWriter.WriteElementString("Ticket", lTicket); } // Write Query / Service XML MemoryStream lXMLMemoryStreamRequest = lXMLWriterRequest.BaseStream as MemoryStream; lXMLWriter.Flush(); lXMLWriterRequest.Flush(); lXMLMemoryStreamRequest.Flush(); lXMLMemoryStreamRequest.Position = 0; lXMLMemoryStreamRequest.WriteTo(lXMLMemoryStream); lXMLWriter.WriteEndElement(); // Response // Get Response lXMLWriter.Flush(); lXMLMemoryStream.Flush(); lXMLMemoryStream.Position = 0; StreamReader lXMLStreamReader = new StreamReader(lXMLMemoryStream); string lResponse = lXMLStreamReader.ReadToEnd(); // Close Writer lXMLWriterRequest.Close(); lXMLWriter.Close(); // Close Reader lXMLReader.Close(); return(lResponse); } catch (Exception e) { // Create XMLWriter MemoryStream lXMLMemoryStream = new MemoryStream(); XmlTextWriter lXMLWriter = new XmlTextWriter(lXMLMemoryStream, new System.Text.UTF8Encoding()); lXMLWriter.WriteStartDocument(); // Write Response lXMLWriter.WriteStartElement("Response"); lXMLWriter.WriteAttributeString("Sequence", lSecuence); lXMLWriter.WriteAttributeString("VersionDTD", lDTDVersionResponse); // Get Time DateTime lEndTime = DateTime.Now; double lElapsedTime = (lEndTime.Ticks - lStartTime.Ticks) / 10000; // Write Statistics lXMLWriter.WriteStartElement("Statistics"); lXMLWriter.WriteAttributeString("StartTime", lStartTime.ToString().Trim()); lXMLWriter.WriteAttributeString("EndTime", lEndTime.ToString().Trim()); lXMLWriter.WriteAttributeString("ElapsedTime", lElapsedTime.ToString().Trim()); lXMLWriter.WriteEndElement(); // Statistics // Write ServiceResponse / QueryResponse lXMLWriter.WriteStartElement(lResponseType); if (lDTDVersion > 2) { if (e is ONException) { ONXml.CreateXMLError(lXMLWriter, e as ONException, lDTDVersion); } else { lXMLWriter.WriteStartElement("Error"); lXMLWriter.WriteAttributeString("Type", "Model"); lXMLWriter.WriteAttributeString("Number", "999"); lXMLWriter.WriteElementString("Error.Message", ""); lXMLWriter.WriteElementString("Error.Params", ""); lXMLWriter.WriteElementString("Error.Trace", ""); lXMLWriter.WriteEndElement(); // Error } } else { lXMLWriter.WriteStartElement("Error"); lXMLWriter.WriteAttributeString("Type", "External"); lXMLWriter.WriteAttributeString("Number", "999"); lXMLWriter.WriteString(e.Message); lXMLWriter.WriteEndElement(); // Error } lXMLWriter.WriteEndElement(); // Service.Response / Query.Response // Write Response lXMLWriter.WriteEndElement(); // Response // Get Response lXMLWriter.Flush(); lXMLMemoryStream.Flush(); lXMLMemoryStream.Position = 0; StreamReader lXMLStreamReader = new StreamReader(lXMLMemoryStream); string lResponse = lXMLStreamReader.ReadToEnd(); // Close Writer lXMLWriter.Close(); return(lResponse); } }