Пример #1
0
        public ConfigRule CreateConfigRule(string variableName, string statCalcName, string periodSelectName)
        {
            ConfigRule rule = new ConfigRule(variableName, statCalcName, periodSelectName);

            rule.PeriodSelect = _selectFactory.GetInstance(periodSelectName);
            rule.StatCalc     = _statCalcFactory.GetInstance(statCalcName);
            return(rule);
        }
Пример #2
0
        public ParseReturnCodes ParseLine(string line, ConfigRule rule, int expectedColumnCount, int lineNumber)
        {
            // split the line on tabs
            string[] parsedLine = line.Split('\t');

            if (parsedLine.Length < 3)
            {
                Console.WriteLine("Error in line number: " + lineNumber + " Line must have at least 3 columns");
                return(ParseReturnCodes.ParseError);
            }

            if (expectedColumnCount != parsedLine.Count())
            {
                Console.WriteLine("Error in line number: " + lineNumber + " Line does not have the same number of columns as header");
                return(ParseReturnCodes.ParseError);
            }

            // only process if variable name matches
            string variableName = parsedLine[1];

            if (rule.VariableName.ToLower() != variableName.ToLower()) //make sure case insensitive
            {
                return(ParseReturnCodes.Skipped);
            }

            List <double> lineValues = null;

            // convert the rest of the columns into a double list
            try
            {
                lineValues = parsedLine.Skip(2).Select(s => double.Parse(s)).ToList();
            }
            catch
            {
                Console.WriteLine("Error in line number: " + lineNumber + " Values can't be converted to double number");
                return(ParseReturnCodes.ParseError);
            }

            rule.ValuesToCompute.Add(rule.PeriodSelect.SelectPeriod(lineValues));

            return(ParseReturnCodes.Processed);
        }
Пример #3
0
        protected ConfigRule ParseLine(string line)
        {
            ConfigRule configRule = null;

            string[] parsedLine = line.Split('\t');
            if (parsedLine.Length < 3)
            {
                Console.WriteLine("Line should have 3 fields, line content:" + line);
                return(null);
            }
            try
            {
                configRule = _configRuleFactory.CreateConfigRule(parsedLine[0], parsedLine[1], parsedLine[2]);
            }
            catch (Exception ex)
            {
                // do some logging with exception
                Console.WriteLine("Error in parsing line content: " + line);
                throw;
            }
            return(configRule);
        }
Пример #4
0
        public List <ConfigRule> Read()
        {
            List <ConfigRule> configRules = new List <ConfigRule>();

            try
            {
                foreach (string line in _repository.ReadConfiguration())
                {
                    ConfigRule rule = ParseLine(line);
                    if (rule != null)
                    {
                        configRules.Add(rule);
                    }
                }
            }
            catch (IOException ex)
            {
                // do some logging with exception
                Console.WriteLine("Error in reading " + _repository.ConfigName);
                throw;
            }
            return(configRules);
        }