예제 #1
0
        private void BtnOpenCode_Click(object sender, EventArgs e)
        {
            if (_ofdSourceCode.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            BtnShowFullSourceCode.Visible = false;
            try
            {
                var sourceCode = ArithmeticFile.Read(_ofdSourceCode.FileName);
                var decoded    = ArithmeticCoding.Decode(sourceCode);

                _lastSaveSourceCode = sourceCode.ToString();
                if (_lastSaveSourceCode.Length > MaxCodeLength)
                {
                    BtnShowFullSourceCode.Visible = true;
                }
                LblSourceCode.Text = "Код: " + _lastSaveSourceCode;
                RtbDecoded.Text    = decoded;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #2
0
        public void TestEncodeWriteAndReadDecode()
        {
            const string source   = "abcdefghklmopqastuvwxyz";
            const string fileName = "test1.acode";

            var fullPath = Path.Combine(GetTestFolder(), fileName);
            var encoded  = ArithmeticCoding.Encode(source);

            ArithmeticFile.Write(fullPath, encoded);
            var read    = ArithmeticFile.Read(fullPath);
            var decoded = ArithmeticCoding.Decode(read);

            Assert.AreEqual(source, decoded);
        }
예제 #3
0
        private void BtnSaveCode_Click(object sender, EventArgs e)
        {
            if (RtbSource.TextLength == 0)
            {
                return;
            }
            if (_sdfEncoded.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            try
            {
                var encoded = ArithmeticCoding.Encode(RtbSource.Text);
                ArithmeticFile.Write(_sdfEncoded.FileName, encoded);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }