Example #1
0
        private async void _queue(FileOperation operation)
        {
            await Task.Run(() =>
            {
                operation.ScheduledTime   = DateTime.UtcNow;
                operation.OperationStatus = FileOperationStatus.Waiting;
                Logger.Info("Operation scheduled: {0}", operation);
                OperationAdded?.Invoke(this, new FileOperationEventArgs(operation));
                if (operation.Kind == TFileOperationKind.Copy || operation.Kind == TFileOperationKind.Move ||
                    operation.Kind == TFileOperationKind.Ingest)
                {
                    IMedia destMedia = operation.Dest;
                    if (destMedia != null)
                    {
                        destMedia.MediaStatus = TMediaStatus.CopyPending;
                    }
                }
                switch (operation.Kind)
                {
                case TFileOperationKind.Ingest:
                    _queueConvertOperation.Enqueue(operation);
                    break;

                case TFileOperationKind.Export:
                    _queueExportOperation.Enqueue(operation);
                    break;

                case TFileOperationKind.Copy:
                case TFileOperationKind.Delete:
                case TFileOperationKind.Loudness:
                case TFileOperationKind.Move:
                    _queueSimpleOperation.Enqueue(operation);
                    break;
                }
            });
        }
        private void _queue(FileOperation operation, bool toTop)
        {
            operation.Owner           = this;
            operation.ScheduledTime   = DateTime.UtcNow;
            operation.OperationStatus = FileOperationStatus.Waiting;
            Logger.Info("Operation scheduled: {0}", operation);
            NotifyOperation(OperationAdded, operation);

            if ((operation.Kind == TFileOperationKind.Copy || operation.Kind == TFileOperationKind.Move || operation.Kind == TFileOperationKind.Convert))
            {
                IMedia destMedia = operation.DestMedia;
                if (destMedia != null)
                {
                    destMedia.MediaStatus = TMediaStatus.CopyPending;
                }
            }
            if (operation.Kind == TFileOperationKind.Convert)
            {
                lock (_queueConvertOperation.SyncRoot)
                {
                    if (toTop)
                    {
                        _queueConvertOperation.Insert(0, operation);
                    }
                    else
                    {
                        _queueConvertOperation.Add(operation);
                    }
                    if (!_isRunningConvertOperation)
                    {
                        _isRunningConvertOperation = true;
                        ThreadPool.QueueUserWorkItem(o => _runOperation(_queueConvertOperation, ref _isRunningConvertOperation));
                    }
                }
            }
            if (operation.Kind == TFileOperationKind.Export)
            {
                lock (_queueExportOperation.SyncRoot)
                {
                    if (toTop)
                    {
                        _queueExportOperation.Insert(0, operation);
                    }
                    else
                    {
                        _queueExportOperation.Add(operation);
                    }
                    if (!_isRunningExportOperation)
                    {
                        _isRunningExportOperation = true;
                        ThreadPool.QueueUserWorkItem(o => _runOperation(_queueExportOperation, ref _isRunningExportOperation));
                    }
                }
            }
            if (operation.Kind == TFileOperationKind.Copy ||
                operation.Kind == TFileOperationKind.Delete ||
                operation.Kind == TFileOperationKind.Loudness ||
                operation.Kind == TFileOperationKind.Move)
            {
                lock (_queueSimpleOperation.SyncRoot)
                {
                    if (toTop)
                    {
                        _queueSimpleOperation.Insert(0, operation);
                    }
                    else
                    {
                        _queueSimpleOperation.Add(operation);
                    }
                    if (!_isRunningSimpleOperation)
                    {
                        _isRunningSimpleOperation = true;
                        ThreadPool.QueueUserWorkItem(o => _runOperation(_queueSimpleOperation, ref _isRunningSimpleOperation));
                    }
                }
            }
        }