private void DownloadFile(object parameter)
 {
     try
     {
         if (parameter != null)
         {
             var downloadingDocument = parameter as DocumentModel;
             if (downloadingDocument.DocUrl != null)
             {
                 FTPHelper.DownloadFile(downloadingDocument.DocUrl);
                 MessageBox.Show($"Document has been downloaded to '{Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\Downloads")}'", "Download Succes", MessageBoxButton.OK, MessageBoxImage.Information);
             }
             else
             {
                 MessageBox.Show("Invalid FTP Path for the document download", "Invalid Path", MessageBoxButton.OK, MessageBoxImage.Error);
             }
         }
     }
     catch (Exception ex)
     {
         App.Current.Dispatcher.Invoke((Action) delegate
         {
             ParentLayout.ShowMessageAsync("Error", ex.Message, MessageDialogStyle.Affirmative, new MetroDialogSettings()
             {
                 ColorScheme = MetroDialogColorScheme.Accented
             });
         });
     }
 }
Example #2
0
        public override int Execute(string[] args)
        {
            // sanity check
            if (args.Length != 3)
            {
                throw new ArgumentException("incorrect number of arguments");
            }

            var ip   = args[1];
            var path = args[2];

            if (path.EndsWith(@"\"))
            {
                path = StringHelper.TrimEnd(path, 1);
            }
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            var files = FTPHelper.GetFileList(ip);

            for (int i = 0; i < files.Count; i++)
            {
                var file     = files[i];
                var progress = (i / (double)files.Count) * 100;

                Progress.Message = "Downloading " + progress.ToString("0") + "% [" + file + "]";

                try
                {
                    FTPHelper.DownloadFile(ip, file, path);
                }
                catch (Exception ex)
                {
                    ConsoleHelper.WriteLine("Error downloading " + file);
                    ConsoleHelper.WriteException(ex);
                }
            }

            ConsoleHelper.WriteLine(files.Count.ToString() + " Files" + ((files.Count != 1) ? "s" : "") + " Downloaded", ConsoleColor.DarkYellow);

            return(ConsoleHelper.EXIT_OK);
        }