Min() public static method

Checks if the value is equal or larger.
If contract fails.
public static Min ( System.DateTime min, System.DateTime value, string messageOrParamName ) : void
min System.DateTime minimum value.
value System.DateTime parameter value.
messageOrParamName string parameter name, or a error message.
return void
Exemplo n.º 1
0
        /// <summary>
        /// Listen for regular HTTP connections
        /// </summary>
        /// <param name="address">IP Address to accept connections on</param>
        /// <param name="port">TCP Port to listen on, default HTTP port is 80.</param>
        /// <param name="factory">Factory used to create <see cref="IHttpClientContext"/>es.</param>
        /// <exception cref="ArgumentNullException"><c>address</c> is null.</exception>
        /// <exception cref="ArgumentException">Port must be a positive number.</exception>
        protected HttpListenerBase(IPAddress address, int port, IHttpContextFactory factory)
        {
            Check.Require(address, "address");
            Check.Min(0, port, "port");
            Check.Require(factory, "factory");

            _address = address;
            _port    = port;
            _factory = factory;
            _factory.RequestReceived += OnRequestReceived;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpClientContext"/> class.
        /// </summary>
        /// <param name="secured">true if the connection is secured (SSL/TLS)</param>
        /// <param name="remoteEndPoint">client that connected.</param>
        /// <param name="stream">Stream used for communication</param>
        /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param>
        /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param>
        /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception>
        /// <exception cref="ArgumentException">Stream must be writable and readable.</exception>
        public HttpClientContext(bool secured, IPEndPoint remoteEndPoint,
                                 Stream stream, IRequestParserFactory parserFactory, int bufferSize, Socket sock)
        {
            Check.Require(remoteEndPoint, "remoteEndPoint");
            Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address");
            Check.Require(stream, "stream");
            Check.Require(parserFactory, "parser");
            Check.Min(4096, bufferSize, "bufferSize");
            Check.Require(sock, "socket");

            if (!stream.CanWrite || !stream.CanRead)
            {
                throw new ArgumentException("Stream must be writable and readable.");
            }

            _bufferSize                  = bufferSize;
            RemoteAddress                = remoteEndPoint.Address.ToString();
            RemotePort                   = remoteEndPoint.Port.ToString();
            _log                         = NullLogWriter.Instance;
            _parser                      = parserFactory.CreateParser(_log);
            _parser.RequestCompleted    += OnRequestCompleted;
            _parser.RequestLineReceived += OnRequestLine;
            _parser.HeaderReceived      += OnHeaderReceived;
            _parser.BodyBytesReceived   += OnBodyBytesReceived;
            _currentRequest              = new HttpRequest();

            IsSecured = secured;
            _stream   = stream;

            _buffer = new byte[bufferSize];

            // by Fumi.Iseki
            SSLCommonName = "";
            if (secured)
            {
                SslStream       _ssl   = (SslStream)_stream;
                X509Certificate _cert1 = _ssl.RemoteCertificate;
                if (_cert1 != null)
                {
                    X509Certificate2 _cert2 = new X509Certificate2(_cert1);
                    if (_cert2 != null)
                    {
                        SSLCommonName = _cert2.GetNameInfo(X509NameType.SimpleName, false);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpClientContext"/> class.
        /// </summary>
        /// <param name="secured">true if the connection is secured (SSL/TLS)</param>
        /// <param name="remoteEndPoint">client that connected.</param>
        /// <param name="stream">Stream used for communication</param>
        /// <param name="clientCertificate">Client security certificate</param>
        /// <param name="parserFactory">Used to create a <see cref="IHttpRequestParser"/>.</param>
        /// <param name="bufferSize">Size of buffer to use when reading data. Must be at least 4096 bytes.</param>
        /// <param name="socket">Client socket</param>
        /// <exception cref="SocketException">If <see cref="Socket.BeginReceive(byte[],int,int,SocketFlags,AsyncCallback,object)"/> fails</exception>
        /// <exception cref="ArgumentException">Stream must be writable and readable.</exception>
        public HttpClientContext(bool secured, IPEndPoint remoteEndPoint, Stream stream,
                                 ClientCertificate clientCertificate, IRequestParserFactory parserFactory, int bufferSize, Socket socket)
        {
            Check.Require(remoteEndPoint, "remoteEndPoint");
            Check.NotEmpty(remoteEndPoint.Address.ToString(), "remoteEndPoint.Address");
            Check.Require(stream, "stream");
            Check.Require(parserFactory, "parser");
            Check.Min(4096, bufferSize, "bufferSize");
            Check.Require(socket, "socket");

            if (!stream.CanWrite || !stream.CanRead)
            {
                throw new ArgumentException("Stream must be writable and readable.");
            }

            _bufferSize                  = bufferSize;
            RemoteAddress                = remoteEndPoint.Address.ToString();
            RemotePort                   = remoteEndPoint.Port.ToString();
            _log                         = NullLogWriter.Instance;
            _parser                      = parserFactory.CreateParser(_log);
            _parser.RequestCompleted    += OnRequestCompleted;
            _parser.RequestLineReceived += OnRequestLine;
            _parser.HeaderReceived      += OnHeaderReceived;
            _parser.BodyBytesReceived   += OnBodyBytesReceived;
            _localEndPoint               = (IPEndPoint)socket.LocalEndPoint;

            HttpRequest request = new HttpRequest();

            request._remoteEndPoint = remoteEndPoint;
            request.Secure          = secured;
            _currentRequest         = request;

            IsSecured          = secured;
            _stream            = stream;
            _clientCertificate = clientCertificate;
            _buffer            = new byte[bufferSize];
        }