Beispiel #1
0
        private bool EvalAsAtom(CSVRow row)
        {
            switch (castAs)
            {
            default:
                switch (aRelation)
                {
                case '=':
                    return(row.GetEntry(fieldName).Equals(fieldValue));

                case '<':
                    return(row.GetEntry(fieldName).CompareTo(fieldValue) < 0);

                case '>':
                    return(row.GetEntry(fieldName).CompareTo(fieldValue) > 0);

                case '#':
                    return(row.GetEntry(fieldName).StartsWith(fieldValue));

                default:
                    return(false);
                }

            case 'd':
                DateTime d1, d2;
                if (!DateTime.TryParse(GetFinalDateIfEmpty(row.GetEntry(fieldName)), out d1))
                {
                    throw new Exception(string.Format(
                                            "Unable to parse {0} as date!",
                                            row.GetEntry(fieldName)));
                }
                if (!DateTime.TryParse(GetFinalDateIfEmpty(fieldValue), out d2))
                {
                    throw new Exception(string.Format(
                                            "Unable to parse {0} as date!",
                                            fieldValue));
                }
                switch (aRelation)
                {
                case '=':
                    return(d1 == d2);

                case '<':
                    return(d1 < d2);

                case '>':
                    return(d1 > d2);

                default:
                    return(false);
                }
            }
        }
Beispiel #2
0
        public void Act(CSVRow row, Dictionary <string, string> vars)
        {
            switch (type)
            {
            case ExpressionType.Print :
                Console.WriteLine(row);
                break;

            case ExpressionType.Set:
                if (fieldValue.Length > 0 &&
                    fieldValue[0] == '$' &&
                    vars.ContainsKey(fieldValue.Substring(1)))
                {
                    row.SetEntry(fieldName, vars[fieldValue.Substring(1)]);
                }
                else
                {
                    row.SetEntry(fieldName, fieldValue);
                }
                break;

            case ExpressionType.Let:
                if (!vars.ContainsKey(fieldName))
                {
                    vars.Add(fieldName, "");
                }
                if (row.Contains(fieldValue))
                {
                    vars[fieldName] = row.GetEntry(fieldValue);
                }
                else
                {
                    vars[fieldName] = fieldValue;
                }
                break;
            }
            if (next != null)
            {
                next.Act(row, vars);
            }
        }