Exemplo n.º 1
0
        public ServerTester(string ns)
        {
            CleanTable    = true;
            Address       = "http://localhost:" + FindFreePort() + "/";
            Configuration = QBitNinjaConfiguration.FromConfiguration();
            Configuration.Indexer.Network          = Network.RegTest;
            Configuration.Indexer.StorageNamespace = ns;
            Stopwatch watch  = new Stopwatch();
            var       server = WebApp.Start(Address, appBuilder =>
            {
                watch.Start();
                var config = new HttpConfiguration
                {
                    IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always
                };
                var setup = ShouldSetup(ns);
                WebApiConfig.Register(config, Configuration, setup);
                if (setup)
                {
                    SetShouldSetup(ns);
                }
                else
                {
                    //This at least should be setup
                    Configuration.Topics.EnsureSetupAsync().Wait();
                }
                _resolver = (QBitNinjaDependencyResolver)config.DependencyResolver;
                appBuilder.UseWebApi(config);
            });

            _disposables.Add(server);
            ChainBuilder = new ChainBuilder(this);
            _resolver.Get <ConcurrentChain>(); //So ConcurrentChain load
            watch.Stop();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var conf = QBitNinjaConfiguration.FromConfiguration();

            conf.EnsureSetup();
            QBitNinjaListener listener = new QBitNinjaListener(conf);

            listener.Listen();
            listener.Wait();
        }
Exemplo n.º 3
0
        public ServerTester(string ns)
        {
            CleanTable    = true;
            Address       = "http://localhost:" + (ushort)RandomUtils.GetUInt32() + "/";
            Configuration = QBitNinjaConfiguration.FromConfiguration();
            Configuration.Indexer.StorageNamespace = ns;
            var server = WebApp.Start(Address, appBuilder =>
            {
                var config = new HttpConfiguration
                {
                    IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always
                };
                WebApiConfig.Register(config, Configuration);
                _resolver = (QBitNinjaDependencyResolver)config.DependencyResolver;
                appBuilder.UseWebApi(config);
            });

            _disposables.Add(server);
            ChainBuilder = new ChainBuilder(this);
            _resolver.Get <ConcurrentChain>(); //So ConcurrentChain load
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var options = new ListenerOptions();

            if (args.Length == 0)
            {
                System.Console.WriteLine(options.GetUsage());
            }
            if (Parser.Default.ParseArguments(args, options))
            {
                if (options.Configuration != null)
                {
                    if (!File.Exists(options.Configuration))
                    {
                        System.Console.WriteLine("File " + new FileInfo(options.Configuration).FullName + " not found");
                        return;
                    }
                    AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", new FileInfo(options.Configuration).FullName);
                }
                var conf = QBitNinjaConfiguration.FromConfiguration();
                conf.EnsureSetup();
                if (options.CancelInit)
                {
                    var indexer = new InitialIndexer(conf);
                    indexer.Cancel();
                }
                if (options.Init)
                {
                    var indexer = new InitialIndexer(conf);
                    indexer.Run();
                }

                List <IDisposable> dispo   = new List <IDisposable>();
                List <Task>        running = new List <Task>();
                try
                {
                    if (options.Listen)
                    {
                        QBitNinjaNodeListener listener = new QBitNinjaNodeListener(conf);
                        dispo.Add(listener);
                        listener.Listen();
                        running.Add(listener.Running);
                    }

                    if (options.Web)
                    {
                        System.Console.WriteLine("Trying to listen on http://*:" + options.Port + "/");
                        var server = WebApp.Start("http://*:" + options.Port, appBuilder =>
                        {
                            var config = new HttpConfiguration();
                            var qbit   = QBitNinjaConfiguration.FromConfiguration();
                            qbit.EnsureSetup();
                            WebApiConfig.Register(config, qbit);
                            UpdateChainListener listener = new UpdateChainListener();
                            dispo.Add(listener);
                            listener.Listen(config);
                            appBuilder.UseWebApi(config);
                            running.Add(new TaskCompletionSource <int>().Task);
                        });
                        dispo.Add(server);
                        System.Console.WriteLine("Server started");
                        Process.Start("http://localhost:" + options.Port + "/blocks/tip");
                    }

                    if (running.Count != 0)
                    {
                        try
                        {
                            running.Add(WaitInput());
                            Task.WaitAny(running.ToArray());
                        }
                        catch (AggregateException aex)
                        {
                            ExceptionDispatchInfo.Capture(aex.InnerException).Throw();
                            throw;
                        }
                    }
                }
                finally
                {
                    foreach (var d in dispo)
                    {
                        d.Dispose();
                    }
                }
            }
        }