/// <summary> /// This method recovers all the population of the database /// </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 population</returns> public override ONCollection FilterInLegacy(ONContext onContext, ONLinkedToList linkedTo, ONOrderCriteria comparer, ONOid startRowOID, int blockSize) { if (InData) { return(null); } ONLinkedToList lLinkedToList = new ONLinkedToList(); // Add linkedToList to the new list foreach (KeyValuePair <ONPath, ONOid> lDictionaryEntry in linkedTo) { lLinkedToList.mLinkedToList.Add(lDictionaryEntry.Key, lDictionaryEntry.Value); } // Add relatedOid to the new list if (mRelatedOid != null) { lLinkedToList.mLinkedToList.Add(ONPath, mRelatedOid); } // Add parameters object[] lParameters = new object[5]; lParameters[0] = onContext; lParameters[1] = linkedTo; lParameters[2] = comparer; lParameters[3] = startRowOID; lParameters[4] = blockSize; return(ONContext.InvoqueMethod(ONContext.GetType_LV(ClassName), "QueryByRelated", lParameters) as ONCollection); }
/// <summary> /// Gets the Agent of the XML mesage /// </summary> /// <param name="xmlReader">The message with the request in XML format</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> private ONOid GetAgent(XmlTextReader xmlReader, double dtdVersion) { ONOid lAgentOID = null; if ((dtdVersion < 3.1) || (xmlReader.IsStartElement("Agent"))) { object[] lParam = new object[2]; lParam[0] = xmlReader; lParam[1] = dtdVersion; xmlReader.ReadStartElement("Agent"); string lAgentClass = xmlReader.GetAttribute("Class"); lAgentOID = ONContext.InvoqueMethod(ONContext.GetType_XML(lAgentClass), "XML2ON", lParam) as ONOid; xmlReader.ReadEndElement(); // Agent } return(lAgentOID); }
/// <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); }
public static void ONChangeTypeToXML(XmlTextWriter xmlWriter, ONChangeDetectionInfo pDifference, double dtdVersion) { if (pDifference.Type != DataTypeEnumerator.OID) { xmlWriter.WriteAttributeString(ONXml.XMLATT_TYPE, GetNameTypeForXml(pDifference.Type)); //Write Old Value xmlWriter.WriteStartElement(XMLTAG_CHANGEDITEMOLDVALUE); GetType_XMLSimple(pDifference.Type, xmlWriter, pDifference.OldValue as ONSimpleType, dtdVersion); xmlWriter.WriteEndElement(); // ChangedItemOldValue //Write New Value xmlWriter.WriteStartElement(XMLTAG_CHANGEDITEMNEWVALUE); GetType_XMLSimple(pDifference.Type, xmlWriter, pDifference.NewValue as ONSimpleType, dtdVersion); xmlWriter.WriteEndElement(); // ChangedItemNewValue } else { xmlWriter.WriteAttributeString(ONXml.XMLATT_TYPE, pDifference.ClassName); //Write Old Value xmlWriter.WriteStartElement(XMLTAG_CHANGEDITEMOLDVALUE); Type lTypeXML = ONContext.GetType_XML(pDifference.ClassName); object[] parameters = new object[4]; parameters[0] = xmlWriter; parameters[1] = pDifference.OldValue; parameters[2] = dtdVersion; parameters[3] = ONXml.XMLTAG_OIDFIELD; ONContext.InvoqueMethod(lTypeXML, "ON2XML", parameters); xmlWriter.WriteEndElement(); // ChangedItemOldValue //Write New Value xmlWriter.WriteStartElement(XMLTAG_CHANGEDITEMNEWVALUE); parameters[1] = pDifference.NewValue; ONContext.InvoqueMethod(lTypeXML, "ON2XML", parameters); xmlWriter.WriteEndElement(); // ChangedItemNewValue } }
/// <summary> /// Treatment the part of the XML message that has links items /// </summary> /// <param name="xmlReader">Variable with the message XML to be treated</param> /// <param name="dtdVersion">Version of the DTD that follows the XML message</param> public ONLinkedToList GetLinkedTo(XmlReader xmlReader, double dtdVersion) { ONLinkedToList lLinkedToList = new ONLinkedToList(); if (!xmlReader.IsStartElement("LinkedTo")) { return(lLinkedToList); } if (xmlReader.IsEmptyElement) { xmlReader.ReadStartElement("LinkedTo"); return(lLinkedToList); } xmlReader.ReadStartElement("LinkedTo"); while (xmlReader.IsStartElement("Link.Item")) { ONPath lPath = new ONPath(xmlReader.GetAttribute("Role")); xmlReader.ReadStartElement("Link.Item"); object[] lParam = new object[2]; lParam[0] = xmlReader; lParam[1] = dtdVersion; string lClassInstance = xmlReader.GetAttribute("Class"); ONOid lInstance = ONContext.InvoqueMethod(ONContext.GetType_XML(lClassInstance), "XML2ON", lParam) as ONOid; lLinkedToList[lPath] = lInstance; xmlReader.ReadEndElement(); // Link.Item } xmlReader.ReadEndElement(); // LinkedTo return(lLinkedToList); }
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>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); }
/// <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); }
/// <summary> /// Treatment of the XML message that has a service 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 XMLRequestService(ref string ticket, ONOid agentOID, XmlTextReader xmlReader, out XmlTextWriter xmlWriter, double dtdVersion, string clientName) { try { // Read Response string lService = xmlReader.GetAttribute("Service"); xmlReader.ReadStartElement("Service.Request"); // Create XMLWriterRequest MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); MemoryStream lXMLMemoryStreamService = new MemoryStream(); XmlTextWriter lXmlWriterService = new XmlTextWriter(lXMLMemoryStreamService, new UTF8Encoding()); // Set Service Parameters object[] lParameters = new object[6]; lParameters[0] = ticket; lParameters[1] = agentOID; lParameters[2] = xmlReader; lParameters[3] = lXmlWriterService; lParameters[4] = dtdVersion; lParameters[5] = clientName; // Execute ONContext.InvoqueMethod(this, typeof(ONServiceXMLAttribute), "<Service>" + lService + "</Service>", lParameters); ticket = lParameters[0] as string; // Read Request xmlReader.ReadEndElement(); // Service.Request xmlReader.ReadEndElement(); // Request // Write Response xmlWriter.WriteStartElement("Service.Response"); xmlWriter.WriteStartElement("Error"); xmlWriter.WriteAttributeString("Type", "Model"); xmlWriter.WriteAttributeString("Number", "0"); if (dtdVersion > 2) { xmlWriter.WriteElementString("Error.Message", ""); xmlWriter.WriteElementString("Error.Params", ""); xmlWriter.WriteElementString("Error.Trace", ""); } xmlWriter.WriteEndElement(); // Error // Write Outbound Arguments lXmlWriterService.Flush(); lXMLMemoryStreamService.Flush(); lXMLMemoryStreamService.Position = 0; xmlWriter.WriteRaw(new StreamReader(lXMLMemoryStreamService).ReadToEnd()); // Write Response xmlWriter.WriteEndElement(); // Service.Response } catch (ONException e) { MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Service.Response"); CreateXMLError(xmlWriter, e, dtdVersion); xmlWriter.WriteEndElement(); // Service.Response return; } catch (Exception e) { string message = e.Message; MemoryStream lXMLMemoryStream = new MemoryStream(); xmlWriter = new XmlTextWriter(lXMLMemoryStream, new UTF8Encoding()); // Write Response xmlWriter.WriteStartElement("Service.Response"); xmlWriter.WriteStartElement("Error"); xmlWriter.WriteAttributeString("Type", "External"); xmlWriter.WriteAttributeString("Number", "999"); if (dtdVersion <= 2) { xmlWriter.WriteString(e.Message); } else { if (e is ONSystemException) { ArrayList trace = ((ONSystemException)e).mTraceInformation; xmlWriter.WriteElementString("Error.Message", message); 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(); // Service.Response return; } }
/// <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; } }
public void Preprocess(MarshalByRefObject inst, IMessage msg) { if (mServiceCacheItem == null) { mServiceCacheItem = ONServiceCacheItem.Get("Action", ClassName, ServiceName); } IMethodCallMessage lMsg = msg as IMethodCallMessage; int lIndex = 0; // Extract Action ONAction lAction = inst as ONAction; // Shared Event Control if (lAction.OnContext.InSharedContext == true) // No-Principal Shared Event { return; } lAction.OnContext.InSharedContext = true; mReflexivePrincipal = true; // Shared Event Arguments (in Shared Event order) HybridDictionary lReflexiveEventArguments = new HybridDictionary(true); HybridDictionary lReflexiveEventArgumentsInfo = new HybridDictionary(true); int i = 0; foreach (ParameterInfo lArgument in lMsg.MethodBase.GetParameters()) { ONSharedArgumentAttribute[] lReflexiveArgumentsInfo = lArgument.GetCustomAttributes(typeof(ONSharedArgumentAttribute), false) as ONSharedArgumentAttribute[]; foreach (ONSharedArgumentAttribute lReflexiveArgumentInfo in lReflexiveArgumentsInfo) { lReflexiveEventArgumentsInfo[lArgument.Name] = lReflexiveArgumentInfo; break; } lReflexiveEventArguments[lArgument.Name] = lMsg.Args[i]; i++; } // Shared Event Arguments for each Class (in Shared Event order) mServiceCacheItems = new List <ONServiceCacheItem>(); foreach (DictionaryEntry lEntry in lReflexiveEventArgumentsInfo) { string lReflexiveArgumentName = lEntry.Key as String; ONSharedArgumentAttribute lReflexiveArgumentInfo = lEntry.Value as ONSharedArgumentAttribute; // Create Instance ONInstance lInstance = (lReflexiveEventArguments[lReflexiveArgumentName] as ONOid).GetInstance(lAction.OnContext); if (lInstance == null) { throw new ONInstanceNotExistException(null, "", (lReflexiveEventArguments[lReflexiveArgumentName] as ONOid).ClassName); } // Create Action ONAction lReflexiveAction = ONContext.GetComponent_Action(lReflexiveArgumentInfo.ClassName, lAction.OnContext); //lSharedAction.Instance lReflexiveAction.Instance = lInstance; // Copy arguments MethodInfo lMethodInfo = ONContext.GetMethods(lReflexiveAction.GetType(), ToStringPartial()); lIndex = 0; object[] lArguments = new object[lReflexiveEventArguments.Count]; foreach (ParameterInfo lParameterInfo in lMethodInfo.GetParameters()) { // Normal Argument lArguments[lIndex++] = lReflexiveEventArguments[lParameterInfo.Name]; } mReflexiveClass = new KeyValuePair <ONAction, object[]>(lReflexiveAction, lArguments); mServiceCacheItems.Add(ONServiceCacheItem.Get("Action", lReflexiveArgumentInfo.ClassName, ServiceName + "_Partial")); object[] lObject = new object[mReflexiveClass.Value.Length]; lObject[0] = mReflexiveClass.Value[1]; lObject[1] = mReflexiveClass.Value[0]; mReflexiveClass.Value[0] = lObject[0]; mReflexiveClass.Value[1] = lObject[1]; } // Take the active Instance lIndex = 0; bool lSharedFind = false; foreach (ONInstance lInstance in lAction.OnContext.TransactionStack) { if (lInstance == mReflexiveClass.Key.Instance) { mReflexiveClass.Key.Instance = lInstance.GetFacet(mReflexiveClass.Key.Instance.ClassName); lSharedFind = true; break; } } if (!lSharedFind) { foreach (ONInstance lInstance in lAction.OnContext.OperationStack) { if (lInstance == mReflexiveClass.Key.Instance) { mReflexiveClass.Key.Instance = lInstance.GetFacet(mReflexiveClass.Key.Instance.ClassName); mReflexiveClass.Key.Instance.OnContext = mReflexiveClass.Key.OnContext; break; } } } // Check State Changes if (lAction.OnContext.NeedsVerification) { mServiceCacheItem.InvoqueCheckState(lAction, lMsg.Args); lAction.OnContext.NeedsVerification = false; } // Push OID to Class Stack mReflexiveClass.Key.OnContext.TransactionStack.Push(mReflexiveClass.Key.Instance); // Check Shared STD if (!lSharedFind) { mServiceCacheItem.InvoqueSTD(mReflexiveClass.Key, mReflexiveClass.Value); } // Take the active Instance bool lFind = false; foreach (ONInstance lInstance in lAction.OnContext.TransactionStack) { if (lInstance == lAction.Instance) { lAction.Instance = lInstance.GetFacet(lAction.Instance.ClassName); lFind = true; break; } } if (!lFind) { foreach (ONInstance lInstance in lAction.OnContext.OperationStack) { if (lInstance == lAction.Instance) { // Saving the old context of the This instance lAction.Instance = lInstance.GetFacet(lAction.Instance.ClassName); mThisOnContext = lAction.Instance.OnContext; lAction.Instance.OnContext = lAction.OnContext; break; } } } // Push OID to Class Stack lAction.OnContext.TransactionStack.Push(lAction.Instance); mInStack = true; // Check STD if (!lFind) { mServiceCacheItem.InvoqueSTD(lAction, lMsg.Args); } // Check Shared Precondition lIndex = 0; mServiceCacheItem.InvoquePrecondition(mReflexiveClass.Key, mReflexiveClass.Value); // Check Precondition mServiceCacheItem.InvoquePrecondition(lAction, lMsg.Args); // Get Initial Values of the instances lAction.OnContext.GetInitialValues(lAction, lMsg.Args); // Throw Check Shared Partials lIndex = 0; if (mReflexiveClass.Key.Instance != lAction.Instance) { ONContext.InvoqueMethod(mReflexiveClass.Key, "_" + ServiceName + "_Partial", mReflexiveClass.Value); } }
private void ReadChangeDetectionItem(XmlReader xmlReader, double dtdVersion, string Name) { // Read the change detection items ONChangeDetectionInfo lCD; try { lCD = (ONChangeDetectionInfo)mChangesDetectionList[Name.ToLower()]; if (lCD == null) { xmlReader.Skip(); return; } } catch { return; } switch (lCD.Type) { case DataTypeEnumerator.Autonumeric: { lCD.OldValue = ONXmlAutonumeric.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Bool: { lCD.OldValue = ONXmlBool.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Blob: { lCD.OldValue = ONXmlBlob.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Date: { lCD.OldValue = ONXmlDate.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.DateTime: { lCD.OldValue = ONXmlDateTime.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Int: { lCD.OldValue = ONXmlInt.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Nat: { lCD.OldValue = ONXmlNat.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Password: { lCD.OldValue = ONXmlPassword.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Real: { lCD.OldValue = ONXmlReal.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.String: { lCD.OldValue = ONXmlString.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Text: { lCD.OldValue = ONXmlText.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Time: { lCD.OldValue = ONXmlTime.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.OID: { object[] lArgs = new object[2]; lArgs[0] = xmlReader; lArgs[1] = dtdVersion; lCD.OldValue = ONContext.InvoqueMethod(ONContext.GetType_XML(lCD.ClassName), "XML2ON", lArgs) as IONType; break; } } }
private void ReadArgument(XmlReader xmlReader, double dtdVersion, string Name) { // Read the arguments and process ONArgumentInfo lArg; try { lArg = (ONArgumentInfo)mArgumentList[Name.ToLower()]; } catch { return; } switch (lArg.Type) { case DataTypeEnumerator.Autonumeric: { lArg.Value = ONXmlAutonumeric.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Bool: { lArg.Value = ONXmlBool.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Blob: { lArg.Value = ONXmlBlob.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Date: { lArg.Value = ONXmlDate.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.DateTime: { lArg.Value = ONXmlDateTime.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Int: { lArg.Value = ONXmlInt.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Nat: { lArg.Value = ONXmlNat.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Password: { lArg.Value = ONXmlPassword.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Real: { lArg.Value = ONXmlReal.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.String: { lArg.Value = ONXmlString.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Text: { lArg.Value = ONXmlText.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.Time: { lArg.Value = ONXmlTime.XML2ON(xmlReader, dtdVersion, ONXml.XMLTAG_LITERAL); break; } case DataTypeEnumerator.OID: { object[] lArgs = new object[2]; lArgs[0] = xmlReader; lArgs[1] = dtdVersion; lArg.Value = ONContext.InvoqueMethod(ONContext.GetType_XML(lArg.ClassName), "XML2ON", lArgs) as IONType; break; } } }