// Add the given parameter to the list. Remove if date is null.
        private void SetDate(string parameter, DateTimeOffset?date)
        {
            NameValueHeaderValue dateParameter = NameValueHeaderValue.Find(_parameters, parameter);

            if (date == null)
            {
                // Remove parameter.
                if (dateParameter != null)
                {
                    _parameters.Remove(dateParameter);
                }
            }
            else
            {
                // Must always be quoted.
                string dateString = "\"" + HttpRuleParser.DateToString(date.Value) + "\"";
                if (dateParameter != null)
                {
                    dateParameter.Value = dateString;
                }
                else
                {
                    Parameters.Add(new NameValueHeaderValue(parameter, dateString));
                }
            }
        }
예제 #2
0
        // Add the given parameter to the list. Remove if date is null.
        private void SetDate(string parameter, DateTimeOffset?date)
        {
            NameValueHeaderValue dateParameter = NameValueHeaderValue.Find(_parameters, parameter);

            if (date == null)
            {
                // Remove parameter.
                if (dateParameter != null)
                {
                    _parameters.Remove(dateParameter);
                }
            }
            else
            {
                // Must always be quoted.
                string dateString = string.Format(CultureInfo.InvariantCulture, "\"{0}\"",
                                                  HttpRuleParser.DateToString(date.Value));
                if (dateParameter != null)
                {
                    dateParameter.Value = dateString;
                }
                else
                {
                    Parameters.Add(new NameValueHeaderValue(parameter, dateString));
                }
            }
        }
예제 #3
0
        public void DateToString_UseRfcSampleTimestamp_FormattedAccordingToRfc1123()
        {
            // We don't need extensive tests, since we let DateTimeOffset do the formatting. This test is just
            // to validate that we use the correct parameters when calling into DateTimeOffset.ToString().
            DateTimeOffset dateTime = new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero);

            Assert.Equal("Sun, 06 Nov 1994 08:49:37 GMT", HttpRuleParser.DateToString(dateTime));
        }
예제 #4
0
 public override string ToString()
 {
     if (_delta.HasValue)
     {
         return(((int)_delta.Value.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo));
     }
     return(HttpRuleParser.DateToString(_date.Value));
 }
예제 #5
0
 public override string ToString()
 {
     if (_entityTag == null)
     {
         return(HttpRuleParser.DateToString(_date.Value));
     }
     return(_entityTag.ToString());
 }
예제 #6
0
        public override string ToString()
        {
            StringBuilder sb = StringBuilderCache.Acquire();

            // Warning codes are always 3 digits according to RFC2616
            sb.Append(_code.ToString("000", NumberFormatInfo.InvariantInfo));

            sb.Append(' ');
            sb.Append(_agent);
            sb.Append(' ');
            sb.Append(_text);

            if (_date.HasValue)
            {
                sb.Append(" \"");
                sb.Append(HttpRuleParser.DateToString(_date.Value));
                sb.Append('\"');
            }

            return(StringBuilderCache.GetStringAndRelease(sb));
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            // Warning codes are always 3 digits according to RFC2616
            sb.Append(code.ToString("000", NumberFormatInfo.InvariantInfo));

            sb.Append(' ');
            sb.Append(agent);
            sb.Append(' ');
            sb.Append(text);

            if (date.HasValue)
            {
                sb.Append(" \"");
                sb.Append(HttpRuleParser.DateToString(date.Value));
                sb.Append('\"');
            }

            return(sb.ToString());
        }
예제 #8
0
        public override string ToString(object value)
        {
            Debug.Assert(value is DateTimeOffset);

            return(HttpRuleParser.DateToString((DateTimeOffset)value));
        }