Esempio n. 1
0
        public TestAuthorizer(TestProbe testProbe)
        {
            //Console.WriteLine("initialize DagSystem");

            Environment.SetEnvironmentVariable("LYRA_NETWORK", "xtest");

            LyraNodeConfig.Init("xtest");

            fakeP2P   = testProbe;
            mockStore = new Mock <IAccountCollectionAsync>();
            var keypair = Signatures.GenerateWallet();

            posWallet = UT_Wallet.Restore(keypair.privateKey);
            var store = new MongoAccountCollection("mongodb://127.0.0.1/xunit", "xunit");

            TheDagSystem = new DagSystem(null, store, null, posWallet, fakeP2P);
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            // lyra network ID must be set early
            var networkId = Environment.GetEnvironmentVariable($"{LyraGlobal.OFFICIALDOMAIN.ToUpper()}_NETWORK");

            if (networkId == null)
            {
                networkId = "devnet";   // for dev convenient
            }
            LyraNodeConfig.Init(networkId);

            // the apis
            services.AddScoped <INodeAPI, NodeAPI>();
            services.AddScoped <INodeTransactionAPI, ApiService>();
            services.AddSingleton <IHostEnv, HostEnvService>();
            services.AddSingleton <IAccountCollectionAsync, MongoAccountCollection>();

            services.AddMvc();
            services.AddControllers();
            services.AddSignalR();

            // workflow need this
            BsonClassMap.RegisterClassMap <LyraContext>(cm =>
            {
                cm.AutoMap();
                cm.SetIsRootClass(false);
            });

            //services.AddGrpc();
            services.AddWorkflow(cfg =>
            {
                // lyra network ID must be set early
                var networkId = Environment.GetEnvironmentVariable($"{LyraGlobal.OFFICIALDOMAIN.ToUpper()}_NETWORK");
                if (networkId == null)
                {
                    networkId = "devnet";   // for dev convenient
                }
                cfg.UseMongoDB(Neo.Settings.Default.LyraNode.Lyra.Database.DBConnect, "Workflow_" + networkId);
                //cfg.UseSqlite($"Data Source={fn};", true);
                cfg.UsePollInterval(new TimeSpan(0, 0, 0, 2));
                //cfg.UseElasticsearch(new ConnectionSettings(new Uri("http://elastic:9200")), "workflows");
            });

            services.AddTransient <Repeator>();
            services.AddTransient <ReqViewChange>();
            services.AddTransient <CustomMessage>();

            services.AddApiVersioning(options => {
                options.DefaultApiVersion = new ApiVersion(1, 0);
                options.AssumeDefaultVersionWhenUnspecified = true;
                options.ReportApiVersions = true;
                options.ApiVersionReader  = new UrlSegmentApiVersionReader();
            });

            services.AddVersionedApiExplorer(options =>
            {
                // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
                // note: the specified format code will format the version as "'v'major[.minor][-status]"
                options.GroupNameFormat = "'v'VVV";

                // note: this option is only necessary when versioning by url segment. the SubstitutionFormat
                // can also be used to control the format of the API version in route templates
                options.SubstituteApiVersionInUrl = true;
            });
            //services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
            //services.AddSwaggerGen(options => options.OperationFilter<SwaggerDefaultValues>());

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = $"{LyraGlobal.PRODUCTNAME} API", Version = "v1"
                });
            });
        }