Ejemplo n.º 1
0
        public FileProcessor()
        {
            // Initialize thread with Work method
            _worker = new Thread(Work);
            _cypher = new FileCypher();

            // Start thread
            _worker.Start();
        }
Ejemplo n.º 2
0
        private void Work()
        {
            while (true)
            {
                string fileName = null;

                // Take the file name
                lock (_locker)
                    if (_fileNamesQueue.Count > 0)
                    {
                        fileName = _fileNamesQueue.Dequeue();

                        // If the queued file name is null, exit
                        if (fileName == null)
                        {
                            return;
                        }
                    }

                if (fileName != null)
                {
                    // Waiting until file creation is done
                    while (!FileCypher.IsFileReady(fileName))
                    {
                        Thread.Sleep(50);
                    }

                    // File is sent to the cypher for encryption/decryption
                    if (Settings.Instance.FswDecrypt)
                    {
                        _cypher.DecryptFile(fileName);
                    }
                    else
                    {
                        _cypher.CryptFile(fileName);
                    }
                }
                else
                {
                    _eventWaitHandle.WaitOne();
                }
            }
        }