Esempio n. 1
0
        /// <summary>
        ///     Event handler for the DoWork function in the download file BackgroundWorker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Help_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                ///Initiate an FTP request
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"ftp://{Properties.Settings.Default.IP}/config.xml");
                request.Timeout     = 10000;
                request.Method      = WebRequestMethods.Ftp.DownloadFile;
                request.Credentials = new NetworkCredential("anonymous", "");

                string lines = null;

                using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
                    lines = reader.ReadToEnd();

                ///Get the XML Text of the file on the RoboRIO
                MainEditor.Dispatcher.Invoke(DispatcherPriority.Normal,
                                             new Action(() => { MainEditor.Clear(); MainEditor.AppendText(lines); }));

                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                response.Close();
                MessageBox.Show($"{response.StatusDescription}", "Download", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Exception thrown in connection\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                MessageBox.Show($"Download Failed", "Fail", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }