private RetryConditionHeaderValue(RetryConditionHeaderValue source)
        {
            Debug.Assert(source != null);

            _delta = source._delta;
            _date = source._date;
        }
Beispiel #2
0
        private RetryConditionHeaderValue(RetryConditionHeaderValue source)
        {
            Debug.Assert(source != null);

            _delta = source._delta;
            _date  = source._date;
        }
 public void Ctor_DateOverload_MatchExpectation()
 {
     RetryConditionHeaderValue retryCondition = new RetryConditionHeaderValue(
         new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
     Assert.Null(retryCondition.Delta);
     Assert.Equal(new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero), retryCondition.Date);
 }
Beispiel #4
0
        private RetryConditionHeaderValue(RetryConditionHeaderValue source)
        {
            Contract.Requires(source != null);

            this.delta = source.delta;
            this.date  = source.date;
        }
        private RetryConditionHeaderValue(RetryConditionHeaderValue source)
        {
            Contract.Requires(source != null);

            _delta = source._delta;
            _date = source._date;
        }
		public static bool TryParse (string input, out RetryConditionHeaderValue parsedValue)
		{
			parsedValue = null;

			var lexer = new Lexer (input);
			var t = lexer.Scan ();
			if (t != Token.Type.Token)
				return false;

			var ts = lexer.TryGetTimeSpanValue (t);
			if (ts != null) {
				if (lexer.Scan () != Token.Type.End)
					return false;

				parsedValue = new RetryConditionHeaderValue (ts.Value);
			} else {
				DateTimeOffset date;
				if (!Lexer.TryGetDateValue (input, out date))
					return false;

				parsedValue = new RetryConditionHeaderValue (date);
			}

			return true;
		}
        public void ToString_UseDifferentRetryConditions_AllSerializedCorrectly()
        {
            RetryConditionHeaderValue retryCondition = new RetryConditionHeaderValue(new TimeSpan(0, 0, 50000000));
            Assert.Equal("50000000", retryCondition.ToString());

            retryCondition = new RetryConditionHeaderValue(new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            Assert.Equal("Thu, 15 Jul 2010 12:33:57 GMT", retryCondition.ToString());
        }
        public void Ctor_EntityTagOverload_MatchExpectation()
        {
            RetryConditionHeaderValue retryCondition = new RetryConditionHeaderValue(new TimeSpan(0, 0, 3));
            Assert.Equal(new TimeSpan(0, 0, 3), retryCondition.Delta);
            Assert.Null(retryCondition.Date);

            Assert.Throws<ArgumentOutOfRangeException>(() => { new RetryConditionHeaderValue(new TimeSpan(1234567, 0, 0)); });
        }
        public void Equals()
        {
            var value = new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today));
            Assert.AreEqual (value, new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today)), "#1");
            Assert.AreNotEqual (value, new RetryConditionHeaderValue (new DateTimeOffset ()), "#2");

            value = new RetryConditionHeaderValue (new TimeSpan (300));
            Assert.AreEqual (value, new RetryConditionHeaderValue (new TimeSpan (300)), "#4");
            Assert.AreNotEqual (value, new RetryConditionHeaderValue (new TimeSpan (44)), "#5");
        }
 private void CheckValidParsedValue(string input, int startIndex, RetryConditionHeaderValue expectedResult,
     int expectedIndex)
 {
     HttpHeaderParser parser = GenericHeaderParser.RetryConditionParser;
     object result = null;
     Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
         string.Format("TryParse returned false. Input: '{0}'", input));
     Assert.Equal(expectedIndex, startIndex);
     Assert.Equal(expectedResult, result);
 }
Beispiel #11
0
        public static bool TryParse(string input, out RetryConditionHeaderValue parsedValue)
        {
            int    index = 0;
            object output;

            parsedValue = null;

            if (GenericHeaderParser.RetryConditionParser.TryParseValue(input, null, ref index, out output))
            {
                parsedValue = (RetryConditionHeaderValue)output;
                return(true);
            }
            return(false);
        }
        public void Clone_Call_CloneFieldsMatchSourceFields()
        {
            RetryConditionHeaderValue source = new RetryConditionHeaderValue(new TimeSpan(0, 0, 123456789));
            RetryConditionHeaderValue clone = (RetryConditionHeaderValue)((ICloneable)source).Clone();

            Assert.Equal(source.Delta, clone.Delta);
            Assert.Null(clone.Date);

            source = new RetryConditionHeaderValue(new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            clone = (RetryConditionHeaderValue)((ICloneable)source).Clone();

            Assert.Null(clone.Delta);
            Assert.Equal(source.Date, clone.Date);
        }
Beispiel #13
0
        public override bool Equals(object obj)
        {
            RetryConditionHeaderValue other = obj as RetryConditionHeaderValue;

            if (other == null)
            {
                return(false);
            }

            if (_delta.HasValue)
            {
                return((other._delta != null) && (_delta.Value == other._delta.Value));
            }

            return((other._date != null) && (_date.Value == other._date.Value));
        }
        public InternalServerErrorException(
			string message, Exception innerException, RetryConditionHeaderValue retryAfter)
            : base(message, innerException)
        {
            HelpLink = "https://api.signhost.com/Help";

            if (retryAfter != null) {
                if (retryAfter.Date != null) {
                    RetryAfter = retryAfter.Date;
                }

                if (retryAfter.Delta != null) {
                    RetryAfter = DateTime.Now + retryAfter.Delta;
                }
            }
        }
        public void GetHashCode_UseSameAndDifferentRetryConditions_SameOrDifferentHashCodes()
        {
            RetryConditionHeaderValue retryCondition1 = new RetryConditionHeaderValue(new TimeSpan(0, 0, 1000000));
            RetryConditionHeaderValue retryCondition2 = new RetryConditionHeaderValue(new TimeSpan(0, 0, 1000000));
            RetryConditionHeaderValue retryCondition3 = new RetryConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RetryConditionHeaderValue retryCondition4 = new RetryConditionHeaderValue(
                new DateTimeOffset(2008, 8, 16, 13, 44, 10, TimeSpan.Zero));
            RetryConditionHeaderValue retryCondition5 = new RetryConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RetryConditionHeaderValue retryCondition6 = new RetryConditionHeaderValue(new TimeSpan(0, 0, 2000000));

            Assert.Equal(retryCondition1.GetHashCode(), retryCondition2.GetHashCode());
            Assert.NotEqual(retryCondition1.GetHashCode(), retryCondition3.GetHashCode());
            Assert.NotEqual(retryCondition3.GetHashCode(), retryCondition4.GetHashCode());
            Assert.Equal(retryCondition3.GetHashCode(), retryCondition5.GetHashCode());
            Assert.NotEqual(retryCondition1.GetHashCode(), retryCondition6.GetHashCode());
        }
        public void Equals_UseSameAndDifferentRetrys_EqualOrNotEqualNoExceptions()
        {
            RetryConditionHeaderValue retryCondition1 = new RetryConditionHeaderValue(new TimeSpan(0, 0, 1000000));
            RetryConditionHeaderValue retryCondition2 = new RetryConditionHeaderValue(new TimeSpan(0, 0, 1000000));
            RetryConditionHeaderValue retryCondition3 = new RetryConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RetryConditionHeaderValue retryCondition4 = new RetryConditionHeaderValue(
                new DateTimeOffset(2008, 8, 16, 13, 44, 10, TimeSpan.Zero));
            RetryConditionHeaderValue retryCondition5 = new RetryConditionHeaderValue(
                new DateTimeOffset(2010, 7, 15, 12, 33, 57, TimeSpan.Zero));
            RetryConditionHeaderValue retryCondition6 = new RetryConditionHeaderValue(new TimeSpan(0, 0, 2000000));

            Assert.False(retryCondition1.Equals(null), "delta vs. <null>");
            Assert.True(retryCondition1.Equals(retryCondition2), "delta vs. delta");
            Assert.False(retryCondition1.Equals(retryCondition3), "delta vs. date");
            Assert.False(retryCondition3.Equals(retryCondition1), "date vs. delta");
            Assert.False(retryCondition3.Equals(retryCondition4), "date vs. different date");
            Assert.True(retryCondition3.Equals(retryCondition5), "date vs. date");
            Assert.False(retryCondition1.Equals(retryCondition6), "delta vs. different delta");
        }
Beispiel #17
0
        public static bool TryParse(string input, out RetryConditionHeaderValue parsedValue)
        {
            parsedValue = null;

            var lexer = new Lexer(input);
            var t     = lexer.Scan();

            if (t != Token.Type.Token)
            {
                return(false);
            }

            var ts = lexer.TryGetTimeSpanValue(t);

            if (ts != null)
            {
                if (lexer.Scan() != Token.Type.End)
                {
                    return(false);
                }

                parsedValue = new RetryConditionHeaderValue(ts.Value);
            }
            else
            {
                DateTimeOffset date;
                if (!Lexer.TryGetDateValue(input, out date))
                {
                    return(false);
                }

                parsedValue = new RetryConditionHeaderValue(date);
            }

            return(true);
        }
        internal static int GetRetryConditionLength(string?input, int startIndex, out object?parsedValue)
        {
            Debug.Assert(startIndex >= 0);

            parsedValue = null;

            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
            {
                return(0);
            }

            int current = startIndex;

            // Caller must remove leading whitespace.
            DateTimeOffset date         = DateTimeOffset.MinValue;
            int            deltaSeconds = -1; // use -1 to indicate that the value was not set. 'delta' values are always >=0

            // We either have a timespan or a date/time value. Determine which one we have by looking at the first char.
            // If it is a number, we have a timespan, otherwise we assume we have a date.
            char firstChar = input[current];

            if ((firstChar >= '0') && (firstChar <= '9'))
            {
                int deltaStartIndex = current;
                int deltaLength     = HttpRuleParser.GetNumberLength(input, current, false);

                // The value must be in the range 0..2^31
                if ((deltaLength == 0) || (deltaLength > HttpRuleParser.MaxInt32Digits))
                {
                    return(0);
                }

                current = current + deltaLength;
                current = current + HttpRuleParser.GetWhitespaceLength(input, current);

                // RetryConditionHeaderValue only allows 1 value. There must be no delimiter/other chars after 'delta'
                if (current != input.Length)
                {
                    return(0);
                }

                if (!HeaderUtilities.TryParseInt32(input, deltaStartIndex, deltaLength, out deltaSeconds))
                {
                    return(0); // int.TryParse() may return 'false' if the value has 10 digits and is > Int32.MaxValue.
                }
            }
            else
            {
                if (!HttpDateParser.TryParse(input.AsSpan(current), out date))
                {
                    return(0);
                }

                // If we got a valid date, then the parser consumed the whole string (incl. trailing whitespace).
                current = input.Length;
            }

            RetryConditionHeaderValue result = new RetryConditionHeaderValue();

            if (deltaSeconds == -1) // we didn't change delta, so we must have found a date.
            {
                result._date = date;
            }
            else
            {
                result._delta = new TimeSpan(0, 0, deltaSeconds);
            }

            parsedValue = result;
            return(current - startIndex);
        }
        public void RetryAfter_ReadAndWriteProperty_CallsForwardedToHttpGeneralHeaders()
        {
            Assert.Null(headers.RetryAfter);

            RetryConditionHeaderValue retry = new RetryConditionHeaderValue(new TimeSpan(0, 1, 10));
            headers.RetryAfter = retry;
            Assert.Same(retry, headers.RetryAfter);

            headers.RetryAfter = null;
            Assert.Null(headers.RetryAfter);
            Assert.False(headers.Contains("RetryAfter"),
                "Header store should not contain a header 'ETag' after setting it to null.");
        }
 private void CheckValidParse(string input, RetryConditionHeaderValue expectedResult)
 {
     RetryConditionHeaderValue result = RetryConditionHeaderValue.Parse(input);
     Assert.Equal(expectedResult, result);
 }
        public static bool TryParse(string input, out RetryConditionHeaderValue parsedValue)
        {
            int index = 0;
            object output;
            parsedValue = null;

            if (GenericHeaderParser.RetryConditionParser.TryParseValue(input, null, ref index, out output))
            {
                parsedValue = (RetryConditionHeaderValue)output;
                return true;
            }
            return false;
        }
        internal static int GetRetryConditionLength(string input, int startIndex, out object parsedValue)
        {
            Contract.Requires(startIndex >= 0);

            parsedValue = null;

            if (string.IsNullOrEmpty(input) || (startIndex >= input.Length))
            {
                return 0;
            }

            int current = startIndex;

            // Caller must remove leading whitespaces.
            DateTimeOffset date = DateTimeOffset.MinValue;
            int deltaSeconds = -1; // use -1 to indicate that the value was not set. 'delta' values are always >=0

            // We either have a timespan or a date/time value. Determine which one we have by looking at the first char.
            // If it is a number, we have a timespan, otherwise we assume we have a date.
            char firstChar = input[current];

            if ((firstChar >= '0') && (firstChar <= '9'))
            {
                int deltaStartIndex = current;
                int deltaLength = HttpRuleParser.GetNumberLength(input, current, false);

                // The value must be in the range 0..2^31
                if ((deltaLength == 0) || (deltaLength > HttpRuleParser.MaxInt32Digits))
                {
                    return 0;
                }

                current = current + deltaLength;
                current = current + HttpRuleParser.GetWhitespaceLength(input, current);

                // RetryConditionHeaderValue only allows 1 value. There must be no delimiter/other chars after 'delta'
                if (current != input.Length)
                {
                    return 0;
                }

                if (!HeaderUtilities.TryParseInt32(input.Substring(deltaStartIndex, deltaLength), out deltaSeconds))
                {
                    return 0; // int.TryParse() may return 'false' if the value has 10 digits and is > Int32.MaxValue.
                }
            }
            else
            {
                if (!HttpRuleParser.TryStringToDate(input.Substring(current), out date))
                {
                    return 0;
                }

                // If we got a valid date, then the parser consumed the whole string (incl. trailing whitespaces).
                current = input.Length;
            }

            RetryConditionHeaderValue result = new RetryConditionHeaderValue();

            if (deltaSeconds == -1) // we didn't change delta, so we must have found a date.
            {
                result._date = date;
            }
            else
            {
                result._delta = new TimeSpan(0, 0, deltaSeconds);
            }

            parsedValue = result;
            return current - startIndex;
        }
 private void CheckValidTryParse(string input, RetryConditionHeaderValue expectedResult)
 {
     RetryConditionHeaderValue result = null;
     Assert.True(RetryConditionHeaderValue.TryParse(input, out result));
     Assert.Equal(expectedResult, result);
 }
 private static void CallGetRetryConditionLength(string input, int startIndex, int expectedLength,
     out RetryConditionHeaderValue result)
 {
     object temp = null;
     Assert.Equal(expectedLength, RetryConditionHeaderValue.GetRetryConditionLength(input, startIndex,
         out temp));
     result = temp as RetryConditionHeaderValue;
 }
        public void Properties()
        {
            var value = new RetryConditionHeaderValue (new TimeSpan (5000));
            Assert.IsNull (value.Date, "#1");
            Assert.AreEqual (new TimeSpan (5000), value.Delta, "#2");

            value = new RetryConditionHeaderValue (new DateTimeOffset (DateTime.Today));
            Assert.AreEqual (new DateTimeOffset (DateTime.Today), value.Date, "#3");
            Assert.IsNull (value.Delta, "#4");
        }
 public static bool TryParse(string input, out RetryConditionHeaderValue parsedValue)
 {
 }