public BlittableJsonReaderObject ParseJson(string json) { using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json))) { return(Context.ReadForMemory(stream, "json")); } }
private static object ConvertType(JsonOperationContext context, IFieldable field, FieldType fieldType, IState state) { if (field.IsBinary) { ThrowBinaryValuesNotSupported(); } var stringValue = field.StringValue(state); if (stringValue == Constants.Documents.Indexing.Fields.NullValue || stringValue == null) { return(null); } if (stringValue == Constants.Documents.Indexing.Fields.EmptyString || stringValue == string.Empty) { return(string.Empty); } if (fieldType.IsJson == false) { return(stringValue); } var bytes = Encodings.Utf8.GetBytes(stringValue); var ms = new MemoryStream(bytes); return(context.ReadForMemory(ms, field.Name)); }
private int SupervisorReadResponseAndGetVersion(JsonOperationContext ctx, BlittableJsonTextWriter writer, Stream stream, string url) { using (var responseJson = ctx.ReadForMemory(stream, _readStatusUpdateDebugString + "/Read-Handshake-Response")) { var headerResponse = JsonDeserializationServer.TcpConnectionHeaderResponse(responseJson); switch (headerResponse.Status) { case TcpConnectionStatus.Ok: return(headerResponse.Version); case TcpConnectionStatus.AuthorizationFailed: throw new AuthorizationException( $"Node with ClusterTag = {ClusterTag} replied to initial handshake with authorization failure {headerResponse.Message}"); case TcpConnectionStatus.TcpVersionMismatch: if (headerResponse.Version != TcpNegotiation.OutOfRangeStatus) { return(headerResponse.Version); } //Kindly request the server to drop the connection WriteOperationHeaderToRemote(writer, headerResponse.Version, drop: true); throw new InvalidOperationException($"Node with ClusterTag = {ClusterTag} replied to initial handshake with mismatching tcp version {headerResponse.Message}"); default: throw new InvalidOperationException($"{url} replied with unknown status {headerResponse.Status}, message:{headerResponse.Message}"); } } }
private static dynamic GetDocumentFromString(string json, JsonOperationContext context) { var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)); var reader = context.ReadForMemory(ms, "doc"); return(new DynamicBlittableJson(new Document { Data = reader })); }
private MoreLikeThisQueryServerSide GetMoreLikeThisQuery(JsonOperationContext context, HttpMethod method) { if (method == HttpMethod.Get) { //MoreLikeThisQueryServerSide.Create(HttpContext, GetPageSize(), context); throw new NotImplementedException(); } var json = context.ReadForMemory(RequestBodyStream(), "morelikethis/query"); return(MoreLikeThisQueryServerSide.Create(json)); }
private async Task <(FacetQueryServerSide FacetQuery, long?FacetsEtag)> GetFacetQuery(JsonOperationContext context, HttpMethod method) { if (method == HttpMethod.Get) { return(await FacetQueryServerSide.Create(HttpContext, GetStart(), GetPageSize(), context)); } var json = context.ReadForMemory(RequestBodyStream(), "facet/query"); // read from cache here return(FacetQueryServerSide.Create(json, context, Database.QueryMetadataCache)); }
private SuggestionQueryServerSide GetSuggestionQuery(JsonOperationContext context, HttpMethod method) { if (method == HttpMethod.Get) { throw new NotImplementedException("RavenDB-8882"); } var indexQueryJson = context.ReadForMemory(RequestBodyStream(), "suggestion/query"); // read from cache here return(SuggestionQueryServerSide.Create(indexQueryJson)); }
private SuggestionQueryServerSide GetSuggestionQuery(JsonOperationContext context, HttpMethod method) { if (method == HttpMethod.Get) { //MoreLikeThisQueryServerSide.Create(HttpContext, GetPageSize(), context); throw new NotImplementedException(); } var indexQueryJson = context.ReadForMemory(RequestBodyStream(), "suggestion/query"); // read from cache here return(SuggestionQueryServerSide.Create(indexQueryJson)); }
public async Task <BlittableJsonReaderObject> InvokeAndReadObjectAsync(RouteInformation route, JsonOperationContext context, Dictionary <string, StringValues> parameters = null) { var response = await InvokeAsync(route, parameters); try { return(context.ReadForMemory(response.Body, $"read/local endpoint/{route.Path}")); } catch (InvalidStartOfObjectException e) { //precaution, ideally this exception should never be thrown throw new InvalidOperationException("Expected to find a blittable object as a result of debug endpoint, but found something else (see inner exception for details). This should be investigated as all RavenDB endpoints are supposed to return an object.", e); } }
private static object ConvertType(JsonOperationContext context, IFieldable field, FieldType fieldType, IState state) { if (field.IsBinary) { ThrowBinaryValuesNotSupported(); } var stringValue = field.StringValue(state); if (stringValue == null) { return(null); } if (stringValue == string.Empty) { return(string.Empty); } if (field.IsTokenized == false) { // NULL_VALUE and EMPTY_STRING fields aren't tokenized // this will prevent converting fields with a "NULL_VALUE" string to null switch (stringValue) { case Constants.Documents.Indexing.Fields.NullValue: return(null); case Constants.Documents.Indexing.Fields.EmptyString: return(string.Empty); } } if (fieldType.IsJson == false) { return(stringValue); } return(context.ReadForMemory(stringValue, field.Name)); }
private MoreLikeThisQueryServerSide GetMoreLikeThisQuery(JsonOperationContext context) { var json = context.ReadForMemory(RequestBodyStream(), "morelikethis/query"); return(MoreLikeThisQueryServerSide.Create(json)); }
private void ReadServerResponses(Stream stream) { bool completed = false; using (var context = new JsonOperationContext(4096, 1024)) { do { using (var response = context.ReadForMemory(stream, "bulk/insert/message")) { if (response == null) { // we've got disconnection without receiving "Completed" message ReportProgress("Bulk insert aborted because connection with server was disrupted before acknowledging completion"); throw new InvalidOperationException("Connection with server was disrupted before acknowledging completion"); } string responseType; //TODO: make this strong typed? if (response.TryGet("Type", out responseType)) { string msg; switch (responseType) { case "Error": string exceptionString; if (response.TryGet("Exception", out exceptionString) == false) { throw new InvalidOperationException("Invalid response from server " + (response.ToString() ?? "null")); } msg = $"Bulk insert aborted because of server-side exception. Exception information from server : {Environment.NewLine} {exceptionString}"; ReportProgress(msg); throw new BulkInsertAbortedExeption(msg); case "Processing": // do nothing. this is hearbeat while server is really busy break; case "Waiting": if (_isThrottling) { _isThrottling = false; _throttlingEvent.Set(); } break; case "Processed": { long processedSize; if (response.TryGet("Size", out processedSize) == false) { throw new InvalidOperationException("Invalid Processed response from server " + (response.ToString() ?? "null")); } if (_sentAccumulator - processedSize > _maxDiffSizeBeforeThrottling) { if (_isThrottling == false) { _throttlingEvent.Reset(); _isThrottling = true; } } else { if (_isThrottling) { _isThrottling = false; _throttlingEvent.Set(); } } } break; case "Completed": ReportProgress("Connection closed successfully"); completed = true; break; default: { msg = "Received unexpected message from a server : " + responseType; ReportProgress(msg); throw new BulkInsertProtocolViolationExeption(msg); } } } _lastHeartbeat = SystemTime.UtcNow; } } while (completed == false); } }