private void EncodeButton_Click(object sender, RoutedEventArgs e)
        {
            // progress bar config
            BackgroundWorker worker = new BackgroundWorker();

            worker.WorkerReportsProgress = true;
            worker.RunWorkerCompleted   += Worker_RunWorkerCompletedEncryption;
            worker.DoWork          += Worker_DoWorkEncryption;
            worker.ProgressChanged += Worker_ProgressChangedEncryption;


            //get values from the user (from gui)
            EncryptionOutput eo           = GetSelectedValuesFromGUIEncryption();
            bool             correctInput = eo.IsInputCorrect;

            if (correctInput)
            {
                worker.RunWorkerAsync(eo);
            }
            else
            {
                MessageBoxResult result =
                    MessageBox.Show(eo.ErrorMessage,
                                    "Błędne dane wejściowe", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        private EncryptionOutput GetSelectedValuesFromGUIEncryption()
        {
            //enter values from input controls to EncryptionInput object
            EncryptionInput ei = new EncryptionInput(InputFileTextBox.Text,
                                                     OutputFileTextBox.Text, cipherModeComboBox.Text,
                                                     RecipentsListBox.SelectedItems);

            EncryptionOutput eo = InputHandlers.ParseEncryptionValues(ei);

            return(eo);
        }
        private void Worker_DoWorkEncryption(object sender, DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;

            worker.ReportProgress(0);

            EncryptionOutput eo = (EncryptionOutput)e.Argument;

            Encryption encryption = new Encryption(eo.InputFilePath, eo.OutputFilePath,
                                                   Globals.blockSize, eo.CipherMode, eo.FileExtension, eo.Recipents);

            encryption.GenerateEncodedFile(worker);
        }
        public static EncryptionOutput ParseEncryptionValues(EncryptionInput ei)
        {
            bool   readingAllOK = true;
            string errorMsg     = "";

            //retrieve input file and output file name
            string inputFilePath = ei.InputFile;

            if (string.IsNullOrEmpty(inputFilePath) ||
                !File.Exists(inputFilePath))
            {
                readingAllOK = false;
                errorMsg    += "Błędnie wybrany plik do zaszyfrowania.\n";
            }

            //get input file extension
            string fileExtension = "";

            try
            {
                fileExtension = System.IO.Path.GetExtension(inputFilePath);
            }catch (ArgumentException e)
            {
                readingAllOK = false;
                errorMsg    += "Błędne rozszerzenie pliku wejściowego.\n";
            }

            //get output file name
            string outputFileName = ei.OutputFile;

            if (string.IsNullOrEmpty(outputFileName) ||
                (outputFileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0))
            {
                readingAllOK = false;
                errorMsg    += "Błędna nazwa pliku wyjściowego.\n";
            }

            string outputFilePath = "";

            try
            {
                string outDirectory = System.IO.Path.GetDirectoryName(inputFilePath);
                outputFilePath = outDirectory + "\\" + outputFileName;
            }
            catch (Exception e)
            {
                readingAllOK = false;
                errorMsg    += "Błędny katalog pliku wejściowego.\n";
            }

            //retrieve cipher mode
            string cipherMode = ei.CipherMode;


            //retrieve selected recipents from listbox
            System.Collections.IList items = ei.ListItems;
            List <User> recipents          = items.Cast <User>().ToList();

            if (recipents == null || recipents.Count == 0)
            {
                readingAllOK = false;
                errorMsg    += "Brak wybranych odbiorców pliku.\n";
            }

            //create and return an object keeping track of all read data
            EncryptionOutput eo = new EncryptionOutput(readingAllOK,
                                                       inputFilePath, outputFilePath, cipherMode, fileExtension,
                                                       recipents, errorMsg);

            return(eo);
        }