public void DownloadFile(string url, string file) { // Create a download item. Download download = new Download(url, file); // If the same file had previously been downloaded, // let the old one assume the identity of the new. Download existingDownload = _downloads.SingleOrDefault(d => d == download); // Show the downloads bar. //DownloadsVisible = true; if (existingDownload != null) { download = existingDownload; } else { _downloads.Add(download); } // Start downloading. download.Start(); // Show the Downloads window. DownloadsWindow.Show(dockPanel); }
private static DownloadCollection DBMapping(DBDownloadCollection dbCollection) { if (dbCollection == null) return null; DownloadCollection collection = new DownloadCollection(); foreach (DBDownload dbItem in dbCollection) { Download item = DBMapping(dbItem); collection.Add(item); } return collection; }
private static DownloadCollection DBMapping(DBDownloadCollection dbCollection) { if (dbCollection == null) { return(null); } DownloadCollection collection = new DownloadCollection(); foreach (DBDownload dbItem in dbCollection) { Download item = DBMapping(dbItem); collection.Add(item); } return(collection); }
private static async Task <DownloadCollection> GetDownloadables(string url, string extension) { var downloadResults = new DownloadCollection(); var uri = new Uri(url); var httpHandler = new HttpClientHandler() { MaxConnectionsPerServer = int.MaxValue }; using (var wc = new HttpClient(httpHandler)) { Console.WriteLine("Scraping: " + url); var data = await wc.GetByteArrayAsync(url); if (data != null && data.Length > 0) { var source = Encoding.UTF8.GetString(data, 0, data.Length - 1); source = WebUtility.HtmlDecode(source); var resultat = new HtmlDocument(); resultat.LoadHtml(source); //Parse results var resultLinks = resultat.DocumentNode.Descendants().Where (x => (x.Name == "a" && x.Attributes["href"] != null && (extension == null || x.InnerText.ToLower().EndsWith("/") || x.InnerText.ToLower().EndsWith(extension.ToLower())))).ToList(); foreach (var results in resultLinks) { var name = results.InnerText.Trim(); if (name.EndsWith("/") || name.Contains('.')) { downloadResults.Add(new DownloadResult { Name = name, Url = string.Concat(url.ToString(), "/", name), BaseUrl = url }); } } } }//WebClient return(downloadResults); }
/// <summary> /// Generates a template xml to base custom scripts off of. /// </summary> /// <param name="savePath">The location the template will be saved.</param> public void GenerateXmlTemplate(string savePath) { ServiceManager.Services.LogService.WriteHeader("Generating Xml Template..."); #region Script 1 Script script = new Script(); script.Name = "Script 1"; script.Description = "Does nothing"; Executable executable = new Executable(); executable.Path = "C:/Temp/nothing.ps1"; ArgumentCollection argCollection = new ArgumentCollection(); argCollection.Add(new Argument() { Key = "-i", Value = "C:/Temp/something.bin" }); argCollection.Add(new Argument() { Key = "-x", Value = "" }); ExitCodeCollection exitCollection = new ExitCodeCollection(); exitCollection.Add(new ExitCode() { Value = 0, Message = "Files deleted", IsSuccess = true }); exitCollection.Add(new ExitCode() { Value = 1, Message = "Files failed to delete" }); exitCollection.Add(new ExitCode() { Value = 2, Message = "Couldn't find any files" }); // Add all elements into the single script file. script.Arguments = argCollection; script.ExitCodes = exitCollection; script.Executable = executable; #endregion #region Script 2 Script script2 = new Script(); script2.Name = "Script 2"; script2.Description = "Does nothing"; Executable executable2 = new Executable(); executable2.Path = "C:/Temp/Downloads/Extracted/SomethingThatWasInAZip.exe"; ArgumentCollection argCollection2 = new ArgumentCollection(); argCollection2.Add(new Argument() { Key = "-install" }); argCollection2.Add(new Argument() { Key = "-silent" }); ExitCodeCollection exitCollection2 = new ExitCodeCollection(); exitCollection2.Add(new ExitCode() { Value = 0, Message = "Script 2 has installed", IsSuccess = true }); exitCollection2.Add(new ExitCode() { Value = 1, Message = "Failed to install." }); exitCollection2.Add(new ExitCode() { Value = 2, Message = "Installed but limited." }); // Add all elements into the single script file. script2.Arguments = argCollection; script2.ExitCodes = exitCollection; script2.Executable = executable; // Add the single script above into a collection of scripts. ScriptCollection scriptCollection = new ScriptCollection(); scriptCollection.Add(script); scriptCollection.Add(script2); #endregion ServiceManager.Services.LogService.WriteLine("Generating Download Collection..."); DownloadCollection downloadCollection = new DownloadCollection(); downloadCollection.TimeOut = 60; downloadCollection.RefreshRate = 10; downloadCollection.Add(new Download() { Name = "Nothing Powershell Script", Description = "This script does nothing", DownloadUrl = "www.blank.com/nothing.ps1", DestinationPath = "C:/Temp/Downloads/nothing.ps1" }); downloadCollection.Add(new Download() { Name = "Test Zip File", Description = "This zip has nothing", DownloadUrl = "www.blank.com/nothing.zip", DestinationPath = "C:/Temp/Downloads", ExtractionPath = "C:/Temp/Downloads/Extracted" }); // Add the 2 main elements, the scripts to run and the downloads to download. Setup setup = new Setup(); setup.Scripts = scriptCollection; setup.Downloads = downloadCollection; ServiceManager.Services.LogService.WriteLine("Saving file to: \"{0}\"", savePath); setup.Serialize(savePath); }