Exemplo n.º 1
0
        internal ServerHttpTransport(Identity identity, Authentication authentication, bool useHttps, IEnvelopeStorage <Message> messageStorage, IEnvelopeStorage <Notification> notificationStorage, TimeSpan expirationInactivityInternal = default(TimeSpan))
        {
            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }
            if (messageStorage == null)
            {
                throw new ArgumentNullException(nameof(messageStorage));
            }
            if (notificationStorage == null)
            {
                throw new ArgumentNullException(nameof(notificationStorage));
            }

            _identity                     = identity;
            _authentication               = authentication;
            Compression                   = SessionCompression.None;
            Encryption                    = useHttps ? SessionEncryption.TLS : SessionEncryption.None;
            _messageStorage               = messageStorage;
            _notificationStorage          = notificationStorage;
            _expirationInactivityInternal = expirationInactivityInternal.Equals(default(TimeSpan)) ? TimeSpan.FromSeconds(60) : expirationInactivityInternal;
            Expiration                    = DateTimeOffset.UtcNow.Add(_expirationInactivityInternal);

            _authenticationTaskCompletionSource = new TaskCompletionSource <Session>();
            _closingTaskCompletionSource        = new TaskCompletionSource <Session>();
            _inputBufferBlock = new BufferBlock <Envelope>();
            _pendingNotificationsDictionary = new ConcurrentDictionary <string, Tuple <Event, TaskCompletionSource <Notification> > >();
            _pendingCommandsDictionary      = new ConcurrentDictionary <string, TaskCompletionSource <Command> >();
        }
        public DeleteEnvelopeByIdHttpProcessor(IEnvelopeStorage <T> envelopeStorage, string path)
        {
            _envelopeStorage = envelopeStorage;

            Methods = new HashSet <string> {
                Constants.HTTP_METHOD_DELETE
            };
            Template = new UriTemplate(string.Format("/{0}/{{id}}", path));
        }
Exemplo n.º 3
0
        public GetEnvelopesHttpProcessor(IEnvelopeStorage <T> envelopeStorage, string path)
        {
            _envelopeStorage = envelopeStorage;

            Methods = new HashSet <string> {
                Constants.HTTP_METHOD_GET
            };
            Template = new UriTemplate(string.Format("/{0}", path));
        }
        /// <summary>
        /// Creates a new instance of the HttpTransportListener class.
        /// </summary>
        /// <param name="port">The port for listening.</param>
        /// <param name="hostName">Name of the host for binding.</param>
        /// <param name="useHttps">if set to <c>true</c> the listener endpoint will use HTTPS.</param>
        /// <param name="requestTimeout">The request timeout.</param>
        /// <param name="writeExceptionsToOutput">if set to <c>true</c> the exceptions details will be written in the response body.</param>
        /// <param name="httpServer">The HTTP server instance.</param>
        /// <param name="httpTransportProvider">The HTTP transport provider instance.</param>
        /// <param name="serializer">The serializer instance.</param>
        /// <param name="messageStorage">The message storage instance.</param>
        /// <param name="notificationStorage">The notification storage instance.</param>
        /// <param name="processors">The processors.</param>
        /// <param name="traceWriter">The trace writer.</param>
        public HttpTransportListener(int port, string hostName  = "*", bool useHttps        = false, TimeSpan requestTimeout = default(TimeSpan), TimeSpan transportExpirationInactivityInterval = default(TimeSpan), bool writeExceptionsToOutput = true,
                                     int maxDegreeOfParallelism = 1, IHttpServer httpServer = null, IHttpTransportProvider httpTransportProvider = null, IDocumentSerializer serializer          = null, IEnvelopeStorage <Message> messageStorage = null,
                                     IEnvelopeStorage <Notification> notificationStorage = null, IHttpProcessor[] processors = null, ITraceWriter traceWriter = null)
        {
            _useHttps = useHttps;
            var scheme = _useHttps ? Uri.UriSchemeHttps : Uri.UriSchemeHttp;

            _writeExceptionsToOutput = writeExceptionsToOutput;
            _maxDegreeOfParallelism  = maxDegreeOfParallelism;
            _requestTimeout          = requestTimeout != default(TimeSpan) ? requestTimeout : TimeSpan.FromSeconds(Constants.DEFAULT_REQUEST_TIMEOUT);

            var basePath = string.Format("{0}://{1}:{2}", scheme, hostName, port);
            var prefixes = new string[]
            {
                Constants.ROOT + Constants.MESSAGES_PATH + Constants.ROOT,
                Constants.ROOT + Constants.COMMANDS_PATH + Constants.ROOT,
                Constants.ROOT + Constants.NOTIFICATIONS_PATH + Constants.ROOT
            };

            var fullPrefixes = prefixes.Select(p => basePath + p).ToArray();

            var safeHostName = hostName;

            if (hostName.Equals("*") || hostName.Equals("+"))
            {
                safeHostName = "localhost";
            }

            var baseUri = new Uri(string.Format("{0}://{1}:{2}", scheme, safeHostName, port));

            ListenerUris = prefixes
                           .Select(p => new Uri(baseUri, p))
                           .ToArray();

            _httpServer          = httpServer ?? new HttpServer(fullPrefixes, AuthenticationSchemes.Basic);
            _serializer          = serializer ?? new DocumentSerializer();
            _messageStorage      = messageStorage ?? new DictionaryEnvelopeStorage <Message>();
            _notificationStorage = notificationStorage ?? new DictionaryEnvelopeStorage <Notification>();
            _traceWriter         = traceWriter;

            transportExpirationInactivityInterval = transportExpirationInactivityInterval != default(TimeSpan) ? transportExpirationInactivityInterval : TimeSpan.FromSeconds(Constants.DEFAULT_TRANSPORT_EXPIRATION_INACTIVITY_INTERVAL);
            _httpTransportProvider = httpTransportProvider ?? new HttpTransportProvider(_useHttps, _messageStorage, _notificationStorage, transportExpirationInactivityInterval);
            _httpTransportProvider.TransportCreated += async(sender, e) => await _transportBufferBlock.SendAsync(e.Transport, _listenerCancellationTokenSource.Token).ConfigureAwait(false);

            // Context processors
            _uriTemplateTable = new UriTemplateTable(baseUri);
            if (processors == null)
            {
                processors = CreateProcessors();
            }
            foreach (var processor in processors)
            {
                _uriTemplateTable.KeyValuePairs.Add(new KeyValuePair <UriTemplate, object>(processor.Template, processor));
            }
            _uriTemplateTable.MakeReadOnly(true);
        }
Exemplo n.º 5
0
        public GetEnvelopeByIdHttpProcessorBase(IEnvelopeStorage <T> envelopeStorage, string path)
        {
            _envelopeStorage = envelopeStorage;
            _serializer      = new DocumentSerializer();

            Methods = new HashSet <string> {
                Constants.HTTP_METHOD_GET
            };
            Template = new UriTemplate(string.Format("/{0}/{{id}}", path));
        }
Exemplo n.º 6
0
        public HttpTransportProvider(bool useHttps, IEnvelopeStorage <Message> messageStorage, IEnvelopeStorage <Notification> notificationStorage,
                                     TimeSpan expirationInactivityInterval, TimeSpan expirationTimerInterval = default(TimeSpan), TimeSpan closeTransportTimeout = default(TimeSpan))
        {
            _useHttps                     = useHttps;
            _messageStorage               = messageStorage;
            _notificationStorage          = notificationStorage;
            _transportDictionary          = new ConcurrentDictionary <string, ITransportSession>();
            _expirationInactivityInterval = expirationInactivityInterval;
            _closeTransportTimeout        = closeTransportTimeout != default(TimeSpan) ? closeTransportTimeout : TimeSpan.FromSeconds(60);

            if (expirationTimerInterval.Equals(default(TimeSpan)))
            {
                expirationTimerInterval = TimeSpan.FromSeconds(5);
            }
            _expirationTimer          = new Timer(expirationTimerInterval.TotalMilliseconds);
            _expirationTimer.Elapsed += ExpirationTimer_Elapsed;
            _expirationTimer.Start();
        }
Exemplo n.º 7
0
 public GetMessageByIdHttpProcessor(IEnvelopeStorage <Message> messageStorage)
     : base(messageStorage, Constants.MESSAGES_PATH)
 {
     _serializer = new DocumentSerializer();
 }
 public GetNotificationByIdHttpProcessor(IEnvelopeStorage <Notification> notificationStorage)
     : base(notificationStorage, Constants.NOTIFICATIONS_PATH)
 {
 }
 public GetMessagesHttpProcessor(IEnvelopeStorage <Message> messageStorage)
     : base(messageStorage, Constants.MESSAGES_PATH)
 {
 }
Exemplo n.º 10
0
 public MockGetEnvelopeByIdHttpProcessorBase(IEnvelopeStorage <Envelope> envelopeStorage, string path)
     : base(envelopeStorage, path)
 {
     GetEnvelopeResponseFunc = (e, r) => null;
 }
Exemplo n.º 11
0
 public DeleteMessageByIdHttpProcessor(IEnvelopeStorage <Message> messageStorage)
     : base(messageStorage, Constants.MESSAGES_PATH)
 {
 }