예제 #1
0
        public object GetValue(ConfigDefault Item)
        {
            var targJson = Configs;

            if (Item.SubCategory != null)
            {
                targJson = (JObject)targJson.Property(Item.SubCategory).Value;
            }
            if (Item.Key != ConfigDefault.LangFilePath.Key && Item.Key != ConfigDefault.AuthList.Key)
            {
                if (!typeof(System.Collections.IEnumerable).IsAssignableFrom(Item.ValueType) || Item.ValueType == typeof(string))
                {
                    Log(MessageStatus.Info, String.Format(LogStrings.Info.General.GetConfigValue, Item.Key, targJson.Property(Item.Key).Value.ToObject(Item.ValueType)));
                }
                else
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var item in targJson.Property(Item.Key).Value.ToObject(Item.ValueType) as System.Collections.IEnumerable)
                    {
                        sb.Append(Environment.NewLine);
                        sb.Append(item.ToString());
                    }
                    Log(MessageStatus.Info, String.Format(LogStrings.Info.General.GetConfigValue, Item.Key, sb.ToString()));
                }
            }
            return(targJson.Property(Item.Key).Value.ToObject(Item.ValueType));
        }
예제 #2
0
        void AddNewConfig(ConfigDefault Config, object Value)
        {
            var item = NewConfig.FirstOrDefault(c => c.Key.Key == Config.Key);

            if (item.Value != null)
            {
                NewConfig.Remove(item);
            }
            NewConfig.Add(new KeyValuePair <ConfigDefault, object>(Config, Convert.ChangeType(Value, Config.ValueType)));
            this.ApplyBtn.Enabled = true;
        }
예제 #3
0
 public void SetValue(ConfigDefault Item, object Value)
 {
     Log(MessageStatus.Info, string.Format(LogStrings.Info.General.SetConfigValue, Item.Key, Value));
     if (Item.SubCategory != null)
     {
         (Configs.Property(Item.SubCategory).Value as JObject).Property(Item.Key).Value = JToken.FromObject(Value);
     }
     else
     {
         Configs.Property(Item.Key).Value = JToken.FromObject(Value);
     }
 }
예제 #4
0
        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");
        }
예제 #5
0
        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);
            }
        }