Пример #1
0
        public override void WriteTop(double count, double offset, TopType topType)
        {
            if (topType == TopType.Range)
            {
                this.IncrementStatementDepth();
                StringBuilder        builder = null;
                System.IO.TextWriter writer  = this.Writer;

                if (writer is System.IO.StringWriter)
                {
                    System.IO.StringWriter sw = writer as System.IO.StringWriter;
                    builder = sw.GetStringBuilder();
                }

                _range = new RangeOptions()
                {
                    Count              = (int)count - 1,              //as we use between and we start from offset 1 - this works
                    Offset             = (int)offset,
                    SelectInjectOffset = builder.Length,
                    Builder            = builder,
                    CollectingFields   = true
                };
            }
            else
            {
                base.WriteTop(count, offset, topType);
            }
        }
        /// <summary>
        /// Remove range of pages from password-protected document of known format
        /// </summary>
        /// <param name="fileName">source file</param>
        public static void RemovePagesRangeFromProtectedKnownFormatDoc(string fileName)
        {
            //ExStart:RemovePagesRangeFromProtectedKnownFormatDoc
            string sourceFile = CommonUtilities.sourcePath + fileName;
            // Preparing.
            string       password     = "";
            int          startPage    = 2;
            int          endPage      = 4;
            RangeMode    mode         = RangeMode.AllPages;
            RangeOptions rangeOptions = new RangeOptions(startPage, endPage, mode);

            rangeOptions.Password   = password;
            rangeOptions.FileFormat = FileFormat.Docx;
            Stream openFile = new FileStream(sourceFile, FileMode.Open);

            // Main method.
            DocumentResult result         = new DocumentHandler().RemovePages(openFile, rangeOptions);
            Stream         documentStream = result.Stream;
            //output file
            var fileStream = File.Create(CommonUtilities.outputPath + "OutPut." + FileFormat.Docx);

            documentStream.CopyTo(fileStream);
            documentStream.Close();
            //ExEnd:RemovePagesRangeFromProtectedKnownFormatDoc
        }
Пример #3
0
        public ValueRangeToken(LeoMember member, TVal from, TVal to, RangeOptions options) : base(member)
        {
            _from = from;
            _to   = to;

            _options = options;
        }
        /// <summary>
        /// Splitting  by page ranges to several documents
        /// </summary>
        /// <param name="fileName">source file</param>
        public static void SplittingByPageRanges(string fileName)
        {
            //ExStart:SplittingByPageRanges
            string sourceFile = CommonUtilities.sourcePath + fileName;
            // Preparing.
            string       password     = "******";
            int          startPage    = 5;
            int          endPage      = 8;
            RangeMode    mode         = RangeMode.EvenPages;
            RangeOptions rangeOptions = new RangeOptions(startPage, endPage, mode);

            rangeOptions.Password   = password;
            rangeOptions.FileFormat = FileFormat.Pdf;
            Stream openFile = new FileStream(sourceFile, FileMode.Open);

            // Main method.
            MultiDocumentResult splitResult = new DocumentHandler().Split(openFile, rangeOptions);

            for (int i = 0; i < splitResult.Documents.Count; i++)
            {
                Stream documentStream = splitResult.Documents[i].Stream;
                //output file
                var fileStream = File.Create(CommonUtilities.outputPath + "OutPut " + i + "." + FileFormat.Pdf);
                documentStream.CopyTo(fileStream);
                documentStream.Close();
            }
            //ExEnd:SplittingByPageRanges
        }
Пример #5
0
        /// <inheritdoc />
        public ValueRangeToken(VerifiableMemberContract contract, TVal from, TVal to, RangeOptions options) : base(contract)
        {
            _from = from;
            _to   = to;

            _options = options;
        }
Пример #6
0
        private static async Task Main()
        {
            //Create a HttpClient
            using (HttpClient client = new HttpClient())
            {
                //Create a builder to the accept-encoding header. We need this to construct which encodings we would like to accept in the response.
                AcceptEncodingBuilder acceptEncoding = new AcceptEncodingBuilder();
                acceptEncoding.Add(AcceptEncodingType.Identity, 0.5f);
                acceptEncoding.Add(AcceptEncodingType.Compress, 0.1f);

                //Add the Accept-Encoding header to the HttpClient
                client.DefaultRequestHeaders.Add(acceptEncoding.HeaderName, acceptEncoding.Build());

                //Now we create some options for the next header. These change the behavior of the builder.
                RangeOptions rangeOptions = new RangeOptions();
                rangeOptions.DiscardInvalidRanges   = true;
                rangeOptions.MergeOverlappingRanges = true;
                rangeOptions.ShortenRanges          = true;
                rangeOptions.SortRanges             = true;

                //Create a RangeBuilder with the options we just made
                RangeBuilder range = new RangeBuilder(Options.Create(rangeOptions));
                range.Add(0, 10_000);
                range.Add(5, 100); //This range is overlapping, but that's okay since MergeOverlappingRanges is set to true.

                //We add the Range header to the HttpClient
                client.DefaultRequestHeaders.Add(range.HeaderName, range.Build());

                //We send the request to a website that echo the headers back to us in the response.
                string echo = await client.GetStringAsync(new Uri("http://scooterlabs.com/echo")).ConfigureAwait(false);

                //The response is written to the console
                Console.WriteLine(echo);
            }
        }
Пример #7
0
        /// <summary>
        /// Creates a new <see cref="NumberConstraint"/> value.
        /// </summary>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="rangeOptions">The range options.</param>
        /// <param name="multipleOf">The value which the range should be a multiple of.</param>
        /// <param name="required"></param>
        public NumberConstraint(Number?minimum, Number?maximum, RangeOptions rangeOptions, Number?multipleOf, bool required)
        {
            // Validate min/max/multiple
            rangeOptions &= RangeOptions.Inclusive;
            if (!minimum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MinimumInclusive;
            }
            if (!maximum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MaximumInclusive;
            }

            if (maximum.HasValue)
            {
                if (minimum.HasValue)
                {
                    // Ensure min and max are of the same general type (integer, real or decimal)
                    if (minimum.Value.Kind != maximum.Value.Kind)
                    {
                        throw new ArgumentOutOfRangeException(nameof(maximum), $"{nameof(NumberConstraint)} {nameof(minimum)} and {nameof(maximum)} should have the same {nameof(NumberKinds)}");
                    }

                    if (minimum.Value > maximum.Value)
                    {
                        throw new ArgumentOutOfRangeException(nameof(maximum));
                    }

                    if (minimum.Value == maximum.Value &&
                        rangeOptions != RangeOptions.Inclusive)
                    {
                        throw new ArgumentOutOfRangeException(nameof(maximum));
                    }
                }

                if (multipleOf.HasValue)
                {
                    // Ensure min and max are of the same general type (integer, real or decimal)
                    if (multipleOf.Value.Kind != maximum.Value.Kind)
                    {
                        throw new ArgumentOutOfRangeException(nameof(multipleOf), $"{nameof(NumberConstraint)} {nameof(multipleOf)} and {nameof(maximum)} should have the same {nameof(NumberKinds)}");
                    }

                    if (multipleOf.Value > maximum.Value)
                    {
                        throw new ArgumentOutOfRangeException(nameof(multipleOf));
                    }
                }
            }

            Minimum      = minimum;
            Maximum      = maximum;
            MultipleOf   = multipleOf;
            RangeOptions = rangeOptions;
            Required     = required;
        }
Пример #8
0
        /// <summary>Returns the fully qualified type name of this instance.</summary>
        /// <returns>The fully qualified type name.</returns>
        public override string ToString()
        {
            if (!IsConstrained)
            {
                return(string.Empty);
            }

            // Use set notation for open/closed boundaries
            var sb = new StringBuilder();

            if (RangeOptions.HasFlag(RangeOptions.MinimumInclusive))
            {
                sb.Append("[");
            }
            else
            {
                sb.Append("(");
            }

            if (Minimum.HasValue)
            {
                sb.Append(Minimum.Value.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                sb.Append("-∞");
            }

            sb.Append(", ");

            if (Maximum.HasValue)
            {
                sb.Append(Maximum.Value.ToString(CultureInfo.InvariantCulture));
            }
            else
            {
                sb.Append("∞");
            }

            if (RangeOptions.HasFlag(RangeOptions.MaximumInclusive))
            {
                sb.Append("]");
            }
            else
            {
                sb.Append(")");
            }

            if (MultipleOf.HasValue &&
                MultipleOf.Value != 0)
            {
                sb.Append(" * ").Append(MultipleOf.Value.ToString(CultureInfo.InvariantCulture));
            }

            return(sb.ToString());
        }
Пример #9
0
        /// <summary>
        /// Creates a new <see cref="NumberRange"/> value.
        /// </summary>
        /// <param name="minimum">The minimum count.</param>
        /// <param name="maximum">The maximum count.</param>
        /// <param name="rangeOptions">The range options.</param>
        public CountRange(uint?minimum, uint?maximum, RangeOptions rangeOptions)
        {
            rangeOptions &= RangeOptions.Inclusive;
            if (!minimum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MinimumInclusive;
            }
            if (!maximum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MaximumInclusive;
            }

            Minimum      = minimum;
            Maximum      = maximum;
            RangeOptions = rangeOptions;
        }
Пример #10
0
        /// <summary>
        /// Creates a new <see cref="NumberRange"/> value.
        /// </summary>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="multipleOf">The value which the range should be a multiple of.</param>
        /// <param name="rangeOptions">The range options.</param>
        public NumberRange(Number?minimum, Number?maximum, Number?multipleOf, RangeOptions rangeOptions)
        {
            rangeOptions &= RangeOptions.Inclusive;
            if (!minimum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MinimumInclusive;
            }
            if (!maximum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MaximumInclusive;
            }

            Minimum      = minimum;
            Maximum      = maximum;
            MultipleOf   = multipleOf;
            RangeOptions = rangeOptions;
        }
Пример #11
0
        /// <summary>
        /// Creates a new <see cref="DoubleConstraint"/> value.
        /// </summary>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="rangeOptions">The range options.</param>
        /// <param name="multipleOf">The value which the value should be a multiple of.</param>
        /// <param name="required">Whether or not a value is required.</param>
        public DoubleConstraint(double?minimum, double?maximum, RangeOptions rangeOptions, double?multipleOf, bool required)
        {
            rangeOptions &= RangeOptions.Inclusive;
            if (!minimum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MinimumInclusive;
            }
            if (!maximum.HasValue)
            {
                rangeOptions &= ~RangeOptions.MaximumInclusive;
            }

            // Validate min/max/multiple
            if (maximum.HasValue)
            {
                if (minimum.HasValue)
                {
                    if (minimum.Value > maximum.Value)
                    {
                        throw new ArgumentOutOfRangeException(nameof(maximum));
                    }

                    if (minimum.Value == maximum.Value &&
                        rangeOptions != RangeOptions.Inclusive)
                    {
                        throw new ArgumentOutOfRangeException(nameof(maximum));
                    }
                }

                if (multipleOf.HasValue &&
                    multipleOf.Value > maximum.Value)
                {
                    throw new ArgumentOutOfRangeException(nameof(multipleOf));
                }
            }

            Minimum      = minimum;
            Maximum      = maximum;
            RangeOptions = rangeOptions;
            MultipleOf   = multipleOf;
            Required     = required;
        }
Пример #12
0
        public override void EndSelectStatement()
        {
            base.EndSelectStatement();
            if (_range != null)
            {
                string[] fields = _range.Fields.ToArray();
                string   order  = "";
                if (_range.OrderStartIndex > 0)
                {
                    if (_range.OderEndIndex <= 0)
                    {
                        _range.OderEndIndex = _range.Builder.Length;
                    }
                    order = _range.Builder.ToString(_range.OrderStartIndex, _range.OderEndIndex - _range.OrderStartIndex);
                    _range.Builder.Remove(_range.OrderStartIndex, _range.OderEndIndex - _range.OrderStartIndex);
                }
                else
                {
                    order = string.Join(",", fields);
                }


                //Inject the SELECT ROW_NUMBER() OVER(...) AS _rowNum, [Sort1], [Sort2] into the SQL statement
                string extrasorts = _range.Sorts.Count == 0 ? "" : (string.Join(", ", _range.Sorts.ToArray()) + ", ");
                string rowselect  = string.Format(ROWSELECT_FORMAT, order, ROWNUM_VAR, extrasorts);

                _range.Builder.Insert(_range.SelectInjectOffset, rowselect);

                rowselect = string.Format(OUTER_ROWSELECT_FRONT, string.Join(", ", fields));
                _range.Builder.Insert(0, rowselect);
                rowselect = string.Format(OUTER_ROWSELECT_END, ROWSELECT_TABLENAME, ROWNUM_VAR,
                                          _range.Offset, _range.Count, _range.Count + _range.Offset
                                          , order);

                _range.Builder.Append(rowselect);
                this.DecrementStatementDepth();
                _range = null;
            }
        }
Пример #13
0
        public ValueRangeToken(LeoMember member, object from, object to, RangeOptions options) : base(member)
        {
            if (from is null || to is null)
            {
                _from = default;
                _to   = default;
                _returnFalseDirectly = true;
            }

            if (!_returnFalseDirectly && from is IComparable from0)
            {
                _from = from0;
            }
            else
            {
                _from = default;
                _returnFalseDirectly = true;
            }

            if (!_returnFalseDirectly && to is IComparable to0)
            {
                _to = to0;
            }
            else
            {
                _to = default;
                _returnFalseDirectly = true;
            }

            if (!_returnFalseDirectly && _from !.CompareTo(_to) > 0)
            {
                _returnFalseDirectly = true;
            }

            _options = options;
        }
        /// <summary>
        /// Trim document of known format by page numbers range
        /// </summary>
        /// <param name="fileName">source file</param>
        public static void TrimDocumentByPageNumRange(string fileName)
        {
            //ExStart:TrimDocumentUnknownFormat
            string sourceFile = CommonUtilities.sourcePath + fileName;
            // Preparation.
            string       password     = "******";
            int          startPage    = 1;
            int          endPage      = 5;
            RangeMode    mode         = RangeMode.AllPages;
            RangeOptions rangeOptions = new RangeOptions(startPage, endPage, mode);

            rangeOptions.Password   = password;
            rangeOptions.FileFormat = FileFormat.Pdf;
            Stream openFile = new FileStream(sourceFile, FileMode.Open);

            // Main method.
            DocumentResult result         = new DocumentHandler().Trim(openFile, rangeOptions);
            Stream         documentStream = result.Stream;
            var            fileStream     = File.Create(CommonUtilities.outputPath + "OutPut." + FileFormat.Pdf);

            documentStream.CopyTo(fileStream);
            documentStream.Close();
            //ExEnd:TrimDocumentUnknownFormat
        }
Пример #15
0
        public static List <string> GetRangeOptions()
        {
            var options = new RangeOptions();

            return(options.GetFieldValues());
        }
Пример #16
0
 /// <summary>
 /// Creates a new <see cref="NumberConstraint"/> value.
 /// </summary>
 /// <param name="minimum">The minimum value.</param>
 /// <param name="maximum">The maximum value.</param>
 /// <param name="rangeOptions">The range options.</param>
 public NumberConstraint(Number?minimum, Number?maximum, RangeOptions rangeOptions)
     : this(minimum, maximum, rangeOptions, default, default)
 {
 }
Пример #17
0
 /// <summary>
 /// Creates a new <see cref="DoubleConstraint"/> value.
 /// </summary>
 /// <param name="minimum">The minimum value.</param>
 /// <param name="maximum">The maximum value.</param>
 /// <param name="rangeOptions">The range options.</param>
 public DoubleConstraint(double?minimum, double?maximum, RangeOptions rangeOptions)
     : this(minimum, maximum, rangeOptions, default, default)
 {
 }
Пример #18
0
        public Range(TValue start, TValue end, RangeOptions options)
        {
            if (options.HasFlag(RangeOptions.IsEmpty))
            {
                // clear other flags
                _options = RangeOptions.IsEmpty;
                Start    = default(TValue);
                End      = default(TValue);
                return;
            }

            if (ReferenceEquals(start, null))
            {
                options &= ~RangeOptions.HasStart;
            }

            if (ReferenceEquals(end, null))
            {
                options &= ~RangeOptions.HasEnd;
            }

            if (!options.HasFlag(RangeOptions.HasStart))
            {
                start    = default(TValue);
                options &= ~RangeOptions.IncludingStart;
            }

            if (!options.HasFlag(RangeOptions.HasEnd))
            {
                end      = default(TValue);
                options &= ~RangeOptions.IncludingEnd;
            }

            _options = options;

            if (!options.HasFlag(RangeOptions.HasStart) || !options.HasFlag(RangeOptions.HasEnd))
            {
                Start = start;
                End   = end;
                return;
            }

            Debug.Assert(start != null, "start != null");
            var compare = start.CompareTo(end);

            if (compare > 0)
            {
                throw new ArgumentException("'Start' must be less or equal to the 'End' parameter");
            }

            Start = start;
            End   = end;

            if (compare == 0)
            {
                if (!(options.HasFlag(RangeOptions.IncludingStart) ||
                      options.HasFlag(RangeOptions.IncludingEnd)))
                {
                    // empty
                    Start    = default(TValue);
                    End      = default(TValue);
                    _options = RangeOptions.IsEmpty;
                }
                else
                {
                    // ensure that everything are included
                    _options |= RangeOptions.IncludingStart | RangeOptions.IncludingEnd;
                }
            }
        }
Пример #19
0
 public DateRangeModel(RangeOptions rangeOptions, DateRangeCode defaultRangeCode, string title)
 {
     DateRangeCode = defaultRangeCode;
     RangeOptions  = rangeOptions;
     Title         = title;
 }
 /// <summary>
 /// Range... from .. to .. <br />
 /// 位于区间
 /// </summary>
 /// <param name="registrar"></param>
 /// <param name="from"></param>
 /// <param name="to"></param>
 /// <param name="options"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static IPredicateValidationRegistrar <T> Range <T>(this IValueFluentValidationRegistrar <T> registrar, object from, object to, RangeOptions options = RangeOptions.OpenInterval)
 {
     registrar._impl().ExposeValueRuleBuilder().Range(from, to, options);
     return((IPredicateValidationRegistrar <T>)registrar);
 }
Пример #21
0
 public DateRangeModel(RangeOptions rangeOptions, DateRangeCode defaultRangeCode)
 {
     DateRangeCode = defaultRangeCode;
     RangeOptions  = rangeOptions;
 }
Пример #22
0
 /// <summary>
 /// Creates a new <see cref="DecimalConstraint"/> value.
 /// </summary>
 /// <param name="minimum">The minimum value.</param>
 /// <param name="maximum">The maximum value.</param>
 /// <param name="rangeOptions">The range options.</param>
 public DecimalConstraint(decimal?minimum, decimal?maximum, RangeOptions rangeOptions)
     : this(minimum, maximum, rangeOptions, default, default)
 {
 }
Пример #23
0
        //`1

        public static IPredicateValueRuleBuilder <T> Range <T>(this IValueRuleBuilder <T> builder, object from, object to, RangeOptions options = RangeOptions.OpenInterval)
        {
            var current = builder._impl();

            current.State.CurrentToken = new ValueRangeToken(current._contract, from, to, options);
            return(current);
        }
Пример #24
0
 /// <summary>
 /// Creates a new <see cref="NumberRange"/> value.
 /// </summary>
 /// <param name="minimum">The minimum value.</param>
 /// <param name="maximum">The maximum value.</param>
 /// <param name="rangeOptions">The range options.</param>
 public NumberRange(Number?minimum, Number?maximum, RangeOptions rangeOptions)
     : this(minimum, maximum, null, rangeOptions)
 {
 }
Пример #25
0
 /// <summary>
 /// Creates a new <see cref="Int64Constraint"/> value.
 /// </summary>
 /// <param name="minimum">The minimum value.</param>
 /// <param name="maximum">The maximum value.</param>
 /// <param name="rangeOptions">The range options.</param>
 public Int64Constraint(long?minimum, long?maximum, RangeOptions rangeOptions)
     : this(minimum, maximum, rangeOptions, default, default)
 {
 }