Ejemplo n.º 1
0
        private void DecodeButton_Click(object sender, RoutedEventArgs e)
        {
            string EncodedText = TransformedAvalon.Text;

            if (EncodedText.Length == 0)
            {
                MessageBox.Show("Text in right field is empty!", "Warning!", MessageBoxButton.OK);
                return;
            }

            int    codingIndex = _codes[TypeOfCoding];
            string decoded     = "";

            switch (codingIndex)
            {
            case 0:
                Coding.Haffman.Decoder decoderHaffmen = new Coding.Haffman.Decoder();
                decoded = decoderHaffmen.Decode(EncodedText, (Dictionary <string, char>)_dictionary);
                break;

            case 1:
                Coding.ShannonFano.Decoder decoderFanoShannon = new Coding.ShannonFano.Decoder();
                decoded = decoderFanoShannon.Decode(EncodedText, (Dictionary <string, char>)_dictionary);
                break;

            case 2:
                Coding.ArithmeticCoding.Decoder decoderArythmetic = new Coding.ArithmeticCoding.Decoder();
                decoded = decoderArythmetic.Decode((Dictionary <char, long>)_dictionary,
                                                   ParseBigInteger(EncodedText), ParsePower(EncodedText));
                break;

            case 3:
                Coding.RleAndBurrowsWheeler.Decoder decoderBWT = new Coding.RleAndBurrowsWheeler.Decoder();
                decoded = decoderBWT.Decode(ParseTransformResult(EncodedText));
                break;

            case 4:
                Coding.Lz77.Decoder decoderLZ = new Coding.Lz77.Decoder();
                decoded = decoderLZ.Decode(ParseNodes(EncodedText));
                break;
            }
            InitialAvalon.Clear();
            InitialAvalon.Text = decoded;
        }
Ejemplo n.º 2
0
        private void FileButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter      = "Text files (*.txt)|*.txt|All files (*.*)|*.*",
                Multiselect = false,
                Title       = "Choose the file"
            };

            if (ofd.ShowDialog() == true)
            {
                string filePath = ofd.FileName;
                FilePathLabel.Content = ofd.FileName;
                using (StreamReader sr = new StreamReader(filePath))
                {
                    InitialText = sr.ReadToEnd();
                }
                InitialAvalon.Clear();
                InitialAvalon.Text = InitialText;
            }
        }