private static async Task GetFileBySha256Async(GetFileBySha256Options options, CancellationToken cancellationToken = default) { CLIENT.IEvaluationService evaluationService = CreateService(options); CLIENT.EvaluationFile evaluationFile = await evaluationService.GetFileBySha256(options.Hash, cancellationToken); WriteOutput(evaluationFile, options.OutputFormat, Console.Out); }
/// <summary> /// Gets an evaluation file with a specified SHA-256 hash. /// </summary> /// <param name="hash">the SHA-256 hash of the file</param> /// <param name="cancellationToken">the cancellation token</param> /// <returns>the task returning the evaluation file</returns> /// <exception cref="ArgumentNullException">a required argument is null</exception> /// <exception cref="EvaluationFileNotFoundException">an evaluation file with the specified hash does not exist</exception> public async Task <EvaluationFile> GetFileBySha256( string hash, CancellationToken cancellationToken = default) { if (hash == null) { throw new ArgumentNullException(nameof(hash)); } try { API.EvaluationFile serverEvaluationFile = await _client.FileBySha256Async(hash, cancellationToken); EvaluationFile evaluationFile = API.Conversion.ConvertEvaluationFile(serverEvaluationFile); return(evaluationFile); } catch (API.ApiClientException ex) when(ex.StatusCode == (int)HttpStatusCode.NotFound) { throw new EvaluationFileNotFoundException($"An evaluation file with the specified SHA-256 hash `{hash}` was not found.", ex); } catch (API.ApiClientException ex) when(ex.StatusCode == (int)HttpStatusCode.Unauthorized) { throw new AuthenticationException($"The request could not be authenticated.", ex); } catch (API.ApiClientException ex) when(ex.StatusCode == (int)HttpStatusCode.Forbidden) { throw new AuthorizationException($"The requested operation could not be authorized.", ex); } catch (API.ApiClientException ex) when(ex.StatusCode == (int)HttpStatusCode.InternalServerError) { throw new EvaluationServiceException($"An internal server error has occurred.", ex); } catch (API.ApiClientException ex) { throw new EvaluationServiceException($"An unexpected result was received.", ex); } }