by
0 18
0
4
1,338
1
Top 1% !
Famous
Tagged
Specified
Popularity: 22413rd place

Published on:

Architecturex86_64
LanguageC#
Windows VersionWindows7

Parse: Parses a given line from console as a command if any.

Parses a given line from console as a command if any.

<param name="line">The line to be parsed.</param>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1373940/Parse--Parses-a-given-line-from-console-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Serilog; private static readonly Dictionary<CommandGroupAttribute, CommandGroup> CommandGroups = new Dictionary<CommandGroupAttribute, CommandGroup>(); static CommandManager() { RegisterCommandGroups(); } /// <summary> /// Parses a given line from console as a command if any. /// </summary> /// <param name="line">The line to be parsed.</param> public static void Parse(string line) { string output = string.Empty; string command; string parameters; var found = false; if (line == null) return; if (line.Trim() == string.Empty) return; if (!ExtractCommandAndParameters(line, out command, out parameters)) { output = "Unknown command: " + line; Log.Information(output); return; } foreach (var pair in CommandGroups) { if (pair.Key.Name != command) continue; output = pair.Value.Handle(parameters); found = true; break; } if (found == false) output = string.Format("Unknown command: {0} {1}", command, parameters); if (output != string.Empty) Log.Information(output); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus