// Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="maxQueryParameterCount">The maximum parameter count per query.</param>
        protected CommandProcessor(CommandFactory factory, int maxQueryParameterCount)
        {
            ArgumentValidator.EnsureArgumentNotNull(factory, "factory");
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(maxQueryParameterCount, 0, "maxQueryParameterCount");
            Factory = factory;
            MaxQueryParameterCount = maxQueryParameterCount;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="maxSize">Max size of the original cache. Ideally it should be devisible by 3</param>
 /// <param name="keyExtractor">Extracts key value from caching item.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxSize"/> is less than 3.</exception>
 public FastConcurrentLruCache(int maxSize, Converter <TItem, TKey> keyExtractor)
 {
     ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(maxSize, 3, nameof(maxSize));
     MaxSize      = maxSize;
     KeyExtractor = keyExtractor;
     realCache    = new FastConcurrentLru <TKey, TItem>(maxSize);
 }
        /// <summary>Generates a list of integral numbers within a specified range.</summary>
        /// <param name="start">The value of the first integer in the sequence.</param>
        /// <param name="count">The number of sequential integers to generate.</param>
        /// <returns>An List&lt;Int32&gt; that contains a range of sequential integral numbers.</returns>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="count"/> is less than 0.-or-
        /// <paramref name="start"/> + <paramref name="count"/> -1 is larger than <see cref="F:System.Int32.MaxValue"/>.</exception>
        public static List <int> RangeToList(int start, int count)
        {
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(count, 0, "count");
            var result = new List <int>(count);

            result.AddRange(Enumerable.Range(start, count));
            return(result);
        }
Ejemplo n.º 4
0
 /// <inheritdoc/>
 public override void Validate()
 {
     ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(CacheSize, 0, "CacheSize");
     if (DefaultCommandTimeout != null)
     {
         ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(DefaultCommandTimeout.Value, 0, "DefaultCommandTimeout");
     }
 }
        /// <summary>Generates a list that contains one repeated value.</summary>
        /// <param name="element">The value to be repeated.</param>
        /// <param name="count">The number of times to repeat the value in the generated sequence.</param>
        /// <typeparam name="TResult">The type of the value to be repeated in the result sequence.</typeparam>
        /// <returns>An <see cref="T:System.Collections.Generic.List`1" /> that contains a repeated value.</returns>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="count"/> is less than 0.</exception>
        public static List <TResult> RepeatToList <TResult>(TResult element, int count)
        {
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(count, 0, "count");
            var result = new List <TResult>(count);

            for (var i = 0; i < count; ++i)
            {
                result.Add(element);
            }
            return(result);
        }
        /// <summary>Generates an array that contains one repeated value.</summary>
        /// <param name="element">The value to be repeated.</param>
        /// <param name="count">The number of times to repeat the value in the generated sequence.</param>
        /// <typeparam name="TResult">The type of the value to be repeated in the result sequence.</typeparam>
        /// <returns>An array that contains a repeated value.</returns>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="count"/> is less than 0.</exception>
        public static TResult[] RepeatToArray <TResult>(TResult element, int count)
        {
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(count, 0, "count");
            var result = new TResult[count];

            for (var i = 0; i < count; ++i)
            {
                result[i] = element;
            }
            return(result);
        }
        /// <summary>Generates an array of integral numbers within a specified range.</summary>
        /// <param name="start">The value of the first integer in the sequence.</param>
        /// <param name="count">The number of sequential integers to generate.</param>
        /// <returns>An array that contains a range of sequential integral numbers.</returns>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        /// <paramref name="count"/> is less than 0.-or-
        /// <paramref name="start"/> + <paramref name="count"/> -1 is larger than <see cref="F:System.Int32.MaxValue"/>.</exception>
        public static int[] RangeToArray(int start, int count)
        {
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(count, 0, "count");
            var result = new int[count];
            var index  = 0;

            foreach (var value in Enumerable.Range(start, count))
            {
                result[index++] = value;
            }
            return(result);
        }
Ejemplo n.º 8
0
        internal CustomProximityTerm(IOperator source, ICollection <IProximityOperand> proximityTerms, long maxDistance, bool matchOrder)
            : base(SearchConditionNodeType.CustomProximityTerm, source)
        {
            if (proximityTerms.Count < 2)
            {
                throw new ArgumentException(string.Format(Strings.ExCollectionShouldContainAtLeastXElements, 2));
            }
            ArgumentValidator.EnsureArgumentNotNull(proximityTerms, "proximityTerms");
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(maxDistance, 0, "maxDistance");

            Terms       = new ReadOnlyList <IProximityOperand>(proximityTerms.ToList());
            MaxDistance = maxDistance;
            MatchOrder  = matchOrder;
        }
Ejemplo n.º 9
0
        private string GetDecimalValue(int precision, int scale, int zerosInPrecision, int zerosInScale)
        {
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(precision, 1, "precision");
            ArgumentValidator.EnsureArgumentIsLessThanOrEqual(precision, 38, "precision");
            ArgumentValidator.EnsureArgumentIsGreaterThanOrEqual(scale, 0, "scale");
            ArgumentValidator.EnsureArgumentIsLessThanOrEqual(scale, precision - 1, "scale");
            ArgumentValidator.EnsureArgumentIsLessThanOrEqual(zerosInPrecision, precision - scale, "zerosInPrecision");
            ArgumentValidator.EnsureArgumentIsLessThanOrEqual(zerosInScale, scale, "zerosInScale");

            if (zerosInScale > scale)
            {
                throw new ArgumentException("", "zerosInScale");
            }

            var meaningfulfloor = string.Join("", Enumerable.Repeat('1', scale - zerosInScale));
            var irrelevantFloor = string.Join("", Enumerable.Repeat('0', zerosInScale));
            var floor           = meaningfulfloor + irrelevantFloor;
            var ceiling         = string.Join("", Enumerable.Repeat('1', precision - scale - zerosInPrecision));

            return(floor.Length + zerosInPrecision + ceiling.Length != precision
        ? throw new Exception("Precision and scale mismatch")
        : ceiling + "." + floor);
        }