Пример #1
0
        /// <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>
        /// Updates the details.
        /// </summary>
        /// <param name="media">The media.</param>
        /// <param name="batchId">The batch id.</param>
        public void UpdateDetails(Media media, Guid batchId)
        {
            UploadBatch batch = _mediaQueueRepository.GetUploadBatch(batchId);

            AddMediaToAlbum(batch, media.MediaId);
            _mediaQueueRepository.InsertBatchIdAndMediaId(batchId, media.MediaId);


            media.Tags   = batch.Tags;
            media.Day    = (batch.Day ?? media.Day);
            media.Month  = (batch.Month ?? media.Month);
            media.Year   = (batch.Year ?? media.Year);
            media.Status = batch.MediaStatus.ParseEnum <MediaStatus>();
            _mediaRepository.Save(media);

            _uploaderMediaRepository.UpdateMediaStatus(media.MediaId, MediaUploadState.Queued);
            SaveLocation(batch, media.Owner.UserId);
        }