Пример #1
0
        public static bool CheckFiles(string originalFileName)
        {
            bool check = true;

            Stopwatch watchEncode = new Stopwatch();
            Stopwatch watchDecode = new Stopwatch();

            watchEncode.Start();
            Encoder.Encode("files\\" + originalFileName, "encode\\" + originalFileName + Generals.FileExt);
            watchEncode.Stop();

            watchDecode.Start();
            Decoder.Decode("encode\\" + originalFileName + Generals.FileExt, "result\\RESULT" + originalFileName);
            watchDecode.Stop();

            FileStream   fsOrigin = new FileStream("files\\" + originalFileName, FileMode.Open, FileAccess.Read);
            FileStream   fsResult = new FileStream("result\\RESULT" + originalFileName, FileMode.Open, FileAccess.Read);
            BinaryReader brOrigin = new BinaryReader(fsOrigin);
            BinaryReader brResult = new BinaryReader(fsResult);

            if (fsOrigin.Length < fsResult.Length || fsOrigin.Length > fsResult.Length) // Wenn die Originaldatei kleiner als das Ergebnis ist, dann ist sowieso was nicht richtig | Selbe andersrum
            {
                check = false;
            }

            while (fsOrigin.Position < fsOrigin.Length)
            {
                if (brOrigin.ReadByte() != brResult.ReadByte())
                {
                    check = false;
                }
            }

            fsOrigin.Flush();
            fsResult.Flush();

            brOrigin.Close();
            brResult.Close();
            fsOrigin.Close();
            fsResult.Close();

            FileStream originalFS = new FileStream("files\\" + originalFileName, FileMode.Open, FileAccess.Read);
            FileStream tomFS      = new FileStream("encode\\" + originalFileName + Generals.FileExt, FileMode.Open, FileAccess.Read);
            FileStream resultFS   = new FileStream("result\\RESULT" + originalFileName, FileMode.Open, FileAccess.Read);

            string content = $"{originalFileName};{originalFS.Length - tomFS.Length};{originalFS.Length - resultFS.Length};{check};{originalFS.Length};{watchEncode.Elapsed.TotalSeconds};{tomFS.Length};{watchDecode.Elapsed.TotalSeconds}";

            originalFS.Flush();
            tomFS.Flush();
            resultFS.Flush();
            originalFS.Close();
            tomFS.Close();
            resultFS.Close();

            StreamWriter sw = new StreamWriter("result.txt", true);

            sw.WriteLine(content);
            sw.Close();

            return(check);
        }
Пример #2
0
        /// <summary>
        /// Indicates for the User that something is happending by starting/stopping a animation and disabeling/enableing the button
        /// Encodes or Decodes depending on which button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void DeEnCode_Click(object sender, RoutedEventArgs e)
        {
            // Sets Cursor to Wait to indicate that something is happening for User
            Window.Cursor = Cursors.Wait;

            // Starts progress Animation of Button and Circle
            MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(encode, true);
            MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndicatorVisible(encode, true);
            progressBar.Visibility = Visibility.Visible;

            // Disables all elements so that no new operation can be done
            chooseFile.IsEnabled           = false;
            destinationDirectory.IsEnabled = false;
            destinationName.IsEnabled      = false;
            encode.IsEnabled = false;
            decode.IsEnabled = false;



            // En- or Decodes depeding on the Button Name
            switch ((sender as Button).Name)    // Sets the sender object to a Button object so that the Name of the Button is readable
            {
            // Awaits Method asynchronously so that the window does not freeze
            case "encode":
                await Task.Run(() => Encoder.Encode());

                break;

            case "decode":
                await Task.Run(() => Decoder.Decode());

                break;
            }



            // Stops progress Animation of Button and Cricle
            progressBar.Visibility = Visibility.Hidden;
            MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(encode, false);
            MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndicatorVisible(encode, false);

            // Enables all elements again
            chooseFile.IsEnabled           = true;
            destinationDirectory.IsEnabled = true;
            destinationName.IsEnabled      = true;
            encode.IsEnabled = true;
            decode.IsEnabled = true;

            // Sets Cursor back to default
            Window.Cursor = Cursors.Arrow;

            // Initializes new MessageBox Object
            MessageBox mb = new MessageBox(resourceDictionary);

            // Shows MessageBox
            mb.Show();

            // Awaits 1 Second
            await Task.Run(() => System.Threading.Thread.Sleep(1000));

            // Sets MainWindow back to StartupLayout
            StartupWindow();
        }
Пример #3
0
        /// <summary>
        /// Starts the Unit Test
        /// </summary>
        public static void StartTest()
        {
            // Changes file name to random names
            RadnomFileNames();

            // The results of the test
            List <StringBuilder> results = new List <StringBuilder>();

            // First Encoding second Decoding
            for (int chooseOperation = 0; chooseOperation < 2; chooseOperation++)
            {
                // Files to en/decode
                FileInfo[] files = null;
                switch (chooseOperation)
                {
                case 0:     // Get File without ttpack extenstion
                    files = new DirectoryInfo(_directory).GetFiles();
                    break;

                case 1:     // Get Files with ttpack extesntion
                    files = new DirectoryInfo(_directory).GetFiles("*.ttpack");
                    break;
                }

                // For each file in UnitTest-directory
                foreach (FileInfo file in files)
                {
                    // Result of current test
                    StringBuilder result = new StringBuilder();

                    // Upadtes Values
                    Values.source = file;
                    Values.destinationDirectory = Values.source.DirectoryName;
                    System.Windows.Application.Current.Dispatcher.Invoke(() => System.Windows.Application.Current.Windows.OfType <MainWindow>().First().destinationName.Text = Values.source.Name);

                    // To measure time operation took
                    var timer = new System.Diagnostics.Stopwatch();
                    timer.Start();

                    switch (chooseOperation)
                    {
                    case 0:
                        Encoder.Encode();
                        result.Append("encoding").Append(_colon);
                        break;

                    case 1:
                        Decoder.Decode();
                        result.Append("decoding").Append(_colon);
                        break;
                    }

                    timer.Stop();


                    long orgLength         = file.Length;                                 // Length of original file
                    long newLength         = new FileInfo(Values.destinationPath).Length; // Length of new file (ttpack or decoded)
                    long differenceLenghts = orgLength - newLength;                       // Difference of lengths

                    // Append information of test  to result StringBuilder
                    result.Append(file.Name).Append(_colon)
                    .Append(file.Extension).Append(_colon)
                    .Append(string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}:{4:D3}", timer.Elapsed.Days, timer.Elapsed.Hours, timer.Elapsed.Minutes, timer.Elapsed.Seconds, timer.Elapsed.Milliseconds)).Append(_colon)
                    .Append(orgLength).Append(_colon)
                    .Append(newLength).Append(_colon)
                    .Append(differenceLenghts);

                    // Add result to results list
                    results.Add(result);
                }

                // Message Box
                System.Windows.Application.Current.Dispatcher.Invoke(() => {
                    MessageBox mb = new MessageBox();
                    mb.text.Text  = "Done with test" + chooseOperation;
                    mb.Show();
                });
            }

            // Message Box
            System.Windows.Application.Current.Dispatcher.Invoke(() => {
                MessageBox mb = new MessageBox();
                mb.text.Text  = "Writing result files now";
                mb.Show();
            });


            WriteResults(ref results);
        }