public static IServerBuilder UseMessagePack(this IServerBuilder serverBuilder)
        {
            var serviceCollection = serverBuilder.GetServiceCollection();

            serviceCollection.AddSingleton <IPacketSerialiser, MessagePackPacketSerialiser>();
            return(serverBuilder);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Makes the x42 server use all the required features - <see cref="BaseFeature" />.
        /// </summary>
        /// <param name="serverBuilder">Builder responsible for creating the server.</param>
        /// <returns>x42 server builder's interface to allow fluent code.</returns>
        public static IServerBuilder UseBaseFeature(this IServerBuilder serverBuilder)
        {
            serverBuilder.ConfigureFeature(features =>
            {
                features
                .AddFeature <BaseFeature>()
                .FeatureServices(services =>
                {
                    services.AddSingleton(serverBuilder.ServerSettings.LoggerFactory);
                    services.AddSingleton(serverBuilder.ServerSettings.DataFolder);
                    services.AddSingleton <IX42ServerLifetime, X42ServerLifetime>();
                    services.AddSingleton <ServerFeatureExecutor>();
                    services.AddSingleton <X42Server>().AddSingleton(provider =>
                    {
                        return(provider.GetService <X42Server>() as IX42Server);
                    });
                    services.AddSingleton(DateTimeProvider.Default);
                    services.AddSingleton <IAsyncLoopFactory, AsyncLoopFactory>();

                    // Console
                    services.AddSingleton <IServerStats, ServerStats>();
                });
            });

            return(serverBuilder);
        }
Ejemplo n.º 3
0
 public void Register(string name, IServerBuilder builder)
 {
     if (Servers.ContainsKey(name))
     {
         throw new ServerRegistrationException($"The server '{name}' has already been registered with the server registry. Perhaps you are accidentally including it in more than one IRegisterServers implementation.");
     }
     Servers.Add(name, builder);
 }
Ejemplo n.º 4
0
        public ServerMain(IServerBuilder serverBuilder, IPacketRegistrator packetRegistrator)
        {
            _packetRegistrator = packetRegistrator;
            _serverContainer   = serverBuilder.Build();

            _serverContainer.ConnectionLost        += ServerConnectionLost;
            _serverContainer.ConnectionEstablished += ServerServerEstablished;
        }
Ejemplo n.º 5
0
        public static IServerBuilder UseProtobufNet(this IServerBuilder serverBuilder)
        {
            var serviceCollection = serverBuilder.GetServiceCollection();

            serviceCollection.AddSingleton <IPacketSerialiser, ProtoBufNetSerialiser>();

            return(serverBuilder);
        }
        public static IServerBuilder UseZeroFormatter(this IServerBuilder serverBuilder)
        {
            var serviceCollection = serverBuilder.GetServiceCollection();

            serviceCollection.AddSingleton <IPacketSerialiser, ZeroFormatterPacketSerialiser>();

            return(serverBuilder);
        }
 private void WhenSetLeaderSetup()
 {
     try
     {
         _serverBuilder = _services.AddFaXianZhe(_configRoot).SetLeader();
     }
     catch (Exception ex)
     {
         _ex = ex;
     }
 }
 private void WhenWithoutConfigSetup()
 {
     try
     {
         _serverBuilder = _services.AddFaXianZhe();
     }
     catch (Exception ex)
     {
         _ex = ex;
     }
 }
        public void Init()
        {
            NinjectConfig.RebindAction = kernel =>
            {
                kernel.Rebind<IRepository<Book>>().ToConstant(MocksFactory.BooksRepository);
                kernel.Rebind<IRepository<Author>>().ToConstant(MocksFactory.AuthorsRepository);
            };

            MyWebApi.Server().Starts<Startup>();
            this.server = MyWebApi.Server().Working();
        }
        public void Init()
        {
            NinjectConfig.RebindAction = kernel =>
            {
                kernel.Rebind <IRepository <Book> >().ToConstant(MocksFactory.BooksRepository);
                kernel.Rebind <IRepository <Author> >().ToConstant(MocksFactory.AuthorsRepository);
                kernel.Rebind <ApplicationUserManager>().ToConstant(MocksFactory.ApplicationUserManager);
            };

            this.server = MyWebApi.Server().Starts <Startup>();

            this.GetAccessToken();
        }
        public void Init()
        {
            NinjectConfig.RebindAction = kernel =>
            {
                kernel.Rebind<IRepository<Book>>().ToConstant(MocksFactory.BooksRepository);
                kernel.Rebind<IRepository<Author>>().ToConstant(MocksFactory.AuthorsRepository);
                kernel.Rebind<ApplicationUserManager>().ToConstant(MocksFactory.ApplicationUserManager);
            };

            this.server = MyWebApi.Server().Starts<Startup>();

            this.GetAccessToken();
        }
        public void Initialize()
        {
            NinjectConfig.RebindAction = kernel =>
            {
                kernel.Rebind<IRepository<Category>>().ToConstant(MocksFactory.GetCategoriesRepository());
                kernel.Rebind<ICategoriesService>().ToConstant(MocksFactory.GetCategoriesService());
                kernel.Rebind<ApplicationUserManager>().ToConstant(MocksFactory.ApplicationUserManager);
            };

            this.server = MyWebApi.Server().Starts<Startup>();

               //// this.GetAccessToken();

            AutoMapper.Mapper.CreateMap<Category, CategoryDataTransferModel>();
        }
Ejemplo n.º 13
0
 public ApiFeature(
     IServerBuilder x42ServerBuilder,
     X42Server x42Server,
     ApiFeatureOptions apiFeatureOptions,
     ApiSettings apiSettings,
     ILoggerFactory loggerFactory,
     ICertificateStore certificateStore)
 {
     serverBuilder          = x42ServerBuilder;
     this.x42Server         = x42Server;
     this.apiFeatureOptions = apiFeatureOptions;
     this.apiSettings       = apiSettings;
     this.certificateStore  = certificateStore;
     logger = loggerFactory.CreateLogger(GetType().FullName);
 }
Ejemplo n.º 14
0
        /// <summary>
        ///     Makes the x42 server builder use specific server settings.
        /// </summary>
        /// <param name="builder">x42 server builder to change server settings for.</param>
        /// <param name="serverSettings">Server settings to be used.</param>
        /// <returns>Interface to allow fluent code.</returns>
        public static IServerBuilder UseServerSettings(this IServerBuilder builder, ServerSettings serverSettings)
        {
            ServerBuilder serverBuilder = builder as ServerBuilder;

            serverBuilder.ServerSettings = serverSettings;
            serverBuilder.ServerNode     = serverSettings.ServerNode;

            builder.ConfigureServices(service =>
            {
                service.AddSingleton(serverBuilder.ServerSettings);
                service.AddSingleton(serverBuilder.ServerNode);
            });

            return(builder.UseBaseFeature());
        }
Ejemplo n.º 15
0
        /// <summary>
        ///     Adds SQL components to the server.
        /// </summary>
        /// <param name="serverBuilder">The object used to build the current node.</param>
        /// <returns>The server builder, enriched with the new component.</returns>
        public static IServerBuilder UseSql(this IServerBuilder serverBuilder)
        {
            LoggingConfiguration.RegisterFeatureNamespace <DatabaseFeatures>("database");

            serverBuilder.ConfigureFeature(features =>
            {
                features
                .AddFeature <DatabaseFeatures>()
                .FeatureServices(services =>
                {
                    services.AddSingleton <DatabaseFeatures>();
                    services.AddSingleton <DatabaseSettings>();
                });
            });

            return(serverBuilder);
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     Adds x42 Client components to the server.
        /// </summary>
        /// <param name="serverBuilder">The object used to build the current node.</param>
        /// <returns>The server builder, enriched with the new component.</returns>
        public static IServerBuilder UseX42Client(this IServerBuilder serverBuilder)
        {
            LoggingConfiguration.RegisterFeatureNamespace <X42ClientFeature>("x42client");

            serverBuilder.ConfigureFeature(features =>
            {
                features
                .AddFeature <X42ClientFeature>()
                .FeatureServices(services =>
                {
                    services.AddSingleton <X42ClientFeature>();
                    services.AddSingleton <X42ClientSettings>();
                });
            });

            return(serverBuilder);
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     Adds profile components to the server.
        /// </summary>
        /// <param name="serverBuilder">The object used to build the current node.</param>
        /// <returns>The server builder, enriched with the new component.</returns>
        public static IServerBuilder UseProfile(this IServerBuilder serverBuilder)
        {
            LoggingConfiguration.RegisterFeatureNamespace <ProfileFeature>("profile");

            serverBuilder.ConfigureFeature(features =>
            {
                features
                .AddFeature <ProfileFeature>()
                .DependOn <DatabaseFeatures>()
                .FeatureServices(services =>
                {
                    services.AddSingleton <ProfileFeature>();
                });
            });

            return(serverBuilder);
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     Adds network components to the server.
        /// </summary>
        /// <param name="serverBuilder">The object used to build the current node.</param>
        /// <returns>The server builder, enriched with the new component.</returns>
        public static IServerBuilder UseNetwork(this IServerBuilder serverBuilder)
        {
            LoggingConfiguration.RegisterFeatureNamespace <NetworkFeatures>("network");

            serverBuilder.ConfigureFeature(features =>
            {
                features
                .AddFeature <NetworkFeatures>()
                .DependOn <DatabaseFeatures>()
                .FeatureServices(services =>
                {
                    services.AddSingleton <NetworkFeatures>();
                    services.AddSingleton <NetworkSettings>();
                });
            });

            return(serverBuilder);
        }
Ejemplo n.º 19
0
        public static IServerBuilder UseApi(this IServerBuilder serverBuilder,
                                            Action <ApiFeatureOptions> optionsAction = null)
        {
            // TODO: move the options in to the feature builder
            ApiFeatureOptions options = new ApiFeatureOptions();

            optionsAction?.Invoke(options);

            serverBuilder.ConfigureFeature(features =>
            {
                features
                .AddFeature <ApiFeature>()
                .FeatureServices(services =>
                {
                    services.AddSingleton(serverBuilder);
                    services.AddSingleton(options);
                    services.AddSingleton <ApiSettings>();
                    services.AddSingleton <ICertificateStore, CertificateStore>();
                });
            });

            return(serverBuilder);
        }
Ejemplo n.º 20
0
        protected IServerBuilder AddDefaultSettings(IServerBuilder builder, NetConnectionParameters parameters)
        {
            var config = (IConfiguration)Services.GetService(typeof(IConfiguration));

            var tcpPort = (parameters.TcpPort > 0) ? parameters.TcpPort : config.GetValue <int>("Network:TcpPort");
            var udpPort = (parameters.UdpPort > 0) ? parameters.UdpPort : config.GetValue <int>("Network:UdpPort");

            return(builder
                   .UseTcp(tcpPort)
                   .UseUdp(udpPort)
                   .UseZeroFormatter()
                   .UseConfiguration(config)
                   .ConfigureLogging(logBuilder =>
            {
                logBuilder.AddConfiguration(config.GetSection("Logging"));
                logBuilder.AddConsole();
            })
                   .RegisterTypes(serviceCollection =>
            {
                serviceCollection.AddSingleton(c => this);
                serviceCollection.AddSingleton(c => this.Chat);
                this.RegisterTypes(serviceCollection);
            }));
        }
Ejemplo n.º 21
0
 public static IServerBuilder UseNoql(this IServerBuilder serverBuilder)
 {
     throw new NotImplementedException("NoSQL is not yet supported");
 }
Ejemplo n.º 22
0
 public Server(IServerBuilder server, ClientsViewModel clientVm)
 {
     _clientVm      = clientVm;
     _serverBuilder = server;
 }
Ejemplo n.º 23
0
 public void TestInit()
 {
     server = MyWebApi.Server().Starts<Startup>();
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Called before building the <see cref="IServer"/>.
 /// </summary>
 /// <param name="builder">The server builder.</param>
 protected virtual void OnServerBuild(IServerBuilder builder)
 {
     builder
     .RegisterPacketHandler <User.Packets.LoginPacket, LoginServerHandler <TUser> >()
     .RegisterPacketHandler <Chat.Packets.ChatPacket, ChatServerHandler <TUser> >();
 }
Ejemplo n.º 25
0
 public ServerDirector(IServerBuilder serverBuilder)
 {
     ServerBuilder = serverBuilder ?? throw new ArgumentNullException(nameof(serverBuilder));
 }
Ejemplo n.º 26
0
 /// <summary>
 ///     Makes the x42 server builder use the default server settings.
 /// </summary>
 /// <param name="builder">x42 server builder to change server settings for.</param>
 /// <returns>Interface to allow fluent code.</returns>
 public static IServerBuilder UseDefaultServerSettings(this IServerBuilder builder)
 {
     return(builder.UseServerSettings(ServerSettings.Default(builder.ServerNode)));
 }
 public static void Init(TestContext testContext)
 {
     server = MyWebApi.Server().Starts<Startup>();
 }
Ejemplo n.º 28
0
 public static void Init(TestContext testContext)
 {
     server = MyWebApi.Server().Starts <Startup>();
 }
Ejemplo n.º 29
0
 public ServerTests()
 {
     httpServer = MyHttpServer.WorkingRemotely(BaseAddress);
 }
Ejemplo n.º 30
0
 public Server(IServerBuilder server)
 {
     _serverBuilder = server;
 }
Ejemplo n.º 31
0
 public void Init()
 {
     _server = MyWebApi.Server().Starts <Startup>();
 }