本文整理汇总了C#中IConsole.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# IConsole.WriteLine方法的具体用法?C# IConsole.WriteLine怎么用?C# IConsole.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConsole
的用法示例。
在下文中一共展示了IConsole.WriteLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileCS
private void CompileCS(IConsole console, IStandardProject superProject, IStandardProject project, ISourceFile file,
string outputFile)
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(BaseDirectory, "Roslyn", "csc.exe");
if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName))
{
console.WriteLine("Unable to find compiler (" + startInfo.FileName + ") Please check project compiler settings.");
}
else
{
startInfo.WorkingDirectory = project.Solution.CurrentDirectory;
startInfo.Arguments = string.Format("{0} /out:{1} {2}", GetCSCCompilerArguments(superProject, project, file),
outputFile, file.Location);
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
//console.WriteLine (Path.GetFileNameWithoutExtension(startInfo.FileName) + " " + startInfo.Arguments);
using (var process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) => { console.WriteLine(e.Data); };
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
console.WriteLine();
console.WriteLine(e.Data);
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
}
}
示例2: Run
public Prompt Run(System.Collections.Generic.IDictionary<string, string> args, IConsole console)
{
foreach (var p in args)
{
console.WriteLine(String.Format("{0} = {1}", p.Key, p.Value ?? "null"));
}
return Prompt.Stop;
}
示例3: PlayGame
/// <summary>
/// The main game cycle.
/// </summary>
/// <param name="gameBoard">the game board it is played on</param>
/// <param name="userInput">the user UI handling object</param>
public static void PlayGame(Board gameBoard, IConsole userInput)
{
int gameBoardSize = gameBoard.Rows;
int rows = gameBoard.Rows;
int cols = gameBoard.Cols;
int detonatedMinesCounter = 0;
do
{
int row;
int col;
bool isValidCell = false;
do
{
EnterCoordinates(out row, out col, userInput);
bool isInField = (row >= 0 && row < gameBoardSize) &&
(col >= 0 && col < gameBoardSize);
isValidCell = isInField &&
gameBoard.GameBoard[row, col] != "-" &&
gameBoard.GameBoard[row, col] != "X";
if (!isValidCell)
{
userInput.WriteLine("Invalid move!");
}
} while (!isValidCell);
ExplosionHandler.HitMine(gameBoard, row, col);
detonatedMinesCounter++;
userInput.WriteLine(gameBoard.ToString());
} while (!IsGameOver(gameBoard));
userInput.WriteLine("Game over. Detonated mines: " + detonatedMinesCounter);
}
示例4: Save
public void Save(IConsole console)
{
try
{
console.WriteLine("Saving new NuSpec: {0}", FilePath);
var nuspecText = ToNuspecFileText();
File.WriteAllText(FilePath, nuspecText);
}
catch (Exception)
{
console.WriteError("Could not save file: {0}", FilePath);
throw;
}
}
示例5: Main
public static void Main(string[] args)
{
_controller = Container.Resolve<IController>();
_console = Container.Resolve<IConsole>();
string userInput;
while ((userInput = _console.ReadLine()).ToLower() != "exit")
{
_controller.Run(userInput);
}
_console.WriteLine("Good bye!");
}
示例6: Execute
public override void Execute(IConsole console)
{
int x = 1;
string input;
int option = -1;
while (true)
{
console.WriteLine("****************************************");
console.WriteLine("*\t" + _menu_header_text);
console.WriteLine("****************************************");
console.Write("\n\n");
console.WriteLine("0 - Return");
foreach (var entry in entries)
{
console.WriteLine(x.ToString() + " - " + entry.menu_text);
}
while (option < 0)
{
console.Write("Enter Selection: ");
try
{
input = console.ReadLine();
}
catch (IOException)
{
input = null;
}
if (input != null)
{
if (int.TryParse(input, out x))
{
if ((x >= 0) && (x <= entries.Count()))
{
option = x;
break;
}
}
}
console.WriteLine("\nInvalid selection");
}
if (option > 0)
{
entries[option - 1].Execute(console);
option = -1;
}
else if (option == 0)
break;
}
return;
}
示例7: Main
public static void Main(string[] argv)
{
System.Console.Title = "RxCmd";
Program.Console = new ConsoleAdapter(System.Console.Write);
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
Compose();
ProtocolManager.Load();
do
{
PrintConsole();
string line = System.Console.ReadLine();
if (line != null)
{
in_prompt = false;
string command = line.Substring(0, line.IndexOf(' ') > 0 ? line.IndexOf(' ') : line.Length);
if (String.IsNullOrEmpty(command)) continue;
bool valid = false;
foreach (ICommand c in commands)
{
if (c.Name.Equals(command, StringComparison.OrdinalIgnoreCase) ||
c.Aliases.Any(x => x.Equals(command, StringComparison.OrdinalIgnoreCase)))
{
object[] args = line.Split(' ').Skip(1).Cast<Object>().ToArray();
in_command = true;
c.Execute(args);
valid = true;
in_command = false;
}
}
if (!valid)
{
Console.WriteLine("The command \"{0}\" was not found. Please check spelling and try again.", command);
}
}
} while (!exit);
}
示例8: Size
public override ProcessResult Size(IConsole console, Project project, LinkResult linkResult)
{
ProcessResult result = new ProcessResult();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(Settings.ToolChainLocation, "arm-none-eabi-size.exe");
if (!File.Exists(startInfo.FileName))
{
console.WriteLine("Unable to find tool (" + startInfo.FileName + ") check project compiler settings.");
result.ExitCode = -1;
return result;
}
startInfo.Arguments = string.Format("{0}", linkResult.Executable);
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
using (var process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) =>
{
console.WriteLine(e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
console.WriteLine(e.Data);
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
result.ExitCode = process.ExitCode;
}
return result;
}
示例9: Compile
public override CompileResult Compile(IConsole console, Project superProject, Project project, SourceFile file, string outputFile)
{
CompileResult result = new CompileResult();
var startInfo = new ProcessStartInfo();
if (file.Language == Language.Cpp)
{
startInfo.FileName = Path.Combine(Settings.ToolChainLocation, "arm-none-eabi-g++.exe");
}
else
{
startInfo.FileName = Path.Combine(Settings.ToolChainLocation, "arm-none-eabi-gcc.exe");
}
startInfo.WorkingDirectory = project.Solution.CurrentDirectory;
if (!File.Exists(startInfo.FileName))
{
result.ExitCode = -1;
console.WriteLine("Unable to find compiler (" + startInfo.FileName + ") Please check project compiler settings.");
}
else
{
string fileArguments = string.Empty;
if (file.Language == Language.Cpp)
{
fileArguments = "-x c++ -std=c++14 -fno-use-cxa-atexit";
}
startInfo.Arguments = string.Format("{0} {1} {2} -o{3} -MMD -MP", GetCompilerArguments(superProject, project, file.Language), fileArguments, file.Location, outputFile);
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
// console.WriteLine (Path.GetFileNameWithoutExtension(startInfo.FileName) + " " + startInfo.Arguments);
using (var process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) =>
{
console.WriteLine(e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
console.WriteLine();
console.WriteLine(e.Data);
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
result.ExitCode = process.ExitCode;
}
}
return result;
}
示例10: Link
public override LinkResult Link(IConsole console, Project superProject, Project project, CompileResult assemblies, string outputDirectory)
{
LinkResult result = new LinkResult();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(Settings.ToolChainLocation, "arm-none-eabi-gcc.exe");
if (project.Type == ProjectType.StaticLibrary)
{
startInfo.FileName = Path.Combine(Settings.ToolChainLocation, "arm-none-eabi-ar.exe");
}
startInfo.WorkingDirectory = project.Solution.CurrentDirectory;
if (!File.Exists(startInfo.FileName))
{
result.ExitCode = -1;
console.WriteLine("Unable to find linker executable (" + startInfo.FileName + ") Check project compiler settings.");
return result;
}
// GenerateLinkerScript(project);
string objectArguments = string.Empty;
foreach (string obj in assemblies.ObjectLocations)
{
objectArguments += obj + " ";
}
string libs = string.Empty;
foreach (string lib in assemblies.LibraryLocations)
{
libs += lib + " ";
}
if (!Directory.Exists(outputDirectory))
{
Directory.CreateDirectory(outputDirectory);
}
string outputName = Path.GetFileNameWithoutExtension(project.Location) + ".elf";
if (project.Type == ProjectType.StaticLibrary)
{
outputName = "lib" + Path.GetFileNameWithoutExtension(project.Name) + ".a";
}
var executable = Path.Combine(outputDirectory, outputName);
string linkedLibraries = string.Empty;
//foreach (var libraryPath in project.SelectedConfiguration.LinkedLibraries)
//{
// string relativePath = Path.GetDirectoryName(libraryPath);
// string libName = Path.GetFileNameWithoutExtension(libraryPath).Substring(3);
// linkedLibraries += string.Format(" -L\"{0}\" -l{1}", relativePath, libName);
//}
foreach (var lib in project.BuiltinLibraries)
{
linkedLibraries += string.Format("-l{0} ", lib);
}
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
startInfo.Arguments = string.Format("{0} -o{1} {2} -Wl,--start-group {3} {4} -Wl,--end-group", GetLinkerArguments(project), executable, objectArguments, linkedLibraries, libs);
if (project.Type == ProjectType.StaticLibrary)
{
startInfo.Arguments = string.Format("rvs {0} {1}", executable, objectArguments);
}
//console.WriteLine(Path.GetFileNameWithoutExtension(startInfo.FileName) + " " + startInfo.Arguments);
//console.WriteLine ("[LL] - " + startInfo.Arguments);
using (var process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) =>
{
//console.WriteLine(e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null && !e.Data.Contains("creating"))
{
console.WriteLine(e.Data);
}
};
process.BeginOutputReadLine();
//.........这里部分代码省略.........
示例11: Link
private void Link(IConsole console, Project superProject, CompileResult compileResult, CompileResult linkResults)
{
var binDirectory = compileResult.Project.GetBinDirectory(superProject);
if (!Directory.Exists(binDirectory))
{
Directory.CreateDirectory(binDirectory);
}
string outputLocation = binDirectory;
string executable = Path.Combine(outputLocation, compileResult.Project.Name);
if (compileResult.Project.Type == ProjectType.StaticLibrary)
{
executable = Path.Combine(outputLocation, "lib" + compileResult.Project.Name);
executable += ".a";
}
else
{
executable += ".elf";
}
if (!Directory.Exists(outputLocation))
{
Directory.CreateDirectory(outputLocation);
}
console.OverWrite(string.Format("[LL] [{0}]", compileResult.Project.Name));
var linkResult = Link(console, superProject, compileResult.Project, compileResult, outputLocation);
if (linkResult.ExitCode == 0)
{
if (compileResult.Project.Type == ProjectType.StaticLibrary)
{
linkResults.LibraryLocations.Add(executable);
}
else
{
console.WriteLine();
Size(console, compileResult.Project, linkResult);
linkResults.ExecutableLocations.Add(executable);
}
}
else if(linkResults.ExitCode == 0)
{
linkResults.ExitCode = linkResult.ExitCode;
}
}
示例12: ReadBoardSize
/// <summary>
/// Reads from the input the game size.
/// </summary>
/// <param name="userInput">the user UI handling object</param>
/// <returns>the size of the game board</returns>
public static int ReadBoardSize(IConsole userInput)
{
userInput.Write("Welcome to \"Battle Field game.\" Enter battlefield size: N = ");
int gameBoardSize = Convert.ToInt32(userInput.ReadLine());
while (gameBoardSize < 1 || gameBoardSize > 10)
{
userInput.WriteLine("Enter a number between 1 and 10!");
gameBoardSize = Convert.ToInt32(userInput.ReadLine());
}
return gameBoardSize;
}
示例13: ObjCopy
public async Task<ProcessResult> ObjCopy(IConsole console, IProject project, LinkResult linkResult, AssemblyFormat format)
{
var result = new ProcessResult();
var commandName = Path.Combine(BinDirectory, $"{SizePrefix}objcopy" + Platform.ExecutableExtension);
if(PlatformSupport.CheckExecutableAvailability(commandName, BinDirectory))
{
string formatArg = "binary";
switch (format)
{
case AssemblyFormat.Binary:
formatArg = "binary";
break;
case AssemblyFormat.IntelHex:
formatArg = "ihex";
break;
}
string outputExtension = ".bin";
switch (format)
{
case AssemblyFormat.Binary:
outputExtension = ".bin";
break;
case AssemblyFormat.IntelHex:
outputExtension = ".hex";
break;
case AssemblyFormat.Elf32:
outputExtension = ".elf";
break;
}
var arguments = $"-O {formatArg} {linkResult.Executable} {Path.GetDirectoryName(linkResult.Executable)}{Platform.DirectorySeperator}{Path.GetFileNameWithoutExtension(linkResult.Executable)}{outputExtension}";
console.WriteLine($"Converting to {format.ToString()}");
result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) => console.WriteLine(e.Data), (s, e) => console.WriteLine(e.Data), false, string.Empty, false);
}
else
{
console.WriteLine("Unable to find tool (" + commandName + ") check project compiler settings.");
result.ExitCode = -1;
}
return result;
}
示例14: CompileLLVMIR
private void CompileLLVMIR(IConsole console, IStandardProject superProject, IStandardProject project, ISourceFile file,
string llvmBinary, string outputFile)
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(BaseDirectory, "LLVM", "llc.exe");
if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName))
{
console.WriteLine("Unable to find compiler (" + startInfo.FileName + ") Please check project compiler settings.");
}
else
{
startInfo.WorkingDirectory = Path.Combine(BaseDirectory, "Llilum\\ZeligBuild\\Host\\bin\\Debug");
startInfo.Arguments =
string.Format(
"-O0 -code-model=small -data-sections -relocation-model=pic -march=thumb -mcpu=cortex-m4 -filetype=obj -mtriple=Thumb-NoSubArch-UnknownVendor-UnknownOS-GNUEABI-ELF -o={0} {1}",
outputFile, llvmBinary);
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
//console.WriteLine (Path.GetFileNameWithoutExtension(startInfo.FileName) + " " + startInfo.Arguments);
using (var process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) => { console.WriteLine(e.Data); };
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
console.WriteLine();
console.WriteLine(e.Data);
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
}
}
示例15: StartAsync
public override async Task<bool> StartAsync(IToolChain toolchain, IConsole console, IProject project)
{
var result = true;
var settings = GetSettings(project);
console.Clear();
console.WriteLine("[JLink] - Starting GDB Server...");
// TODO allow people to select the device.
var startInfo = new ProcessStartInfo();
startInfo.Arguments = string.Format("-select USB -device {0} -if {1} -speed 12000 -noir", settings.TargetDevice, Enum.GetName(typeof (JlinkInterfaceType), settings.Interface));
startInfo.FileName = Path.Combine(BaseDirectory, "JLinkGDBServerCL" + Platform.ExecutableExtension);
if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName))
{
console.WriteLine("[JLink] - Error unable to find executable.");
return false;
}
// Hide console window
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
var processes = Process.GetProcessesByName("JLinkGDBServerCL");
foreach (var process in processes)
{
process.Kill();
}
Task.Factory.StartNew(async () =>
{
using (var process = Process.Start(startInfo))
{
jlinkProcess = process;
process.OutputDataReceived += (sender, e) =>
{
if (DebugMode && !string.IsNullOrEmpty(e.Data))
{
console.WriteLine("[JLink] - " + e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
{
console.WriteLine("[JLink] - " + e.Data);
}
;
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
await CloseAsync();
console.WriteLine("[JLink] - GDB Server Closed.");
jlinkProcess = null;
result = false;
}
});
while (jlinkProcess == null)
{
Thread.Sleep(10);
}
StoppedEventIsEnabled = false;
if (result)
{
result = await base.StartAsync(toolchain, console, project);
if (result)
{
console.WriteLine("[JLink] - Connecting...");
asyncModeEnabled = (await new GDBSetCommand("mi-async", "on").Execute(this)).Response == ResponseCode.Done;
result = (await new TargetSelectCommand(":2331").Execute(this)).Response == ResponseCode.Done;
if (result)
{
await new MonitorCommand("halt").Execute(this);
await new MonitorCommand("reset").Execute(this);
//new MonitorCommand("reg r13 = (0x00000000)").Execute(this);
//new MonitorCommand("reg pc = (0x00000004)").Execute(this);
await new TargetDownloadCommand().Execute(this);
console.WriteLine("[JLink] - Connected.");
}
StoppedEventIsEnabled = true;
}
}
//.........这里部分代码省略.........