public void EnqueueJob(NzbDecoderJob job)
        {
            lock (_synchroObject)
            {
                if (job != null)
                {
                    lock (job.Part)
                    {
                        job.Part.Status = NzbPartStatus.QueuedDecoding;
                    }
                }

                _queuedJobs.Enqueue(job);

                Monitor.Pulse(_synchroObject);
            }
        }
        private void Decode(NzbDecoderJob job)
        {
            string originalFilename = null;
            var decoderFactory = new NzbDecoderFactory();

            var decoder = decoderFactory.CreateDecoder(job.Part, job.RawSegmentsDirectory, job.FileEncoding);

            byte[] decodedBytes = decoder.Decode(out originalFilename);

            if (!Directory.Exists(job.DestinationDirectory))
            {
                Directory.CreateDirectory(job.DestinationDirectory);
            }

            string fullPath = Path.Combine(job.DestinationDirectory, originalFilename);

            using (var fileStream = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, _hddCacheSize))
            {
                fileStream.Flush(true);

                fileStream.Write(decodedBytes, 0, decodedBytes.Length);
            }

            lock (job.Part.Segments)
            {
                var segments = job.Part.Segments;
                foreach (var currentSegment in job.Part.Segments)
                {
                    string rawSegmentsPath = null;
                    lock (currentSegment)
                    {
                        rawSegmentsPath = Path.Combine(job.RawSegmentsDirectory, currentSegment.Id);
                    }

                    if (File.Exists(rawSegmentsPath))
                    {
                        File.Delete(rawSegmentsPath);
                    }
                }
            }
        }
        private void SegmentDownloadedCheckpoint(NzbDownloadJob downloadJob)
        {
            lock (_isDisposedSynchronization)
            {
                if (_isDisposed)
                {
                    return;
                }
            }

            var downloadedSegment = downloadJob.Segment;

            lock (downloadedSegment.Parent)
            {
                var parent = downloadedSegment.Parent;
                var numberOfSuccessfullyDownloadedSegments = parent.Segments.Where(seg => seg.Status == NzbSegmentStatus.Downloaded).Count();

                if (parent.Segments.Count == numberOfSuccessfullyDownloadedSegments)
                {
                    parent.Status = NzbPartStatus.Downloaded;

                    var job = new NzbDecoderJob(downloadJob.TemporaryDirectory, downloadJob.DownloadDirectory, downloadedSegment.Parent, Encoding.GetEncoding("iso-8859-1"), PartDecodedCheckpoint);

                    _decoderQueue.EnqueueJob(job);
                }
            }
        }