Esempio n. 1
0
        public WorldServices()
        {
            var serviceCollection = new ServiceCollection();

            var builder = serviceCollection
                          .AddLogging()
                          .AddClient()
                          .UseSharedFileRouteManager("d:\\Login.txt");

            IServiceProvider serviceProvider = null;

            builder.UseDotNettyTransport();
            serviceProvider = serviceCollection.BuildServiceProvider();

            var serviceProxyGenerater = serviceProvider.GetRequiredService <IServiceProxyGenerater>();
            var serviceProxyFactory   = serviceProvider.GetRequiredService <IServiceProxyFactory>();
            var services = serviceProxyGenerater.GenerateProxys(new[] { typeof(Common.ServicesInterface.WorldInterface) }).ToArray();

            //创建IUserService的代理。
            sWorldService = serviceProxyFactory.CreateProxy <Common.ServicesInterface.WorldInterface>(services.Single(typeof(Common.ServicesInterface.WorldInterface).IsAssignableFrom));


            Task.Run(async() =>
            {
                sWroldInfo = new WorldInfo();
                sWroldInfo = await sWorldService.RegisterWorld(sWroldInfo);
                Console.WriteLine("本服务器编号:" + sWroldInfo.WorldId + " 服务器名称:" + sWroldInfo.Name);
                Console.Title            += " " + sWroldInfo.Name;
                ChannelEntity.world       = sWorldService;
                ChannelEntity.worldEntity = sWroldInfo;
            }).Wait();

            WorldEvent().ConfigureAwait(true);
        }