protected override void OnReadResponse(ResponseStreamReader responseStreamReader) { var requestResponse = responseStreamReader.Read <TDocument>(); CurrentCursorId = requestResponse.CursorId.HasValue ? requestResponse.CursorId.Value : 0; Response.SetDocuments(requestResponse.ReturnedDocuments); }
protected override void OnRequestSent() { using (var responseStream = Connection.GetPipeStream()) { using (var responseReader = new ResponseStreamReader(responseStream)) { OnReadResponse(responseReader); } } }
protected virtual void OnReadResponse(ResponseStreamReader responseStreamReader) { var requestResponse = responseStreamReader.Read <TDocument>(); Response.SetDocuments(requestResponse.ReturnedDocuments); if (!requestResponse.CursorExists) { return; } var queryCmd = this as QueryDocumentsCommand <TDocument>; if (queryCmd != null) { var numOfDocsToReturn = queryCmd.NumberOfDocumentsToReturn; if (numOfDocsToReturn > 1 && numOfDocsToReturn == requestResponse.NumberOfReturnedDocuments) { //TODO: Kill cursor return; } } GetMoreCommand <TDocument> getMoreCommand = null; while (requestResponse.CursorExists) { if (getMoreCommand == null) { getMoreCommand = new GetMoreCommand <TDocument>(Connection, requestResponse.CursorId.Value, requestResponse.NumberOfReturnedDocuments.Value) { FullCollectionName = NodeName } } ; getMoreCommand.Execute(); Response.AddDocuments(getMoreCommand.Response.Documents); if (getMoreCommand.Response.NumberOfDocuments < 1 || !getMoreCommand.CursorHasMoreResult) { break; } } //Note that if a cursor is read until exhausted //(read until OP_QUERY or OP_GETMORE returns zero for the cursor id), //there is no need to kill the cursor. } }
/// <summary> /// Overrides, since there is no need to extract more documents /// via cursor as a normal response command. /// </summary> /// <param name="responseStreamReader"></param> protected override void OnReadResponse(ResponseStreamReader responseStreamReader) { var response = responseStreamReader.Read <SimoKeyValues>(); var document = response.ReturnedDocuments[0]; var commandWasOk = document.GetDouble("ok") == 1.0; if (commandWasOk) { return; } var errMsg = MongoDbErrorMessage.FromDocument(document); if (errMsg == null) { return; } throw new SimoCommandException(ExceptionMessages.DatabaseCommand_CommandWasNotOk, errMsg); }
/**************************************************************************/ private void ProcessCssPage() { HttpWebRequest req = null; HttpWebResponse res = null; string ResponseErrorCondition = null; Boolean IsAuthenticating = false; DebugMsg(string.Format("ProcessCssPage: {0}", "")); try { req = WebRequest.CreateHttp(this.DocUrl); req.Method = "GET"; req.Timeout = this.Timeout; req.KeepAlive = false; req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; this.PrepareRequestHttpHeaders(req: req); IsAuthenticating = this.AuthenticateRequest(req); MacroscopePreferencesManager.EnableHttpProxy(req); res = ( HttpWebResponse )req.GetResponse(); } catch (UriFormatException ex) { DebugMsg(string.Format("ProcessCssPage :: UriFormatException: {0}", ex.Message)); ResponseErrorCondition = ex.Message; } catch (TimeoutException ex) { DebugMsg(string.Format("ProcessCssPage :: TimeoutException: {0}", ex.Message)); ResponseErrorCondition = ex.Message; } catch (WebException ex) { DebugMsg(string.Format("ProcessCssPage :: WebException: {0}", ex.Message)); DebugMsg(string.Format("ProcessCssPage :: WebException: {0}", ex.Status)); DebugMsg(string.Format("ProcessCssPage :: WebException: {0}", ( int )ex.Status)); ResponseErrorCondition = ex.Status.ToString(); } if (res != null) { string RawData = ""; this.ProcessResponseHttpHeaders(req, res); if (IsAuthenticating) { this.VerifyOrPurgeCredential(); } // Get Response Body try { DebugMsg(string.Format("MIME TYPE: {0}", this.MimeType)); Stream ResponseStream = res.GetResponseStream(); StreamReader ResponseStreamReader; if (this.GetCharacterEncoding() != null) { ResponseStreamReader = new StreamReader(ResponseStream, this.GetCharacterEncoding()); } else { ResponseStreamReader = new StreamReader(ResponseStream); } RawData = ResponseStreamReader.ReadToEnd(); this.ContentLength = RawData.Length; // May need to find bytes length this.SetWasDownloaded(true); } catch (WebException ex) { DebugMsg(string.Format("WebException: {0}", ex.Message)); if (ex.Response != null) { this.SetStatusCode((( HttpWebResponse )ex.Response).StatusCode); } else { this.SetStatusCode(( HttpStatusCode )ex.Status); } RawData = ""; this.ContentLength = 0; } catch (Exception ex) { DebugMsg(string.Format("Exception: {0}", ex.Message)); this.SetStatusCode(HttpStatusCode.BadRequest); this.ContentLength = 0; } if (!string.IsNullOrEmpty(RawData)) { ExCSS.Parser ExCssParser = new ExCSS.Parser(); ExCSS.StyleSheet ExCssStylesheet = ExCssParser.Parse(RawData); this.ProcessCssOutlinks(ExCssStylesheet); } else { DebugMsg(string.Format("ProcessCssPage: ERROR: {0}", this.GetUrl())); } /** Custom Filters ------------------------------------------------- **/ if (!string.IsNullOrEmpty(RawData)) { if ( MacroscopePreferencesManager.GetCustomFiltersEnable() && MacroscopePreferencesManager.GetCustomFiltersApplyToCss()) { MacroscopeCustomFilters CustomFilter = this.DocCollection.GetJobMaster().GetCustomFilter(); if ((CustomFilter != null) && (CustomFilter.IsEnabled())) { this.ProcessGenericCustomFiltered( CustomFilter: CustomFilter, GenericText: RawData ); } } } /** Data Extractors ------------------------------------------------ **/ if (!string.IsNullOrEmpty(RawData)) { if ( MacroscopePreferencesManager.GetDataExtractorsEnable() && MacroscopePreferencesManager.GetDataExtractorsApplyToCss()) { this.ProcessGenericDataExtractors(GenericText: RawData); } } /** Title ---------------------------------------------------------- **/ { MatchCollection reMatches = Regex.Matches(this.DocUrl, "/([^/]+)$"); string DocumentTitle = null; foreach (Match match in reMatches) { if (match.Groups[1].Value.Length > 0) { DocumentTitle = match.Groups[1].Value.ToString(); break; } } if (DocumentTitle != null) { this.SetTitle(DocumentTitle, MacroscopeConstants.TextProcessingMode.NO_PROCESSING); DebugMsg(string.Format("TITLE: {0}", this.GetTitle())); } else { DebugMsg(string.Format("TITLE: {0}", "MISSING")); } } res.Close(); res.Dispose(); } if (ResponseErrorCondition != null) { this.ProcessErrorCondition(ResponseErrorCondition); } }