Пример #1
0
        private async void LoadClick(object sender, RoutedEventArgs e)
        {
            string input = searchBox_Textbox.Text;

            if (ContainsSpecialChars(input))
            {
                MessageBox.Show("Input can only contain numbers & alphanumeric characters");
                return;
            }

            // Server request
            ImageAnimationController controller = ImageBehavior.GetAnimationController(loadingGif_Image);

            controller.Play();

            Connection connection = new Connection();

            status_Textblock.Text = "Connecting...";
            await connection.Connect(Settings.Default.ServerIP, Settings.Default.ServerPort);

            status_Textblock.Text = "Connected";
            FileInfoRequest request = new FileInfoRequest(input);

            status_Textblock.Text = "Checking for file...";
            await connection.SendPacket(request);

            FileInfoResponse response = await connection.ReceivePacket() as FileInfoResponse;

            connection.Close();
            await Task.Delay(1000);

            status_Textblock.Text = "Got response...";
            controller.Pause();

            if (response != null && response.Exists)
            {
                DownloadWindow window = new DownloadWindow(response.File);
                window.Owner = this;
                window.Show();
                window.Closing += DownloadWindowClosing;

                windows.Add(window);
            }
            else
            {
                status_Textblock.Text = "Invalid response!";
            }
        }
Пример #2
0
        private async void DownloadButtonClick(object sender, RoutedEventArgs e)
        {
            Connection connection = new Connection();
            await connection.Connect(Settings.Default.ServerIP, Settings.Default.ServerPort);

            DownloadWindow window = sender as DownloadWindow;
            NetworkFile    file   = window.File;

            // Moet uiteindelijk in een apart download window worden gemaakt
            await connection.SendPacket(new FileDownloadRequest(file.ID));

            connection.FileTransferProgressChanged += (o, ev) =>
            {
            };
            await connection.ReceiveFileAsync(file.Name, file.FileSize);
        }
Пример #3
0
        private void DownForm(string fileNames)
        {
            //Set the sender and receiver
            string sender   = _partner;
            string receiver = LoginName;

            //Select a file to download

            //null esetén meg se nyitom
            if (string.IsNullOrEmpty(fileNames))
            {
                MessageBox.Show("Nem találhatóak fájlok!", "Fáljletöltés");
            }
            //Adat esetén megnyitom
            else
            {
                DownloadWindow down_window;
                down_window = new DownloadWindow(fileNames);
                if (down_window.ShowDialog() ?? false)
                {
                    string toDownload = down_window.selectedFile;
                    string pathDown   = Data.FILES_FOLDER + (sender.Equals(Data.PUBLIC_ID) ? Data.PUBLIC_ID : (sender + "-" + receiver));
                    Directory.CreateDirectory(pathDown);

                    //Download the selected file
                    Task.Factory.StartNew(() => DownloadTask(pathDown + "\\" + toDownload, sender, receiver));
                }
                else
                {
                    new Thread(() =>
                    {
                        MessageBox.Show("Sikertelen fájlválsztás.", "Client Download");
                    }).Start();
                }
            }
        }