public async Task <UploadImageResult> UploadImage(MemoryStream memoryStream, Guid mapId) { var image = new Image(); using (var md5 = MD5.Create()) { image.ImageKey = BitConverter.ToString(md5.ComputeHash(memoryStream)).Replace("-", "").ToLower(); } memoryStream.Position = 0; image.Location = await _storageAdapter.UploadFile($"{image.Id}.jpg", memoryStream, _storageContainerName); if (string.IsNullOrEmpty(image.Location)) { image.Status = ImageStatus.Errored; await _imagesRepository.InsertImage(image); return(UploadFailureResult()); } if (!await _imagesRepository.InsertImage(image)) { return(UploadFailureResult()); } image.Location = await _storageAdapter.GetFileUriWithKey($"{image.Id}.jpg", _storageContainerName); if (string.IsNullOrEmpty(image.Location)) { await _imagesRepository.UpdateImageStatus(image.Id, ImageStatus.Errored); return(UploadFailureResult()); } if (!await _queueAdapter.SendMessage(new ImageProcessRequest(image, mapId), "single-image")) { await _imagesRepository.UpdateImageStatus(image.Id, ImageStatus.Errored); return(UploadFailureResult()); } if (!await _imagesRepository.UpdateImageStatus(image.Id, ImageStatus.AwaitingProcessing)) { return(UploadFailureResult()); } return(UploadSuccessResult(image)); }
/// <summary> /// Sends the envelope. /// </summary> /// <param name="envelope">The envelope.</param> protected void SendEnvelope(IMessageEnvelope envelope) { try { envelope.User = this.UserName; envelope.Originator = this.Originator; envelope.ReplyTo = this.ReplyTo; envelope.ExpiresOn = this.ExpiresOn; envelope.MessageUID = Guid.NewGuid(); envelope.MessageSentOn = DateTime.UtcNow; _queueManager.SendMessage(envelope); logger.LogPublish(envelope, string.Empty, envelope.Message.GetType()); } catch (System.Exception exception) { logger.LogPublishFailure(envelope, string.Empty, exception, envelope.Message.GetType()); throw; } }