コード例 #1
0
        private async Task <List <ImageData> > GetImagesThroughBrokerAsync(List <Guid> imagesIds, List <string> errors)
        {
            if (imagesIds is null || !imagesIds.Any())
            {
                return(null);
            }

            try
            {
                Response <IOperationResult <IGetImagesResponse> > response =
                    await _rcGetImages.GetResponse <IOperationResult <IGetImagesResponse> >(
                        IGetImagesRequest.CreateObj(imagesIds, ImageSource.User));

                if (response.Message.IsSuccess && response.Message.Body.ImagesData.Any())
                {
                    return(response.Message.Body.ImagesData);
                }

                _logger.LogWarning(
                    "Error while getting images with images ids: {ImagesIds}.\nErrors: {Errors}",
                    string.Join(", ", imagesIds),
                    string.Join('\n', response.Message.Errors));
            }
            catch (Exception exc)
            {
                _logger.LogError(
                    exc,
                    "Cannot get images with images ids: {ImagesIds}.",
                    string.Join(", ", imagesIds));
            }

            errors.Add("Cannot get images. Please try again later.");

            return(null);
        }
コード例 #2
0
        private async Task <List <ImageData> > GetUsersAvatarsAsync(List <Guid> imagesIds, List <string> errors)
        {
            if (imagesIds == null || !imagesIds.Any())
            {
                return(null);
            }

            try
            {
                Response <IOperationResult <IGetImagesResponse> > response =
                    await _rcGetImages.GetResponse <IOperationResult <IGetImagesResponse> >(
                        IGetImagesRequest.CreateObj(imagesIds, ImageSource.News));

                if (response.Message.IsSuccess)
                {
                    return(response.Message.Body.ImagesData);
                }

                _logger.LogWarning(
                    "Error while getting images by ids: {ImagesIds}. Reason:{Errors}",
                    string.Join(", ", imagesIds),
                    string.Join('\n', response.Message.Errors));
            }
            catch (Exception exc)
            {
                _logger.LogError("Can not get images by ids: {ImagesIds}. {ErrorsMessage}", imagesIds, exc.Message);
            }

            errors.Add("Can not get images. Please try again later.");

            return(null);
        }