コード例 #1
0
        public static Client.EvaluationFile ConvertEvaluationFile(EvaluationFile source)
        {
            var target = new Client.EvaluationFile
            {
                FileName    = source.FileName,
                Sha256      = source.Sha256,
                Status      = ConvertEvaluationStatus(source.Status),
                StatusDate  = source.StatusDate,
                IsMalicious = source.Malicious,
                Message     = source.Message,
            };

            return(target);
        }
        /// <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);
            }
        }