public Aria2cProcessStarter(IFileFinder fileFinder,
                             Aria2cConfig config,
                             Logger logger)
     : base(fileFinder, logger)
 {
     _config = config;
 }
        public Aria2cWebSocketWatcher(Aria2cConfig config, Logger logger)
        {
            _config = config;
            _logger = logger;
            _socket = new WebSocket(_config.WebSocketUrl);

            AttachEvents();
        }
        public void Can_subscribe_to_recieve_messages()
        {
            var config = new Aria2cConfig { WebSocketUrl = "ws://echo.websocket.org" };
            var fakeLogger = new Mock<Logger>();
            const string methodToWatch = "aria2.onDownloadStarted";

            var watcher = new Aria2cWebSocketWatcher(config,fakeLogger.Object)
                .Connect();
        }
Exemple #4
0
 public Aria2cServer(IProcessStarter processStarter,
                     IServerValidationRunner serverValidationRunner,
                     Aria2cConfig config,
                     Logger logger,
                     IServerWatcher serverWatcher)
 {
     _processStarter = processStarter;
     _serverValidationRunner = serverValidationRunner;
     _config = config;
     _logger = logger;
     _serverWatcher = serverWatcher;
 }
        public void When_calling_Run_should_call_Find_in_IFileFinder()
        {
            var mockFileFinder = new Mock<IFileFinder>();
            var fakeLogger = new Mock<Logger>();
            var config = new Aria2cConfig {Port = "7000"};

            mockFileFinder
                .Setup(c => c.Find())
                .Returns(Environment.SystemDirectory + "\\notepad.exe");

            IProcessStarter processStarter = new Aria2cProcessStarter(mockFileFinder.Object, config, fakeLogger.Object)
                {
                    DownloadedFilesDirPath = () => Assembly.GetExecutingAssembly().Location
                };

            processStarter.Run();

            mockFileFinder.Verify(c=>c.Find(), Times.Once());
        }
        public void Can_exit_process()
        {
            var fakeFileFinder = new Mock<IFileFinder>();
            var fakeLogger = new Mock<Logger>();
            var config = new Aria2cConfig { Port = "7000" };

            fakeFileFinder
                .Setup(c => c.Find())
                .Returns(Environment.SystemDirectory + "\\notepad.exe");

            IProcessStarter processStarter = new Aria2cProcessStarter(fakeFileFinder.Object, config, fakeLogger.Object)
            {
                DownloadedFilesDirPath = () => Assembly.GetExecutingAssembly().Location
            };

            processStarter.Run();

            Thread.Sleep(1000);

            processStarter.Exit();
        }
Exemple #7
0
        public void Get_status()
        {
            var config = new Aria2cConfig
            {
                Executable = "",
                Id = Guid.NewGuid().ToString(),
                JsonrpcUrl = "http://localhost:6800/jsonrpc",
                JsonrpcVersion = "2.0",
                RpcPort = 6800,
                WebSocketUrl = "ws://localhost:6800/jsonrpc"
            };

            var logger = LogManager.GetCurrentClassLogger();

            IClient client = new Aria2cJsonRpcClient(config,
                                                   new Aria2cWebSocketWatcher(config,
                                                                              logger).Connect(),
                                                   logger);

            var status = client.GetStatus("6ad3263090c0ea45");
        }
Exemple #8
0
        public void Add_download()
        {
            string appRoot = @"C:\work\aria4net";
            var fakeFomatter = new Mock<IPathFormatter>();

            var logger = LogManager.GetCurrentClassLogger();

            var config = new Aria2cConfig
                {
                    Executable = Path.Combine(appRoot, "tools\\aria2-1.16.3-win-32bit-build1\\aria2c.exe"),
                    Id = Guid.NewGuid().ToString(),
                    JsonrpcUrl = "http://localhost:6800/jsonrpc",
                    JsonrpcVersion = "2.0",
                    WebSocketUrl = "ws://localhost:6800/jsonrpc"
                };

            var watcher = new Aria2cWebSocketWatcher(config, logger);

            IServer server = new Aria2cServer(
                new Aria2cProcessStarterWithWindow(
                    new Aria2cFinder(config, fakeFomatter.Object), config, logger) { DownloadedFilesDirPath = () => "c:\\temp" },
                    new DefaultValidationRunner(),
                    config,
                    logger,
                    watcher);

            server.Start();

            IClient client = new Aria2cJsonRpcClient(config,
                                                     watcher,
                                                     logger);

            client.AddTorrent(
                "ftp://download.warface.levelupgames.com.br/Warface/Installer/Instalador_Client_LevelUp_1.0.34.006.torrent");

            server.Stop();
        }
 public Aria2cProcessStarterWithWindow(IFileFinder fileFinder, Aria2cConfig config, Logger logger)
     : base(fileFinder, config, logger)
 {
 }
Exemple #10
0
 public Aria2cFinder(Aria2cConfig config, IPathFormatter formatter = null)
 {
     _config = config;
     _formatter = formatter ?? new DefaultPathFormatter();
 }
Exemple #11
0
        private static void Main(string[] args)
        {
            string appRoot =
                Path.GetDirectoryName(
                    Path.GetDirectoryName(
                        Path.GetDirectoryName(
                            Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)))));

            var logger = LogManager.GetCurrentClassLogger();

            var config = new Aria2cConfig
                {
                    Executable = Path.Combine(appRoot, "tools\\aria2-1.16.3-win-32bit-build1\\aria2c.exe"),
                    Id = "downloader-session"

                };

            var watcher = new Aria2cWebSocketWatcher(config,
                                                     logger);

            IServer server = new Aria2cServer(
                new Aria2cProcessStarter(
                    new Aria2cFinder(config, new DefaultPathFormatter(new WindowsPathTokenizer())),
                    config,
                    logger)
                    {
                        DownloadedFilesDirPath = () => "c:\\temp"
                    },
                new DefaultValidationRunner(),
                config,
                logger,
                watcher);

            server.Start();

            IClient client = new Aria2cJsonRpcClient(config,
                                                     watcher,
                                                     logger);

            client.ChangeDestinationPath(@"C:\temp\torrents");

            var url1 =
                "http://download.warface.levelupgames.com.br/Warface/Installer/Instalador_Client_LevelUp_1.0.34.006.torrent";

            var gid1 = "";

            client.DownloadCompleted +=
                (sender, eventArgs) => Console.WriteLine("Download concluido {0}", eventArgs.Status.Gid);

            client.DownloadProgress += (o, e) => Console.WriteLine(
                "\r{7} Status {5} | Progress {0:N1} % | Speed {1:N2} Mb/s | Eta {2:N0} s | Downloaded {3:N2}  Mb | Remaining {6:N2} Mb | Total {4:N2} Mb",
                e.Status.Progress,
                e.Status.DownloadSpeed.ToMegaBytes(),
                e.Status.Eta,
                e.Status.CompletedLength.ToMegaBytes(),
                e.Status.TotalLength.ToMegaBytes(),
                e.Status.Status,
                (e.Status.Remaining).ToMegaBytes(),
                e.Status.Gid);

            gid1 = client.AddTorrent(url1, new[] {1});

            Console.ReadKey();

            client.Shutdown();
        }
Exemple #12
0
        public void Start_stop_server()
        {
            string appRoot = @"C:\work\aria4net";
            var fakeWatcher = new Mock<IServerWatcher>();
            var fakeFomatter = new Mock<IPathFormatter>();

            var logger = LogManager.GetCurrentClassLogger();

            var config = new Aria2cConfig
                {
                    Executable = Path.Combine(appRoot, "tools\\aria2-1.16.3-win-32bit-build1\\aria2c.exe")
                };

            IServer server = new Aria2cServer(
                new Aria2cProcessStarterWithWindow(
                    new Aria2cFinder(config, fakeFomatter.Object), config, logger),
                    new DefaultValidationRunner(),
                    config,
                    logger,
                    fakeWatcher.Object);

            server.Start();

            Thread.Sleep(1000);

            server.Stop();
        }