示例#1
0
        public void Initialize()
        {
            var commandsReader1 = new CommandFileReader($"file{Program.Node}.txt");

            _timerExecutor = new TimerExecutor(
                commandsReader1.ReadCommands().ToArray(),
                command =>
            {
                //Console.WriteLine($"Executing command {command.Time}...");
                switch (command.Type)
                {
                case CommandType.Insert:
                    // ReSharper disable once PossibleInvalidOperationException
                    return(InsertAsync(command.Key, command.Value.Value));

                case CommandType.Select:
                    return(command.Key != null
                                ? SelectAsync(command.Key)
                                : SelectAllAsync());

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });

            IsInitialized = true;

            _mainTask = Task.Run(async() =>
            {
                await WaitInitAsync();

                Console.WriteLine("Start executing...");
                await _timerExecutor.Execute();
            });
        }
示例#2
0
        static async Task Main(string[] args)
        {
            if (args.Length != 3)
            {
                throw new ArgumentException();
            }

            var filePath1       = args[0];
            var filePath2       = args[1];
            var filePath3       = args[2];
            var commandsReader1 = new CommandFileReader(filePath1);
            var commandsReader2 = new CommandFileReader(filePath2);
            var commandsReader3 = new CommandFileReader(filePath3);
            var executor        = new TimerExecutor(
                commandsReader1.ReadCommands()
                .Concat(commandsReader2.ReadCommands())
                .Concat(commandsReader3.ReadCommands())
                .ToArray(),
                command =>
            {
                //Console.WriteLine($"Executing command {command.Time}...");
                switch (command.Type)
                {
                case CommandType.Insert:
                    // ReSharper disable once PossibleInvalidOperationException
                    return(InsertAsync(command.Key, command.Value.Value));

                case CommandType.Select:
                    return(command.Key != null
                                ? SelectAsync(command.Key)
                                : SelectAllAsync());

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });

            await WaitSlavesAsync();

            Console.WriteLine("Start executing...");
            await executor.Execute();

            Console.WriteLine("Show stats...");
            await ShowStatsAsync();

            Console.WriteLine("Done!");
        }