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 SetGetConfig(string Arg) { if (Arg == "-list") { StringBuilder sb = new StringBuilder(); foreach (var configItem in ConfigDefault.GetPossibleValues()) { sb.Append(Environment.NewLine); sb.Append(configItem.Key); sb.Append(" - "); sb.Append(configItem.ValueType.Name); sb.Append(" - "); sb.Append(Config.GetValue(configItem)); } Log(MessageStatus.Info, sb.ToString().Remove(0, Environment.NewLine.Length)); return; } var splitted = Arg.Split(' '); var option = splitted[0]; var value = string.Empty; var configName = string.Empty; if (option == "set") { configName = splitted[splitted.Length - 2]; } else if (option == "get") { configName = splitted[splitted.Length - 1]; } else { Log(MessageStatus.Error, LogStrings.Error.General.InvalidArgument + option); return; } if ((option == "set" && splitted.Length < 4) || (option == "get" && splitted.Length < 3)) { Log(MessageStatus.Error, LogStrings.Error.General.InvalidUsage); return; } #warning Refactor this var subCateName = splitted[1]; var config = ConfigDefault.GetPossibleValues().Find(c => c.SubCategory.ToLower() == subCateName && c.Key.ToLower() == configName); if (config != null) { if (option == "set") { value = splitted[splitted.Length - 1]; try { Config.SetValue(config, Convert.ChangeType(value, config.ValueType)); } catch (FormatException) { Log(MessageStatus.Error, LogStrings.Error.General.InvalidArgument + value); return; } Log(MessageStatus.Info, string.Format(LogStrings.Info.General.SetConfigValue, config.Key, value)); return; } else { Log(MessageStatus.Info, string.Format(LogStrings.Info.General.GetConfigValue, config.Key, Config.GetValue(config))); return; } } else { Log(MessageStatus.Error, LogStrings.Error.General.InvalidArgument + subCateName + "/" + configName); } }