public static NotFoundCommand Load(UserConsole console, Storage storage)
        {
            var mem       = new MemoryStream(storage.Read());
            var schedule  = new List <Action>();
            var variables = new List <int>();

            using var binReader = new BinaryReader(mem);

            binReader.ReadByte();
            var x     = binReader.ReadInt64();
            var count = binReader.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                schedule.Add((Action)binReader.ReadByte());
            }

            var command = new NotFoundCommand(console, storage, x)
            {
                Schedule = schedule
            };

            command.Save();
            return(command);
        }
        public override void Run(UserConsole userConsole, Storage storage)
        {
            var x          = 420L;
            var storedData = storage.Read();

            if (storedData.Length != 0)
            {
                var binaryReader = new BinaryReader(new MemoryStream(storedData));
                var typeByte     = binaryReader.ReadByte();
                var type         = (CommandType)typeByte;
                var command      = Load(userConsole, storage, type);

                if (!command.IsComplete)
                {
                    command.Run();
                }
                x = command.LastRandValue;
            }
            while (true)
            {
                Command command;
                var     input = userConsole.ReadLine();
                switch (input.Trim())
                {
                case "exit":
                    storage.Write(Array.Empty <byte>());
                    return;

                case "add":
                    command = new AddCommand(userConsole, storage, x);
                    break;

                case "median":
                    command = new MedianCommand(userConsole, storage, x);
                    break;

                case "help":
                    command = new HelpCommand(userConsole, storage, x);
                    break;

                case "rand":
                    command = new RandomCommand(userConsole, storage, x);
                    break;

                default:
                    command = new NotFoundCommand(userConsole, storage, x);
                    break;
                }
                command.Run();
                x = command.LastRandValue;
            }
        }
        private Command Load(UserConsole userConsole, Storage storage, CommandType type)
        {
            switch (type)
            {
            case CommandType.Help:
                return(HelpCommand.Load(userConsole, storage));

            case CommandType.Random:
                return(RandomCommand.Load(userConsole, storage));

            case CommandType.Add:
                return(AddCommand.Load(userConsole, storage));

            case CommandType.Median:
                return(MedianCommand.Load(userConsole, storage));

            case CommandType.NotFound:
                return(NotFoundCommand.Load(userConsole, storage));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }