Exemple #1
0
        static async Task Main(string[] args)
        {
            var pollingPeriod = TimeSpan.FromSeconds(1);

            var greetings = Task.Run(async() =>
            {
                Console.WriteLine("Welcome to useless polling application!");

                // display latest previous batch of polled units here (loaded from database)
                DBService dBService = new DBService();
                dBService.readLastRecord();

                Console.WriteLine("Select polling interval measured in seconds and press Enter");

                pollingPeriod = await SelectPollingPeriod(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10));

                Console.WriteLine("Press ESC to exit or any other key to log it\n");
            });
            await greetings;

            var cancelSource = new CancellationTokenSource();
            var transmitter  = new Subject <Data.PollerUnit>();

            var poller = new PolledConsumerWrapper(transmitter, pollingPeriod, onNewBatchObserved, cancelSource);

            var polleach = Task.Run(() =>
            {
                while (!cancelSource.IsCancellationRequested)
                {
                    var key = Console.ReadKey();

                    if (key.Key == ConsoleKey.Escape)
                    {
                        cancelSource.Cancel();
                        break;
                    }

                    transmitter.OnNext(new Data.PollerUnit()
                    {
                        Timestamp = DateTimeOffset.Now,
                        Content   = key.KeyChar.ToString()
                    });
                }
            });

            await polleach;

            cancelSource.Cancel();
        }
Exemple #2
0
        public static string period = null; //this shit

        static async Task Main(string[] args)
        {
            using (dbService db = new dbService())
            {
                var dt = db.csharp_test
                         .FromSqlRaw($"SELECT * FROM `csharp_test` WHERE `id`=(SELECT MAX(`id`)FROM `csharp_test`)")
                         .ToList();
                Console.WriteLine("Последняя сохраненная группа:");

                foreach (table_csharp_test u in dt)
                {
                    Console.Write(
                        $"момент нажатия:\n{u.moment_presses}нажатая клавиша:\n{u.keystroke}интервал опроса:{u.duration_sec} сек.");
                }
            }

            var pollingPeriod = TimeSpan.FromSeconds(1);

            var greetings = Task.Run(async() =>
            {
                Console.WriteLine(
                    "\n\nДобро пожаловать в бесполезное приложение для опроса!"); //Welcome to useless polling application!

                // display latest previous batch of polled units here (loaded from database)

                Console.WriteLine(
                    "Выберите интервал опроса измеряемый в секундах и нажмите клавишу Enter"); //Select pollling interval measured in seconds and press Enter

                pollingPeriod = await SelectPollingPeriod(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(10));
                Console.WriteLine(
                    "Нажмите ESC для выхода или любую другую клавишу для входа в систему\n"); //Press ESC to exit or any other key to log it
            });
            await greetings;

            var cancelSource = new CancellationTokenSource();
            var transmitter  = new Subject <Data.PollerUnit>();

            var poller = new PolledConsumerWrapper(transmitter, pollingPeriod, onNewBatchObserved, cancelSource);

            period = pollingPeriod.Seconds.ToString();
            var polleach = Task.Run(() =>
            {
                while (!cancelSource.IsCancellationRequested)
                {
                    var key = Console.ReadKey();

                    if (key.Key == ConsoleKey.Escape)
                    {
                        cancelSource.Cancel();
                        break;
                    }

                    transmitter.OnNext(new Data.PollerUnit()
                    {
                        Timestamp = DateTimeOffset.Now,
                        Content   = key.KeyChar.ToString()
                    });
                }
            });
            await polleach;

            cancelSource.Cancel();
        }