private string ListAllCommands(ConsoleCommands Commands, string CategoryName = null) { StringBuilder sb = new StringBuilder(); foreach (var command in Commands.GetCommands()) { sb.Append(Environment.NewLine); if (CategoryName != null) { sb.Append(CategoryName + ' '); } sb.Append(FormatCommandHelp(command)); } var subcates = Commands.GetSubCategories(); if (subcates.Count != 0) { foreach (var subcate in subcates) { if (CategoryName != null) { sb.Append(ListAllCommands(subcate.Value, CategoryName + ' ' + subcate.Key)); } else { sb.Append(ListAllCommands(subcate.Value, subcate.Key)); } } } return(sb.ToString()); }
public NullUtilVk(Action <MessageStatus, string> PrintConsole, bool IsGui = false) { //Creating variables _PrintConsole = PrintConsole; this.IsGui = IsGui; _StartupDate = DateTime.Now; AuthCreds = new AuthInstance(); //Setting up enviroment for logging LogWriterToDo = new List <string>(); if (!Directory.Exists(Environment.CurrentDirectory + Constants.LogDirSuffix)) { Directory.CreateDirectory(Environment.CurrentDirectory + Constants.LogDirSuffix); } File.Create(Environment.CurrentDirectory + Constants.LogDirSuffix + "\\" + _StartupDate.ToString(Constants.LogFileName) + ".log").Dispose(); //_logger = new RestartableThread(new ThreadStart(LogWriterRun)); //_logger.IsBackground = true; //_logger.Name = "Log Writer Thread"; //_logger.Priority = ThreadPriority.Lowest; _logger = new Thread(new ThreadStart(LogWriterRun)); _logger.IsBackground = true; _logger.Name = "Log Writer Thread"; _logger.Start(); Log(MessageStatus.Info, "Initializing NullUtilVk API"); Log(MessageStatus.Info, "Initialing Vk API"); _VkApi = new VkApi(); Log(MessageStatus.Info, "Initialing Vk API succesed"); //Creating config file if needed Log(MessageStatus.Info, "Creating default config if needed"); Config.Create(ConfigDefault.GetPossibleValues(), ConfigDefault.GetSubCategories()); Log(MessageStatus.Info, "Creating default config succesed"); DB.Create(); //Initializing console commands Log(MessageStatus.Info, "Registering console commands"); _Commands = new ConsoleCommands(); RegisterConsoleCommands(ref _Commands); //_Commands = RegisterConsoleCommands(); Log(MessageStatus.Info, "Registered " + _Commands.GetCommands().Count.ToString() + " commands successfuly"); Log(MessageStatus.Info, "Creating lang file"); //Creating sample lang file Config.CreateDefaultLangFile(); Log(MessageStatus.Info, "Initialized NullUtilVk API"); }
private void CommandDigger(ConsoleCommands Commands, string CommandAndArgs) { string[] splitted = CommandAndArgs.Split(' '); string command = splitted[0]; string args = string.Empty; if (splitted.Length > 1) { for (int i = 1; i < splitted.Length; i++) { args += splitted[i]; args += ' '; } args = args.Remove(args.Length - 1); } if (Commands.GetSubCategories() != null && Commands.GetSubCategories().ContainsKey(command)) { CommandDigger(Commands.GetSubCategories()[command], args); return; } var targetCommand = Commands.GetCommands().Find(c => c.Alias == command); if (targetCommand != null) { if (targetCommand.NeedAuth && !IsAuthorize) { Log(MessageStatus.Error, LogStrings.Error.General.AuthRequired); return; } else { targetCommand.Logic(args); return; } } Log(MessageStatus.Error, LogStrings.Error.General.UnknownCommand + command); }