Ejemplo n.º 1
0
        /// <summary>
        /// Uses the supplied <see cref="IQueryficationContext"/> to build the final query string.
        /// </summary>
        /// <param name="queryficationContext">The supplied <see cref="IQueryficationContext"/>.</param>
        /// <returns>An <see cref="QueryficationResult"/> that contains information about the output.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="queryficationContext"/>' cannot be null. </exception>
        /// <exception cref="PropertyMustBeSpecifiedException">The 'ValueProcessor' property of one of the parameters inside the <see cref="IQueryficationContext"/> is null.</exception>
        public QueryficationResult Queryfy(IQueryficationContext queryficationContext)
        {
            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            var processedValues = new Dictionary <String, String>();

            foreach (var parameter in queryficationContext.Parameters)
            {
                if (parameter.ValueProcessor == null)
                {
                    throw new PropertyMustBeSpecifiedException("ValueProcessor", parameter);
                }

                var value = parameter.Value;
                if (value == null)
                {
                    if (!(parameter.ValueProcessor is NullValueProcessor))
                    {
                        continue;
                    }
                }
                else
                {
                    value = parameter.ValueProcessor.Process(queryficationContext.CreateProcessingContext(value));
                }

                processedValues.Add(parameter.ParameterName, (String)value);
            }

            return(new QueryficationResult(this.configuration, processedValues));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a query from the supplied <see cref="IQueryficationContext"/>.
        /// </summary>
        /// <returns>An <see cref="QueryficationResult"/> instance with information about the result.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="queryficationContext"/>' cannot be null. </exception>
        public QueryficationResult Queryfy(IQueryficationContext queryficationContext)
        {
            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            return(this.queryficationBuilder.Queryfy(queryficationContext));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FluentQueryfy"/> class.
        /// </summary>
        /// <param name="queryfyDotNet">An implementation of the <see cref="IQueryfyDotNet"/> interface.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="queryfyDotNet"/>' cannot be null. </exception>
        public FluentQueryfy([NotNull] IQueryfyDotNet queryfyDotNet)
        {
            if (queryfyDotNet == null)
            {
                throw new ArgumentNullException(nameof(queryfyDotNet));
            }

            this.queryfyDotNet        = queryfyDotNet;
            this.queryficationContext = this.queryfyDotNet.CreateQueryficationContext();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks if the supplied parameter exists. Uses a <see cref="Expression{Func{T, TProperty}}"/> to identify the parameter.
        /// </summary>
        /// <param name="queryficationContext">The <see cref="IQueryficationContext"/>.</param>
        /// <param name="propertySelector">A <see cref="Expression{Func{T, TProperty}}"/> which selects the property.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="queryficationContext"/>' and '<paramref name="propertySelector"/>' cannot be null. </exception>
        public static void Remove <T, TProperty>([NotNull] this IQueryficationContext queryficationContext, [NotNull] Expression <Func <T, TProperty> > propertySelector)
        {
            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            if (propertySelector == null)
            {
                throw new ArgumentNullException(nameof(propertySelector));
            }

            queryficationContext.Remove(propertySelector);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks if the supplied parameter exists. Uses a <see cref="Expression{Func{T, TProperty}}"/> to identify the parameter.
        /// </summary>
        /// <param name="queryficationContext">The <see cref="IQueryficationContext"/>.</param>
        /// <param name="propertySelector">A <see cref="Expression{Func{T, TProperty}}"/> which selects the property.</param>
        /// <returns><c>true</c> if the parameter was found; otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="queryficationContext"/>' and '<paramref name="propertySelector"/>' cannot be null. </exception>
        public static Boolean Exists <T, TProperty>([NotNull]  this IQueryficationContext queryficationContext, [NotNull] Expression <Func <T, TProperty> > propertySelector)
        {
            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            if (propertySelector == null)
            {
                throw new ArgumentNullException(nameof(propertySelector));
            }

            return(queryficationContext.Exists(propertySelector));
        }
Ejemplo n.º 6
0
        public static QueryficationResult Queryfy([NotNull] Object source, [NotNull] IQueryficationContext queryficationContext)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            return(Default.Queryfy(source, queryficationContext));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Fills the <see cref="IQueryficationContext"/> with the properties from the supplied <see cref="object"/>.
        /// </summary>
        /// <param name="source">The <see cref="object"/> that gets analyzed.</param>
        /// <param name="queryficationContext">The <see cref="IQueryficationContext"/>.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="source"/>' and '<paramref name="queryficationContext"/>' cannot be null. </exception>
        public void Fill(Object source, IQueryficationContext queryficationContext)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var instanceType = source.GetType();

            var propertyReflector = this.propertyReflectorSelector.GetPropertyReflector(instanceType);
            var sourceProperties  = this.FilterNecessaryProperties(instanceType, propertyReflector.ReflectProperties(source));

            this.FillCore(source, sourceProperties, queryficationContext);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FluentQueryParameter"/> class.
        /// </summary>
        /// <param name="queryficationContext">An implementation of the <see cref="IQueryficationContext"/> interface.</param>
        /// <param name="fluentQueryfy">An implementation of the <see cref="IFluentQueryfy"/> interface.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="queryficationContext"/>' and '<paramref name="fluentQueryfy"/>' cannot be null. </exception>
        public FluentQueryParameter([NotNull] IQueryficationContext queryficationContext, [NotNull] IFluentQueryfy fluentQueryfy)
        {
            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            if (fluentQueryfy == null)
            {
                throw new ArgumentNullException(nameof(fluentQueryfy));
            }

            this.queryficationContext = queryficationContext;
            this.fluentQueryfy        = fluentQueryfy;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a query fromt he supplied source <see cref="Object"/> and <see cref="IQueryficationContext"/>.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="queryficationContext">The <see cref="IQueryficationContext"/>.</param>
        /// <returns>An <see cref="QueryficationResult"/> instance with information about the result.</returns>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="source"/>' and '<paramref name="queryficationContext"/>' cannot be null. </exception>
        public QueryficationResult Queryfy(Object source, IQueryficationContext queryficationContext)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            queryficationContext.Import(source);
            return(this.Queryfy(queryficationContext));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Adds a new <see cref="QueryParameter"/>.
        /// </summary>
        /// <param name="queryficationContext">The <see cref="IQueryficationContext"/>.</param>
        /// <param name="source">The source object.</param>
        /// <param name="propertySelector">A <see cref="Expression{Func{T, TProperty}}"/> which selects the property.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="queryficationContext"/>', '<paramref name="source"/>' and '<paramref name="propertySelector"/>' cannot be null. </exception>
        public static void AddParameter <T, TProperty>([NotNull] this IQueryficationContext queryficationContext, [NotNull] T source, [NotNull] Expression <Func <T, TProperty> > propertySelector)
        {
            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (propertySelector == null)
            {
                throw new ArgumentNullException(nameof(propertySelector));
            }

            queryficationContext.AddParameter(source, propertySelector);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Fills the <see cref="IQueryficationContext"/> with the properties from the supplied <see cref="Object"/>.
        /// </summary>
        /// <param name="source">The <see cref="Object"/> that gets analyzed.</param>
        /// <param name="properties">An <see cref="IEnumerable{PropertyInfo}"/> of properties from the source type.</param>
        /// <param name="queryficationContext">The <see cref="IQueryficationContext"/>.</param>
        /// <exception cref="ArgumentNullException">The value of '<paramref name="source"/>', '<paramref name="properties"/>' and '<paramref name="queryficationContext"/>' cannot be null. </exception>
        private void FillCore([NotNull] Object source, [NotNull] IEnumerable <PropertyInfo> properties, [NotNull] IQueryficationContext queryficationContext)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (queryficationContext == null)
            {
                throw new ArgumentNullException(nameof(queryficationContext));
            }

            foreach (var propertyMetadata in properties.Select(info => this.propertyMetadataFactory.GetPropertyMetadata(info)))
            {
                if (propertyMetadata.IsIgnoredOnQueryfy)
                {
                    this.OnSkipProperty(source, propertyMetadata);
                    continue;
                }

                var propertyValue = propertyMetadata.Property.GetValue(source);
                if (propertyMetadata.IsParameterGroup && propertyValue != null)
                {
                    this.Fill(propertyValue, queryficationContext);
                }
                else
                {
                    if (propertyValue != null || propertyMetadata.ValueProcessorType == typeof(NullValueProcessor))
                    {
                        var queryParameter = this.GetParameterFromPropertyCore(propertyMetadata);
                        queryParameter.Value = propertyValue;
                        queryficationContext.AddParameter(queryParameter);
                    }
                }
            }

            var extendedQueryfication = source as INeedExtendedQueryfication;

            if (extendedQueryfication != null)
            {
                extendedQueryfication.Queryfy(queryficationContext);
            }
        }