Compare commits
2
Commits
master
...
ServiceDriver
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
48f56e76d4 | ||
|
|
05e6c40a57 |
No files matched your search
@@ -15,7 +15,7 @@
|
||||
<OutputType>WinExe</OutputType>
|
||||
<StartupObject>mbts.ui.shell.App</StartupObject>
|
||||
<RootNamespace>bts</RootNamespace>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
<Version>1.0.0</Version>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
<Version>1.0.0</Version>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -20,6 +20,9 @@ namespace sparkcmd
|
||||
if (args.FirstOrDefault() == "usertest") {
|
||||
user_test();
|
||||
}
|
||||
else if (args.FirstOrDefault() == "service") {
|
||||
new ServiceDriver().run(args.Skip(1));
|
||||
}
|
||||
else if (args.FirstOrDefault() == "synthetic") {
|
||||
synthetic_test();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using bts.api.admin;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace sparkcmd
|
||||
{
|
||||
class ServiceDriver
|
||||
{
|
||||
|
||||
string menu(string prompt, params string[] options) {
|
||||
while (true) {
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(prompt);
|
||||
for (int x = 0; x < options.Length; ++x) {
|
||||
Console.WriteLine($"{x}. {options[x]}");
|
||||
}
|
||||
var k = Console.ReadKey();
|
||||
Console.WriteLine();
|
||||
if (Int32.TryParse(k.KeyChar.ToString(), out int c) &&
|
||||
c >= 0 && c < options.Length) {
|
||||
return options[c];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string prompt(string prompt, int indent = 0) {
|
||||
Console.Write(new String(' ', indent));
|
||||
Console.Write(prompt);
|
||||
return Console.ReadLine();
|
||||
}
|
||||
|
||||
T prompt2<T>(string msg, Func<string,T> andthen) {
|
||||
while(true) {
|
||||
var str = prompt(msg);
|
||||
try {
|
||||
return andthen(str);
|
||||
}catch(Exception e) {
|
||||
Console.WriteLine(e);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
T json_value_prompt<T>() {
|
||||
T value = default;
|
||||
do {
|
||||
var serialized = prompt($"Enter {typeof(T).Name} as json: ");
|
||||
serialized = serialized.Trim(' ', '\t', '\r', '\n');
|
||||
if (serialized[0] != '{') serialized = "{" + serialized;
|
||||
if (serialized.Last() != '}') serialized += "}";
|
||||
try {
|
||||
value = JsonConvert.DeserializeObject<T>(serialized);
|
||||
} catch(Exception e) { Console.WriteLine(e); }
|
||||
} while(value == null);
|
||||
return value;
|
||||
}
|
||||
|
||||
public void run(IEnumerable<string> args) {
|
||||
// input service name
|
||||
//
|
||||
var service_name = args.FirstOrDefault() ?? prompt("Service Name: ");
|
||||
var service_type = Type.GetType(service_name);
|
||||
// List methods
|
||||
var service_methods = service_type.GetMethods().Select(md => md.Name).ToArray();
|
||||
menu("Which method do you want to call?", service_methods);
|
||||
|
||||
|
||||
// var ps = json_value_prompt<SecurityScope>();
|
||||
// Console.WriteLine(ps.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
<Platforms>x64</Platforms>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<Version>1.0.0</Version>
|
||||
<LangVersion>7.2</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -17,6 +17,7 @@ echo OUT=$OUT
|
||||
rm -rf $OUT/api
|
||||
mkdir -p $OUT/api
|
||||
mkdir -p $OUT/api/fable
|
||||
# BUILD_DIR
|
||||
|
||||
if [ "$#" -gt 0 ]
|
||||
then
|
||||
|
||||
Reference in new issue
Block a user