public async Task AddTest()
        {
            var builder = new ContainerBuilder();

            builder.RegisterInstance(new Logger()).As <ILoggerFacade>();
            var container = builder.Build();

            IConfigureFile configure = new ConfigureFile().Load(@"D:\transfer-configure.json");

            configure.SetValue(TransferService.DownloaderContextKey, new TransferContextSettings {
                MaxParallelTranspoterCount = 4
            });

            ITransferService service = new TransferService(container).Initialize(configure);

            service.Run();
        }
        public void UseTest()
        {
            ServicePointManager.DefaultConnectionLimit = 99999;

            var builder = new ContainerBuilder();

            builder.RegisterInstance(new Logger()).As <ILoggerFacade>();
            IContainer container = builder.Build();

            IConfigureFile configure = new ConfigureFile().Load(@"D:\transfer-configure.json");

            configure.SetValue(TransferService.DownloaderContextKey, new TransferContextSettings {
                MaxParallelTranspoterCount = 4
            });

            ITransferService service = new TransferService(container).Initialize(configure);

            service.Run();

            var downloader = service.UseDefaultDownloaderBuilder()
                             .From("http://download.accelerider.com:888/Made%20in%20Abyss.mkv")
                             .To(@"D:\test-file2.rar")
                             .Configure(settings =>
            {
                settings.MaxErrorCount = 3;
                settings.AutoSwitchUri = true;
                settings.BlockSize     = DataSize.OneMB * 50;
                settings.ThreadCount   = 16;
            })
                             .Build();

            var managedToken = service.Register(downloader).AsUnmanaged();

            managedToken.Start();


            while (downloader.Status != TransferStatus.Completed)
            {
                Thread.Sleep(1000);
                Debug.WriteLine($"{downloader.Id}: {downloader.Status} - {downloader.CompletedSize}/{downloader.TotalSize} ");
            }
        }
        private async Task SignInAsync(string username, string passwordMd5)
        {
            EventAggregator.GetEvent <MainWindowLoadingEvent>().Publish(true);

            var httpClient = new HttpClient();

            var disco = await httpClient.GetDiscoveryDocumentAsync("http://localhost:5000/");

            if (disco.IsError)
            {
                Notifier.Error(disco.Error);
                EventAggregator.GetEvent <MainWindowLoadingEvent>().Publish(false);
                return;
            }

            var tokenResponse = await httpClient.RequestPasswordTokenAsync(new PasswordTokenRequest
            {
                Address      = disco.TokenEndpoint,
                ClientId     = "wpf client",
                ClientSecret = "77DAABEF-697A-4CC1-A400-3CC561B9AD83",
                Scope        = "api1 openid profile",
                UserName     = "******",
                Password     = "******"
            });

            if (tokenResponse.IsError)
            {
                Notifier.Error(tokenResponse.Error);
                EventAggregator.GetEvent <MainWindowLoadingEvent>().Publish(false);
                return;
            }

            var apiClient = new HttpClient();

            apiClient.SetBearerToken(tokenResponse.AccessToken);

            var response = await apiClient.GetAsync(disco.UserInfoEndpoint);

            if (response.IsSuccessStatusCode)
            {
                System.Windows.Application.Current.Properties["AccessToken"] = tokenResponse.AccessToken;
                var content = await response.Content.ReadAsStringAsync();

                Notifier.Success(Localizer["Login Success"]);
            }
            else
            {
                Notifier.Error(Localizer["Login Failed"]);
                EventAggregator.GetEvent <MainWindowLoadingEvent>().Publish(false);
                ConfigureFile.SetValue(ConfigureKeys.AutoSignIn, false);
                return;
            }

            // Saves data.
            ConfigureFile.SetValue(ConfigureKeys.Username, IsRememberMe ? username : string.Empty);
            ConfigureFile.SetValue(ConfigureKeys.Password, IsRememberMe ? passwordMd5.EncryptByDes() : string.Empty);
            ConfigureFile.SetValue(ConfigureKeys.AutoSignIn, IsAutoSignIn);

            // Launches main window and closes itself.
            ShellManager.Switch <LoginWindow, MainWindow>();
        }