Primitive settingsmanager
This commit is contained in:
1 parent
bd4f840d27
commit
243b82a6d7
3 files changed
+85
-9
No files matched your search
@@ -0,0 +1,37 @@
|
||||
using bts.api.core;
|
||||
using bts.api.persistence;
|
||||
using bts.api.user;
|
||||
using bts.test;
|
||||
using mbts.persist;
|
||||
using mbts.ui.shell;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.settings {
|
||||
public class SettingsManagerTool {
|
||||
public static void run() {
|
||||
var sc = new ServiceContext();
|
||||
var users = sc.locate<UserService>();
|
||||
var persist = sc.locate<PersistenceService>("settings");
|
||||
var user_list = users.get_users(new GetUsersRequest());
|
||||
var user_names = user_list.Users.Select(u => u.Login);
|
||||
var from = ConsoleEx.prompt("From User", user_names);
|
||||
var from_persist = new UserUISettings(user_list.Users.First(u => u.Login == from).Id, persist, null);
|
||||
|
||||
var workspaces = from_persist.query<WorkspaceDefinition>(WorkspacesModel.WORKSPACE_NAMESPACE, ".*").Result;
|
||||
var selected_ws = ConsoleEx.prompt("Choose workspace:", workspaces.Select(w => w.key));
|
||||
|
||||
var to = ConsoleEx.prompt("To User", user_names);
|
||||
|
||||
var name = ConsoleEx.input_prompt("Rename workspace?", selected_ws);
|
||||
|
||||
var confirm = ConsoleEx.prompt($"copy workspace '{selected_ws}' from {from} to {to} and name it '{name}'. Confirm?", "Yes", "No");
|
||||
if (confirm == "Yes") {
|
||||
var ws_blob = workspaces.First(w => w.key == selected_ws).value;
|
||||
var to_persist = new UserUISettings(user_list.Users.First(u => u.Login == to).Id, persist, null);
|
||||
to_persist.set(WorkspacesModel.WORKSPACE_NAMESPACE, name, ws_blob).Wait();
|
||||
Console.WriteLine("Done");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace bts.test {
|
||||
public static class ConsoleEx {
|
||||
@@ -21,17 +23,34 @@ namespace bts.test {
|
||||
}
|
||||
|
||||
public static T prompt<T>(string prompt, params T[] options) {
|
||||
Console.WriteLine(prompt);
|
||||
for (int x = 1; x <= options.Length; ++x) {
|
||||
return ConsoleEx.prompt(prompt, (IEnumerable<T>)options);
|
||||
}
|
||||
public static T prompt<T>(string prompt, IEnumerable<T> options) {
|
||||
WriteLine(prompt, ConsoleColor.Yellow);
|
||||
for (int x = 0; x < options.Count(); ++x) {
|
||||
Write($"{x}. ", ConsoleColor.Yellow);
|
||||
WriteLine(options[x].ToString());
|
||||
WriteLine(options.ElementAt(x).ToString());
|
||||
}
|
||||
int response;
|
||||
do {
|
||||
Int32.TryParse(Console.ReadKey().ToString(), out response);
|
||||
if (response > options.Length) response = 0;
|
||||
} while (response == 0);
|
||||
return options[response];
|
||||
int response = 0;
|
||||
bool success = false;
|
||||
while(!success) {
|
||||
var key = Console.ReadKey();
|
||||
success = Int32.TryParse(key.KeyChar.ToString(), out response);
|
||||
if (response > options.Count()) success = false;
|
||||
}
|
||||
var value = options.ElementAt(response);
|
||||
Console.WriteLine(" >> " + value.ToString());
|
||||
Console.WriteLine();
|
||||
return value;
|
||||
}
|
||||
|
||||
public static string input_prompt(string prompt, string default_result) {
|
||||
Write(prompt + " (", ConsoleColor.Yellow);
|
||||
Write(default_result, ConsoleColor.White);
|
||||
Write(") ", ConsoleColor.Yellow);
|
||||
var result = Console.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(result)) return default_result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using ManyConsole;
|
||||
using System.Reflection;
|
||||
|
||||
namespace bts {
|
||||
|
||||
public class SettinsManagerCommand : ConsoleCommand {
|
||||
public SettinsManagerCommand() {
|
||||
IsCommand("SettingsManager", "Copy workspaces around");
|
||||
}
|
||||
|
||||
public override int Run(string[] remainingArguments) {
|
||||
var asm = Assembly.Load("spark");
|
||||
var type = asm.GetType("bts.settings.SettingsManagerTool");
|
||||
var run = type.GetMethod("run", BindingFlags.Static | BindingFlags.Public);
|
||||
run.Invoke(null, new object[0]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user