コード例 #1
0
ファイル: Program.cs プロジェクト: manfered/grpctest
        static async Task Main(string[] args)
        {
            Server server = null;

            try
            {
                server = new Server()
                {
                    Services = { GreetingService.BindService(new GreetingServiceImpl()),
                                 CalculatorService.BindService(new CalculatorServiceImpl()),
                                 CounterService.BindService(new CounterServiceImpl()),
                                 UploadService.BindService(new UploadServiceImpl()),
                                 ConversationService.BindService(new ConversationServiceImpl()) },
                    Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
                };

                server.Start();
                Console.WriteLine($"The server is listening on the port : {Port}");
                Console.ReadKey();
            }
            catch (IOException ex)
            {
                Console.WriteLine($"The server failed to start : {ex.Message}");
                throw;
            }
            finally
            {
                if (server != null)
                {
                    await server.ShutdownAsync();
                }
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            // Connecting to MySQL DB
            MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

            connBuilder.Add("Database", "shop");
            connBuilder.Add("Data Source", "localhost");
            connBuilder.Add("User Id", "root");
            connBuilder.Add("Password", "admin#123");
            connBuilder.Add("SslMode", "none");

            MySqlConnection connection = new MySqlConnection(connBuilder.ConnectionString);

            cmd = connection.CreateCommand();

            connection.Open();

            // Build a server
            var server = new Server
            {
                Services = { GreetingService.BindService(new GreeterServiceImpl()) },
                Ports    = { new ServerPort(Host, Port, ServerCredentials.Insecure) }
            };

            // Start server
            server.Start();

            Console.WriteLine("GreeterServer listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            // Stopping MySql and Server Connection
            connection.Close();
            server.ShutdownAsync().Wait();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            const int _port = 50056;

            Grpc.Core.Server server = null;
            try
            {
                server = new Grpc.Core.Server()
                {
                    Services = { GreetingService.BindService(new GreetingServiceImpl()) },
                    Ports    = { new ServerPort("localhost", _port, ServerCredentials.Insecure) }
                };
                server.Start();
                Console.WriteLine(($"The Server is listening on port : {_port}"));
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine($"Server Connection Error: {e.Message}");
            }
            finally
            {
                server?.ShutdownAsync().Wait();
            }
        }
コード例 #4
0
        static async Task Main(string[] args)
        {
            Server server = null;

            try
            {
                // reflection-1
                var reflectionServiceImpl = new ReflectionServiceImpl(
                    GreetingService.Descriptor
                    , CalculatorService.Descriptor
                    , PrimeNumberDecompositionService.Descriptor
                    , SqrtService.Descriptor
                    , DeadlineService.Descriptor
                    , ServerReflection.Descriptor
                    );

                server = new Server
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImplementation()),
                        CalculatorService.BindService(new CalculatorServiceImplementation()),
                        PrimeNumberDecompositionService.BindService(new PrimeNumberDecompositionServiceImplementation()),

                        // errors
                        SqrtService.BindService(new SqrtServiceImplementation()),
                        // deadlines
                        DeadlineService.BindService(new DeadlineServiceImplementation()),

                        // reflection-2
                        ServerReflection.BindService(reflectionServiceImpl)
                    },
                    Ports =
                    {
                        await CreateUnsecureServerPort(Host, Port)
                    }
                };

                server.Start();
                Console.WriteLine($"Server is listening on {Port}");
                Console.ReadLine();
            }
            catch (IOException ex)
            {
                Console.WriteLine($"Server failed to start: {ex.Message}");
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Server failed: {ex.Message}");
                throw;
            }
            finally
            {
                if (server != null)
                {
                    await server.ShutdownAsync();
                }
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                server = new Server()
                {
                    Services = { GreetingService.BindService(new GreetingServiceImpl()) },
                    Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
                };

                server.Start();
                Console.WriteLine("The server is listening on the port: " + Port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The server failed to start: " + e.Message);
                throw;
            } finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
コード例 #6
0
 static void Main(string[] args)
 {
     Grpc.Core.Server server = null;
     try
     {
         server = new Grpc.Core.Server()
         {
             //Services = {SqrtService.BindService(new SqrtServiceImpl())},
             Services = { GreetingService.BindService(new GreetingServiceImpl()) },
             //Services = {CalcService.BindService(new CalculatorServiceImpl())},
             Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
         };
         server.Start();
         Console.WriteLine("Server is listening on port: " + port);
         Console.ReadKey();
     }
     catch (IOException ex)
     {
         Console.WriteLine("server did not start on port: " + port);
         throw;
     }
     finally
     {
         if (server != null)
         {
             server.ShutdownAsync().Wait();
         }
     }
 }
コード例 #7
0
        public string Action(string name)
        {
            var    service = new GreetingService();
            string message = service.Greet(name);

            return(message.ToUpper());
        }
コード例 #8
0
 public GreetingServiceGreetShould()
 {
     _timeService = new TestTimeService()
     {
         Now = DateTime.Now
     };
     _greetingService = new GreetingService(_timeService);
 }
コード例 #9
0
ファイル: Program.cs プロジェクト: simple555a/DotNetAppDev
        private static void WithoutUsingContainer()
        {
            IGreetingService service = new GreetingService();
            var controller           = new HelloController(service);
            var greeting             = controller.Action("Matthias");

            Console.WriteLine(greeting);
        }
コード例 #10
0
ファイル: GreetingTests.cs プロジェクト: donmares/DonM.Crowe
        private GreetingController InitController()
        {
            var config = new ConfigurationBuilder().AddJsonFile("appsettings.test.json").Build();
            GreetingRepoFile   repo       = new GreetingRepoFile(config);
            GreetingService    service    = new GreetingService(config, repo);
            GreetingController controller = new GreetingController(service);

            return(controller);
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: odinscode/mentoring
        static void Main(string[] args)
        {
            var defaultUser = string.Empty;

            if (args.Length != 0)
            {
                defaultUser = args[0];
            }
            System.Console.WriteLine(GreetingService.GreetPerson(defaultUser));
        }
コード例 #12
0
        public TeamspeakActor(GreetingService greetingService, Settings settings, ILogger <TeamspeakActor> logger)
        {
            _nicknamesCache  = new ConcurrentDictionary <int, string>();
            _greetingService = greetingService;
            _settings        = settings;
            _system          = Context.System;
            _logger          = logger;

            ReceiveAsync <MessageArgs>(RespondWhoIsInTeamspeak);
            ReceiveAsync <Pulse>(PulseServerAsync);
        }
コード例 #13
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                var serverCertificate  = File.ReadAllText("ssl/server.crt");
                var serverKey          = File.ReadAllText("ssl/server.key");
                var keyCertificatePair = new KeyCertificatePair(serverCertificate, serverKey);
                var caCertificate      = File.ReadAllText("ssl/ca.crt");

                var credentials = new SslServerCredentials(new List <KeyCertificatePair>()
                {
                    keyCertificatePair
                }, caCertificate, true);

                // ./evans.exe -r -p 50051
                var greetingServiceReflectionServiceImpl   = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor);
                var calculatorServiceReflectionServiceImpl = new ReflectionServiceImpl(CalculatorService.Descriptor, ServerReflection.Descriptor);
                var blogServiceReflectionServiceImpl       = new ReflectionServiceImpl(BlogService.Descriptor, ServerReflection.Descriptor);

                server = new Server()
                {
                    Services =
                    {
                        BlogService.BindService(new BlogServiceImpl()),
                        ServerReflection.BindService(blogServiceReflectionServiceImpl),
                        GreetingService.BindService(new GreetingServiceImpl()),
                        //ServerReflection.BindService(greetingServiceReflectionServiceImpl),
                        CalculatorService.BindService(new CalculatorServiceImpl()),
                        //ServerReflection.BindService(calculatorServiceReflectionServiceImpl)
                    },
                    Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) }
                };
                server.Start();
                Console.WriteLine("The server is listening on the port :" + port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The server failed to start:" + e.Message);
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
コード例 #14
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                var reflectionServiceImpl = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor);

                var serverCert = File.ReadAllText("ssl/server.crt");
                var serverKey  = File.ReadAllText("ssl/server.key");
                var keypair    = new KeyCertificatePair(serverCert, serverKey);
                var cacert     = File.ReadAllText("ssl/ca.crt");

                var credentials = new SslServerCredentials(
                    new List <KeyCertificatePair>()
                {
                    keypair
                }, cacert, true);

                server = new Server()
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImp()),
                        CalculatorService.BindService(new CalculatorServiceImp()),
                        SqrtService.BindService(new SqrtServiceImpl()),
                        GreetDeadlinesService.BindService(new GreetingDeadlinesImpl()),
                        ServerReflection.BindService(reflectionServiceImpl)
                    },

                    Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
                };

                server.Start();

                Console.WriteLine("The server is listening on the port {0}", Port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The server failed to start: ", e.Message);
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
コード例 #15
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                var serverCert = File.ReadAllText("ssl/server.crt");
                var serverKey  = File.ReadAllText("ssl/server.key");
                var keypair    = new KeyCertificatePair(serverCert, serverKey);
                var caCrt      = File.ReadAllText("ssl/ca.crt");

                var credentials = new SslServerCredentials(new List <KeyCertificatePair>()
                {
                    keypair
                }, caCrt, true);

                server = new Server()
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImpl()),
                        SumService.BindService(new SumServiceImpl()),
                        PrimeNumbersService.BindService(new PrimeNumbersServiceImpl()),
                        AverageService.BindService(new AverageServiceImpl()),
                        MaxService.BindService(new MaxServiceImpl()),
                        SqrtService.BindService(new SquareRootServiceImpl()),
                        ServerReflection.BindService(new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor))
                    },

                    Ports = { new ServerPort("localhost", port, credentials) }
                };

                server.Start();
                Console.WriteLine($"Server is listening on port: {port}");
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine($"Server failed to start - {e.Message}");
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
コード例 #16
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            EditText userNameInput = FindViewById <EditText>(Resource.Id.UserNameInput);
            TextView userGreeted   = FindViewById <TextView>(Resource.Id.UserGreeted);
            Button   greetButton   = FindViewById <Button>(Resource.Id.GreetButton);

            greetButton.Click += (sender, e) =>
            {
                userGreeted.Text = GreetingService.GreetPerson(userNameInput.Text);
            };
        }
コード例 #17
0
        public void Get_WhenCalled_ReturnsThreeItems()
        {
            // Arrange
            var data        = this.GetTestList();
            var mockSet     = GetQueryableMockDbSet(data);
            var mockContext = new Mock <HelloESDCContext>();

            mockContext.Setup(c => c.Greetings).Returns(mockSet.Object);
            var service = new GreetingService(mockContext.Object);

            // Act
            var greetings = service.GetAllItems();

            // Assert
            greetings.Count().Should().Be(3);
        }
コード例 #18
0
        public void TestServer()
        {
            var rootCert    = File.ReadAllText($"{Folder}ca.pem");
            var keyCertPair = new KeyCertificatePair(
                File.ReadAllText($"{Folder}server0.pem"),
                File.ReadAllText($"{Folder}server0.key"));
            var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert, SslClientCertificateRequestType.DontRequest);

            var server = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
            {
                Ports = { new ServerPort("localhost", 555, serverCredentials) },
            };

            server.Services.Add(GreetingService.BindService(new GreeterServerImp()));
            server.Start();
        }
コード例 #19
0
        static void Main(string[] args)
        {
            //FOR SSL------------------------------------
            //var serverCert = File.ReadAllText("ssl/server.crt");
            //var serverKey = File.ReadAllText("ssl/server.key");
            //var keypair = new KeyCertificatePair(serverCert, serverKey);
            //var caCert = File.ReadAllText("ssl/ca.crt");

            //var credentials = new SslServerCredentials(new List<KeyCertificatePair>() { keypair }, caCert, true);
            //---------------------------------------------------
            //FOR REFLECTION
            var reflectionServiceImpl = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor);
            //-------------------------------------------------------

            Server server = null;

            try
            {
                server = new Server()
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImpl()),
                        ServerReflection.BindService(reflectionServiceImpl) //FOR REFLECTION
                    },                                                      //it tells server when client calls greet function, it will call the implementaion of it which is GreetingServiceImpl()

                    Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }//WITHOUT SSL
                    //Ports = { new ServerPort("localhost", Port, credentials) }//WITH SSL
                };
                server.Start();
                Console.WriteLine("The Server is listening on Port : " + Port);
                Console.ReadKey();
            }
            catch (IOException ex)
            {
                Console.WriteLine("The Server failed to start : " + ex.Message);
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();//running synchronously here.can be asyncronous if server and client is in different system
                }
            }
        }
コード例 #20
0
        public static void Main(string[] args)
        {
            // Build a server
            var server = new Server
            {
                Services = { GreetingService.BindService(new GreeterServiceImpl()) },
                Ports    = { new ServerPort(Host, Port, ServerCredentials.Insecure) }
            };

            // Start server
            server.Start();

            Console.WriteLine("GreeterServer listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }
コード例 #21
0
        static void Main(string[] args)
        {
            var serverCert = File.ReadAllText("ssl/server.crt");
            var serverKey  = File.ReadAllText("ssl/server.key");
            var caCert     = File.ReadAllText("ssl/ca.crt");

            var keyPair = new KeyCertificatePair(serverCert, serverKey);

            var credentials = new SslServerCredentials(new List <KeyCertificatePair>()
            {
                keyPair
            }, caCert, true);

            Server server = null;

            try
            {
                server = new Server()
                {
                    Services = { GreetingService.BindService(new GreetingServiceImpl()),
                                 SqrtService.BindService(new SqrtServiceImpl()) },
                    Ports = { new ServerPort("localhost", port, credentials) }
                };

                server.Start();
                Console.WriteLine($"Server listening on port : {port}");
                Console.WriteLine("Press any key ...");
                Console.ReadKey();
            }
            catch (IOException ex)
            {
                Console.WriteLine($"The server failed to start: {ex}");
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
コード例 #22
0
        public static void Main(string[] args)
        {
            // Build a server
            var server = new Server
            {
                Services = { GreetingService.BindService(new GreeterServiceImpl()) },
                Ports    = { new ServerPort(Host, Port, ServerCredentials.Insecure) }
            };

            CancellationTokenSource tokenSource = new CancellationTokenSource();
            var serverTask = RunServiceAsync(server, tokenSource.Token);

            Console.WriteLine("GreeterServer listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            tokenSource.Cancel();
            Console.WriteLine("Shutting down...");
            serverTask.Wait();
        }
コード例 #23
0
 public IHttpActionResult Get()
 {
     try
     {
         GreetingService         greetingService = new GreetingService();
         IEnumerable <IGreeting> greetingList;
         greetingList = greetingService.Fetch().ToList();
         if (greetingList != null)
         {
             return(Ok(greetingList));
         }
         else
         {
             return(NotFound());
         }
     }
     catch (Exception e)
     {
         return(Json(e.Message + " " + e.InnerException));
     }
 }
コード例 #24
0
 public IHttpActionResult Get(int id)
 {
     //Implementation of Get By Id
     try
     {
         GreetingService greetingService = new GreetingService();
         IGreeting       greeting        = greetingService.Fetch(id);
         if (greeting != null)
         {
             return(Ok(greeting));
         }
         else
         {
             return(NotFound());
         }
     }
     catch (Exception e)
     {
         return(Json(e.Message + " " + e.InnerException));
     }
 }
コード例 #25
0
        static void Main(string[] args)
        {
            var serverCert        = File.ReadAllText("../../../ssl/server.crt");
            var serverKey         = File.ReadAllText("../../../ssl/server.key");
            var caCert            = File.ReadAllText("../../../ssl/ca.crt");
            var channelCredential = new SslServerCredentials(new List <KeyCertificatePair> {
                new KeyCertificatePair(serverCert, serverKey)
            }, caCert, true);
            var serviceDesc = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor);

            Grpc.Core.Server server = new Grpc.Core.Server
            {
                Services = { GreetingService.BindService(new GreetingServiceImpl()),
                             PrimeNumberDecomposition.BindService(new PrimeNumberDecompositionServiceImpl()),
                             SquareRootService.BindService(new SquareRootServiceImpl()),
                             ServerReflection.BindService(serviceDesc) },
                //Ports = { new ServerPort("localhost", 5000, ServerCredentials.Insecure) }
                Ports = { new ServerPort("localhost", 5000, channelCredential) }
            };
            server.Start();
            Console.WriteLine("server started...");
            Console.ReadLine();
        }
コード例 #26
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            var greetingService = new GreetingService();

            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            name = name ?? data?.name;

            if (name != null)
            {
                var greeting = greetingService.GetGreeting(name);
                return((ActionResult) new OkObjectResult(greeting));
            }

            return(new BadRequestObjectResult("Please pass a name on the query string or in the request body"));
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: prasadravan78/gRPC
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                server = new Server
                {
                    Services =
                    {
                        GreetingService.BindService(new GreetingServiceImplementation())
                    },
                    Ports =
                    {
                        new ServerPort("localhost", portNumber, ServerCredentials.Insecure)
                    }
                };

                server.Start();
                Console.WriteLine("Server started on port number: " + portNumber);

                Console.ReadKey();
            }
            catch (IOException exception)
            {
                Console.WriteLine("The server failed to start." + exception.Message);
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
コード例 #28
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                var keypair     = new KeyCertificatePair(File.ReadAllText("ssl/server.crt"), File.ReadAllText("ssl/server.key"));
                var cacert      = File.ReadAllText("ssl/ca.crt");
                var credentials = new SslServerCredentials(new List <KeyCertificatePair>()
                {
                    keypair
                }, cacert, false);

                server = new Server()
                {
                    Services = { GreetingService.BindService(new GreetingServiceImpl()) },
                    Ports    = { new ServerPort("localhost", Port, credentials) }
                };

                server.Start();
                Console.WriteLine("The server is listening on the port : " + Port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The server failed to start : " + e.Message);
                throw;
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
コード例 #29
0
        public void Configure(
            IApplicationBuilder app,
            IStringLocalizer <Startup> startupStringLocalizer,
            IStringLocalizer <YellingService> yellingLocalizer,
            IStringLocalizer <GreetingService> greetingLocalizer)
        {
            var supportedCultures = new List <CultureInfo>
            {
                new CultureInfo("en-US"),
                new CultureInfo("en-AU"),
                new CultureInfo("en-GB"),
                new CultureInfo("es-ES"),
                new CultureInfo("ja-JP"),
                new CultureInfo("fr-FR"),
                new CultureInfo("zh"),
                new CultureInfo("zh-CN")
            };

#if NET461
            supportedCultures.Add(new CultureInfo("zh-CHT"));
#elif NETCOREAPP2_0
#else
#error Target framework needs to be updated
#endif
            var options = new RequestLocalizationOptions
            {
                DefaultRequestCulture = new RequestCulture("en-US"),
                SupportedCultures     = supportedCultures,
                SupportedUICultures   = supportedCultures
            };
            // Optionally create an app-specific provider with just a delegate, e.g. look up user preference from DB.
            // Inserting it as position 0 ensures it has priority over any of the default providers.
            //options.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
            //{

            //}));

            app.UseRequestLocalization(options);

            app.Use(async(context, next) =>
            {
                if (context.Request.Path.Value.EndsWith("favicon.ico"))
                {
                    // Pesky browsers
                    context.Response.StatusCode = 404;
                    return;
                }

                context.Response.StatusCode  = 200;
                context.Response.ContentType = "text/html; charset=utf-8";

                var requestCultureFeature = context.Features.Get <IRequestCultureFeature>();
                var requestCulture        = requestCultureFeature.RequestCulture;

                await context.Response.WriteAsync(
                    $@"<!doctype html>
<html>
<head>
    <title>{startupStringLocalizer["Request Localization"]}</title>
    <style>
        body {{ font-family: 'Segoe UI', Helvetica, Sans-Serif }}
        h1, h2, h3, h4, th {{ font-family: 'Segoe UI Light', Helvetica, Sans-Serif }}
        th {{ text-align: left }}
    </style>
    <script>
        function useCookie() {{
            var culture = document.getElementById('culture');
            var uiCulture = document.getElementById('uiCulture');
            var cookieValue = '{CookieRequestCultureProvider.DefaultCookieName}=c='+culture.options[culture.selectedIndex].value+'|uic='+uiCulture.options[uiCulture.selectedIndex].value;
            document.cookie = cookieValue;
            window.location = window.location.href.split('?')[0];
        }}

        function clearCookie() {{
            document.cookie='{CookieRequestCultureProvider.DefaultCookieName}=""""';
        }}
    </script>
</head>
<body>");
                var classLib   = new GreetingService(greetingLocalizer);
                var yellingLib = new YellingService(yellingLocalizer);

                await context.Response.WriteAsync($"<h1>ClassLib {classLib.SayHello()}</h1>");
                await context.Response.WriteAsync($"<h1>Yelling (Outsidenamespace): {yellingLib.GetYellingHello()}</h1>");
                await context.Response.WriteAsync($"<h1>{startupStringLocalizer["Request Localization Sample"]}</h1>");
                await context.Response.WriteAsync($"<h1>{startupStringLocalizer["Hello"]}</h1>");
                await context.Response.WriteAsync("<form id=\"theForm\" method=\"get\">");
                await context.Response.WriteAsync($"<label for=\"culture\">{startupStringLocalizer["Culture"]}: </label>");
                await context.Response.WriteAsync("<select id=\"culture\" name=\"culture\">");
                await WriteCultureSelectOptions(context);
                await context.Response.WriteAsync("</select><br />");
                await context.Response.WriteAsync($"<label for=\"uiCulture\">{startupStringLocalizer["UI Culture"]}: </label>");
                await context.Response.WriteAsync("<select id=\"uiCulture\" name=\"ui-culture\">");
                await WriteCultureSelectOptions(context);
                await context.Response.WriteAsync("</select><br />");
                await context.Response.WriteAsync("<input type=\"submit\" value=\"go QS\" /> ");
                await context.Response.WriteAsync($"<input type=\"button\" value=\"go cookie\" onclick='useCookie();' /> ");
                await context.Response.WriteAsync($"<a href=\"/\" onclick='clearCookie();'>{startupStringLocalizer["reset"]}</a>");
                await context.Response.WriteAsync("</form>");
                await context.Response.WriteAsync("<br />");
                await context.Response.WriteAsync("<table><tbody>");
                await context.Response.WriteAsync($"<tr><th>Winning provider:</th><td>{requestCultureFeature.Provider?.GetType()?.Name}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current request culture:"]}</th><td>{requestCulture.Culture.DisplayName} ({requestCulture.Culture})</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current request UI culture:"]}</th><td>{requestCulture.UICulture.DisplayName} ({requestCulture.UICulture})</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current thread culture:"]}</th><td>{CultureInfo.CurrentCulture.DisplayName} ({CultureInfo.CurrentCulture})</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current thread UI culture:"]}</th><td>{CultureInfo.CurrentUICulture.DisplayName} ({CultureInfo.CurrentUICulture})</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current date (invariant full):"]}</th><td>{DateTime.Now.ToString("F", CultureInfo.InvariantCulture)}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current date (invariant):"]}</th><td>{DateTime.Now.ToString(CultureInfo.InvariantCulture)}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current date (request full):"]}</th><td>{DateTime.Now.ToString("F")}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current date (request):"]}</th><td>{DateTime.Now.ToString()}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current time (invariant):"]}</th><td>{DateTime.Now.ToString("T", CultureInfo.InvariantCulture)}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Current time (request):"]}</th><td>{DateTime.Now.ToString("T")}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Big number (invariant):"]}</th><td>{(Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.InvariantCulture)}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Big number (request):"]}</th><td>{(Math.Pow(2, 42) + 0.42).ToString("N")}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Big number negative (invariant):"]}</th><td>{(-Math.Pow(2, 42) + 0.42).ToString("N", CultureInfo.InvariantCulture)}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Big number negative (request):"]}</th><td>{(-Math.Pow(2, 42) + 0.42).ToString("N")}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Money (invariant):"]}</th><td>{2199.50.ToString("C", CultureInfo.InvariantCulture)}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Money (request):"]}</th><td>{2199.50.ToString("C")}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Money negative (invariant):"]}</th><td>{(-2199.50).ToString("C", CultureInfo.InvariantCulture)}</td></tr>");
                await context.Response.WriteAsync($"<tr><th>{startupStringLocalizer["Money negative (request):"]}</th><td>{(-2199.50).ToString("C")}</td></tr>");
                await context.Response.WriteAsync("</tbody></table>");
                await context.Response.WriteAsync(
                    @"</body>
</html>");
            });
        }
コード例 #30
0
        private void GreetingButton_Click(object sender, EventArgs e)
        {
            var userName = this.EnterNameTextbox.Text;

            MessageBox.Show(GreetingService.GreetPerson(userName));
        }