예제 #1
0
        public async Task <ArtifactPayload?> Get(ArtifactId id, CancellationToken token = default)
        {
            id.VerifyNotNull(nameof(id));

            var actorKey = new ActorKey((string)id);

            _logger.LogTrace($"{nameof(Get)}: actorKey={actorKey}, id={id.Id}");

            IArtifactPayloadActor actor = _actorHost !.GetActor <IArtifactPayloadActor>(actorKey);

            return(await actor.Get(token));
        }
예제 #2
0
        public async Task <ArtifactPayload?> Get(ArtifactId id, CancellationToken token = default)
        {
            id.VerifyNotNull(nameof(id));

            byte[] fileData = await _dataLakeStore.Read(RealPath(id), token : token);

            if (fileData == null || fileData.Length == 0)
            {
                return(null);
            }

            return(fileData.ToArtifactPayload(id));
        }
예제 #3
0
        public async Task <bool> Delete(ArtifactId id, CancellationToken token = default)
        {
            id.VerifyNotNull(nameof(id));
            _logger.LogTrace($"{nameof(Delete)}: Id={id}");

            HttpResponseMessage response = await _httpClient.DeleteAsync($"api/artifact/{id.ToBase64()}", token);

            return(response.StatusCode switch
            {
                HttpStatusCode.OK => true,
                HttpStatusCode.NotFound => false,

                _ => throw new HttpRequestException($"Invalid http code={response.StatusCode}"),
            });
예제 #4
0
        public static ArtifactPayload ToArtifactPayload(this byte[] subject, ArtifactId articleId)
        {
            subject.VerifyAssert(x => x?.Length > 0, $"{nameof(subject)} is empty");
            articleId.VerifyNotNull(nameof(articleId));

            var payload = new ArtifactPayload
            {
                Id             = (string)articleId,
                PackagePayload = Convert.ToBase64String(subject),
                Hash           = Convert.ToBase64String(MD5.Create().ComputeHash(subject)),
            };

            payload.Verify();
            return(payload);
        }
예제 #5
0
        public async Task <ArtifactPayload?> Get(ArtifactId id, CancellationToken token = default)
        {
            id.VerifyNotNull(nameof(id));
            _logger.LogTrace($"{nameof(Get)}: Id={id}");

            try
            {
                return(await _httpClient.GetFromJsonAsync <ArtifactPayload?>($"api/artifact/{id.ToBase64()}", token));
            }
            catch (HttpRequestException ex)
            {
                _logger.LogError(ex, $"{nameof(Get)}: id={id} failed");
                return(null);
            }
        }
예제 #6
0
        public async Task <bool> Delete(ArtifactId id, CancellationToken token = default)
        {
            id.VerifyNotNull(nameof(id));

            return(await _dataLakeStore.Delete(RealPath(id), token : token));
        }