예제 #1
0
        public static void SaveConfig(IConfigFile config)
        {
            ConfigNameAttribute attr = (ConfigNameAttribute)config.GetType().GetCustomAttributes(typeof(ConfigNameAttribute), false).FirstOrDefault();
            string cfgName           = attr == null?config.GetType().Name : attr.name;

            File.WriteAllText(GetPath(cfgName), JsonUtility.ToJson(config));
        }
예제 #2
0
        public static IConfigFile GetConfig(string name = null)
        {
            XFrmWorkAttribute first = PluginProvider.GetFirstPlugin(typeof(IConfigFile), name);

            if (first == null)
            {
                return(null);
            }
            IConfigFile instance = null;

            if (configFiles.TryGetValue(first.Name, out instance))
            {
                return(instance);
            }


            try
            {
                instance = PluginProvider.GetObjectInstance <IConfigFile>(first.Name);

                instance.ReadConfig(instance.SavePath);
            }
            catch (Exception ex)
            {
                if (instance == null)
                {
                    throw new Exception("不包含任何有关配置文件的任何信息,请检查");
                }
                instance.RebuildConfig();
                instance.SaveConfig();
            }
            configFiles.Add(first.Name, instance);
            return(instance);
        }
예제 #3
0
        public static T GetConfig <T>(string name = null) where T : class, IConfigFile
        {
            if (name == null)
            {
                name = AttributeHelper.GetCustomAttribute(typeof(T)).Name;
            }
            IConfigFile instance = null;

            if (configFiles.TryGetValue(name, out instance))
            {
                return(instance as T);
            }

            instance = PluginProvider.GetObjectInstance <IConfigFile>(name) ??
                       PluginProvider.GetObjectInstance(typeof(T)) as IConfigFile;
            try
            {
                instance.ReadConfig(instance.SavePath);
            }
            catch (Exception ex)
            {
                instance.RebuildConfig();
                instance.SaveConfig();
            }
            configFiles.Add(name, instance);
            return(instance as T);
        }
예제 #4
0
        public WorldController(IWorldView view, IControllerFactory controllerFactory, IMessageBus messageBus, IConfigFile <Config> configFile, IFileSystem fileSystem)
            : base(view)
        {
            messageBus.ThrowIfNull(nameof(messageBus));

            _controllerFactory = controllerFactory.EnsureNotNull(nameof(controllerFactory));
            _configFile        = configFile.EnsureNotNull(nameof(configFile));
            _fileSystem        = fileSystem.EnsureNotNull(nameof(fileSystem));

            AddDisposables(
                messageBus.GetObservable <WorldChangedMessage>().Subscribe(ReceiveMessage),
                View.FileCloseWorldRequested.Subscribe(x => CloseWorld()),
                View.FileExitRequested.Subscribe(x => Exit()),
                View.FileNewWorldRequested.Subscribe(x => NewWorld()),
                View.FileOpenWorldRequested.Subscribe(x => OpenWorld()),
                View.FileSaveWorldAsRequested.Subscribe(x => SaveWorldAs()),
                View.FileSaveWorldRequested.Subscribe(x => SaveWorld()),
                View.HelpAboutRequested.Subscribe(x => About()),
                View.ToolsOptionsRequested.Subscribe(x => Options()),
                View.ViewClosing.Subscribe(x => x.Cancel = !ViewClosing(x.CloseReason == CloseReason.UserClosing)),
                View.WorldVariablesRequested.Subscribe(x => Variables()));

            View.RestoreBounds(_configFile.Config.Views.World.Bounds);
            View.SetTitle(ViewTitle);
            View.HideWorldToolStrips();
            View.DisableCloseWorldToolStripItems();
            View.DisableSaveWorldToolStripItems();
            View.DisableSaveWorldAsToolStripItems();
        }
예제 #5
0
 public string Create(IConfigFile configFile, string extension)
 {
     Precondition.ArgumentNotNull(configFile, nameof(configFile));
     return(string.IsNullOrWhiteSpace(extension)
         ? configFile.Metadata.Key
         : $"{configFile.Metadata.Key}.{extension}");
 }
예제 #6
0
        public static async Task <bool> LoadConfigAsync <T>(IConfigFile file, T value) where T : class
        {
            var config = Config.Create(file.ConfigType);

            try
            {
                var content = await file.ReadAllTextAsync();

                if (!string.IsNullOrEmpty(content))
                {
                    if (value == null)
                    {
                        value = config.Deserialize <T>(content);
                    }
                    else
                    {
                        config.PopulateObject(content, value);
                        await file.WriteAllTextAsync(config.Serialize(value));
                    }
                }
                else
                {
                    await file.WriteAllTextAsync(config.Serialize(value));
                }
            }
            catch (ConfigDeserializingException)
            {
                await file.WriteAllTextAsync(config.Serialize(value));

                return(false);
            }
            catch (ConfigSerializingException) { return(false); }

            return(true);
        }
예제 #7
0
        private static IEnumerable <Server> GetServerList(IConfigFile file)
        {
            var result  = new List <Server>();
            var servers = file.Namespaces.Where(x => x.Name.ToLower().StartsWith("server-"));

            foreach (var s in servers)
            {
                try
                {
                    result.Add(new Server()
                    {
                        Host     = s.Properties.FirstOrDefault(x => x.Name.ToLower().Equals("host")).Value,
                        Password = s.Properties.FirstOrDefault(x => x.Name.ToLower().Equals("password")).Value,
                        Port     = Convert.ToInt32(s.Properties.FirstOrDefault(x => x.Name.ToLower().Equals("port")).Value)
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Something went wrong parsing server");
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }

            return(result);
        }
예제 #8
0
        private int RollTeamFiller()
        {
            IConfigFile config = ConfigManager.Manager.Config;
            int         teamID = config.GetIntValue("filler_team_id", (int)Smod2.API.Team.CLASSD);

            return(teamID);
        }
예제 #9
0
        private Smod2.API.Team RollTeam()
        {
            IConfigFile config       = ConfigManager.Manager.Config;
            List <int>  respawnQueue = this.plugin.GetRespawnQueue();
            int         teamID;

            bool isUsingSmartPicker = config.GetBoolValue("smart_class_picker", false);

            if (isUsingSmartPicker)
            {
                // Smart picker is enabled
                // Using fake smart picker
                teamID = this.RollTeamSmart();
                return((Smod2.API.Team)teamID);
            }

            if (this.teamsSpawned.Count >= respawnQueue.Count)
            {
                // Overflow
                // Using filler picker
                teamID = this.RollTeamFiller();
                return((Smod2.API.Team)teamID);
            }

            // Picking next team from queue
            teamID = respawnQueue[this.teamsSpawned.Count];
            return((Smod2.API.Team)teamID);
        }
예제 #10
0
        /// <summary>
        /// Creates a new DatabaseLint object and sets up the configuration according to the specified configuration file
        /// </summary>
        public DatabaseLint(String configurationFile) : this()
        {
            this.ConfigFile = new XMLConfigFile(configurationFile);

            this.Config.Connection = ConfigFile.GetConnection();

            //Get SQL rules from config file and add to allExecutables
            var SQLRules = ConfigFile.GetSQLRules();

            this.AllExecutables.AddExecutables(SQLRules);

            //Select rules from executables
            this.Config.AllRules = this.AllExecutables.GetRules().Select(e => (IRule)e);

            //Load property values from config rule
            foreach (var r in Config.AllRules)
            {
                ConfigFile.ConfigureRule(r);
            }

            //Filter out rules which should not be run
            this.Config.RulesToRun = this.Config.AllRules.Where(r => ConfigFile.RunRule(r));

            //Tables to run
            this.Config.TablesToCheck = ConfigFile.GetTablesToCheck();
        }
예제 #11
0
 public bool Save(IConfigFile cf)
 {
     try
     {
         IniConfigFile conf = (IniConfigFile)cf;
         using (StreamWriter sw = new StreamWriter(conf.Name))
         {
             for (int i = 0; i < conf.Sections.Count; i++)
             {
                 if (!string.IsNullOrEmpty(conf.Sections[i].Name))
                 {
                     string sectionLine = string.Format("[{0}]", conf.Sections[i].Name);
                     sw.WriteLine(sectionLine);
                 }
                 for (int j = 0; j < conf.Sections[i].KeyValuePairs.Count; j++)
                 {
                     string keyValueLine = string.Format("{0}={1}", conf.Sections[i].KeyValuePairs[j].Key, conf.Sections[i].KeyValuePairs[j].Value);
                     sw.WriteLine(keyValueLine);
                 }
                 sw.WriteLine();
             }
             sw.Flush();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
예제 #12
0
        public void TestInitialize()
        {
            _config = new ConfigFile<Scripts>(_scriptsConfig);
            
            _store = new ScriptStore(_config);

            _scripts = _config.Load();
        }
 public void Test_LoadFile()
 {
     _configFile = _configManager.Load(@"test_files\AccuracyTest.ini");
     Assert.AreEqual(_configFile.Namespaces.Count, 2);
     Assert.AreEqual(_configFile.Namespaces[0].Name, "AccuracyNamespace1");
     Assert.AreEqual(_configFile.Namespaces[1].Name, "AccuracyNamespace2");
     _configManager.RemoveFile(@"test_files\AccuracyTest.ini");
 }
예제 #14
0
        public static async Task <bool> SaveConfigAsync <T>(IConfigFile file, T defaultValue = default(T)) where T : class
        {
            var config = Config.Create(file.ConfigType);

            try { await file.WriteAllTextAsync(config.Serialize(defaultValue)); }
            catch (ConfigSerializingException) { return(false); }

            return(true);
        }
예제 #15
0
        public WorldVariableController(IWorldVariableView view, IConfigFile <Config> configFile)
            : base(view)
        {
            _configFile = configFile.EnsureNotNull(nameof(configFile));

            AddDisposables(View.ViewClosing.Subscribe(x => ViewClosing()));

            View.RestoreBounds(_configFile.Config.Views.WorldVariable.Bounds);
        }
예제 #16
0
파일: Program.cs 프로젝트: rocketblast/rnet
        private static void PrintConfig(IConfigFile file)
        {
            var iniNamespace = file.Namespaces.FirstOrDefault(x => x.Name.ToLower().Equals("node"));

            foreach (var prop in iniNamespace.Properties)
            {
                var values = String.Join(", ", prop.Values);
                Console.WriteLine("{0} = {1}", prop.Name, values);
            }
        }
예제 #17
0
        public ScriptRunnerFactory(IConfigFile <Runners> config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            _config = config;

            Initialize();
        }
        private void PopulateRespawnQueue()
        {
            IConfigFile config  = ConfigManager.Manager.Config;
            string      teamIDs = config.GetStringValue("team_respawn_queue", "4014314031441404134040143");

            foreach (char teamID in teamIDs)
            {
                this.respawnQueue.Add((int)Char.GetNumericValue(teamID));
            }
        }
        public void Test_GetNamespace()
        {
            _configFile = _configManager.Load(@"test_files\AccuracyTest.ini");

            Assert.AreEqual(_configManager.GetNamespace("AccuracyNamespace1").Name, "AccuracyNamespace1");
            Assert.AreEqual(_configManager.GetNamespace("AccuracyNamespace1").Properties.Length, 3);
            Assert.AreEqual(_configManager.GetNamespace("AccuracyNamespace2").Name, "AccuracyNamespace2");
            Assert.AreEqual(_configManager.GetNamespace("AccuracyNamespace2").Properties.Length, 3);

            _configManager.RemoveFile(@"test_files\AccuracyTest.ini");
        }
예제 #20
0
        public ScriptStore(IConfigFile <Scripts> config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            _config = config;

            Initialize();
        }
        public void Test_Values()
        {
            _configFile = _configManager.Load(@"test_files\AccuracyTest.ini");

            Assert.AreEqual(_configManager.GetValues("AccuracyNamespace1", "AccuracyProp1").Count, 1);
            Assert.AreEqual(_configManager.GetValues("AccuracyNamespace1", "AccuracyProp2").Count, 2);
            Assert.AreEqual(_configManager.GetValues("AccuracyNamespace1", "AccuracyProp3").Count, 3);
            Assert.AreEqual(_configManager.GetValues("AccuracyNamespace2", "AccuracyProp1").Count, 3);
            Assert.AreEqual(_configManager.GetValues("AccuracyNamespace2", "AccuracyProp2").Count, 2);
            Assert.AreEqual(_configManager.GetValues("AccuracyNamespace2", "AccuracyProp3").Count, 1);

            _configManager.RemoveFile(@"test_files\AccuracyTest.ini");
        }
        public void Test_GetProperty()
        {
            _configFile = _configManager.Load(@"test_files\AccuracyTest.ini");

            Assert.AreEqual(_configManager.GetProperty("AccuracyNamespace1", "AccuracyProp1").Value, "AccuracyValue1");
            Assert.AreEqual(_configManager.GetProperty("AccuracyNamespace1", "AccuracyProp2").Value, "AccuracyValue2");
            Assert.AreEqual(_configManager.GetProperty("AccuracyNamespace1", "AccuracyProp3").Value, "AccuracyValue3");
            Assert.AreEqual(_configManager.GetProperty("AccuracyNamespace2", "AccuracyProp1").Value, "AccuracyValue3");
            Assert.AreEqual(_configManager.GetProperty("AccuracyNamespace2", "AccuracyProp2").Value, "AccuracyValue2");
            Assert.AreEqual(_configManager.GetProperty("AccuracyNamespace2", "AccuracyProp3").Value, "AccuracyValue1");

            _configManager.RemoveFile(@"test_files\AccuracyTest.ini");
        }
예제 #23
0
파일: Program.cs 프로젝트: rocketblast/rnet
        private static String GetProperty(IConfigFile file, String section, String property)
        {
            var iniNamespace = file.Namespaces.FirstOrDefault(x => x.Name.ToLower().Equals(section));
            var prop         = iniNamespace.Properties.FirstOrDefault(x => x.Name.ToLower().Equals(property));

            if (prop != null)
            {
                return(String.Join(", ", prop.Values));
            }
            else
            {
                return(String.Empty);
            }
        }
예제 #24
0
        public WorldVariablesController(IWorldVariablesView view, IControllerFactory controllerFactory, IMessageBus messageBus, IConfigFile <Config> configFile)
            : base(view)
        {
            _controllerFactory = controllerFactory.EnsureNotNull(nameof(controllerFactory));
            _messageBus        = messageBus.EnsureNotNull(nameof(messageBus));
            _configFile        = configFile.EnsureNotNull(nameof(configFile));

            AddDisposables(
                View.NewRequested.Subscribe(x => NewRequested()),
                View.EditRequested.Subscribe(EditRequested),
                View.DeleteRequested.Subscribe(DeleteRequested));

            View.RestoreBounds(configFile.Config.Views.WorldVariables.Bounds, false);
            View.RestoreVariablesListColumnWidths(configFile.Config.Views.WorldVariables.ColumnWidths);
        }
        public NewWorldController(INewWorldView view, IConfigFile <Config> configFile, IGuidFactory guidFactory, ISystemClock systemClock)
            : base(view)
        {
            _configFile  = configFile.EnsureNotNull(nameof(configFile));
            _guidFactory = guidFactory.EnsureNotNull(nameof(guidFactory));
            _systemClock = systemClock.EnsureNotNull(nameof(systemClock));
            _viewModel   = new NewWorldViewModel
            {
                Author   = _configFile.Config.Views.NewWorld.DefaultAuthor,
                IdAsGuid = _guidFactory.Random(),
                Version  = "1.0"
            };

            AddDisposables(View.IdGenerationRequested.Subscribe(x => _viewModel.IdAsGuid = _guidFactory.Random()));
        }
예제 #26
0
 public DatabaseLint()
 {
     //Load all executables
     this.AllExecutables = RuleLoader.LoadRules();
     //Save standard config if none exist
     if (DBLint.Settings.IsNormalContext)
     {
         /*
          * if (!File.Exists(Settings.CONFIG_FILE))
          *  PropertyUtils.SaveProperties(this.AllExecutables.GetExecutables(), Settings.CONFIG_FILE);
          * PropertyUtils.LoadProperties(this.AllExecutables.GetExecutables(), Settings.CONFIG_FILE);
          */
     }
     this.RuleController = new RuleController();
     this.IssueCollector = new IssueCollector();
     this.Config         = new Configuration();
     this.ConfigFile     = new XMLConfigFile(Settings.XMLCONFIG);
 }
예제 #27
0
 public override IConfigFile GetConfigFile(string runtimePath, string fileName)
 {
     if (_ConfigFile == null)
     {
         fileName = fileName.Replace("-_-", ".");
         IConfigFile dirFile = new ConfigDirFile(runtimePath, fileName);
         if (dirFile.Exists)
         {
             _ConfigFile=dirFile;
         }
         IConfigFile runDirFile = new ConfigRunDirFile(runtimePath, fileName);
         if (runDirFile.Exists)
         {
             _ConfigFile = runDirFile;
         }
     }
     return _ConfigFile;
 }
예제 #28
0
파일: Run.cs 프로젝트: aquilax1/DBLint
        //Constructor, create run from config file
        public Run(IConfigFile config)
        {
            this.ConfigFile = config;

            //Load all executables
            this.Executables = RuleLoader.LoadRules();

            if (this.ConfigFile.IsValid())
            {
                //Configure executables
                this.configureRulesFromConfig();

                //Extract connection from config
                this.Connection = config.GetConnection();

                //Set RulesToRun from the config file and configure
                this.setRulesToRunFromConfig();
            }
        }
예제 #29
0
        public ConfigurationViewModel(IConfigurationProvider configurationProvider, IWindowManager windowManager, IConfigFile configFile, IConfigurationTester configurationTester, IProcessorConfigurationValidator validator)
        {
            _configurationProvider = configurationProvider;
            _windowManager         = windowManager;
            _configFile            = configFile;
            _configurationTester   = configurationTester;
            SelectFile             = new RelayCommand(
                p => true,
                p => { LocalDirectory = _windowManager.ShowDirectoryDialog(); });

            Save = new RelayCommand(
                p => true,
                p => { SaveConfiguration(); });

            Test = new RelayCommand(
                p => true,
                p => { CheckIfConfigurationIsValid(true); });
            _validator = validator;
        }
예제 #30
0
        private static void LoadConfig(Type t)
        {
            ConfigNameAttribute attr = (ConfigNameAttribute)t.GetCustomAttributes(typeof(ConfigNameAttribute), false).FirstOrDefault();
            string cfgName           = attr == null ? t.Name : attr.name;

            string path = GetPath(cfgName);

            if (Directory.Exists(ConfigFolder) && File.Exists(path))
            {
                configFiles.Add(cfgName, (IConfigFile)JsonUtility.FromJson(File.ReadAllText(path), t));
            }
            else
            {
                IConfigFile cfg = (IConfigFile)Activator.CreateInstance(t);
                configFiles.Add(cfgName, cfg);

                Directory.CreateDirectory(ConfigFolder);
                File.WriteAllText(path, JsonUtility.ToJson(cfg));// save default
            }
        }
        public void OnSetRole(PlayerSetRoleEvent ev)
        {
            if (this.rolesWithoutInventory.Contains(ev.Role))
            {
                return;
            }

            IConfigFile config = ConfigManager.Manager.Config;
            string      shard  = DIEventHandler.ConvertRoleIDToString(ev.Role);

            int[] items = config.GetIntListValue("default_item_" + shard, true);

            foreach (Item item in ev.Player.GetInventory())
            {
                item.Remove();
            }

            Timer operate = new Timer {
                Interval  = 50,
                AutoReset = false,
                Enabled   = true
            };

            operate.Elapsed += delegate {
                foreach (Item item in ev.Player.GetInventory())
                {
                    item.Remove();
                }

                foreach (int item in items)
                {
                    if (item == -1)
                    {
                        continue;
                    }

                    ev.Player.GiveItem((ItemType)item);
                }
            };
        }
예제 #32
0
        internal static IConfigFile ReadConfigFile(this RemoteFileAccess remoteFileAccess,
                                                   IMetaService m_metaService,
                                                   string configFileName)
        {
            IConfigFile configFile = null;
            uint        handle     = 0U;
            string      path       = configFileName;

            remoteFileAccess.OpenFile(path, RemoteFileAccess.FileAccessMode.ReadAccess, ref handle);
            Siemens.Automation.OMSPlus.Managed.FileInfo info = new Siemens.Automation.OMSPlus.Managed.FileInfo();
            remoteFileAccess.GetFileInfo(configFileName, ref info);
            uint bytes_to_read = (uint)info.size;

            byte[] buffer = new byte[(int)bytes_to_read];
            uint   read   = 0U;

            remoteFileAccess.ReadFile(handle, ref buffer, bytes_to_read, RemoteFileAccess.CurrentPosition, ref read);
            byte[] bytes = new byte[(int)read];
            for (uint index = 0U; index < read; ++index)
            {
                bytes[(int)index] = buffer[(int)index];
            }
            string @string = new UTF8Encoding().GetString(bytes);

            remoteFileAccess.CloseFile(handle);
            XDocument innerDocument = m_metaService.ParseConfigFile(@string);

            if (innerDocument != null)
            {
                string fileName = Path.GetFileName(configFileName);
                ConfigFileParameters configFileParameters = GetConfigFileParameters(innerDocument, fileName);
                if (configFileParameters != null)
                {
                    configFile = new ConfigFile(configFileParameters);
                }
            }
            return(configFile);
        }
        private void PopulateEnabledSCPs()
        {
            string[] prefixes =
            {
                "scp049",
                "scp079",
                "scp096",
                "scp106",
                "scp173",
                "scp939_53",
                "scp939_89"
            };
            IConfigFile config = ConfigManager.Manager.Config;

            foreach (string prefix in prefixes)
            {
                bool isDisabled = config.GetBoolValue(prefix + "_disable", false);
                if (isDisabled)
                {
                    continue;
                }

                Role role = LaterJoin.ConvertSCPPrefixToRoleID(prefix);
                if (role == Role.UNASSIGNED)
                {
                    this.Error("Trying to convert unknown prefix: " + prefix);
                    continue;
                }

                int amount = config.GetIntValue(prefix + "_amount", 1);
                while (amount > 0)
                {
                    this.enabledSCPs.Add(role);
                    amount--;
                }
            }
        }
예제 #34
0
 public static void Init(Type type, IConfigFile config)
 {
     LocalizableAttribute.Init(type, config);
     ConfigurableAttribute.Init(type, config);
 }
        public void Test_GetConfigFiles()
        {
            var len = _configManager.ConfigFiles.Length;
            _configFile = _configManager.Load(@"test_files\AccuracyTest.ini");
            Assert.AreEqual(_configManager.ConfigFiles.Length - len, 1);
            _configFile = _configManager.Load(@"test_files\AccuracyTest.xml");
            Assert.AreEqual(_configManager.ConfigFiles.Length - len, 2);

            _configManager.RemoveFile(@"test_files\AccuracyTest.ini");
            _configManager.RemoveFile(@"test_files\AccuracyTest.xml");
        }
        public void Test_GetConfigFile()
        {
            _configFile = _configManager.Load(@"test_files\AccuracyTest.ini");
            _configFile = _configManager.Load(@"test_files\AccuracyTest.xml");

            Assert.AreEqual(_configManager.GetConfigFile(@"test_files\AccuracyTest.ini").Namespaces.Count, 2);
            Assert.AreEqual(_configManager.GetConfigFile(@"test_files\AccuracyTest.xml").Namespaces.Count, 2);

            _configManager.RemoveFile(@"test_files\AccuracyTest.ini");
            _configManager.RemoveFile(@"test_files\AccuracyTest.xml");
        }
        public void CheckIfDisabled()
        {
            IConfigFile config = ConfigManager.Manager.Config;

            this.isDisabled = config.GetBoolValue("sf_lj_disable", false);
        }