Ejemplo n.º 1
0
        public TestServiceProvider()
        {
            var services = new ServiceProvider().ServiceCollection;


            //Services = services;
            var bootstrapper = new BootstrapManager(services);

            _serviceProvider = ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(services);
        }
Ejemplo n.º 2
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     if (instance != this)
     {
         Destroy(this);
     }
     DontDestroyOnLoad(this);
 }
Ejemplo n.º 3
0
 private void Load()
 {
     if (checkDialog.IsOpen)
     {
         checkDialog.CloseDialog();
     }
     byte[] save = File.ReadAllBytes(GameStateModel.GetSaveLocation(selectedPath));
     byte[] meta = File.ReadAllBytes(GameStateModel.GetSaveMetaLocation(selectedPath));
     //TODO : Bootstrap 같은 형식으로 Boot 클래스가 필요함.
     BootstrapManager.getInstance().RebootGameWithData(GameStateModel.Deserialize <GameStateModel>(save),
                                                       GameStateModel.Deserialize <GameStateModel.SaveMeta>(meta));
     CloseMenu();
 }
Ejemplo n.º 4
0
        public static void Test(string host, int port, string localHost, int?localPort)
        {
            System.Console.ReadLine();

            //var serviceProxyManager = Init(host, port, localHost, localPort);
            var serviceProxyManager = InitWithConfig(host, port, localHost, localPort);

            //var serviceProxyManager = InitWithZookeeper(host, port, localHost, localPort);

            System.Console.ReadLine();

            var beginTime = DateTime.Now;

            for (var i = 0; i < 1; i++)
            {
                CallGetServiceName();
                CallAddCustomer().Wait();
                CallGetCustomer();
                CallQueryCustomer().Wait();
                CallRemoveCustomer();
                CallQueryCustomer().Wait();
                CallRemoveAllCustomer();
                CallQueryCustomer().Wait();
            }

            CallAddOrder().Wait();
            CallQueryOrder().Wait();

            var endTime = DateTime.Now;

            System.Console.WriteLine($"Start time: {beginTime.ToString("yyyy-MM-dd HH:mm:ss")}");
            System.Console.WriteLine($"End time: {endTime.ToString("yyyy-MM-dd HH:mm:ss")} Used time: {endTime - beginTime}");

            System.Console.ReadLine();

            if (serviceSubscriber != null)
            {
                serviceSubscriber.Dispose();
            }

            serviceProxyManager.CloseAsync().ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    System.Console.WriteLine(task.Exception.InnerException.Message);
                    return;
                }
                System.Console.WriteLine("Closed");
            }).ContinueWith(task => BootstrapManager.Disable());
        }
Ejemplo n.º 5
0
        protected void Application_Start()
        {
            BootstrapManager.GetInstance().AppServerInitialize();

            //注册路由
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            //RouteConfig.RegisterRoutes(RouteTable.Routes);

            //设置API返回格式
            GlobalConfiguration.Configuration.Formatters.Clear();
            GlobalConfiguration.Configuration.Formatters.Add(new JsonFormatter());
            GlobalConfiguration.Configuration.Services.Replace(typeof(IContentNegotiator), new JsonContentNegotiator(new JsonFormatter()));

            //注册管道事件
            Configure(GlobalConfiguration.Configuration);
        }
Ejemplo n.º 6
0
        public static void Test()
        {
            System.Console.ReadLine();

            var serviceProxyManager = InitWithConfig();

            System.Console.ReadLine();

            DoTest();

            System.Console.ReadLine();

            serviceProxyManager.CloseAsync().ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    System.Console.WriteLine(task.Exception.InnerException.Message);
                    return;
                }
                System.Console.WriteLine("Closed");
            }).ContinueWith(task => BootstrapManager.Disable());
        }
        public ServiceProvider()
        {
            var wantedPath =
                Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())));
            IHostingEnvironment env = new HostingEnvironment {
                ContentRootPath = wantedPath
            };

            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", true, true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();

            var services = new ServiceCollection();

            services.AddSingleton <IConfiguration>(Configuration);
            services.Configure <Application>(Configuration.GetSection("Application"));
            services.AddLogging();

            services.AddSingleton <IDocumentExecuter, DocumentExecuter>();
            services.AddSingleton <IDocumentWriter, DocumentWriter>();

            services.AddSingleton <IDependencyResolver>(s => new FuncDependencyResolver(s.GetRequiredService));

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  b => b.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });
            ServiceCollection = services;
            var bs = new BootstrapManager(services);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please input enter to begin.");
            Console.ReadLine();

            Console.InputEncoding  = Encoding.UTF8;
            Console.OutputEncoding = Encoding.UTF8;

            //配置客户端日志工厂
            LoggerManager.ClientLoggerFactory.AddConsole(LogLevel.Error);

            //加载配置文件
            string path       = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
            var    configRoot = new ConfigurationBuilder()
                                .AddJsonFile(path)
                                .Build();

            var clientConfig = configRoot.GetClientConfig();

            var serializer = new ProtoBufSerializer(LoggerManager.ClientLoggerFactory);

            var serviceProxyManager = new ServiceProxyManager();

            //创建Autofac容器并注册服务类型
            var container = GetAutofacContainer(serviceProxyManager);

            if (clientConfig.ServiceProxies != null)
            {
                //注册服务代理
                foreach (var config in clientConfig.ServiceProxies)
                {
                    var serviceProxy = new ServiceProxy(
                        config.ProxyName,
                        config?.Services)
                                       .AddServices(config.ProxyTypes)
                                       .AddClients(
                        new NodeClientBuilder()
                        .ConfigConnections(config.Connections)
                        .ConfigSerializer(serializer)
                        .ConfigLoginHandler(new DefaultLoginHandler(configRoot.GetDefaultLoginHandlerConfig(config.ProxyName), serializer))             //配置登录处理器
                        .UseDotNetty()
                        .Build()
                        );
                    serviceProxyManager.Regist(serviceProxy);
                }
            }

            try
            {
                //连接服务
                serviceProxyManager.ConnectAsync().Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    if (e is NetworkException netEx)
                    {
                        Console.WriteLine($"Connect has net error. Host={netEx.Host}, Port={netEx.Port}, Message={netEx.Message}");
                    }
                    else
                    {
                        throw e;
                    }
                }
            }

            try
            {
                //调用服务
                var sampleService = container.Resolve <ISampleService>();
                var result        = sampleService.Welcome("XNode");
                Console.WriteLine(result);
            }
            catch (RequestTimeoutExcption ex)
            {
                Console.WriteLine($"Timeout: RequestId={ex.Request.Id}");
            }
            catch (ServiceCallException ex)
            {
                Console.WriteLine($"Service call exception: ExceptionId={ex.ExceptionId}, ExceptionMessage={ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }

            Console.ReadLine();

            //关闭服务连接
            serviceProxyManager.CloseAsync();

            //关闭DotNetty事件循环
            BootstrapManager.Disable();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please input enter to begin.");
            Console.ReadLine();

            Console.InputEncoding  = Encoding.UTF8;
            Console.OutputEncoding = Encoding.UTF8;

            //配置客户端日志工厂
            LoggerManager.ClientLoggerFactory.AddConsole(LogLevel.Error);

            //加载配置文件
            string path       = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
            var    configRoot = new ConfigurationBuilder()
                                .AddJsonFile(path)
                                .Build();

            var clientConfig = configRoot.GetClientConfig();

            var serviceProxyManager = new ServiceProxyManager();

            //创建Autofac容器并注册服务类型
            var container = GetAutofacContainer(serviceProxyManager);

            //配置服务发现
            var zookeeperConfig       = configRoot.GetZookeeperConfig();
            var zookeeperClientConfig = configRoot.GetZookeeperClientConfig();

            var serializerList = new List <ISerializer>()
            {
                new MsgPackSerializer(LoggerManager.ClientLoggerFactory),
                new ProtoBufSerializer(LoggerManager.ClientLoggerFactory)
            };

            var serviceProxyFactory = ServiceProxyCreator.CreateDefaultServiceProxyFactory(null);
            var nodeClientFactory   = NodeClientManager.CreateDefaultNodeClientFactory(zookeeperClientConfig, serializerList, LoggerManager.ClientLoggerFactory);

            var serviceSubscriber = new ServiceSubscriber(zookeeperConfig,
                                                          LoggerManager.ClientLoggerFactory,
                                                          new ServiceProxyCreator(LoggerManager.ClientLoggerFactory, serviceProxyFactory, zookeeperClientConfig.Services),
                                                          new NodeClientManager(LoggerManager.ClientLoggerFactory, nodeClientFactory))
                                    .Subscribe(container.GetNodeServiceProxyTypes())
                                    .RegistTo(serviceProxyManager);

            try
            {
                //连接服务
                serviceProxyManager.ConnectAsync().Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    if (e is NetworkException netEx)
                    {
                        Console.WriteLine($"Connect has net error. Host={netEx.Host}, Port={netEx.Port}, Message={netEx.Message}");
                    }
                    else
                    {
                        throw e;
                    }
                }
            }

            try
            {
                //调用服务
                var sampleService = container.Resolve <ISampleService>();
                var result        = sampleService.Welcome("XNode");
                Console.WriteLine(result);
            }
            catch (RequestTimeoutExcption ex)
            {
                Console.WriteLine($"Timeout: RequestId={ex.Request.Id}");
            }
            catch (ServiceCallException ex)
            {
                Console.WriteLine($"Service call exception: ExceptionId={ex.ExceptionId}, ExceptionMessage={ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }

            Console.ReadLine();

            //关闭服务订阅
            serviceSubscriber.Dispose();

            //关闭服务连接
            serviceProxyManager.CloseAsync().Wait();

            //关闭DotNetty事件循环
            BootstrapManager.Disable();
        }
Ejemplo n.º 10
0
 void Start()
 {
     inst_boot = BootstrapManager.getInstance();
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please input enter to start customer server.");
            Console.ReadLine();

            Console.InputEncoding  = Encoding.UTF8;
            Console.OutputEncoding = Encoding.UTF8;

            //配置服务端日志工厂,为了能看到服务调用细节,此处将日志级别设置为Information
            LoggerManager.ServerLoggerFactory.AddConsole(LogLevel.Information);

            //配置客户端日志工厂,为了能看到服务调用细节,此处将日志级别设置为Information
            LoggerManager.ClientLoggerFactory.AddConsole(LogLevel.Information);

            //加载配置文件
            string path       = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
            var    configRoot = new ConfigurationBuilder()
                                .AddJsonFile(path)
                                .Build();

            var serviceProxyManager = new ServiceProxyManager();
            var container           = GetAutofacContainer(serviceProxyManager);

            #region 客户端配置

            var clientConfig = configRoot.GetClientConfig();

            var serializer = new ProtoBufSerializer(LoggerManager.ClientLoggerFactory);

            var serviceCaller = new ServiceCallerBuilder()
                                .Append(new ZipkinCaller(serializer)) //添加ZipkinCaller
                                .UseDefault()
                                .Build();

            if (clientConfig.ServiceProxies != null)
            {
                foreach (var config in clientConfig.ServiceProxies)
                {
                    var serviceProxy = new ServiceProxy(
                        config.ProxyName,
                        config?.Services,
                        serviceCaller)
                                       .AddServices(config.ProxyTypes)
                                       .AddClients(
                        new NodeClientBuilder()
                        .ConfigConnections(config.Connections)
                        .ConfigSerializer(serializer)
                        .UseDotNetty()
                        .Build()
                        );
                    serviceProxyManager.Regist(serviceProxy);
                }
            }

            #endregion

            #region  务端配置

            var serverConfig = configRoot.GetServerConfig();

            //配置服务
            var nodeServer = new NodeServerBuilder()
                             .ApplyConfig(serverConfig)
                             .ConfigSerializer(new ProtoBufSerializer(LoggerManager.ServerLoggerFactory))
                             .AddServiceProcessor(new ZipkinProcessor()) //添加ZipkinProcessor
                             .UseAutofac(container)
                             .UseDotNetty(serverConfig.ServerInfo)
                             .Build();

            #endregion

            //Zipkin配置
            new ZipkinBootstrapper("CustomerServer")
            .ZipkinAt("192.168.108.131")
            .WithSampleRate(1.0)
            .Start();

            try
            {
                //连接服务
                serviceProxyManager.ConnectAsync().Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    if (e is NetworkException netEx)
                    {
                        Console.WriteLine($"Connect has net error. Host={netEx.Host}, Port={netEx.Port}, Message={netEx.Message}");
                    }
                    else
                    {
                        throw e;
                    }
                }
            }

            //启动服务
            nodeServer.StartAsync().Wait();

            Console.ReadLine();

            //关闭服务连接
            serviceProxyManager.CloseAsync();

            //关闭DotNetty事件循环
            BootstrapManager.Disable();

            //关闭服务
            nodeServer.StopAsync();
        }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please input enter to begin.");
            Console.ReadLine();

            Console.InputEncoding  = Encoding.UTF8;
            Console.OutputEncoding = Encoding.UTF8;

            //配置客户端日志工厂
            LoggerManager.ClientLoggerFactory.AddConsole(LogLevel.Error);

            //加载配置文件
            string path       = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
            var    configRoot = new ConfigurationBuilder()
                                .AddJsonFile(path)
                                .Build();

            var serviceProxyManager = new ServiceProxyManager();
            var container           = GetAutofacContainer(serviceProxyManager);

            #region 客户端配置

            var clientConfig = configRoot.GetClientConfig();

            var serializer = new ProtoBufSerializer(LoggerManager.ClientLoggerFactory);

            var serviceCaller = new ServiceCallerBuilder()
                                .Append(new ZipkinCaller(serializer)) //添加ZipkinCaller
                                .UseDefault()
                                .Build();

            if (clientConfig.ServiceProxies != null)
            {
                foreach (var config in clientConfig.ServiceProxies)
                {
                    var serviceProxy = new ServiceProxy(
                        config.ProxyName,
                        config?.Services,
                        serviceCaller)
                                       .AddServices(config.ProxyTypes)
                                       .AddClients(
                        new NodeClientBuilder()
                        .ConfigConnections(config.Connections)
                        .ConfigSerializer(serializer)
                        .UseDotNetty()
                        .Build()
                        );
                    serviceProxyManager.Regist(serviceProxy);
                }
            }

            #endregion

            //Zipkin配置
            new ZipkinBootstrapper("Client")
            .ZipkinAt("192.168.108.131")
            .WithSampleRate(1.0)
            .Start();

            try
            {
                //连接服务
                serviceProxyManager.ConnectAsync().Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    if (e is NetworkException netEx)
                    {
                        Console.WriteLine($"Connect has net error. Host={netEx.Host}, Port={netEx.Port}, Message={netEx.Message}");
                    }
                    else
                    {
                        throw e;
                    }
                }
            }

            try
            {
                //调用服务
                var customerService = container.Resolve <ICustomerService>();
                var customer        = customerService.GetCustomers(1).Result;
                Console.WriteLine($"Id = {customer.Id}, Name = {customer.Name}");
                Console.WriteLine("Orders:");
                foreach (var order in customer.Orders)
                {
                    Console.WriteLine($"OrderId = {order.Id}");
                    Console.WriteLine($"Detail:");
                    foreach (var detail in order.Detail)
                    {
                        Console.WriteLine($"GoodsId = {detail.GoodsId}, GoodsName = {detail.GoodsName}, Price = {detail.Price}, Amount = {detail.Amount}");
                    }
                    Console.WriteLine("-----------------------------------");
                }
            }
            catch (RequestTimeoutExcption ex)
            {
                Console.WriteLine($"Timeout: RequestId={ex.Request.Id}");
            }
            catch (ServiceCallException ex)
            {
                Console.WriteLine($"Service call exception: ExceptionId={ex.ExceptionId}, ExceptionMessage={ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}");
            }

            Console.ReadLine();

            //关闭服务连接
            serviceProxyManager.CloseAsync();

            //关闭DotNetty事件循环
            BootstrapManager.Disable();
        }
Ejemplo n.º 13
0
        static void Main()
        {
            try
            {
                #region Register global exception events
                //设置应用程序处理异常方式:ThreadException处理
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                #endregion

                #region Application Entrance
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                BonusSkins.Register();
                SkinManager.EnableFormSkins();

                if (BootstrapManager.IsLaunched)
                {
                    XtraMessageBox.Show("该程序已经在运行!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Environment.Exit(0);
                }

                if (BootstrapManager.IsHardwareExist)
                {
                    var result = MessageBox.Show("激光危险,请小心使用!", "消息", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.No)
                    {
                        Environment.Exit(0);
                    }
                }
                else
                {
                    XtraMessageBox.Show("找不到运动控制卡,将进入到演示模式!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                MainView frm = new MainView();
                //BootstrapManager.Attatch("加载主界面…", () => frm = new MainView());
                if (!BootstrapManager.Intialize())
                {
                    Environment.Exit(0);
                }

                //Get associated file path if valid
                var args = Environment.GetCommandLineArgs();
                if (args.Length > 1)
                {
                    frm.ProjectFilePath = args[1];
                }

                Application.Run(frm);
                #endregion
            }
            catch (Exception ex)
            {
                string str = GetExceptionMsg(ex, string.Empty);
                MessageBox.Show(str, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogUtil.Instance.Error(str);
            }
        }