示例#1
0
        public IEnumerable <Area> LoadConfiguration()
        {
            var configPath = Path.Combine(_parameter.ConfigurationDirectory.FullName, CONFIG_FILENAME);

            if (File.Exists(configPath))
            {
                configuration configuration = null;

                try
                {
                    _logger.Info("Loading configuration from path '{0}'", configPath);
                    configuration = _xmlToObject.ReadXml <configuration>(configPath);
                }
                catch (Exception excpetion)
                {
                    _logger.Error(excpetion, "Error during parsing configurationfile at [{0}]", configPath);
                }

                if (configuration != null)
                {
                    var areaKeys = new List <string>(configuration.Items.Length);
                    foreach (var area in configuration.Items)
                    {
                        if (areaKeys.Contains(area.name))
                        {
                            _logger.Error("Configuration [{0}] contains more than one area with name [{1}]. Area will be ignored", configPath, area.name);
                            continue;
                        }
                        areaKeys.Add(area.name);
                        var areaElementKeys = new List <string>(area.Items.Length);
                        var areaObject      = new Area()
                        {
                            Name = area.name
                        };
                        foreach (var item in area.Items)
                        {
                            var algorithm = item as algorithm;
                            if (algorithm != null)
                            {
                                if (HandleAlgorithmObject(areaElementKeys, algorithm, configPath, area, areaObject))
                                {
                                    continue;
                                }
                            }

                            var setting = item as setting;
                            if (setting != null)
                            {
                                HandleSettingObject(areaElementKeys, setting, configPath, area, areaObject);
                            }
                        }
                        yield return(areaObject);
                    }
                }
            }
            else
            {
                _logger.Info("No configurationfile found at location [{0}]", configPath);
            }
        }
示例#2
0
        public IEnumerable <FileSorting> LoadConfig()
        {
            Debugger.Launch();
            var configPath = new DirectoryInfo(Path.Combine(_parameter.ConfigurationDirectory.FullName, "FileSorting"));

            if (configPath.Exists)
            {
                foreach (var configFile in configPath.GetFiles("*.xml"))
                {
                    _logger.Info("Loading file sorting configuration from path '{0}'", configFile.FullName);
                    var config = _xmlToObject.ReadXml <FileSortingConfiguration>(configFile.FullName);

                    foreach (var rule in config.Rules)
                    {
                        yield return(CreateSorting(rule, config));
                    }
                }
            }
            else
            {
                _logger.Error("No file sorting configuration with extensio *.xml at path '{0}' found. Please create a configuration", configPath);
            }
        }