Exemplo n.º 1
0
        public decimal RequestDepositAmount()
        {
            outputHandler.WriteLine(DepositRequestQuestionText);

            bool    isInputDepositValid = false;
            decimal depositAmount       = 0;

            while (!isInputDepositValid)
            {
                string  input       = inputHandler.ReadLine();
                decimal parsedValue = 0;
                if (IsValid(input, out parsedValue))
                {
                    isInputDepositValid = true;
                    decimal.TryParse(input, out depositAmount);
                }
                else
                {
                    outputHandler.WriteLine(DepositAmountInvalidText);
                }
            }

            currentPlayer.Balance = depositAmount;

            return(depositAmount);
        }
        public void ShowWelcomeMessage()
        {
            var currentDate = _dateTimeProvider.GetCurrentDateTime();

            _outputHandler.WriteLine(string.Format(Resources.DateTimeSentence, currentDate.ToLongDateString()));
            var message = currentDate.IsChristmas() ? Resources.MerryChristmas : Resources.Welcome;

            _outputHandler.WriteLine(message);
        }
Exemplo n.º 3
0
        private static void PerformCommand <T>(CommonOptions options, IOutputHandler outputHandler, string action, Func <IList <T> > fileList, Func <CommonOptions, IOutputHandler, T, byte[], long> operation)
        {
            outputHandler.Write("{0} started", action);

            var sw = Stopwatch.StartNew();

            var files = fileList();

            if (files == null || files.Count == 0)
            {
                outputHandler.WriteLine(" (no files found)");
                return;
            }

            outputHandler.WriteVerboseOrNormalLine("", " ({0} files)", files.Count);
            var totalSize = files.Sum(o => operation(options, outputHandler, o, options.BinaryKey));

            sw.Stop();

            if (totalSize != 0)
            {
                if (options.Verbose)
                {
                    var avgSpeed    = "--";
                    var elapsedSecs = sw.ElapsedMilliseconds / 1000;
                    totalSize = totalSize / (1024 * 1024);

                    if (totalSize != 0 && elapsedSecs != 0)
                    {
                        avgSpeed = (totalSize / elapsedSecs).ToString(CultureInfo.InvariantCulture);
                    }

                    outputHandler.WriteVerboseLine("{0} of {1} files complete ({2}MB in {3:hh\\:mm\\:ss}, avg {4}MB/s)", action, files.Count, totalSize, sw.Elapsed, avgSpeed);
                }
                else
                {
                    outputHandler.WriteLine("{0} of {1} files complete", action, files.Count);
                }
            }
        }
Exemplo n.º 4
0
        public static long PerformDecryption(CommonOptions options, IOutputHandler outputHandler, string file, byte[] key)
        {
            outputHandler.WriteVerbose("{0} => ", file.Replace(options.SourceDir, "").TrimStart(new[] { Path.DirectorySeparatorChar }));

            var result = FileEncrypter.DecryptFile(options.DestinationDir, file, key);

            if (result.HasResult)
            {
                outputHandler.WriteVerboseLine(result.Result.Item1.Replace(options.DestinationDir, "").TrimStart(new[] { Path.DirectorySeparatorChar }));
                return(result.Result.Item2);
            }

            outputHandler.WriteLine("Failed to decrypt file! ({0})", result.ErrorMessage);
            return(0);
        }
Exemplo n.º 5
0
        public void Run()
        {
            outputHandler.WriteLine("Welcome to Moai 🗿");
            inputHandler.PressAnyKey();
            outputHandler.Clear();
            var board  = new Board(outputHandler);
            var player = CreatePlayer();

            board.AddBeing(player);

            board.Display();

            while (true)
            {
                board.PerformFrame();
            }
        }
Exemplo n.º 6
0
        public static void Generate(IOutputHandler outputHandler)
        {
            var key = FileEncrypter.GenerateKey();

            outputHandler.WriteLine("Generated key: {0}", Convert.ToBase64String(key));
        }
Exemplo n.º 7
0
 public void PressAnyKey()
 {
     outputHandler.WriteLine("Press any key...");
     Console.ReadKey(true);
 }