コード例 #1
0
        public async Task ExecuteDelete(int serviceId, int imageId)
        {
            var file = await _servicesGateway.GetFile(imageId).ConfigureAwait(false);

            if (file == null)
            {
                return;
            }
            var images = file?.Url == null?Array.Empty <string>() : file.Url.Split(';');

            var resizedFileName  = images.Length > 1 ? images[1] : null;
            var originalFileName = images.Length > 0 ? images[0] : null;

            try
            {
                if (originalFileName != null)
                {
                    await _repositoryGateway.DeleteImage(originalFileName).ConfigureAwait(false);
                }
                if (resizedFileName != null)
                {
                    await _repositoryGateway.DeleteImage(resizedFileName).ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                LoggingHandler.LogError("Error deleting object from S3.");
            }
            try
            {
                await _servicesGateway.DeleteFileInfo(serviceId, file).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                LoggingHandler.LogError("Error deleting image.");
            }
        }