Ejemplo n.º 1
0
        private volatile bool _disposedValue = false;         // To detect redundant calls

        public RegTestFixture()
        {
            RuntimeParams.SetDataDir(Path.Combine(Common.DataDir, "RegTests", "Backend"));
            RuntimeParams.LoadAsync().GetAwaiter().GetResult();
            var hostedServices = new HostedServices();

            BackendRegTestNode = TestNodeBuilder.CreateAsync(hostedServices, callerFilePath: "RegTests", callerMemberName: "BitcoinCoreData").GetAwaiter().GetResult();

            var testnetBackendDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Tests", "RegTests", "Backend"));

            IoHelpers.TryDeleteDirectoryAsync(testnetBackendDir).GetAwaiter().GetResult();
            Thread.Sleep(100);
            Directory.CreateDirectory(testnetBackendDir);
            Thread.Sleep(100);
            var config = new Config(
                BackendRegTestNode.RpcClient.Network,
                BackendRegTestNode.RpcClient.CredentialString.ToString(),
                new IPEndPoint(IPAddress.Loopback, Network.Main.DefaultPort),
                new IPEndPoint(IPAddress.Loopback, Network.TestNet.DefaultPort),
                BackendRegTestNode.P2pEndPoint,
                new IPEndPoint(IPAddress.Loopback, Network.Main.RPCPort),
                new IPEndPoint(IPAddress.Loopback, Network.TestNet.RPCPort),
                BackendRegTestNode.RpcEndPoint);
            var configFilePath = Path.Combine(testnetBackendDir, "Config.json");

            config.SetFilePath(configFilePath);
            config.ToFile();

            var roundConfig         = CreateRoundConfig(Money.Coins(0.1m), Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);
            var roundConfigFilePath = Path.Combine(testnetBackendDir, "CcjRoundConfig.json");

            roundConfig.SetFilePath(roundConfigFilePath);
            roundConfig.ToFile();

            var conf = new ConfigurationBuilder()
                       .AddInMemoryCollection(new[] { new KeyValuePair <string, string>("datadir", testnetBackendDir) })
                       .Build();

            BackendEndPoint       = $"http://localhost:{CryptoHelpers.RandomInt(37130, 37999)}/";
            BackendEndPointUri    = new Uri(BackendEndPoint);
            BackendEndPointApiUri = new Uri(BackendEndPointUri, $"/api/v{Constants.BackendMajorVersion}/");

            BackendHost = Host.CreateDefaultBuilder()
                          .ConfigureWebHostDefaults(webBuilder => webBuilder
                                                    .UseStartup <Startup>()
                                                    .UseConfiguration(conf)
                                                    .UseWebRoot("../../../../WalletWasabi.Backend/wwwroot")
                                                    .UseUrls(BackendEndPoint))
                          .Build();

            Global = (Global)BackendHost.Services.GetService(typeof(Global));
            Global.HostedServices = hostedServices;
            var hostInitializationTask = BackendHost.RunWithTasksAsync();

            Logger.LogInfo($"Started Backend webhost: {BackendEndPoint}");

            var delayTask = Task.Delay(3000);

            Task.WaitAny(delayTask, hostInitializationTask);             // Wait for server to initialize (Without this OSX CI will fail)
        }
Ejemplo n.º 2
0
        public RegTestFixture()
        {
            BackendNodeBuilder = NodeBuilder.CreateAsync(nameof(RegTestFixture)).GetAwaiter().GetResult();
            BackendNodeBuilder.CreateNodeAsync().GetAwaiter().GetResult();
            BackendNodeBuilder.StartAllAsync().GetAwaiter().GetResult();
            BackendRegTestNode = BackendNodeBuilder.Nodes[0];

            var rpc = BackendRegTestNode.CreateRpcClient();

            var config = new Config(rpc.Network, rpc.Authentication, IPAddress.Loopback.ToString(), IPAddress.Loopback.ToString(), BackendRegTestNode.Endpoint.Address.ToString(), Network.Main.DefaultPort, Network.TestNet.DefaultPort, BackendRegTestNode.Endpoint.Port);

            var roundConfig = new CcjRoundConfig(Money.Coins(0.1m), Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);

            Backend.Global.Instance.InitializeAsync(config, roundConfig, rpc).GetAwaiter().GetResult();

            BackendEndPoint = $"http://localhost:{new Random().Next(37130, 38000)}/";
            BackendHost     = WebHost.CreateDefaultBuilder()
                              .UseStartup <Startup>()
                              .UseUrls(BackendEndPoint)
                              .Build();

            var hostInitializationTask = BackendHost.RunAsync();

            Logger.LogInfo($"Started Backend webhost: {BackendEndPoint}", nameof(Global));

            var delayTask = Task.Delay(3000);

            Task.WaitAny(delayTask, hostInitializationTask);             // Wait for server to initialize (Without this OSX CI will fail)
        }
Ejemplo n.º 3
0
        public RegTestFixture()
        {
            BackendNodeBuilder = NodeBuilder.CreateAsync().GetAwaiter().GetResult();
            BackendNodeBuilder.CreateNodeAsync().GetAwaiter().GetResult();
            BackendNodeBuilder.StartAllAsync().GetAwaiter().GetResult();
            BackendRegTestNode = BackendNodeBuilder.Nodes[0];

            var rpc = BackendRegTestNode.CreateRpcClient();

            var authString = rpc.Authentication.Split(':');

            var config = new Config(rpc.Network, authString[0], authString[1]);

            var roundConfig = new CcjRoundConfig(Money.Coins(0.1m), 144, 0.1m, 100, 120, 60, 60, 60, 1);

            Global.InitializeAsync(config, roundConfig, rpc).GetAwaiter().GetResult();

            BackendEndPoint = $"http://localhost:{new Random().Next(37130, 38000)}/";
            BackendHost     = WebHost.CreateDefaultBuilder()
                              .UseStartup <Startup>()
                              .UseUrls(BackendEndPoint)
                              .Build();

            var hostInitializationTask = BackendHost.RunAsync();

            Logger.LogInfo <SharedFixture>($"Started Backend webhost: {BackendEndPoint}");

            var delayTask = Task.Delay(3000);

            Task.WaitAny(delayTask, hostInitializationTask);             // Wait for server to initialize (Without this OSX CI will fail)
        }
Ejemplo n.º 4
0
        public void Dispose()
        {
            // Cleanup tests...

            BackendHost?.StopAsync().GetAwaiter().GetResult();
            BackendHost?.Dispose();
            BackendRegTestNode?.TryKillAsync(cleanFolder: true).GetAwaiter().GetResult();
            BackendNodeBuilder?.Dispose();
        }
Ejemplo n.º 5
0
        public void Dispose()
        {
            // Cleanup tests...

            BackendHost?.StopAsync();
            BackendHost?.Dispose();
            BackendRegTestNode?.Kill(cleanFolder: true);
            BackendNodeBuilder?.Dispose();
        }
Ejemplo n.º 6
0
        public AppSettings(IKeyValueStore store)
        {
            _store = store;

            Conventions = new ConventionsPreferences();
            Identity    = new BackendHost();
            Friends     = new BackendHost();
            Chat        = new BackendHost();
        }
Ejemplo n.º 7
0
        public RegTestFixture()
        {
            BackendNodeBuilder = NodeBuilder.CreateAsync(EnvironmentHelpers.GetMethodName()).GetAwaiter().GetResult();
            BackendNodeBuilder.CreateNodeAsync().GetAwaiter().GetResult();
            BackendNodeBuilder.StartAllAsync().GetAwaiter().GetResult();
            BackendRegTestNode = BackendNodeBuilder.Nodes[0];

            var connectionString = $"{BackendRegTestNode.Creds.UserName}:{BackendRegTestNode.Creds.Password}";

            var testnetBackendDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Tests", "Backend"));

            IoHelpers.DeleteRecursivelyWithMagicDustAsync(testnetBackendDir).GetAwaiter().GetResult();
            Thread.Sleep(100);
            Directory.CreateDirectory(testnetBackendDir);
            Thread.Sleep(100);
            var config = new Config(
                BackendNodeBuilder.Network, connectionString,
                new IPEndPoint(IPAddress.Loopback, Network.Main.DefaultPort),
                new IPEndPoint(IPAddress.Loopback, Network.TestNet.DefaultPort),
                BackendRegTestNode.P2pEndPoint,
                new IPEndPoint(IPAddress.Loopback, Network.Main.RPCPort),
                new IPEndPoint(IPAddress.Loopback, Network.TestNet.RPCPort),
                BackendRegTestNode.RpcEndPoint);
            var configFilePath = Path.Combine(testnetBackendDir, "Config.json");

            config.SetFilePath(configFilePath);
            config.ToFileAsync().GetAwaiter().GetResult();

            var roundConfig         = CreateRoundConfig(Money.Coins(0.1m), Constants.OneDayConfirmationTarget, 0.7, 0.1m, 100, 120, 60, 60, 60, 1, 24, true, 11);
            var roundConfigFilePath = Path.Combine(testnetBackendDir, "CcjRoundConfig.json");

            roundConfig.SetFilePath(roundConfigFilePath);
            roundConfig.ToFileAsync().GetAwaiter().GetResult();

            var conf = new ConfigurationBuilder()
                       .AddInMemoryCollection(new[] { new KeyValuePair <string, string>("datadir", testnetBackendDir) })
                       .Build();

            BackendEndPoint = $"http://localhost:{new Random().Next(37130, 38000)}/";
            BackendHost     = WebHost.CreateDefaultBuilder()
                              .UseStartup <Startup>()
                              .UseConfiguration(conf)
                              .UseWebRoot("../../../../WalletWasabi.Backend/wwwroot")
                              .UseUrls(BackendEndPoint)
                              .Build();
            Global = (Backend.Global)BackendHost.Services.GetService(typeof(Backend.Global));
            var hostInitializationTask = BackendHost.RunWithTasksAsync();

            Logger.LogInfo($"Started Backend webhost: {BackendEndPoint}");

            var delayTask = Task.Delay(3000);

            Task.WaitAny(delayTask, hostInitializationTask);             // Wait for server to initialize (Without this OSX CI will fail)
        }
Ejemplo n.º 8
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    BackendHost?.StopAsync().GetAwaiter().GetResult();
                    BackendHost?.Dispose();
                    BackendRegTestNode?.TryStopAsync().GetAwaiter().GetResult();
                }

                _disposedValue = true;
            }
        }
Ejemplo n.º 9
0
        public async void Start()
        {
            var settings = _store.GetObservable <AppSettings>(nameof(AppSettings)).Wait();

            if (settings != null)
            {
                SetupFinished = settings.SetupFinished;
                ServiceId     = settings.ServiceId;
                Conventions   = settings.Conventions;
                Identity      = settings.Identity;
                Friends       = settings.Friends;
                Chat          = settings.Chat;
            }
            else
            {
                LoadFromRessource();
                await Persist();
            }

            ResourceKeys.NicknameMaxLength      = Conventions.NicknameMaxLength;
            ResourceKeys.StatusMessageMaxLength = Conventions.StatusMessageMaxLength;
        }
Ejemplo n.º 10
0
 public Vindow(IVindowBackend customBackend) : this()
 {
     BackendHost.SetCustomBackend(customBackend);
 }
Ejemplo n.º 11
0
 public NativeWindowFrame(IWindowFrameBackend backend)
 {
     BackendHost.SetCustomBackend(backend);
 }
Ejemplo n.º 12
0
 public XwtComponent()
 {
     backendHost = CreateBackendHost ();
     backendHost.Parent = this;
 }
Ejemplo n.º 13
0
 public Display()
 {
     BackendHost.EnsureBackendLoaded();
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Load from an embedded json ressource.
        /// </summary>
        private void LoadFromRessource(string relativePath = "YoApp.Clients.Ressources")
        {
            var name = (!ResourceKeys.IsDebug)
                ? $"{relativePath}.appsettings.json"
                : $"{relativePath}.appsettings.Development.json";

            var assembly = typeof(AppSettings).GetTypeInfo().Assembly;

            var stream = assembly.GetManifestResourceStream(name);

            if (stream == null && ResourceKeys.IsDebug)
            {
                stream = assembly.GetManifestResourceStream($"{relativePath}.appsettings.json");
            }
            else if (stream == null)
            {
                return;
            }

            using (var reader = new System.IO.StreamReader(stream))
            {
                var json         = reader.ReadToEnd();
                var intermediate = JsonConvert.DeserializeObject <JObject>(json);

                //App
                var appToken = intermediate["App"];
                ServiceId = (string)appToken["ServiceId"];

                //Conventions
                var conventionsToken = intermediate["Conventions"];
                Conventions.NicknameMaxLength      = (int)conventionsToken["NicknameMaxLength"];
                Conventions.StatusMessageMaxLength = (int)conventionsToken["StatusMessageMaxLength"];
                Conventions.PhoneNumberMaxLength   = (int)conventionsToken["PhoneNumberMaxLength"];
                Conventions.DefaultStatusMessage   = (string)conventionsToken["DefaultStatusMessage"];

                //Backend
                var backendTokenIdentity = intermediate["Backend"]["Identity"];
                Identity = new BackendHost
                {
                    Host    = (string)backendTokenIdentity["Host"],
                    Port    = (int)backendTokenIdentity["Port"],
                    Secure  = (bool)backendTokenIdentity["Secure"],
                    TimeOut = (int)backendTokenIdentity["TimeOut"]
                };

                var backendTokenFriends = intermediate["Backend"]["Friends"];
                Friends = new BackendHost
                {
                    Host    = (string)backendTokenFriends["Host"],
                    Port    = (int)backendTokenFriends["Port"],
                    Secure  = (bool)backendTokenFriends["Secure"],
                    TimeOut = (int)backendTokenFriends["TimeOut"]
                };

                var backendTokenChat = intermediate["Backend"]["Chat"];
                Chat = new BackendHost
                {
                    Host    = (string)backendTokenChat["Host"],
                    Port    = (int)backendTokenChat["Port"],
                    Secure  = (bool)backendTokenChat["Secure"],
                    TimeOut = (int)backendTokenChat["TimeOut"]
                };
            }
        }
Ejemplo n.º 15
0
 internal ScrollControl(IScrollControlBackend backend)
 {
     BackendHost.SetCustomBackend(backend);
     backend.Initialize((ScrollAdjustmentBackendHost)BackendHost);
 }
Ejemplo n.º 16
0
 internal FileDialog()
 {
     filters = new FileDialogFilterCollection (AddRemoveItem);
     backendHost = new BackendHost<FileDialog,IFileDialogBackend> ();
     backendHost.Parent = this;
 }
Ejemplo n.º 17
0
 public XwtComponent()
 {
     backendHost        = CreateBackendHost();
     backendHost.Parent = this;
 }
Ejemplo n.º 18
0
 void ICellViewFrontend.AttachBackend(Widget container, ICellViewBackend backend)
 {
     this.container = container;
     BackendHost.AttachBackend(backend);
 }
Ejemplo n.º 19
0
 internal ScrollAdjustment(IBackend backend)
 {
     BackendHost.SetCustomBackend(backend);
 }
Ejemplo n.º 20
0
 internal FileDialog()
 {
     filters            = new FileDialogFilterCollection(AddRemoveItem);
     backendHost        = new BackendHost <FileDialog, IFileDialogBackend> ();
     backendHost.Parent = this;
 }