Ejemplo n.º 1
0
        private static IDatasetMatchCriterion TryCreate(
            [NotNull] NamedValuesExpression expression,
            [NotNull] NotificationCollection notifications)
        {
            Assert.ArgumentNotNull(expression, nameof(expression));
            Assert.ArgumentNotNull(notifications, nameof(notifications));

            var simpleExpression = expression as SimpleNamedValuesExpression;

            if (simpleExpression != null)
            {
                return(TryCreate(simpleExpression.NamedValues, notifications));
            }

            var conjunction = expression as NamedValuesConjunctionExpression;

            if (conjunction != null)
            {
                return(TryCreate(conjunction, notifications));
            }

            throw new ArgumentException(
                      string.Format("Unsupported expression type: {0}", expression),
                      nameof(expression));
        }
Ejemplo n.º 2
0
        private bool TryCreateExpression(
            [NotNull] string line,
            [NotNull] NotificationCollection notifications,
            [CanBeNull] out NamedValuesExpression expression)
        {
            if (line.IndexOf(_conjunctionSeparator, StringComparison.Ordinal) < 0)
            {
                NamedValues namedValues;
                if (TryCreateNamedValues(line, notifications, out namedValues))
                {
                    expression = new SimpleNamedValuesExpression(namedValues);
                    return(true);
                }

                expression = null;
                return(false);
            }

            string[] parts = line.Split(new[] { _conjunctionSeparator }, StringSplitOptions.None);

            if (parts.Length < 2)
            {
                NotificationUtils.Add(notifications,
                                      "Invalid position of '{0}' on line '{1}'",
                                      _conjunctionSeparator, line);
                expression = null;
                return(false);
            }

            var conjunction = new NamedValuesConjunctionExpression();

            var anyFailure = false;

            foreach (string part in parts)
            {
                NamedValues namedValues;
                if (TryCreateNamedValues(part, notifications, out namedValues))
                {
                    conjunction.Add(namedValues);
                }
                else
                {
                    anyFailure = true;
                }
            }

            if (anyFailure)
            {
                expression = null;
                return(false);
            }

            expression = conjunction;
            return(true);
        }