Beispiel #1
0
            static void WriteFilterPredicate <T>(string name, FilterPredicate <T>?filterPredicate)
            {
                if (filterPredicate == null)
                {
                    return;
                }

                WriteIndent();
                WriteName(name);
                WriteValue(filterPredicate.Expression.Kind.ToString());
                WriteIndent();
                WriteValue(filterPredicate.Expression.Text);
                WriteLine();
            }
Beispiel #2
0
        private static void WriteFilePropertyFilter(
            string name,
            FilterPredicate <long>?sizePredicate,
            FilterPredicate <DateTime>?creationTimePredicate,
            FilterPredicate <DateTime>?modifiedTimePredicate)
        {
            WriteName(name);

            if (sizePredicate == null &&
                creationTimePredicate == null &&
                modifiedTimePredicate == null)
            {
                WriteNullValue();
                WriteLine();
            }
            else
            {
                WriteLine();
                WriteIndent();
                WriteFilterPredicate("creation time", creationTimePredicate);
                WriteFilterPredicate("modified time", modifiedTimePredicate);
                WriteFilterPredicate("size", sizePredicate);
            }
Beispiel #3
0
        public static bool TryParseFileProperties(
            IEnumerable <string> values,
            string optionName,
            out FilterPredicate <DateTime>?creationTimePredicate,
            out FilterPredicate <DateTime>?modifiedTimePredicate,
            out FilterPredicate <long>?sizePredicate)
        {
            creationTimePredicate = null;
            modifiedTimePredicate = null;
            sizePredicate         = null;

            foreach (string value in values)
            {
                Expression? expression  = null;
                OptionValue?optionValue = null;

                try
                {
                    expression = Expression.Parse(value);

                    if (OptionValues.FileProperty_CreationTime.IsKeyOrShortKey(expression.Identifier))
                    {
                        optionValue = OptionValues.FileProperty_CreationTime;

                        creationTimePredicate = new FilterPredicate <DateTime>(
                            expression,
                            PredicateHelpers.GetDateTimePredicate(expression));
                    }
                    else if (OptionValues.FileProperty_ModifiedTime.IsKeyOrShortKey(expression.Identifier))
                    {
                        optionValue = OptionValues.FileProperty_ModifiedTime;

                        modifiedTimePredicate = new FilterPredicate <DateTime>(
                            expression,
                            PredicateHelpers.GetDateTimePredicate(expression));
                    }
                    else if (OptionValues.FileProperty_Size.IsKeyOrShortKey(expression.Identifier))
                    {
                        optionValue = OptionValues.FileProperty_Size;

                        if (expression.Kind == ExpressionKind.DecrementExpression)
                        {
                            WriteOptionError(value, optionName, HelpProvider.GetExpressionsText("  ", includeDate: false));
                            return(false);
                        }

                        sizePredicate = new FilterPredicate <long>(expression, PredicateHelpers.GetLongPredicate(expression));
                    }
                    else
                    {
                        WriteOptionError(value, optionName, OptionValueProviders.FilePropertiesProvider);
                        return(false);
                    }
                }
                catch (ArgumentException)
                {
                    if (expression != null &&
                        optionValue != null)
                    {
                        WriteOptionValueError(
                            expression.Value,
                            optionValue,
                            HelpProvider.GetExpressionsText(
                                "  ",
                                includeDate: optionValue != OptionValues.FileProperty_Size));
                    }
                    else
                    {
                        WriteOptionError(value, optionName, HelpProvider.GetExpressionsText("  "));
                    }

                    return(false);
                }
            }

            return(true);
        }