/// <summary> /// Copy constructor /// </summary> /// <param name="onContext">Context to copy from</param> public ONContext(ONContext onContext) { mOidAgent = onContext.OidAgent; mSqlConnection = null; CalculateQueryInstancesNumber = false; LeafActiveAgentFacets = onContext.LeafActiveAgentFacets; }
/// <summary> /// Method of Copy /// </summary> /// <param name="oid">OID to be copied</param> public virtual void Copy(object oid) { ONOid lOID = oid as ONOid; if (lOID != null) { ClassName = lOID.ClassName; } }
/// <summary> /// Constructor /// </summary> /// <param name="onContext">Context with all the information about the execution of the request</param> /// <param name="className">Name of the class that represents the instance</param> /// <param name="idClass">Identificator of the class</param> public ONInstance(ONContext onContext, string className, string idClass) { ClassName = className; IdClass = idClass; Oid = null; Lmd = ONDateTime.Null; Modified = false; OnContext = onContext; }
public QueryByOidFilter(ONOid oid) : base(oid.ClassName, "QueryByOid") { mOid = oid; Type lDataType = ONContext.GetType_Data(ClassName); InMemory = false; InData = !lDataType.IsSubclassOf(typeof(ONLVData)); InLegacy = lDataType.IsSubclassOf(typeof(ONLVData)); }
public QueryByRelatedFilter(string className, ONPath onPath, ONOid relatedOid) : base(className, "QueryByRelated") { ONPath = onPath; mRelatedOid = relatedOid; Type lDataType = ONContext.GetType_Data(ClassName); InMemory = false; InData = !lDataType.IsSubclassOf(typeof(ONLVData)); InLegacy = lDataType.IsSubclassOf(typeof(ONLVData)); }
/// <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; }
/// <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 PasajeroHorizontalVisibility()); // Linked To List if (linkedTo == null) linkedTo = new ONLinkedToList(); // Call Data try { PasajeroData lData = new PasajeroData(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: PasajeroQuery"; if (e is ONSystemException) { ONSystemException lException = e as ONSystemException; lException.addTraceInformation(ltraceItem); throw lException; } throw new ONSystemException(e, ltraceItem); } } }
/// <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> /// 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; } }
/// <summary> /// Process the XML message that is a search of an instance with their OID. Is empty, it implementation is done in child classes /// </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="dtdVersion">Version of the DTD that follows the XML message</param> public virtual ONCollection QueryByOid(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, double dtdVersion, string clientName) { return null; }
public static string GetNextTicket(double dtdVersion, string clientName, ONOid agentOid) { #region Open xml MemoryStream lXMLMemoryStream = new MemoryStream(); XmlTextWriter lXMLWriter = new XmlTextWriter(lXMLMemoryStream, new System.Text.UTF8Encoding()); lXMLWriter.WriteStartDocument(); #endregion #region Save information lXMLWriter.WriteStartElement("ONTicket"); // Server name lXMLWriter.WriteElementString("Server", mServerName); // Client name lXMLWriter.WriteElementString("Client", clientName); // Agent oid if (agentOid == null) { lXMLWriter.WriteStartElement("Agent"); lXMLWriter.WriteStartElement(ONXml.XMLTAG_OID); lXMLWriter.WriteAttributeString(ONXml.XMLATT_CLASS, "Agente"); lXMLWriter.WriteElementString(ONXml.XMLTAG_OIDFIELD, "DEBUG"); lXMLWriter.WriteEndElement(); // Oid lXMLWriter.WriteEndElement(); // Agent } else { object[] lParam = new object[4]; lParam[0] = lXMLWriter; lParam[1] = agentOid; lParam[2] = dtdVersion; lParam[3] = "OID.Field"; lXMLWriter.WriteStartElement("Agent"); ONContext.InvoqueMethod(ONContext.GetType_XML(agentOid.ClassName), "ON2XML", lParam); lXMLWriter.WriteEndElement(); // Agent } // TimeStamp ONXmlDateTime.ON2XML(lXMLWriter, ONStdFunctions.systemDateTime(), dtdVersion, "Timestamp"); // Validity ONXmlNat.ON2XML(lXMLWriter, new ONNat(mValidity), dtdVersion, "Validity"); lXMLWriter.WriteEndElement(); // ONTicket #endregion #region Get xml lXMLWriter.Flush(); lXMLMemoryStream.Flush(); lXMLMemoryStream.Position = 0; StreamReader lXMLStreamReader = new StreamReader(lXMLMemoryStream); string lText = lXMLStreamReader.ReadToEnd(); #endregion #region Close xml lXMLWriter.Close(); #endregion return CipherTicket(lText); }
/// <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; }
/// <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 }
public void Create_instanceServ(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, XmlWriter xmlWriter, double dtdVersion, string clientName) { // Process the service arguments ONServiceInfo lSInfo = new ONServiceInfo("Clas_1348178673664478Ser_1_Alias", RevisionPasajeroClassText.Create_instanceServiceAlias, "Clas_1348178673664478_Alias", RevisionPasajeroClassText.ClassAlias); lSInfo.AddOIDArgument("p_agrPasajeroAeronave", false, "PasajeroAeronave", "Clas_1348178673664478Ser_1Arg_3_Alias", RevisionPasajeroClassText.Create_instance_P_agrPasajeroAeronaveArgumentAlias); lSInfo.AddOIDArgument("p_agrRevision", false, "Revision", "Clas_1348178673664478Ser_1Arg_4_Alias", RevisionPasajeroClassText.Create_instance_P_agrRevisionArgumentAlias); lSInfo.AddDataValuedArgument("p_atrid_RevisionPasajero", false, DataTypeEnumerator.Autonumeric, 0, "Clas_1348178673664478Ser_1Arg_1_Alias", RevisionPasajeroClassText.Create_instance_P_atrid_RevisionPasajeroArgumentAlias); try { lSInfo.XML2ON(xmlReader, dtdVersion, true); } catch (Exception e) { throw new ONServiceArgumentsException(e, "Clas_1348178673664478_Alias", RevisionPasajeroClassText.ClassAlias, "Clas_1348178673664478Ser_1_Alias", RevisionPasajeroClassText.Create_instanceServiceAlias); } PasajeroAeronaveOid lP_agrPasajeroAeronaveArg = (PasajeroAeronaveOid) ((ONArgumentInfo) lSInfo.mArgumentList["p_agrPasajeroAeronave"]).Value; RevisionOid lP_agrRevisionArg = (RevisionOid) ((ONArgumentInfo) lSInfo.mArgumentList["p_agrRevision"]).Value; ONInt lP_atrid_RevisionPasajeroArg = (ONInt) ((ONArgumentInfo) lSInfo.mArgumentList["p_atrid_RevisionPasajero"]).Value; // Create Context ONServiceContext lOnContext = new ONServiceContext(); lOnContext.OidAgent = agentOid; // Execute Service RevisionPasajeroInstance lInstance = null; try { ONFilterList lFilterList = new ONFilterList(); PasajeroAeronaveInstance lp_agrPasajeroAeronaveInstance = new PasajeroAeronaveInstance(lOnContext); if (lP_agrPasajeroAeronaveArg != null) { lFilterList = new ONFilterList(); lFilterList.Add("HorizontalVisibility", new PasajeroAeronaveHorizontalVisibility()); lp_agrPasajeroAeronaveInstance = lP_agrPasajeroAeronaveArg.GetInstance(lOnContext, lFilterList); if (lp_agrPasajeroAeronaveInstance == null) throw new ONInstanceNotExistException(null, "Clas_1348178542592177_Alias", PasajeroAeronaveClassText.ClassAlias); } RevisionInstance lp_agrRevisionInstance = new RevisionInstance(lOnContext); if (lP_agrRevisionArg != null) { lFilterList = new ONFilterList(); lFilterList.Add("HorizontalVisibility", new RevisionHorizontalVisibility()); lp_agrRevisionInstance = lP_agrRevisionArg.GetInstance(lOnContext, lFilterList); if (lp_agrRevisionInstance == null) throw new ONInstanceNotExistException(null, "Clas_1348178542592347_Alias", RevisionClassText.ClassAlias); } using (RevisionPasajeroServer lServer = new RevisionPasajeroServer(lOnContext, null)) { lServer.Create_instanceServ(lP_agrPasajeroAeronaveArg,lP_agrRevisionArg,lP_atrid_RevisionPasajeroArg); lInstance = lServer.Instance; } ticket = lOnContext.GetTicket(dtdVersion, clientName); } catch (SecurityException) { throw new ONAccessAgentValidationException(null); } catch { throw; } // Write Oid if (dtdVersion >= 3.1) { if (lInstance != null) ON2XML(xmlWriter, lInstance.Oid, dtdVersion, ONXml.XMLTAG_OIDFIELD); } // Write Outbound Arguments xmlWriter.WriteStartElement("Arguments"); // Write Outbound Arguments xmlWriter.WriteEndElement(); // Arguments }
public override void InhFixInstance(ONSqlSelect onSql, ONPath onPath, ONPath OnPath, ONOid oid, bool isLinkedTo) { FixInstance(onSql, onPath, OnPath, oid as AeronaveOid, isLinkedTo); }
public override void InhFixInstance(ONSqlSelect onSql, ONPath onPath, ONPath OnPath, ONOid oid) { FixInstance(onSql, onPath, OnPath, oid as AeronaveOid); }
/// <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); } }
///<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> /// Execution of a sql /// </summary> /// <param name="onSql">Sentence SQL to be executed</param> /// <param name="onFilterList">List of filters to check</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 virtual ONCollection ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria comparer, ONOid startRowOID, int blockSize) { return null; }
public void Edit_instanceServ(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, XmlWriter xmlWriter, double dtdVersion, string clientName) { // Process the service arguments ONServiceInfo lSInfo = new ONServiceInfo("Clas_1348178542592658Ser_3_Alias", PasajeroClassText.Edit_instanceServiceAlias, "Clas_1348178542592658_Alias", PasajeroClassText.ClassAlias); lSInfo.AddOIDArgument("p_thisPasajero", false, "Pasajero", "Clas_1348178542592658Ser_3Arg_1_Alias", PasajeroClassText.Edit_instance_P_thisPasajeroArgumentAlias); try { lSInfo.XML2ON(xmlReader, dtdVersion, true); } catch (Exception e) { throw new ONServiceArgumentsException(e, "Clas_1348178542592658_Alias", PasajeroClassText.ClassAlias, "Clas_1348178542592658Ser_3_Alias", PasajeroClassText.Edit_instanceServiceAlias); } PasajeroOid lP_thisPasajeroArg = (PasajeroOid) ((ONArgumentInfo) lSInfo.mArgumentList["p_thisPasajero"]).Value; // Create Context ONServiceContext lOnContext = new ONServiceContext(); lOnContext.OidAgent = agentOid; // Execute Service PasajeroInstance lInstance = null; try { ONFilterList lFilterList = new ONFilterList(); PasajeroInstance lThisInstance = new PasajeroInstance(lOnContext); if (lP_thisPasajeroArg != null) { lFilterList = new ONFilterList(); lFilterList.Add("HorizontalVisibility", new PasajeroHorizontalVisibility()); lThisInstance = lP_thisPasajeroArg.GetInstance(lOnContext, lFilterList); if (lThisInstance == null) throw new ONInstanceNotExistException(null, "Clas_1348178542592658_Alias", PasajeroClassText.ClassAlias); } using (PasajeroServer lServer = new PasajeroServer(lOnContext, lThisInstance)) { lServer.Edit_instanceServ(lP_thisPasajeroArg); lInstance = lServer.Instance; } ticket = lOnContext.GetTicket(dtdVersion, clientName); } catch (SecurityException) { throw new ONAccessAgentValidationException(null); } catch { throw; } // Write Oid if (dtdVersion >= 3.1) { if (lInstance != null) ON2XML(xmlWriter, lInstance.Oid, dtdVersion, ONXml.XMLTAG_OIDFIELD); } // Write Outbound Arguments xmlWriter.WriteStartElement("Arguments"); // Write Outbound Arguments xmlWriter.WriteEndElement(); // Arguments }
/// <summary> /// Checks if a determinate instance exists /// </summary> /// <param name="oid">OID to search the instance</param> /// <param name="onFilterList">Filters to theck</param> /// <returns>If exists</returns> public override bool Exist(ONOid oid, ONFilterList onFilterList) { if ((onFilterList == null) || (!onFilterList.InMemory)) { ONSqlCount lOnSql = new ONSqlCount(); // Create select and first table string lAlias = lOnSql.CreateAlias(TableName, null, ClassName); lOnSql.AddSelect(lAlias); // Fix instance InhFixInstance(lOnSql, null, null, oid); // Add filter formula if(onFilterList != null) onFilterList.FilterInData(lOnSql, this); // Execute return (Convert.ToInt32(Execute(lOnSql)) > 0); } else return (Search(oid, onFilterList, null) != null); }
public ONCollection QueryByFilter_LMD(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["LMD"] = GetFilter_LMD(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 } //Read Filter Navigation if (xmlReader.IsStartElement("NavFilt")) xmlReader.Skip(); // Create Context ONContext lOnContext = new ONContext(); lOnContext.OidAgent = agentOid; // 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; }
public virtual void InhFixInstance(ONSqlSelect onSql, ONPath onPath, ONPath processedOnPath, ONOid oid, bool isLinkedTo) { }
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> /// 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; }
/// <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) { }
/// <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> /// <param name="initialPath"> This parameter has the path of the instances reached in a For All</param> protected virtual void AddOrderCriteria(ONSqlSelect onSql, ONOrderCriteria comparer, ONOid startRowOid, int blockSize, ONPath initialPath) { }
/// <summary> /// Process the XML message that is a search of instances related with an instance. /// </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="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 ONCollection QueryByRelated(ref string ticket, ref ONOid agentOid, XmlReader xmlReader, ONDisplaySet displaySet, out ONOid startRowOID, out int blockSize, double dtdVersion, string clientName) { startRowOID = null; blockSize = -1; return null; }
/// <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); } }
/// <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> /// Executes the SQL statment over the Data Base connected /// </summary> /// <param name="onSql">This parameter has the current SQL statment</param> /// <param name="onFilterList">List of filters to check</param> /// <param name="comparer">This parameter has all the information refering to the order criteria to add to SQL statment</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 ExecuteSql(ONSql onSql, ONFilterList onFilterList, ONDisplaySet displaySet, ONOrderCriteria orderCriteria, ONOid startRowOid, int blockSize) { AeronaveCollection lQuery = null; bool lWithStartRow = (startRowOid != null).TypedValue; long lCount = -1; if (!lWithStartRow) lCount = 0; IDataReader lDataReader = null; ONSQLConnection lOnSQLConnection = null; try { lDataReader = Execute(onSql) as IDataReader; AeronaveInstance lInstance = null; AeronaveInstance lAntInstance = null; if (lDataReader != null) { object[] lColumns; if(displaySet == null) lColumns = new object[4]; else lColumns = new object[displaySet.ElementsInData]; lQuery = new AeronaveCollection(OnContext); bool lFoundStartRow = false; while (lDataReader.Read()) { lAntInstance = lInstance; // Read Columns lDataReader.GetValues(lColumns); // Read Instance int lIndex = 0; lInstance = LoadFacet(OnContext, displaySet, lColumns, ref lIndex); // Read related attributes if (displaySet != null) LoadRelated(OnContext, displaySet, lColumns, lIndex, lInstance); if (lCount >= 0) // Add the load instance { if ((onFilterList == null) || (!onFilterList.InMemory)) { // Add to the Instance list lQuery.Add(lInstance); lCount++; } else { ONSQLConnection lSQLConnectionOld = (ONSQLConnection) lInstance.OnContext.SqlConnection; // Set another connection because it is imposible to use // the same connection that is used in the DataReader if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; if (onFilterList.FilterInMemory(lInstance)) { // Add to the Instance list lQuery.Add(lInstance); lCount++; } lInstance.OnContext.SqlConnection = lSQLConnectionOld; } } else { if ((orderCriteria != null) && (orderCriteria.InMemory)) // Need to load for ordering in memory after loading { if (lAntInstance != null) { // Set another connection because it is imposible to use // the same connection that is used in the DataReader ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection; if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance); if (lCompare != 0) { if (lFoundStartRow) lCount = 1; else lQuery.Clear(); } // Restores the old connection lInstance.OnContext.SqlConnection = lOnSQLConnectionOld; } if ((onFilterList == null) || (!onFilterList.InMemory)) { // Add to the Instance list lQuery.Add(lInstance); } else { ONSQLConnection lSQLConnectionOld = (ONSQLConnection)lInstance.OnContext.SqlConnection; // Set another connection because it is imposible to use // the same connection that is used in the DataReader if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; if (onFilterList.FilterInMemory(lInstance)) { // Add to the Instance list lQuery.Add(lInstance); } else lCount--; lInstance.OnContext.SqlConnection = lSQLConnectionOld; } if (lInstance.Oid.Equals(startRowOid)) lFoundStartRow = true; } else if (lInstance.Oid.Equals(startRowOid)) // Search the start row lCount = 0; } // Stop loading if ((blockSize != 0) && (lCount > blockSize)) { if (orderCriteria == null) break; else { // Set another connection because it is imposible to use // the same connection that is used in the DataReader ONSQLConnection lOnSQLConnectionOld = lInstance.OnContext.SqlConnection as ONSQLConnection; if (lOnSQLConnection == null) lOnSQLConnection = GetConnection(); lInstance.OnContext.SqlConnection = lOnSQLConnection; int lCompare = orderCriteria.CompareSql(lInstance, lAntInstance); // Restores the old connection lInstance.OnContext.SqlConnection = lOnSQLConnectionOld; if (lCompare > 0) break; } } } } } catch (Exception e) { string ltraceItem = "Method: ExecuteSql, Component: AeronaveData"; if (e is ONSystemException) { ONSystemException lException = e as ONSystemException; lException.addTraceInformation(ltraceItem); throw lException; } throw new ONSystemException(e, ltraceItem); } finally { if (lOnSQLConnection != null) ONDBData.CloseConnection(lOnSQLConnection); if (lDataReader != null) { if (mSqlCommand != null) mSqlCommand.Cancel(); lDataReader.Close(); } Close(); if ((onFilterList != null) && (onFilterList.InMemory) && !lWithStartRow && (lCount <= blockSize)) lQuery.totalNumInstances = lQuery.Count; } return lQuery; }