/* * public static DownloadWindow Register(WebClient client, String downloadLocation) * { * DownloadWindow downloadWindow; * * if (instances == null) * { * downloadWindow = new DownloadWindow(client, downloadLocation); * instances = new List<DownloadWindow>(); * instances.Add(downloadWindow); * return downloadWindow; * } * else if ((downloadWindow = instances.Find(c => c.client == client && c.downloadLocation == downloadLocation)) != null) * return downloadWindow; * else * { * downloadWindow = new DownloadWindow(client, downloadLocation); * instances.Add(downloadWindow); * return downloadWindow; * } * } */ public void Download(/*TaggedWebClient client, */ FileExplorerWindow.LinkInfo linkInfo, CancellationTokenSource cts, bool open) { string path = System.Web.HttpUtility.UrlDecode((Path.Combine(downloadLocation, linkInfo.Url.Substring(1).Replace("/", "\\")))); Directory.CreateDirectory(Path.GetDirectoryName(path)); if (linkInfo.Size != null && linkInfo.Size.Equals("Directory")) { List <FileExplorerWindow.LinkInfo> directoryFiles = FileExplorerWindow.GetDirectoryFiles((new FileExplorerWindow.HttpInfo(httpClient, linkInfo, user, cts))); foreach (FileExplorerWindow.LinkInfo newLinkInfo in directoryFiles) { Download(/*FileExplorerWindow.CreateClient(linkInfo.BaseAddress, user), */ newLinkInfo, cts, false); } } else { TaggedWebClient client = FileExplorerWindow.CreateClient(linkInfo.BaseInfo.BaseAddress, user); clients.Add(client); FileDownloadForm Form2 = new FileDownloadForm(client, linkInfo); //client.Tag = Form2; client.Tag = path; Form2.MdiParent = this; flowLayoutPanel1.Controls.Add(Form2); Form2.Show(); client.DownloadFileCompleted += Client_DownloadFileCompleted; client.DownloadFileAsync(new Uri(linkInfo.FullAddress), path, open); downloadCount++; this.Show(); } }
/// <summary> /// The main entry point for the application. /// </summary> /// private static void StartProgram(KeyValuePair <string, string> user = default(KeyValuePair <string, string>)) { LoginWindow fLogin = new LoginWindow(user); if (!fLogin.IsDisposed && fLogin.ShowDialog() == DialogResult.OK) { user = fLogin.User; FileExplorerWindow fExplorer = new FileExplorerWindow(new FileExplorerWindow.LinkInfo(String.Format(fLogin.Url.Url, user.Key), fLogin.Url, fLogin.Url.FolderName, "Directory", null, "Directory"), user); StartProgram(fExplorer, user); } else { Application.ExitThread(); } }
internal static void StartProgram(FileExplorerWindow fExplorer, KeyValuePair <string, string> user) { Application.Run(fExplorer); if (fExplorer.DialogResult == DialogResult.Retry) { StartProgram(); } else if (fExplorer.DialogResult == DialogResult.Ignore) { StartProgram(user); } else { Application.ExitThread(); } }
public LoginWindow(KeyValuePair <string, string> user) { InitializeComponent(); System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, errors) => certificate != null && certificate.Subject.Contains(CERT, StringComparison.OrdinalIgnoreCase)); pictureBox1.LoadAsync("http://www4.esu.edu/images/esu_logo_large.png"); if (!user.Equals(default(KeyValuePair <string, string>))) { textBox2.Text = user.Key; textBox1.Text = user.Value; //textBox2.ReadOnly = true; //textBox1.ReadOnly = true; } // int index = 0; var urlLocations = FileExplorerWindow.GetLocations(); if (urlLocations.Count <= 0) { MessageBox.Show("Found No Valid Locations...", "No Locations"); this.Close(); return; } urlLocations.Sort((a, b) => a.Index.CompareTo(b.Index)); comboBox1.Items.AddRange(urlLocations.ToArray()); comboBox1.SelectedIndex = 0; //textBox2.Text = "tthornton1"; //textBox1.Text = "Tst12368"; // button1.PerformClick(); }
private void button1_Click(object sender, EventArgs e) { //AddBookmarkWindow bookmarkWindow = new AddBookmarkWindow(); //bookmarkWindow.Show(); //return; user = new KeyValuePair <string, string>(textBox2.Text, textBox1.Text); url = ((FileExplorerWindow.UrlLocation)comboBox1.SelectedItem); // url = new KeyValuePair<string, string>(((UrlLocation)comboBox1.SelectedItem).BaseAddress, String.Format(((UrlLocation)comboBox1.SelectedItem).Url, textBox2.Text)); using (HttpClient client = FileExplorerWindow.CreateHttpClient(url.BaseAddress, user)) if (FileExplorerWindow.CheckIfExists(new FileExplorerWindow.HttpInfo(client, new FileExplorerWindow.LinkInfo(String.Format(url.Url, textBox2.Text), url, url.FolderName, "Directory", null, "Directory"), user))) { DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("Username and/or Password Were Incorrect.\nPlease Try Again...", "Invalid Login"); } }