public static void ForReadME3() { // Create a portable storage using var storage = PortableStorage.Providers.FileStorgeProvider.CreateStorage(@"c:\temp", true, null); // Create a portable download manager var dmOptions = new DownloadManagerOptions() { Storage = storage, MaxOfSimultaneousDownloads = 3 }; using var dm = new DownloadManager(dmOptions); dm.Add("file1.zip", new Uri("https://abcd.com/file1.zip")); dm.Add("file2.zip", new Uri("https://abcd.com/file2.zip")); dm.Add("folder/file3.zip", new Uri("https://abcd.com/file3.zip")); dm.Add("folder/file4.zip", new Uri("https://abcd.com/file4.zip")); dm.Add("folder/file5.zip", new Uri("https://abcd.com/file5.zip")); // wait for downloads while (!dm.IsIdle) { Thread.Sleep(500); } // done }
public void Test_Download_must_start_if_finished_file_doesnot_exist() { var path = Path.Combine(TempPath, Guid.NewGuid().ToString()); using var storage = PortableStorage.Providers.FileStorgeProvider.CreateStorage(path, true, null); var uri = new Uri("https://download.sysinternals.com/files/SysinternalsSuite-ARM64.zip"); var dmOptions = new DownloadManagerOptions() { Storage = storage }; using var dm = new DownloadManager(dmOptions); dm.Add("file1", uri, false); dm.Add("file1", uri, true); Assert.IsFalse(dm.IsIdle, "dowload is not started after second add"); dm.Add("file1", uri); WaitForAllDownloads(dm); storage.DeleteStream("file1"); dm.Add("file1", uri); WaitForAllDownloads(dm); Assert.IsTrue(storage.StreamExists("file1")); }
//[TestMethod] public void Test_Foo() { var path = Path.Combine(TempPath, Guid.NewGuid().ToString()); using var storage = PortableStorage.Providers.FileStorgeProvider.CreateStorage(path, true, null); var uri = new Uri("https://az792536.vo.msecnd.net/vms/VMBuild_20190311/VirtualBox/MSEdge/MSEdge.Win10.VirtualBox.zip"); var dmOptions = new DownloadManagerOptions() { Storage = storage, MaxOfSimultaneousDownloads = 1, PartSize = 1000 * 1000000, MaxPartCount = 1, AllowResuming = true, }; using var dm = new DownloadManager(dmOptions); dm.Add("file1", uri); dm.Start("file1"); while (!dm.IsIdle) { Debug.WriteLine(dm.GetItem().BytesPerSecond / 1000); Thread.Sleep(1000); } Assert.IsTrue(storage.EntryExists("file1")); }
private void button_Click(object sender, RoutedEventArgs e) { string response = textBox.Text; DownloadManager.Config(Bloodcat.PostCAPTCHA(textBox.Text, CAPTCHAData), Server.Blooadcat); DownloadManager.Add(new Beatmapset(new Uri("https://osu.ppy.sh/beatmapsets/628446#osu/1672509")), Server.Blooadcat); }
public void AddDownload(Metadata metadata, string path, long maxLength) { this.Check(); lock (_lockObject) { _downloadManager.Add(metadata, path, maxLength); } }
public void Test_Storage_Download() { var path = Path.Combine(TempPath, Guid.NewGuid().ToString()); using var storage = PortableStorage.Providers.FileStorgeProvider.CreateStorage(path, true, null); var uri = new Uri("https://download.sysinternals.com/files/SysinternalsSuite-ARM64.zip"); var dmOptions = new DownloadManagerOptions() { Storage = storage, MaxOfSimultaneousDownloads = 100 }; using (var dm = new DownloadManager(dmOptions)) { dm.Add("file1", uri, false); dm.Add("file2", uri, false); dm.Add("folder1/file1", uri, false); dm.Add("folder1/file2", uri, false); dm.Add("folder1/file3", uri, false); // no item should be started Assert.AreEqual(0, dm.Items.Count(x => x.IsStarted)); // check the number of added items dm.Start("folder1"); Assert.AreEqual(3, dm.Items.Count(x => x.IsStarted)); WaitForAllDownloads(dm); Assert.AreEqual(2, dm.Items.Count(x => x.State == DownloadState.Stopped), "invalid number of item with none state"); Assert.AreEqual(3, dm.Items.Count(x => x.State == DownloadState.Finished), "invalid number of item with finish state"); } Assert.IsTrue(storage.EntryExists($"folder1/file1"), "item has not been downloaded!"); Assert.IsTrue(storage.EntryExists($"folder1/file2"), "item has not been downloaded!"); Assert.IsTrue(storage.EntryExists($"folder1/file3"), "item has not been downloaded!"); }
static void DownloadByPortableDownloader(string url, string path, DownloadManagerOptions options, bool continueAfterRestart) { var startTime = DateTime.Now; Console.WriteLine($"Download using PortableDownloader. \nMaxPartCount: {options.MaxPartCount}, \nPartSize: {options.PartSize}, \nAllowResuming: {options.AllowResuming}, \nWriteBufferSize: {options.WriteBufferSize}"); Console.WriteLine(); using var storage = PortableStorage.Providers.FileStorgeProvider.CreateStorage(Path.GetDirectoryName(path), true, null); options.Storage = storage; using var dm = new DownloadManager(options); var streamPath = Path.GetFileName(path); //delete old download if (!continueAfterRestart) { if (storage.StreamExists(streamPath)) { storage.DeleteStream(streamPath); } dm.Cancel(streamPath); } dm.Add(streamPath, new Uri(url)); dm.Add(streamPath + "a", new Uri(url)); dm.Add(streamPath + "2", new Uri("https://s3.amazonaws.com/bpacks/bbcpersian/bbcpersian.jpg")); dm.Add(streamPath + "3", new Uri("https://s3.amazonaws.com/bpacks/bbcpersian/bpack_meta.json")); while (!dm.IsIdle) { var item = dm.GetItem(); var totalSeconds = Math.Max(1, (int)(DateTime.Now - startTime).TotalSeconds); var speed = ((float)item.BytesPerSecond / 1000000).ToString("0.00"); Console.WriteLine($"Downloaded: {item.CurrentSize} / { item.TotalSize }, Timer: {totalSeconds} Seconds, Speed: {speed} MB/s "); Thread.Sleep(1000); } ReportSpeed(startTime, dm.GetItem().TotalSize); }
public void AddDownloadEpisode(Episode ep, Quality quality, ADBaseLibrary.Format format, bool logerror = true) { if (IsInDownloadList(ep.Id, quality)) { if (logerror) { Log(LogType.Info, TemplateParser.FilenameFromEpisode(ep, quality, Settings.Instance.DownloadTemplate) + " was already added"); } } else { DownloadItem dinfo = _manager.Add(EpisodeWithDownloadSettings.FromEpisode(ep, quality, format), Settings.Instance.DownloadTemplate, Settings.Instance.DownloadPath); Log(LogType.Info, "Adding " + dinfo.DownloadInfo.FileName + " to downloads"); objDownloads.AddObject(dinfo); if (objDownloads.Items.Count == 1) { objDownloads.SelectedObject = dinfo; } RefreshInfo(); } }
static void Main(string[] args) { Console.Title = "osi_Console"; Console.WriteLine("START"); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var appsettings = config.AppSettings.Settings; string InsoCookie; string BloodcatCookie; if (appsettings["FirstRun"].Value == "true") { string httpHash, httpsHash; RegisterAsDefaultBrowserFunction.Register(out httpHash, out httpsHash); if (httpHash != null) { appsettings["HttpHash"].Value = httpHash; } if (httpsHash != null) { appsettings["HttpsHash"].Value = httpsHash; } while (!(InputCookieFunction.InputInsoCookie(out InsoCookie) | InputCookieFunction.InputBloodcatCookie(out BloodcatCookie))) { Console.WriteLine("请至少满足一个服务器的需求。"); } if (InsoCookie != null) { appsettings["InsoCookie"].Value = InsoCookie; } if (BloodcatCookie != null) { appsettings["BloodcatCookie"].Value = BloodcatCookie; } appsettings["FirstRun"].Value = "false"; } else { RegisterAsDefaultBrowserFunction.RegisterAsDefaultBrowser(appsettings["HttpHash"].Value, appsettings["HttpsHash"].Value); InsoCookie = appsettings["InsoCookie"].Value; BloodcatCookie = appsettings["BloodcatCookie"].Value; if (InsoCookie != null) { if (!Inso.IsCookieValid(InsoCookie)) { Console.WriteLine("Inso Cookie已失效 请重新输入。"); InputCookieFunction.InputInsoCookie(out InsoCookie); appsettings["InsoCookie"].Value = InsoCookie; } else { Console.WriteLine("do_not_remove_this_0w0" + " = " + InsoCookie); Console.WriteLine("Inso Cookie有效。"); } } if (BloodcatCookie != null) { if (!Bloodcat.IsCookieValid(BloodcatCookie)) { Console.WriteLine("Bloodcat Cookie已失效 请重新输入。"); InputCookieFunction.InputBloodcatCookie(out BloodcatCookie); appsettings["BloodcatCookie"].Value = BloodcatCookie; } else { Console.WriteLine("obm_human" + " = " + BloodcatCookie); Console.WriteLine("Bloodcat Cookie有效。"); } } } config.Save(); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { }; DownloadManager downloadMgr = new DownloadManager(); if (InsoCookie != null) { downloadMgr.Config(InsoCookie, Server.Inso, true); } if (BloodcatCookie != null) { downloadMgr.Config(BloodcatCookie, Server.Blooadcat, true); } downloadMgr.MaxDownloaderCount = 2; downloadMgr.FileWriter = DownloadHepler.FileHelper.FileWrite; Console.WriteLine("Start Monitor", System.Drawing.Color.White); NamedPipeServerStream server = new NamedPipeServerStream("osi", PipeDirection.In); while (true) { server.WaitForConnection(); StreamReader sr = new StreamReader(server); string link = sr.ReadToEnd(); Console.WriteLine("Get Link" + " " + link); try { BeatmapsetPackage package = new BeatmapsetPackage(new Beatmapset(link)); package.GetInfoCompleted += delegate(object sender, BeatmapsetPackage.BeatmapsetInfo e) { Console.WriteLine(e.beatmapsetId + " " + e.artist + "-" + e.title); }; package.DownloadProgressChanged += delegate(object sender, BeatmapsetPackage.DownloadProgressChangedArgs e) { Console.WriteLine(e.Status); }; package.WriteFileCompleted += delegate(object sender, BeatmapsetPackage.WriteFileCompletedArg e) { System.Diagnostics.Process.Start(e.Path); }; downloadMgr.Add(package); } catch (Beatmapset.NotValidUri e) { } server.Disconnect(); } }
public void Test_Add_Start_Stop_Restore_Cancel() { var path = Path.Combine(TempPath, Guid.NewGuid().ToString()); using var storage = PortableStorage.Providers.FileStorgeProvider.CreateStorage(path, true, null); var uri = new Uri("https://download.sysinternals.com/files/SysinternalsSuite-ARM64.zip"); var dmOptions = new DownloadManagerOptions() { Storage = storage, MaxOfSimultaneousDownloads = 100 }; using (var dm = new DownloadManager(dmOptions)) { dm.Add("file1", uri, false); dm.Add("file2", uri, false); dm.Add("file3", uri, false); dm.Add("folder1/file1", uri, false); dm.Add("folder1/file2", uri, false); dm.Add("folder1/file3", uri, false); // check the number of added items Assert.AreEqual(6, dm.Items.Length, "Invalid number of added items"); Assert.AreEqual(6, dm.GetItems("/").Length, "Invalid number of added items"); Assert.IsTrue(dm.Items.All(x => x.State == DownloadState.Stopped), "all items but has been in none state"); // start downloading dm.Start("file1"); dm.Start("folder1/file1"); dm.Stop("file3"); // check number of started item Assert.AreEqual(2, dm.Items.Count(x => x.IsStarted), "invalid number of started items"); WaitForAllDownloads(dm); // check for errors Assert.IsFalse(dm.Items.Any(x => x.State == DownloadState.Error), "there is an error in downloads"); // check for downloaded stream Assert.IsTrue(storage.EntryExists("file1")); Assert.IsTrue(storage.EntryExists("folder1/file1")); Assert.AreEqual(2, dm.Items.Count(x => x.State == DownloadState.Finished), "2 items must has been finished"); // check remote finished items dm.RemoveFinishedItems(); Assert.AreEqual(dm.Items.Length, 4, "Invalid number of remained items"); // download another item dm.Start("file3"); // download another item and cancel it dm.Start("folder1/file3"); dm.Cancel("folder1/file3"); WaitForAllDownloads(dm); // check cancel result Assert.AreEqual(1, dm.Items.Count(x => x.State == DownloadState.Finished), "2 items must be finished"); Assert.IsTrue(storage.EntryExists("file3")); Assert.IsFalse(storage.EntryExists($"folder1/file3{dmOptions.DownloadingExtension}"), "item hasn't deleted"); Assert.IsFalse(storage.EntryExists($"folder1/file3{dmOptions.DownloadingInfoExtension}"), "item hasn't deleted"); } //check restoring using (var dm = new DownloadManager(dmOptions)) { Assert.AreEqual(3, dm.Items.Length, 3, "Invalid number of added items"); Assert.AreEqual(1, dm.Items.Count(x => x.State == DownloadState.Finished), "invalid number of finished items"); Assert.AreEqual(2, dm.Items.Count(x => x.State == DownloadState.Stopped), "invalid number of not started items"); dm.Start("folder1/file2"); Assert.AreEqual(1, dm.Items.Count(x => x.IsStarted), "invalid number of started items"); Assert.AreEqual(2, dm.Items.Count(x => x.IsIdle), "invalid number of ilde items"); } // restore downloads after restart using (var dm = new DownloadManager(dmOptions)) { WaitForAllDownloads(dm); Assert.IsTrue(storage.EntryExists("folder1/file2")); } }