public void Download() { NetworkProtocolProviderFactory networkProtocolProviderFactory = new NetworkProtocolProviderFactory(new UrlProtocolParser()); HttpProtocolProvider httpProtocolProvider = new HttpProtocolProvider(new WebRequestManager(new WebRequestFactory())); networkProtocolProviderFactory.RegisterProvider("http", httpProtocolProvider); networkProtocolProviderFactory.RegisterProvider("https", httpProtocolProvider); DownloadTask downloadTask = new DownloadTask( networkProtocolProviderFactory, new DownloadSegmentPositionsCalculator(), new MemoryDownloadStreamManager(), new InMemoryDownloadSettings(200, 5, 8096, 5, 5), new DownloadFileInfo(new Uri("https://androidnetworktester.googlecode.com/files/1mb.txt"), "1mb.txt", 5), new EventManager()); downloadTask.EventManager.EventSubscriber.RegisterConsumer(new ActionEventConsumer<DownloadTaskFinishedEventMessage>(x => { string txt = Encoding.UTF8.GetString(((MemoryStream)x.DownloadStream).ToArray()); txt.ToString(); })); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); downloadTask.StartDownload(); stopwatch.Stop(); stopwatch.Elapsed.ToString(); }
public void Download() { NetworkProtocolProviderFactory networkProtocolProviderFactory = new NetworkProtocolProviderFactory(new UrlProtocolParser()); HttpProtocolProvider httpProtocolProvider = new HttpProtocolProvider(new WebRequestManager(new WebRequestFactory())); networkProtocolProviderFactory.RegisterProvider("http", httpProtocolProvider); networkProtocolProviderFactory.RegisterProvider("https", httpProtocolProvider); EventManager eventManager = new EventManager(); DownloadManager downloadManager = new DownloadManager( new InMemoryDownloadSettings(200, 5, 8096, 5, 5), new MemoryDownloadStreamManager(), networkProtocolProviderFactory, eventManager); downloadManager.Start(); downloadManager.AddNewDownloadTask(new DownloadTaskInfo(new DownloadFileInfo(new Uri("https://androidnetworktester.googlecode.com/files/1mb.txt"), "1mb.txt", 5), true)); downloadManager.AddNewDownloadTask(new DownloadTaskInfo(new DownloadFileInfo(new Uri("http://127.0.0.1:8552/1mb.txt"), "1mb.txt", 5), true)); eventManager.EventSubscriber.RegisterConsumer(new ActionEventConsumer<DownloadTaskFinishedEventMessage>(x => { string txt = Encoding.UTF8.GetString(((MemoryStream)x.DownloadStream).ToArray()); txt.ToString(); })); downloadManager.Shutdown(true); }
public DownloadHelper(IDownloadSettings downloadSettings, IDownloadStreamManager downloadStreamManager) { NetworkProtocolProviderFactory networkProtocolProviderFactory = new NetworkProtocolProviderFactory(new UrlProtocolParser()); HttpProtocolProvider httpProtocolProvider = new HttpProtocolProvider(new WebRequestManager(new WebRequestFactory())); networkProtocolProviderFactory.RegisterProvider("http", httpProtocolProvider); networkProtocolProviderFactory.RegisterProvider("https", httpProtocolProvider); m_EventManager = new EventManager(); m_DownloadManager = new DownloadManager( downloadSettings, downloadStreamManager, networkProtocolProviderFactory, m_EventManager); }
public void CreateProvider(string url, string protocol, string registerProtocol) { Mock<IUrlProtocolParser> urlProtocolParserMock = new Mock<IUrlProtocolParser>(); urlProtocolParserMock.Setup(x => x.Parse(new Uri(url))).Returns(protocol); NetworkProtocolProviderFactory networkProtocolProviderFactory = new NetworkProtocolProviderFactory(urlProtocolParserMock.Object); INetworkProtocolProvider networkProtocolProvider = new Mock<INetworkProtocolProvider>().Object; networkProtocolProviderFactory.RegisterProvider(registerProtocol, networkProtocolProvider); Assert.AreEqual(networkProtocolProvider, networkProtocolProviderFactory.CreateProvider(new Uri(url))); }