/// <summary>
        /// Begins processing the current media item, returning <c>true</c> when the action succeeds.
        /// Specifically, a few properties are updated and the item is persisted to the data store.
        /// If the item cannot be processed (may be null or has a status other than 'Waiting'), this
        /// function returns <c>false</c>.
        /// </summary>
        /// <returns>Returns <c>true</c> when the item has successfully started processing; otherwise
        /// <c>false</c>.</returns>
        private bool BeginProcessItem()
        {
            MediaQueueItem mqItem = GetCurrentMediaQueueItem();

            if (mqItem == null)
            {
                return(false);
            }

            if (!mqItem.Status.Equals(MediaQueueItemStatus.Waiting))
            {
                ProcessNextItemInQueue(false);
                return(false);
            }

            mqItem.Status = MediaQueueItemStatus.Processing;
            mqItem.DateConversionStarted = DateTime.Now;

            //Factory.GetDataProvider().MediaQueue_Save(mediaQueueDto);
            mqItem.Save();

            // Update the item in the collection.
            //MediaQueueItems[mediaQueueDto.MediaQueueId] = mediaQueueDto;

            return(true);
        }
        /// <summary>
        /// Complete processing the current media item by updating the media queue instance and
        /// reseting the status of the conversion queue.
        /// </summary>
        /// <param name="settings">An instance of <see cref="MediaConversionSettings" /> containing
        /// settings and results used in the conversion. A null value is acceptable.</param>
        private void CompleteProcessItem(MediaConversionSettings settings)
        {
            // Update status and persist to data store
            MediaQueueItem mqItem = GetCurrentMediaQueueItem();

            mqItem.DateConversionCompleted = DateTime.Now;

            if (settings != null && settings.FileCreated)
            {
                mqItem.Status = MediaQueueItemStatus.Complete;
            }
            else
            {
                mqItem.Status = MediaQueueItemStatus.Error;

                var    fileName = (settings != null && !String.IsNullOrEmpty(settings.FilePathSource) ? Path.GetFileName(settings.FilePathSource) : "<Unknown>");
                string msg      = String.Format(CultureInfo.CurrentCulture, "Unable to process file '{0}'.", fileName);
                RecordEvent(msg, settings);
            }

            //Factory.GetDataProvider().MediaQueue_Save(mediaQueueDto);
            mqItem.Save();

            // Update the item in the collection.
            //MediaQueueItems[mediaQueueDto.MediaQueueId] = mediaQueueDto;

            Reset();
        }
        /// <summary>
        /// Adds the specified <paramref name="mediaObject" /> to the queue. It will be processed in a first-in, first-out
        /// order. If the media object is already waiting in the queue, no action is taken.
        /// </summary>
        /// <param name="mediaObject">The media object to be processed.</param>
        /// <param name="conversionType">Type of the conversion.</param>
        public void Add(IGalleryObject mediaObject, MediaQueueItemConversionType conversionType)
        {
            lock (_sharedLock)
            {
                var mqItem = new MediaQueueItem
                {
                    MediaQueueId            = int.MinValue,
                    MediaObjectId           = mediaObject.Id,
                    Status                  = MediaQueueItemStatus.Waiting,
                    ConversionType          = conversionType,
                    RotationAmount          = mediaObject.CalculateNeededRotation(),
                    StatusDetail            = String.Empty,
                    DateAdded               = DateTime.Now,
                    DateConversionStarted   = null,
                    DateConversionCompleted = null
                };

                mqItem.Save();
                //Factory.GetDataProvider().MediaQueue_Save(mediaQueueDto);

                MediaQueueItemDictionary.TryAdd(mqItem.MediaQueueId, mqItem);
            }
        }
 /// <summary>
 /// Update the status of the <paramref name="item" /> to the specified <paramref name="status" />.
 /// </summary>
 /// <param name="item">The item whose status is to be updated.</param>
 /// <param name="status">The status to update the item to.</param>
 private static void ChangeStatus(MediaQueueItem item, MediaQueueItemStatus status)
 {
     item.Status = status;
     item.Save();
     //Factory.GetDataProvider().MediaQueue_Save(item);
 }
 /// <summary>
 /// Update the status of the <paramref name="item" /> to the specified <paramref name="status" />.
 /// </summary>
 /// <param name="item">The item whose status is to be updated.</param>
 /// <param name="status">The status to update the item to.</param>
 private static void ChangeStatus(MediaQueueItem item, MediaQueueItemStatus status)
 {
     item.Status = status;
     item.Save();
     //Factory.GetDataProvider().MediaQueue_Save(item);
 }
        /// <summary>
        /// Adds the specified <paramref name="mediaObject" /> to the queue. It will be processed in a first-in, first-out
        /// order. If the media object is already waiting in the queue, no action is taken.
        /// </summary>
        /// <param name="mediaObject">The media object to be processed.</param>
        /// <param name="conversionType">Type of the conversion.</param>
        public void Add(IGalleryObject mediaObject, MediaQueueItemConversionType conversionType)
        {
            lock (_sharedLock)
            {
                var mqItem = new MediaQueueItem
                                                                                {
                                                                                    MediaQueueId = int.MinValue,
                                                                                    MediaObjectId = mediaObject.Id,
                                                                                    Status = MediaQueueItemStatus.Waiting,
                                                                                    ConversionType = conversionType,
                                                                                    RotationAmount = mediaObject.CalculateNeededRotation(),
                                                                                    StatusDetail = String.Empty,
                                                                                    DateAdded = DateTime.Now,
                                                                                    DateConversionStarted = null,
                                                                                    DateConversionCompleted = null
                                                                                };

                mqItem.Save();
                //Factory.GetDataProvider().MediaQueue_Save(mediaQueueDto);

                MediaQueueItemDictionary.TryAdd(mqItem.MediaQueueId, mqItem);
            }
        }