public void RegisterWlItem(RegisterWlItemExtended registerWlItemExtended) { var data = new RegisterWlItemData { ExternalId = registerWlItemExtended.ExternalId, DisplayName = registerWlItemExtended.DisplayName, FullName = registerWlItemExtended.FullName, Note = registerWlItemExtended.Note, WatchlistExternalIds = registerWlItemExtended.WatchlistExternalIds }; registerWlItemExtended.PhotoFiles.ToList().ForEach(pathToPhotoFile => data.ImageData.Add(new RegisterWlItemImageData { Data = File.ReadAllBytes(pathToPhotoFile), MIME = pathToPhotoFile.ToLower().EndsWith($".{Constants.PNG}") ? Constants.PNG_MIME_TYPE : Constants.JPEG_MIME_TYPE })); Repository.Register(data); Log.LogInformation($"WlItem registered. [{data.ExternalId}]"); }
/// <param name="payload">JSON with WatchlistItem ExternalId (if item does not exist then it will be created), </br> /// ImageData with base64 encoded images of single face with MIME type, <br> /// Watchlist ExternalIds which will be linked to WatchlistItem (if watchlists do not exists then they will be created with default threshold).</param> /// <returns>NoContent</returns> /// <exception cref="SwaggerException">A server side error occurred.</exception> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async System.Threading.Tasks.Task <FileResponse> RegisterAsync(RegisterWlItemData payload, System.Threading.CancellationToken cancellationToken) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/rpc/WatchlistItems/Register"); var client_ = _httpClient; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(payload, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json")); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "204" || status_ == "206") { var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false); var fileResponse_ = new FileResponse((int)response_.StatusCode, headers_, responseStream_, null, response_); client_ = null; response_ = null; // response and client are disposed by FileResponse return(fileResponse_); } else if (status_ != "200" && status_ != "204") { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null); } return(default(FileResponse)); } finally { if (response_ != null) { response_.Dispose(); } } } } finally { } }
/// <param name="payload">JSON with WatchlistItem ExternalId (if item does not exist then it will be created), </br> /// ImageData with base64 encoded images of single face with MIME type, <br> /// Watchlist ExternalIds which will be linked to WatchlistItem (if watchlists do not exists then they will be created with default threshold).</param> /// <returns>NoContent</returns> /// <exception cref="SwaggerException">A server side error occurred.</exception> public System.Threading.Tasks.Task <FileResponse> RegisterAsync(RegisterWlItemData payload) { return(RegisterAsync(payload, System.Threading.CancellationToken.None)); }