public static Task <IHttpResponse> QueryByContentIdAsync( [QueryParameter(CheckFileName = true, Name = ContentIdPropertyName)] Guid contentId, [OptionalQueryParameter] int?width, [OptionalQueryParameter] int?height, [OptionalQueryParameter] bool?fill, [OptionalQueryParameter] string renderer, BytesResponse onRawResponse, ImageRawResponse onImageResponse, NotFoundResponse onNotFound, UnauthorizedResponse onUnauthorized) { var response = EastFive.Api.Azure.Content.FindContentByContentIdAsync(contentId, (contentType, image) => { if (renderer.HasBlackSpace()) { if (renderer.ToLower() == "unzip") { using (var compressedStream = new MemoryStream(image)) using (var zipStream = new System.IO.Compression.ZipArchive(compressedStream, ZipArchiveMode.Read)) using (var resultStream = new MemoryStream()) { var zipFile = zipStream.Entries.First(); zipFile.Open().CopyTo(resultStream); var data = resultStream.ToArray(); return(onRawResponse(data, contentType: "application/object", filename: zipFile.Name)); //return request.CreateFileResponse(data, "application/object", filename: zipFile.Name); } } } //if (contentType.StartsWith("video", StringComparison.InvariantCultureIgnoreCase) && // (width.HasValue || height.HasValue || fill.HasValue)) //{ // var videoPreviewImage = default(System.Drawing.Image); // Properties.Resources.video_preview; // return request.CreateImageResponse(videoPreviewImage, // width: width, height: height, fill: fill, // filename: contentId.ToString("N")); //} return(onImageResponse(image, width: width, height: height, fill: fill, filename: contentId.ToString("N"), contentType: contentType)); //return request.CreateImageResponse(image, // width: width, height: height, fill: fill, // filename: contentId.ToString("N"), // contentType: contentType); }, () => onNotFound(), () => onUnauthorized()); return(response); }
/// <summary> Try to parse an Elasticsearch <see cref="ServerError"/> </summary> public static bool TryGetElasticsearchServerError(this BytesResponse response, out ServerError serverError) { serverError = null; if (response.Body == null || response.Body.Length == 0 || response.ResponseMimeType != RequestData.MimeType) { return(false); } var settings = response.ApiCall.ConnectionConfiguration; using var stream = settings.MemoryStreamFactory.Create(response.Body); return(ServerError.TryCreate(stream, out serverError)); }
public bool InsertItemList <T>(string indexName, List <T> data) { StringBuilder body = new StringBuilder(); foreach (T d in data) { body.Append("{\"create\":{\"_index\" : \"" + indexName + "\"}}\n"); body.Append(JsonConvert.SerializeObject(d)); body.Append("\n"); } BytesResponse res = conn.LowLevel.Bulk <BytesResponse>(PostData.String(body.ToString())); return(res.Success); }
public bool InsertItem <T>(string indexName, T data) { BytesResponse res = conn.LowLevel.Index <BytesResponse>(indexName, PostData.Serializable <T>(data)); return(res.Success); }