Example #1
0
        private static void ProcessQueue()
        {
            if (_isProcessing)
            {
                return;
            }

            _isProcessing = true;
            int length = _cache.Count - 1;

            for (int i = length; i >= 0; i--)
            {
                if (_cache.Count < i)
                {
                    continue;
                }

                var entry = _cache.ElementAt(i);

                try
                {
                    // The file should be a second old before we start processing
                    if (entry.Value > DateTime.Now.AddSeconds(-2))
                    {
                        continue;
                    }

                    if (!_store.HasChangedOrIsNew(entry.Key))
                    {
                        _cache.Remove(entry.Key);
                        continue;
                    }

                    _compressor.CompressFile(entry.Key);
                    _cache.Remove(entry.Key);
                }
                catch (IOException)
                {
                    // do nothing. We'll try again
                }
                catch
                {
                    _cache.Remove(entry.Key);
                }
            }

            _isProcessing = false;
        }
        public void ProcessQueue()
        {
            if (_isProcessing)
            {
                return;
            }

            _isProcessing = true;
            int length = _filesToCompress.Count - 1;

            for (int i = length; i >= 0; i--)
            {
                if (_filesToCompress.Count < i)
                {
                    continue;
                }

                var entry = _filesToCompress.ElementAt(i);

                try {
                    // The file should be a second old before we start processing
                    if (entry.Value > DateTime.Now.AddSeconds(-1))
                    {
                        continue;
                    }

                    if (ShouldSkipFileEntry(entry.Key))
                    {
                        _filesToCompress.Remove(entry.Key);
                        Logger.WriteLineToConsole("{0} skipped because it's up to date", entry.Key);
                        continue;
                    }

                    _imageCompressor.CompressFile(entry.Key);
                    _filesToCompress.Remove(entry.Key);
                }
                catch (IOException) {
                    // do nothing. We'll try again
                }
                catch {
                    _filesToCompress.Remove(entry.Key);
                }
            }

            _isProcessing = false;
        }