Beispiel #1
0
        private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            string file = screenshot();

            encryptionClass.EncryptFile(file);
            encryptionClass.DecryptFile(file);
        }
        private void receivePhoto(int size)
        {
            blockUserFromDoingAnythingStupid();
            canMeasureSpeed = true;
            Thread transfSpeed = new Thread(transferSpeed);

            transfSpeed.Start();
            DateTime dateTime = DateTime.Now;
            string   data     = dateTime.ToString();

            data = data.Replace("-", "");
            data = data.Replace(":", "");
            data = data.Replace(" ", "");
            data = data.Replace("/", "");
            data = data.Replace(".", "");
            string fileName = (System.IO.Path.Combine(mainWindowClass.saveFolder, data + ".bmp"));

            byte[]        RecData = new byte[1024];
            int           RecBytes;
            NetworkStream netstream = null;

            mainWindowClass.progressBar.Dispatcher.Invoke(new Action(() => mainWindowClass.progressBar.Maximum = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(size) / Convert.ToDouble(1024)))));
            try
            {
                netstream = client.GetStream();
                FileStream Fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);

                while (size != 0)
                {
                    RecBytes = netstream.Read(RecData, 0, RecData.Length);
                    Fs.Write(RecData, 0, RecBytes);
                    size           -= RecBytes;
                    bytesPerSecond += RecBytes;
                    mainWindowClass.progressBar.Dispatcher.Invoke(new Action(() => mainWindowClass.progressBar.Value++));
                }
                Fs.Close();
            }
            catch (Exception)
            {
            }
            canMeasureSpeed = false;
            encryptionClass.DecryptFile(fileName);
            System.Diagnostics.Process.Start(fileName);
            startMonitoring();
            stopBlockingTheUser();
            mainWindowClass.progressBar.Dispatcher.Invoke(new Action(() => mainWindowClass.progressBar.Value = 0));
        }