Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var containerBuilder = new ContainerBuilder();
            var builder          = new ServiceHostServerBuilder(containerBuilder)
                                   .LoadServices(new[] { "CQRS.IServices", "CQRS.Services" })
                                   .UseMasstransit(new MassTransitOptions
            {
                HostAddress     = new Uri("rabbitmq://localhost/"),
                Username        = "******",
                Password        = "******",
                QueueName       = "Jimu_test",
                SendEndPointUri = new Uri("rabbitmq://localhost/Jimu_test")
            })
                                   .UseDotNettyForTransfer("127.0.0.1", 8006, server => { })
                                   .UseConsulForDiscovery("127.0.0.1", 8500, "JimuService", "127.0.0.1:8006")
            ;

            using (var host = builder.Build())
            {
                host.Run();
                Console.WriteLine("Server start successful.");
                Console.ReadLine();
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            var hostBuilder = new ServiceHostServerBuilder(new Autofac.ContainerBuilder())
                              .UseLog4netLogger()
                              .LoadServices(new string[] { "QuickStart.Services" })
                              .UseDotNettyForTransfer("127.0.0.1", 8001)
                              .UseConsulForDiscovery("127.0.0.1", 8500, "JimuService", $"127.0.0.1:8001")
            ;

            using (var host = hostBuilder.Build())
            {
                host.Run();
                Console.ReadLine();
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();
            var hostBuilder      = new ServiceHostServerBuilder(containerBuilder)
                                   .LoadServices(new[] { "IServices", "Services" })
                                   .UseLog4netLogger()
                                   .UseHttpForTransfer("127.0.0.1", 8001) // http server ip and port,becareful the firewall blocker
                                   .UseInServerForDiscovery()             // in memory discovery mode
            ;

            using (var host = hostBuilder.Build())
            {
                host.Run();
            }
        }
Example #4
0
        private static void Main(string[] args)
        {
            //MonitorTest test = new MonitorTest("test");
            //test.MyMutex.WaitOne();
            //Console.Write("测试");
            //Console.ReadLine();
            ContainerBuilder          containerBuilder = new ContainerBuilder();
            IServiceHostServerBuilder builder          = new ServiceHostServerBuilder(containerBuilder)
                                                         .LoadServices("Lamp.Service.Test")
                                                         .UseRpcForTransfer(8007)
                                                         .UseConsulCheckHealth(new RegisterServer("127.0.0.1", 8500))
                                                         .UseValidation()
                                                         .UseJwtForOAuth(new JwtAuthorizationOptions
            {
                ServerIp          = "127.0.0.1",
                ServerPort        = 8007,
                SecretKey         = "test",
                ExpireTimeSpan    = new TimeSpan(1, 0, 0),
                TokenEndpointPath = "/base/token",
                ValidateLifetime  = true,
                CheckCredential   = o =>
                {
                    if (o.UserName == "admin" && o.Password == "admin")
                    {
                        o.AddClaim("department", "IT部");
                    }
                    else
                    {
                        o.Rejected("401", "acount or password incorrect");
                    }
                }
            });

            //.UseInServerForDiscovery();
            try
            {
                using (Core.IServiceHost host = builder.Build())
                {
                    host.Run();
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.Write(e);
                Console.ReadLine();
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            IServiceHost host = null;

            // register as server
            var builder = new ServiceHostServerBuilder(new ContainerBuilder())
                          .UseLog4netLogger()
                          .LoadServices(new string[] { "Auth.IServices", "Auth.Services" })
                          .UseDotNettyForTransfer("127.0.0.1", 8000)
                          .UseConsulForDiscovery("127.0.0.1", 8500, "JimuService", $"127.0.0.1:8000")
                          .UseJoseJwtForOAuth <DotNettyAddress>(new JwtAuthorizationOptions
            {
                SecretKey         = "123456",
                ExpireTimeSpan    = new TimeSpan(3, 0, 0, 0),
                ValidateLifetime  = true,
                ServerIp          = "127.0.0.1",
                ServerPort        = 8000,
                TokenEndpointPath = "api/oauth/token?username=&password="******"username or password is incorrect.", "");
                    }
                    else
                    {
                        ctx.AddClaim("roles", member.Role);
                        ctx.AddClaim("member", Newtonsoft.Json.JsonConvert.SerializeObject(member));
                    }
                }),
            });

            using (host = builder.Build())
            {
                //InitProxyService();
                host.Run();
                while (true)
                {
                    Console.ReadKey();
                }
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            var containerBuilder = new ContainerBuilder();
            var builder = new ServiceHostServerBuilder(containerBuilder)
                .UseLog4netLogger(new LogOptions
                {
                    EnableConsoleLog = true
                })
                .LoadServices(new[] { "IServices", "Services" })
                .UseHttpForTransfer("127.0.0.1", 8008)
                .UseInServerForDiscovery()
                ;
            using (var hostJimu = builder.Build())
            {
                hostJimu.Run();
                Console.ReadLine();
            }

        }
Example #7
0
 static void Main(string[] args)
 {
     var builder = new ServiceHostServerBuilder(new ContainerBuilder())
      .UseLog4netLogger()
      .LoadServices("News.IServices", "News.Services")
      .UseDotNettyForTransfer("127.0.0.1", 8002)
      .UseConsulForDiscovery("127.0.0.1", 8500, "JimuService", $"127.0.0.1:8002")
      .UseJoseJwtForOAuth<Jimu.DotNettyAddress>(new Jimu.Server.OAuth.JwtAuthorizationOptions
      {
          SecretKey = "123456",
      });
     using (var host = builder.Build())
     {
         host.Run();
         while (true)
         {
             Console.ReadKey();
         }
     }
 }
Example #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var containerBuilder = new ContainerBuilder();
            var builder          = new ServiceHostServerBuilder(containerBuilder)
                                   .UseLog4netLogger(new LogOptions
            {
                EnableConsoleLog = true
            })
                                   .LoadServices(new[] { "IServices", "Services" })
                                   .UseHttpForTransfer("127.0.0.1", 8004)
                                   .UseConsulForDiscovery("127.0.0.1", 8500, "JimuService-", "127.0.0.1:8004")
            ;

            using (var hostJimu = builder.Build())
            {
                hostJimu.Run();
            }
        }
Example #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var containerBuilder = new ContainerBuilder();
            var builder          = new ServiceHostServerBuilder(containerBuilder)
                                   .UseLog4netLogger(new LogOptions
            {
                EnableConsoleLog = true
            })
                                   .LoadServices(new[] { "IServices", "Services" })
                                   .UseDotNettyForTransfer("127.0.0.1", 8001, server => { })
            ;

            using (var hostJimu = builder.Build())
            {
                hostJimu.Run();
                Console.ReadLine();
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var containerBuilder = new ContainerBuilder();
            var builder          = new ServiceHostServerBuilder(containerBuilder)
                                   .UseLog4netLogger(new LogOptions
            {
                EnableConsoleLog = true
            })
                                   .LoadServices(new[] { "IServices", "Services" })
                                   .UseDotNettyForTransfer("127.0.0.1", 8005, server => { })
                                   .UseConsulForDiscovery("127.0.0.1", 8500, "JimuService", "127.0.0.1:8005")
                                   .UseJoseJwtForOAuth <DotNettyAddress>(new Jimu.Server.OAuth.JwtAuthorizationOptions
            {
                ServerIp          = "127.0.0.1",
                ServerPort        = 8005,
                SecretKey         = "test",
                ExpireTimeSpan    = new TimeSpan(1, 0, 0),
                TokenEndpointPath = "token",
                ValidateLifetime  = true,
                CheckCredential   = o =>
                {
                    if (o.UserName == "admin" && o.Password == "admin")
                    {
                        o.AddClaim("department", "IT部");
                    }
                    else
                    {
                        o.Rejected("401", "acount or password incorrect");
                    }
                }
            })
            ;

            using (var hostJimu = builder.Build())
            {
                hostJimu.Run();
                Console.ReadLine();
            }
        }
Example #11
0
        //public static Mutex mutex = new Mutex();
        private static void Main(string[] args)
        {
            //MonitorTest test = new MonitorTest("test1");
            //test.MyMutex.WaitOne();
            //Console.Write(AppDomain.CurrentDomain.BaseDirectory);
            //Console.ReadLine();
            ContainerBuilder          containerBuilder = new ContainerBuilder();
            IServiceHostServerBuilder builder          = new ServiceHostServerBuilder(containerBuilder)
                                                         .LoadServices("Lamp.Service.Test", "Lamp.Service.Test1")
                                                         .UseRpcForTransfer(8008)
                                                         .UseConsulCheckHealth(new RegisterServer("127.0.0.1", 8500))
                                                         .LoadConifg("appsettings.json").UseValidation();

            //.UseInServerForDiscovery();

            using (Core.IServiceHost host = builder.Build())
            {
                host.Run();
                Console.ReadLine();
            }
        }
Example #12
0
        static void Main(string[] args)
        {
            //var op = new DbContextOptions<BloggingContext>();

            //using (var context = new BloggingContext(op))
            //{
            //    var name = context.Database.ProviderName;
            //    // do stuff
            //}
            Configuration = new ConfigurationBuilder()
                            .Add(new JsonConfigurationSource {
                Path = "appsettings.json", ReloadOnChange = true
            })
                            .Build();
            //Log4netOptions log4NetOptions = Configuration.GetSection("Log4netOptions").Get<Log4netOptions>();
            //DbOptions dbOptions = Configuration.GetSection("DbOptions").Get<DbOptions>();

            DbContextOptions dbContextOption = Configuration.GetSection("DbContextOption").Get <DbContextOptions>();


            var containerBuilder = new ContainerBuilder();
            var builder          = new ServiceHostServerBuilder(containerBuilder)
                                   .UseLog4netLogger()
                                   .RegisterService(container =>
            {
                // inject dboptions
                //container.Register(x => dbOptions);
                container.Register(x => dbContextOption);
                container.Register(x => dbContextOption).SingleInstance();
            })
                                   //.LoadServices(new string[] { "DDD.Simple.IServices", "DDD.Simple.Services" }, "DDD.Simple.IServices.*.*Service|DDD.Simple.Services.*.*Service")
                                   //.LoadServices(new[] { "Simple.IServices", "Simple.Services" })
                                   .LoadServices(new[] { "Simple.IServices", "Simple.Services", "Simple.Repository.SqlSugar", "MiniDDD.UnitOfWork.SqlSugar" })
                                   //.LoadServices(new string[] { "DDD.Simple.IServices", "DDD.Simple.Services", "DDD.Simple.Repository.EF", "DbWorker.UnitOfWork.EF" })
                                   //.UseDotNettyServer("127.0.0.1", 8009, server => { })
                                   .UseDotNettyForTransfer("127.0.0.1", 8009)
                                   //.UseNetCoreHttpServer("127.0.0.1", 8009, server => { })
                                   .UseConsulForDiscovery("127.0.0.1", 8500, "JimuService", "127.0.0.1:8009")
                                   .UseJoseJwtForOAuth <DotNettyAddress>(new JwtAuthorizationOptions
            {
                CheckCredential = context =>
                {
                    if (context.UserName == "admin" && context.Password == "admin")
                    {
                        context.AddClaim("username", "DbWorker");
                        context.AddClaim("dep", "IT");
                        context.AddClaim("role", "admin");
                    }
                    else
                    {
                        context.Rejected("username or password are incorrect.", "用户名或密码错误");
                    }
                },
                ValidateLifetime  = true,
                ExpireTimeSpan    = TimeSpan.FromDays(30),
                SecretKey         = "12345678901234567890123456789012",
                ServerIp          = "127.0.0.1",
                ServerPort        = 8009,
                TokenEndpointPath = "oauth/token?username=&password="******"Server start successful.");
                host.Run();
                Console.ReadLine();
            }
        }