private void ExpandFile(object o) { if (!int.TryParse(o.ToString(), out var param)) { _messagingService.Message($"Invalid command"); return; } var requiredBytes = param * 1024 * 1024; var inputStream = _fileReadOpenService.OpenFile(); if (inputStream == null || inputStream.Length > 8 * 1024) { _messagingService.Message($"Invalid input file selected"); return; } var outputStream = _fileWriteService.OpenFile(); if (outputStream == null) { _messagingService.Message($"Invalid output file selected"); return; } using (outputStream) using (inputStream) { var buffer = new byte[inputStream.Length]; var actualRead = inputStream.Read(buffer, 0, buffer.Length); var requiredLoops = requiredBytes / actualRead; for (int i = 0; i < requiredLoops; i++) { outputStream.Write(buffer, 0, actualRead); } } _messagingService.Message($"Successfully expanded file to {param} MB"); }