/// <summary> /// Starts this instance. /// </summary> public void Start() { try { List <MediaQueue> mediaQueue = _mediaQueueRepository.RetrieveQueuedByMediaId(UploaderMedia.Id); foreach (MediaQueue queue in mediaQueue) { User user = _userRepository.RetrieveByPrimaryKey(UploaderMedia.UserId); string ext = Path.GetExtension(queue.Filename); // ReSharper disable PossibleNullReferenceException ext = ext.Replace(".", ""); // ReSharper restore PossibleNullReferenceException const string contentType = "image/{0}"; _fileService.AddFile(user.Username, queue.Filename, string.Format(contentType, ext), queue.MediaBytes); } //Update the media status from 'Queued' to 'Unpublished' _uploaderMediaRepository.UpdateMediaStatus(UploaderMedia.Id, MediaUploadState.Completed); //Delete files from the MediaQueue Table _mediaQueueRepository.Delete(UploaderMedia.Id); } catch (Exception exception) { Logging.Exception(string.Format("TheUploader.Start MediaId:{0}", UploaderMedia.Id), exception, @"C:\Logs\UploadService"); } }
/// <summary> /// Rotates the specified media. /// </summary> /// <param name="media">The media.</param> /// <param name="user">The user.</param> /// <param name="rotate">The rotate.</param> private void Rotate(IEnumerable <MediaFile> media, User user, Func <byte[], byte[]> rotate) { foreach (MediaFile file in media) { byte[] bytes = GetFileBytes(file, user); bytes = rotate(bytes); string contentType = GetContentType(file); _fileService.AddFile(user.Username, file.FilePath, contentType, bytes); _mediaFileRepository.UpdateDimension(file.FileId, file.Height, file.Width); } }
/// <summary> /// Executes the specified parameters. /// </summary> /// <param name="parameters">The parameters.</param> public void Log(SaveLoggingParameters parameters) { try { Guid id = Guid.NewGuid(); //save message to storage _storage.AddFile(QueueConstants.LoggingQueue, id.ToString(), "application/octet-stream", Encoding.Default.GetBytes(parameters.Message)); //queue message for the logging service to process _queue.Send(QueueConstants.LoggingQueue, new QueueLogMessage { Id = id, Endpoint = _settings.RestLoggingEndpoint }); } catch (Exception) { //we can do nothing. } }
/// <summary> /// Saves the specified parameters. /// </summary> /// <param name="parameters">The parameters.</param> public void Save(SaveMediaParameters parameters) { _storage.AddFile(QueueConstants.MediaQueue, parameters.Id.ToString(), "application/octet-stream", parameters.Bytes); _saga.Consume(parameters.Message); }