/// <summary> /// Performs alternatives command for given query. Returns most probable query (could be identical to given one). /// </summary> /// <param name="query">Search query.</param> /// <param name="cr">Parameter 'cr'. Please see <see href="http://www.clusterpoint.com/wiki/XML_Alternatives">Clusterpoint Wiki</see> for detailed description.</param> /// <param name="idif">Parameter 'idif'. Please see <see href="http://www.clusterpoint.com/wiki/XML_Alternatives">Clusterpoint Wiki</see> for detailed description.</param> /// <param name="h">Parameter 'cr'. Please see <see href="http://www.clusterpoint.com/wiki/XML_Alternatives">Clusterpoint Wiki</see> for detailed description.</param> /// <returns>Alternative query.</returns> public string alternatives(string query, float cr = -1, float idif = -1, float h = -1) { CPS_AlternativesRequest request = new CPS_AlternativesRequest(query, cr, idif, h); this.p_lastResponse = this.p_connection.sendRequest(request); CPS_AlternativesResponse response = (CPS_AlternativesResponse)this.p_lastResponse; Dictionary<string, Dictionary<string, CPS_AlternativesResponse.WordInfo>> words = response.getWords(); string res = ""; string xp_accum = ""; string prevxpath = null; foreach (KeyValuePair<string, Dictionary<string, CPS_AlternativesResponse.WordInfo>> pair in words) { string original = pair.Key; string xpath = ""; int pos = 0; if ((pos = original.IndexOf('/')) >= 0) { xpath = original.Substring(0, pos); original = original.Substring(pos + 1); } if (prevxpath != null && xpath != prevxpath) { res += Utils.CPS_Term(xp_accum, prevxpath); xp_accum = ""; } prevxpath = xpath; if (pair.Value.Count > 0) { foreach (KeyValuePair<string, CPS_AlternativesResponse.WordInfo> apair in pair.Value) { xp_accum += (xp_accum == "" ? "" : " ") + apair.Key; break; } } else { xp_accum += (xp_accum == "" ? "" : " ") + original; } } if (xp_accum.Length > 0) res += (res == "" ? "" : " ") + Utils.CPS_Term(xp_accum, prevxpath == null ? "" : prevxpath); return res; }
/// <summary> /// Performs a search command. Returns the documents found in a Dictionary with document IDs as keys and document contents as values. Returned document type depends on returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="query">Query string. See <see cref="CPS.CPS_SearchRequest.setQuery(string)"/> for more info on best practices.</param> /// <param name="offset">Number of documents to skip before including them in results.</param> /// <param name="docs">Maximum document count to return.</param> /// <param name="list">Dictionary with tag xpaths as keys and list options (yes | no | snippet | highlight) as values.</param> /// <param name="ordering">Multiple ordering rules. You can use <see cref="Utils"/> class function to generate these rules.</param> /// <param name="returnType">Defines used return type.</param> /// <param name="stemLang">Defines temming language.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object search(string query, int offset, int docs, Dictionary<string, string> list, List<string> ordering, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS, string stemLang = "") { CPS_SearchRequest request = new CPS_SearchRequest(query, offset, docs, list); if (ordering != null) request.setOrdering(ordering); if (stemLang.Length > 0) request.setStemLang(stemLang); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_SearchResponse)this.p_lastResponse).getDocuments(returnType); }
/// <summary> /// Gets returned documents. /// </summary> /// <param name="type">Defines used return type.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object getDocuments(CPS_Response.DOC_TYPE type = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { return base.getRawDocuments(type); }
/// <summary> /// Retrieves single document from Clusterpoint Server storage. Returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns CPS_SimpleXML. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns XmlElement. /// </summary> /// <param name="id">Document ID.</param> /// <param name="returnType">Defines used return type.</param> /// <returns>Document as CPS_SimpleXml or XmlElement.</returns> public Object retrieveSingle(string id, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { CPS_RetrieveRequest request = new CPS_RetrieveRequest(id); this.p_lastResponse = this.p_connection.sendRequest(request); CPS_LookupResponse response = (CPS_LookupResponse)this.p_lastResponse; if (response.getDocuments() == null) return null; if (returnType == CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { Dictionary<string, XmlElement> ret1 = (Dictionary<string, XmlElement>)(response.getDocuments(returnType)); foreach (KeyValuePair<string, XmlElement> pair in ret1) return pair.Value; } if (returnType == CPS_Response.DOC_TYPE.DOC_TYPE_ARRAY) { return null; } if (returnType == CPS_Response.DOC_TYPE.DOC_TYPE_SIMPLEXML) { Dictionary<string, CPS_SimpleXML> ret3 = (Dictionary<string, CPS_SimpleXML>)(response.getDocuments(returnType)); foreach (KeyValuePair<string, CPS_SimpleXML> pair in ret3) return pair.Value; } return null; }
/// <summary> /// Performs status command. /// </summary> /// <returns>Status information.</returns> public CPS_SimpleXML status() { CPS_StatusRequest request = new CPS_StatusRequest(); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_StatusResponse)this.p_lastResponse).getStatus(); }
/// <summary> /// Begins new transaction. /// </summary> /// <returns>Always true, in case of error throws exception.</returns> public bool beginTransaction() { CPS_BeginTransactionRequest request = new CPS_BeginTransactionRequest(); this.p_lastResponse = this.p_connection.sendRequest(request); return true; }
/// <summary> /// Creates new CPS_Simple class instance. /// </summary> /// <param name="connection">CPS_Connection class instance.</param> public CPS_Simple(CPS_Connection connection) { this.p_connection = connection; this.p_lastResponse = null; }
/// <summary> /// Searches for similar documents by given text. Returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="text">Text to search similar documents to.</param> /// <param name="len">Number of keywords to extract.</param> /// <param name="quota">Minimum number of keywords to match.</param> /// <param name="offset">Number of document to skip before including them in response.</param> /// <param name="docs">Number of document to return.</param> /// <param name="returnType">Defines used return type.</param> /// <param name="query">Additional filtering query.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object similarText(string text, int len, int quota, int offset = -1, int docs = -1, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS, string query = "") { CPS_SimilarTextRequest request = new CPS_SimilarTextRequest(text, len, quota, offset, docs, query); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_SearchResponse)this.p_lastResponse).getDocuments(returnType); }
/// <summary> /// Performs list-paths command. /// </summary> /// <returns>List of available paths.</returns> public List<string> listPaths() { CPS_ListPathsRequest request = new CPS_ListPathsRequest(); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_ListPathsResponse)this.p_lastResponse).getPaths(); }
/// <summary> /// Performs list-words command by a given wildcard. /// </summary> /// <param name="wildcard">Words wildcard.</param> /// <returns>Dictionary of listed words.</returns> public Dictionary<string, Dictionary<string, CPS_ListWordsResponse.WordInfo>> listWords(string wildcard) { CPS_ListWordsRequest request = new CPS_ListWordsRequest(wildcard); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_ListWordsResponse)this.p_lastResponse).getWords(); }
/// <summary> /// Performs list-last command. Returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="list">Dictionary of xpaths as keys and list options (yes | no | snippet | highlight) as values.</param> /// <param name="offset">Defines number of document to skip before including in search results.</param> /// <param name="docs">Defines number of documents to return.</param> /// <param name="returnType">Defines used return type.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object listLast(Dictionary<string, string> list = null, int offset = -1, int docs = -1, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { CPS_ListLastRequest request = new CPS_ListLastRequest(list, offset, docs); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_LookupResponse)this.p_lastResponse).getDocuments(returnType); }
/// <summary> /// Performs list-facets command for multiple facet paths. /// </summary> /// <param name="paths">Facet paths.</param> /// <returns>List of available facets.</returns> public Dictionary<string, List<string>> listFacets(List<string> paths) { CPS_ListFacetsRequest request = new CPS_ListFacetsRequest(paths); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_ListFacetsResponse)this.p_lastResponse).getFacets(); }
/// <summary> /// Deletes multiple documents from Clusterpoint Server storage. /// </summary> /// <param name="ids">List of document IDs.</param> /// <returns>List of document IDs deleted.</returns> public List<string> delete(List<string> ids) { CPS_DeleteRequest request = new CPS_DeleteRequest(ids); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_ModifyResponse)this.p_lastResponse).getModifiedIds(); }
/// <summary> /// Performs search-delete command. /// </summary> /// <param name="query">Search query.</param> /// <returns>Number of documents deleted.</returns> public int searchDelete(string query) { CPS_SearchDeleteRequest request = new CPS_SearchDeleteRequest(query); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_SearchDeleteResponse)this.p_lastResponse).getHits(); }
/// <summary> /// Performs a partial-xreplace command in Clusterpoint Server storage. /// </summary> /// <param name="ids">List of document IDs.</param> /// <param name="operations">List of operations as <see cref="CPS_PRX_Operation"/> to perform.</param> /// <returns>List of document IDs partial-xreplace'd.</returns> public List<string> partialXReplace(List<string> ids, List<CPS_PRX_Operation> operations) { CPS_PartialXRequest request = new CPS_PartialXRequest(ids, operations); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_ModifyResponse)this.p_lastResponse).getModifiedIds(); }
/// <summary> /// Retrieves modification history of the document by revision ID. Returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="id">Document ID.</param> /// <param name="returnDocs">Set to true to return document content (subject to license conditions).</param> /// <param name="returnType">Defines used return type.</param> /// <returns>Revisions as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object showHistory(string id, bool returnDocs = false, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { CPS_ShowHistoryRequest request = new CPS_ShowHistoryRequest(id, returnDocs); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_LookupResponse)this.p_lastResponse).getDocuments(returnType); }
/// <summary> /// Replaces multiple documents in Clusterpoint Server storage. /// </summary> /// <param name="documents">Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement> where key is document ID.</param> /// <returns>List of document IDs replaced.</returns> public List<string> replaceMultiple(Object documents) { CPS_ReplaceRequest request = new CPS_ReplaceRequest(documents); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_ModifyResponse)this.p_lastResponse).getModifiedIds(); }
/// <summary> /// Performs a search command with SQL query. Returns the documents found in a Dictionary with document IDs as keys and document contents as values. Returned document type depends on returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="sql_query">The SQL query string.</param> /// <param name="returnType">Defines used return type.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object sql_search(string sql_query, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { CPS_SQLSearchRequest request = new CPS_SQLSearchRequest(sql_query); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_SearchResponse)this.p_lastResponse).getDocuments(returnType); }
/// <summary> /// Performs retrieve-last command. Returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="offset">Defines number of document to skip before including in search results.</param> /// <param name="docs">Defines number of documents to return.</param> /// <param name="returnType">Defines used return type.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object retrieveLast(int offset = -1, int docs = -1, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { CPS_RetrieveLastRequest request = new CPS_RetrieveLastRequest(offset, docs); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_LookupResponse)this.p_lastResponse).getDocuments(returnType); }
/// <summary> /// Updates single document in Clusterpoint Server storage. /// </summary> /// <param name="id">Document ID.</param> /// <param name="document">Document as CPS_SimpleXML or XmlElement object.</param> /// <returns>List of document IDs updated.</returns> public List<string> updateSingle(string id, Object document) { CPS_UpdateRequest request = new CPS_UpdateRequest(id, document); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_ModifyResponse)this.p_lastResponse).getModifiedIds(); }
/// <summary> /// Retrieves multiple documents from Clusterpoint Server storage. returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, CPS_SimpleXML>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, XmlElement>. /// </summary> /// <param name="ids">List of document IDs.</param> /// <param name="returnType">Defines used return type.</param> /// <returns>Documents as Dictionary<string, CPS_SimpleXML> or Dictionary<string, XmlElement>.</returns> public Object retrieveMultiple(List<string> ids, CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { CPS_RetrieveRequest request = new CPS_RetrieveRequest(ids); this.p_lastResponse = this.p_connection.sendRequest(request); return ((CPS_LookupResponse)this.p_lastResponse).getDocuments(returnType); }
/// <summary> /// Sends request to Clusterpoint Server. Returned CPS_Response should be casted to command-specific response class. /// </summary> /// <param name="request">Request to send.</param> /// <returns>Command-specific CPS_Response object instance.</returns> public CPS_Response sendRequest(CPS_Request request) { bool firstSend = true; string previousRenderedStorage = ""; string requestXml = ""; byte[] requestBytes = null; string rawResponse = ""; bool quit = true; if (this.p_connectionSwitcher != null) this.p_connectionSwitcher.newRequest(request); do { CPS_Exception e = null; if (this.p_connectionSwitcher != null) this.p_connectionString = this.parseConnectionString(this.p_connectionSwitcher.getConnectionString(ref this.p_storageName)); try { if (this.p_transactionId != null) request.setParam("transaction_id", this.p_transactionId); if (firstSend || previousRenderedStorage != this.p_storageName) { requestXml = this.renderRequest(request); requestBytes = Encoding.UTF8.GetBytes(requestXml); previousRenderedStorage = this.p_storageName; if (this.p_debug) { FileStream fs = new FileStream("request.xml", FileMode.Create); fs.Write(requestBytes, 0, requestBytes.Length); fs.Close(); } } firstSend = false; this.p_lastRequestSize = requestXml.Length; this.p_lastNetworkDuration = 0; Stopwatch totTimer = new Stopwatch(); Stopwatch netTimer = new Stopwatch(); totTimer.Start(); if (this.p_connectionString.Scheme.ToLower() == "http") { // TODO: implement HMAC support when server side supports it HttpWebRequest webreq = (HttpWebRequest)HttpWebRequest.Create(this.p_connectionString.OriginalString); webreq.UserAgent = this.p_applicationId; webreq.Method = "POST"; webreq.ContentType = "application/x-www-form-urlencoded"; webreq.ContentLength = requestBytes.Length; webreq.Headers["Recipient"] = this.p_storageName; webreq.Proxy = null; Stream webreq_data; try { webreq_data = webreq.GetRequestStream(); } catch (Exception) { throw new CPS_Exception("Invalid connection string").SetCode(CPS_Exception.ERROR_CODE.INVALID_CONNECTION_STRING); } netTimer.Start(); webreq_data.Write(requestBytes, 0, requestBytes.Length); webreq_data.Close(); netTimer.Stop(); HttpWebResponse webrsp; try { webrsp = (HttpWebResponse)webreq.GetResponse(); } catch (Exception) { throw new CPS_Exception("Invalid connection string").SetCode(CPS_Exception.ERROR_CODE.INVALID_CONNECTION_STRING); } Stream webrsp_data = webrsp.GetResponseStream(); StreamReader webrsp_reader = new StreamReader(webrsp_data); netTimer.Start(); rawResponse = webrsp_reader.ReadToEnd(); webrsp_reader.Close(); netTimer.Stop(); } if (this.p_connectionString.Scheme.ToLower() == "tcp" || this.p_connectionString.Scheme.ToLower() == "tcps") { int port = this.p_connectionString.Port; if (port <= 0) port = 5550; TcpClient tcp; try { netTimer.Start(); tcp = new TcpClient(this.p_connectionString.Host, port); netTimer.Stop(); } catch (SocketException) { netTimer.Stop(); throw new CPS_Exception("Cannot connect to specified server").SetCode(CPS_Exception.ERROR_CODE.SOCKET_ERROR); } catch (Exception) // all other cases { netTimer.Stop(); throw new CPS_Exception("Invalid connection string").SetCode(CPS_Exception.ERROR_CODE.INVALID_CONNECTION_STRING); } NetworkStream net = tcp.GetStream(); System.IO.Stream strm = net; if (this.p_connectionString.Scheme.ToLower() == "tcps") { System.Net.Security.SslStream ssl = new System.Net.Security.SslStream(strm, false, new System.Net.Security.RemoteCertificateValidationCallback(ConnectionServerValidationCallback), null); try { ssl.AuthenticateAsClient(this.p_connectionString.Host); } catch (Exception) { throw new CPS_Exception("Error establishing SSL connection").SetCode(CPS_Exception.ERROR_CODE.SSL_HANDSHAKE); } strm = ssl; } Protobuf pb = new Protobuf(); pb.CreateField(1, Protobuf.WireType.LengthDelimited, requestBytes); pb.CreateStringField(2, this.p_storageName); if (this.p_hmacUserKey != null && this.p_hmacSignKey != null) { string characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; char[] tokenchars = new char[16]; for (int i = 0; i < 16; i++) tokenchars[i] = characters[this.p_random.Next(characters.Length)]; string token = new string(tokenchars); System.DateTime epoch = new System.DateTime(1970, 1, 1, 0, 0, 0, 0).ToUniversalTime(); System.DateTime validity = System.DateTime.Now.ToUniversalTime(); validity.AddSeconds(10); System.TimeSpan dtdiff = validity - epoch; UInt64 unixvalidity = (UInt64)dtdiff.TotalSeconds; pb.CreateStringField(14, token); pb.CreateFixed64Field(15, unixvalidity); pb.CreateStringField(16, this.p_hmacUserKey); pb.CreateStringField(17, CPS_Hasher.SHA1(CPS_Hasher.SHA1(requestXml) + token + unixvalidity + this.p_hmacSignKey)); pb.CreateStringField(18, CPS_Hasher.SHA1_HMAC(this.p_hmacSignKey, requestXml + token + unixvalidity)); } MemoryStream ms = new MemoryStream(); Protobuf_Streamer pbs = new Protobuf_Streamer(ms); pb.WriteToStream(pbs); byte[] header = CPS_Length2Header((int)(ms.Length)); netTimer.Start(); try { strm.Write(header, 0, 8); strm.Write(ms.GetBuffer(), 0, (int)(ms.Length)); } catch (Exception) { netTimer.Stop(); throw new CPS_Exception("Error sending request").SetCode(CPS_Exception.ERROR_CODE.SOCKET_ERROR); } strm.Flush(); try { strm.Read(header, 0, 8); netTimer.Stop(); } catch (Exception) { netTimer.Stop(); throw new CPS_Exception("Error receiving response").SetCode(CPS_Exception.ERROR_CODE.SOCKET_ERROR); } int len = CPS_Header2Length(header); if (len <= 0) throw new CPS_Exception("Invalid response from server").SetCode(CPS_Exception.ERROR_CODE.INVALID_RESPONSE); byte[] recv = new byte[len]; int got = 0; netTimer.Start(); while (got < len) { int br = 0; try { br = strm.Read(recv, got, len - got); if (br == 0) { netTimer.Stop(); throw new CPS_Exception("Server unexpectedly closed connection").SetCode(CPS_Exception.ERROR_CODE.SOCKET_ERROR); } } catch (Exception) { netTimer.Stop(); throw new CPS_Exception("Error receiving response").SetCode(CPS_Exception.ERROR_CODE.SOCKET_ERROR); } got += br; } strm.Close(); netTimer.Stop(); ms = new MemoryStream(recv); pbs = new Protobuf_Streamer(ms); pb = new Protobuf(pbs); rawResponse = pb.GetStringField(1); } totTimer.Stop(); this.p_lastRequestDuration = totTimer.ElapsedMilliseconds; this.p_lastRequestDuration = this.p_lastRequestDuration / 1000.0; this.p_lastNetworkDuration = netTimer.ElapsedMilliseconds; this.p_lastNetworkDuration = this.p_lastNetworkDuration / 1000.0; this.p_lastResponseSize = rawResponse.Length; if (this.p_debug) { FileStream fs = new FileStream("response.xml", FileMode.Create); byte[] responseBytes = Encoding.UTF8.GetBytes(rawResponse); fs.Write(responseBytes, 0, responseBytes.Length); fs.Close(); } } catch (CPS_Exception e_) { e = e_; } if (this.p_connectionSwitcher != null) quit = !this.p_connectionSwitcher.shouldRetry(rawResponse, e); else quit = true; if (quit && e != null) throw e; } while (!quit); switch (request.getCommand()) { case "search": case "similar": return new CPS_SearchResponse(this, request, rawResponse); case "update": case "delete": case "replace": case "partial-replace": case "partial-xreplace": case "insert": case "create-alert": case "update-alerts": case "delete-alerts": return new CPS_ModifyResponse(this, request, rawResponse); case "alternatives": return new CPS_AlternativesResponse(this, request, rawResponse); case "list-words": return new CPS_ListWordsResponse(this, request, rawResponse); case "status": return new CPS_StatusResponse(this, request, rawResponse); case "retrieve": case "list-last": case "list-first": case "retrieve-last": case "retrive-first": case "lookup": case "show-history": return new CPS_LookupResponse(this, request, rawResponse); case "search-delete": return new CPS_SearchDeleteResponse(this, request, rawResponse); case "list-paths": return new CPS_ListPathsResponse(this, request, rawResponse); case "list-facets": return new CPS_ListFacetsResponse(this, request, rawResponse); case "list-alerts": return new CPS_Response(this, request, rawResponse); // TODO: change this !!! default: CPS_Response ret = new CPS_Response(this, request, rawResponse); // This is explicitly processed here, because of .NET limitations. PHP API changes this directly from CPS_Response constructor. if (request.getCommand() == "begin-transaction" || request.getCommand() == "commit-transaction" || request.getCommand() == "rollback-transaction") this.p_transactionId = ret.getTransactionId(); return ret; } }
/// <summary> /// Returns aggregated data from the response, returned type depends on passed returnType parameter. /// If returnType is DOC_TYPE_SIMPLEXML, returns Dictionary<string, List<CPS_SimpleXML>>. /// If returnType is DOC_TYPE_ARRAY, returns null - not supported yet. /// If returnType is DOC_TYPE_STDCLASS, returns Dictionary<string, List>XmlElement>>. /// </summary> /// <param name="returnType">Defines used return type.</param> /// <returns>Aggregate data as Dictionary<string, List<CPS_SimpleXML>> or Dictionary<string, List<XmlElement>>.</returns> public Object getAggregate(CPS_Response.DOC_TYPE returnType = CPS_Response.DOC_TYPE.DOC_TYPE_STDCLASS) { return base.getRawAggregate(returnType); }