Exemplo n.º 1
0
        protected override ITransportServer CreateTransport(KeyValueCollection parameters)
        {
            var queueServerName      = parameters["QueueServerName"];
            var enableGetDescriptors = parameters["EnableGetDescriptors"].ParseTo(true);
            var serializerMimeType   = parameters["SerializerMimeType"];
            var compressorEncoding   = parameters["CompressorEncoding"];
            var serializer           = SerializerManager.GetByMimeType(serializerMimeType);

            if (serializer != null && compressorEncoding.IsNotNullOrEmpty())
            {
                var compressor = CompressorManager.GetByEncodingType(compressorEncoding);
                if (compressor != null)
                {
                    serializer.Compressor = compressor;
                }
            }
            Core.Log.LibDebug("Creating a new MessagingTransportServer with the parameters:");
            Core.Log.LibDebug("\tQueueServerName: {0}", queueServerName.IsNotNullOrWhitespace() ?
                              queueServerName :
                              "Using Default QueueServer from configuration file.");
            Core.Log.LibDebug("\tEnableGetDescriptors: {0}", enableGetDescriptors);
            if (serializerMimeType != null)
            {
                Core.Log.LibDebug("\tSerializer: {0}", serializer);
                if (serializer?.Compressor != null)
                {
                    Core.Log.LibDebug("\tCompressorEncoding: {0}", compressorEncoding);
                }
            }
            var queueServer = queueServerName.IsNotNullOrWhitespace()
                ? Core.Services.GetQueueServer(queueServerName)
                : Core.Services.GetQueueServer();

            return(new MessagingTransportServer(queueServer, serializer));
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        /// <summary>
        /// Create a new storage from a KeyValueCollection parameters
        /// </summary>
        /// <param name="parameters">Parameters to create the storage</param>
        /// <returns>Storage</returns>
        protected override StorageBase CreateStorage(KeyValueCollection parameters)
        {
            var basePath = parameters["BasePath"];
            var indexSerializerMimeType = parameters["IndexSerializerMimeType"] ?? SerializerMimeTypes.WBinary;
            var numberOfSubFolder       = parameters["NumberOfSubFolder"].ParseTo((byte)25);
            var transactionLogThreshold = parameters["TransactionLogThreshold"].ParseTo(250);
            var slowDownWriteThreshold  = parameters["SlowDownWriteThreshold"].ParseTo(1000);
            var storageType             = parameters["StorageType"].ParseTo(FileStorageType.Normal);
            var indexSerializer         = SerializerManager.GetByMimeType <ISerializer>(indexSerializerMimeType);

            SerializerManager.SupressFileExtensionWarning = true;

            switch (storageType)
            {
            case FileStorageType.Normal:
                Core.Log.LibDebug("Creating a new FileStorage with the parameters:");
                Core.Log.LibDebug("\tBasePath: {0}", basePath);
                Core.Log.LibDebug("\tNumberOfSubFolders: {0}", numberOfSubFolder);
                Core.Log.LibDebug("\tTransactionLogThreshold: {0}", transactionLogThreshold);
                Core.Log.LibDebug("\tSlowDownWriteThreshold: {0}", slowDownWriteThreshold);
                Core.Log.LibDebug("\tIndexSerializer: {0}", indexSerializer);
                return(new FileStorage(basePath)
                {
                    NumberOfSubFolders = numberOfSubFolder,
                    TransactionLogThreshold = transactionLogThreshold,
                    SlowDownWriteThreshold = slowDownWriteThreshold,
                    IndexSerializer = (BinarySerializer)indexSerializer
                });
            }
            return(null);
        }
Exemplo n.º 3
0
        public void Init(MQPairConfig config, bool sendOnly)
        {
            if (config is null)
            {
                return;
            }

            Config   = config;
            SendOnly = sendOnly;
            Name     = Config.Name;
            Counters = new MQClientCounters(Name, Config.IgnoreClientCounters);

            SenderSerializer = SerializerManager.GetByMimeType(Config.RequestOptions?.SerializerMimeType);
            if (SenderSerializer != null && Config.RequestOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true)
            {
                SenderSerializer.Compressor = CompressorManager.GetByEncodingType(Config.RequestOptions?.CompressorEncodingType);
            }
            ReceiverSerializer = SerializerManager.GetByMimeType(Config.ResponseOptions?.SerializerMimeType);
            if (ReceiverSerializer != null && Config.ResponseOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true)
            {
                ReceiverSerializer.Compressor = CompressorManager.GetByEncodingType(Config.ResponseOptions?.CompressorEncodingType);
            }

            OnInit();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds all defined routes on a HttpController type
        /// </summary>
        /// <typeparam name="T">Type of HttpControllerBase</typeparam>
        /// <returns>SimpleHttpServer instance</returns>
        public SimpleHttpServer AddHttpControllerRoutes <T>() where T : HttpControllerBase
        {
            var type    = typeof(T);
            var methods = type.GetRuntimeMethods();

            methods.Each(m =>
            {
                var routes = m.GetCustomAttributes <HttpRouteAttribute>().ToArray();
                if (routes?.Any() == true)
                {
                    routes.Each(route => AddRouteHandler(route.Method, route.Url, context =>
                    {
                        var ctl     = Activator.CreateInstance <T>();
                        ctl.Context = context;
                        var mParams = m.GetParameters();
                        if (mParams.Length > 0)
                        {
                            ParameterInfo postObjectParam = null;
                            object postObject             = null;
                            var ivkParams = new List <object>();
                            if (context.Request.HasPostObject)
                            {
                                postObjectParam = mParams.FirstOrDefault(p => p.GetCustomAttribute(typeof(PostObjectAttribute)) != null);
                                if (postObjectParam == null && mParams.Length == 1)
                                {
                                    postObjectParam = mParams[0];
                                }
                                if (postObjectParam != null)
                                {
                                    postObject = Try.Do(() => context.Request.GetPostObject(postObjectParam.ParameterType));
                                }
                            }
                            var dictionary = context.Route.GetRouteParameters(context.Request.Url.AbsolutePath);
                            foreach (var mParam in mParams)
                            {
                                if (mParam == postObjectParam)
                                {
                                    ivkParams.Add(postObject);
                                }
                                else if (dictionary.ContainsKey(mParam.Name))
                                {
                                    ivkParams.Add(dictionary[mParam.Name]);
                                }
                                else
                                {
                                    ivkParams.Add(null);
                                }
                            }

                            var response = m.Invoke(ctl, ivkParams.ToArray());
                            if (response == null)
                            {
                                return;
                            }
                            var serializer = SerializerManager.GetByMimeType(ctl.Context.Response.ContentType);
                            switch (serializer)
                            {
                            case null when response is string:
                                ctl.Context.Response.Write((string)response);
                                break;
Exemplo n.º 5
0
        protected override ITransportClient CreateTransport(KeyValueCollection parameters)
        {
            var queueClientName    = parameters["QueueClientName"];
            var serializerMimeType = parameters["SerializerMimeType"];
            var compressorEncoding = parameters["CompressorEncoding"];
            var serializer         = SerializerManager.GetByMimeType(serializerMimeType);

            if (serializer != null && compressorEncoding.IsNotNullOrEmpty())
            {
                var compressor = CompressorManager.GetByEncodingType(compressorEncoding);
                if (compressor != null)
                {
                    serializer.Compressor = compressor;
                }
            }
            Core.Log.LibDebug("Creating a new MessagingTransportServer with the parameters:");
            Core.Log.LibDebug("\tQueueClientName: {0}", queueClientName);
            if (serializerMimeType != null)
            {
                Core.Log.LibDebug("\tSerializer: {0}", serializer);
                if (serializer?.Compressor != null)
                {
                    Core.Log.LibDebug("\tCompressorEncoding: {0}", compressorEncoding);
                }
            }
            Ensure.ArgumentNotNull(queueClientName, "The QueueClientName parameter in the MessagingTransportClientFactory can't be null.");
            var queueClient = Core.Services.GetQueueClient(queueClientName);

            return(new MessagingTransportClient(queueClient, serializer));
        }
Exemplo n.º 6
0
        protected override ITransportClient CreateTransport(KeyValueCollection parameters)
        {
            var url = parameters["Url"];
            var serializerMimeType = parameters["SerializerMimeType"];
            var serializer         = SerializerManager.GetByMimeType(serializerMimeType);

            Core.Log.LibDebug("Creating a new HttpTransportClient with the parameters:");
            Core.Log.LibDebug("\tUrl: {0}", url);
            Core.Log.LibDebug("\tSerializer: {0}", serializer);
            return(new HttpTransportClient(url, serializer));
        }
Exemplo n.º 7
0
        protected override ITransportClient CreateTransport(KeyValueCollection parameters)
        {
            var host = parameters["Host"];

            if (host == null || host == Factory.SkipInstanceValue)
            {
                Core.Log.Warning("Skipping transport instance by Host value.");
                return(null);
            }
            var strPort = parameters["Port"];

            if (strPort == null || strPort == Factory.SkipInstanceValue)
            {
                Core.Log.Warning("Skipping transport instance by Port value.");
                return(null);
            }
            var port = strPort.ParseTo(0);

            var timeout            = parameters["Timeout"].ParseTo(20000);
            var serializerMimeType = parameters["SerializerMimeType"];
            var socketsPerClient   = parameters["SocketsPerClient"].ParseTo <byte>(1);
            var compressorEncoding = parameters["CompressorEncoding"];
            var serializer         = SerializerManager.GetByMimeType(serializerMimeType);

            if (compressorEncoding.IsNotNullOrEmpty())
            {
                var compressor = CompressorManager.GetByEncodingType(compressorEncoding);
                if (compressor != null)
                {
                    serializer.Compressor = compressor;
                }
            }
            var lclient = new DefaultTransportClient(host, port, socketsPerClient, serializer)
            {
                InvokeMethodTimeout = timeout
            };
            ITransportClient client = lclient;

            Core.Log.LibDebug("Creating a new DefaultTransportClient with parameters:");
            Core.Log.LibDebug("\tHost: {0}", host);
            Core.Log.LibDebug("\tPort: {0}", port);
            Core.Log.LibDebug("\tSocketsPerClient: {0}", socketsPerClient);
            if (serializerMimeType == null)
            {
                return(client);
            }
            Core.Log.LibDebug("\tSerializer: {0}", serializer);
            if (serializer?.Compressor != null)
            {
                Core.Log.LibDebug("\tCompressorEncoding: {0}", compressorEncoding);
            }
            return(client);
        }
Exemplo n.º 8
0
        protected override ITransportServer CreateTransport(KeyValueCollection parameters)
        {
            var port = parameters["Port"].ParseTo(0);
            var enableGetDescriptors = parameters["EnableGetDescriptors"].ParseTo(true);
            var serializerMimeType   = parameters["SerializerMimeType"];
            var serializer           = SerializerManager.GetByMimeType(serializerMimeType);

            Core.Log.LibDebug("Creating a new HttpTransportServer with the parameters:");
            Core.Log.LibDebug("\tPort: {0}", port);
            Core.Log.LibDebug("\tEnableGetDescriptors: {0}", enableGetDescriptors);
            Core.Log.LibDebug("\tSerializer: {0}", serializer);
            return(new HttpTransportServer(port, serializer, enableGetDescriptors));
        }
Exemplo n.º 9
0
        public RestClient(string baseUrl = null, ISerializer serializer = null)
        {
            var handler = new DecompressionHandler
            {
                InnerHandler = new HttpClientHandler()
            };

            _client = new HttpClient(handler);
            if (baseUrl.IsNotNullOrEmpty())
            {
                _client.BaseAddress = new Uri(baseUrl);
            }
            Serializer = serializer ?? (SerializerManager.GetByMimeType <ITextSerializer>(SerializerMimeTypes.Json) ?? SerializerManager.DefaultTextSerializer);
        }
Exemplo n.º 10
0
        public void Init(MQPairConfig config)
        {
            if (config == null)
            {
                return;
            }
            Config = config;

            Name             = Config.Name;
            SenderSerializer = SerializerManager.GetByMimeType(Config.RequestOptions?.SerializerMimeType);
            if (SenderSerializer != null && Config.RequestOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true)
            {
                SenderSerializer.Compressor = CompressorManager.GetByEncodingType(Config.RequestOptions?.CompressorEncodingType);
            }
            ReceiverSerializer = SerializerManager.GetByMimeType(Config.ResponseOptions?.SerializerMimeType);
            if (ReceiverSerializer != null && Config.ResponseOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true)
            {
                ReceiverSerializer.Compressor = CompressorManager.GetByEncodingType(Config.ResponseOptions?.CompressorEncodingType);
            }

            OnInit();
        }
Exemplo n.º 11
0
        protected override ITransportServer CreateTransport(KeyValueCollection parameters)
        {
            var strPort = parameters["Port"];

            if (strPort == null || strPort == Factory.SkipInstanceValue)
            {
                Core.Log.Warning("Skipping transport instance by Port value.");
                return(null);
            }
            var port = strPort.ParseTo(0);
            var serializerMimeType = parameters["SerializerMimeType"];
            var compressorEncoding = parameters["CompressorEncoding"];
            var serializer         = SerializerManager.GetByMimeType(serializerMimeType);

            if (compressorEncoding.IsNotNullOrEmpty())
            {
                var compressor = CompressorManager.GetByEncodingType(compressorEncoding);
                if (compressor != null)
                {
                    serializer.Compressor = compressor;
                }
            }
            var tServer = new DefaultTransportServer(port, serializer);

            Core.Log.LibDebug("Creating a new DefaultTransportServer with parameters:");
            Core.Log.LibDebug("\tPort: {0}", port);
            if (serializerMimeType != null)
            {
                Core.Log.LibDebug("\tSerializer: {0}", serializer);
                if (serializer?.Compressor != null)
                {
                    Core.Log.LibDebug("\tCompressorEncoding: {0}", compressorEncoding);
                }
            }
            return(tServer);
        }
Exemplo n.º 12
0
        public void StartListeners()
        {
            if (_tokenSource != null)
            {
                StopListeners();
            }

            Core.Log.InfoBasic("Configuring server mode for {0} with ResponseServer = {1}", Name, ResponseServer);
            if (ResponseServer)
            {
                ReceiverSerializer = SerializerManager.GetByMimeType(Config.ResponseOptions?.SerializerMimeType);
                if (ReceiverSerializer != null && Config.ResponseOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true)
                {
                    ReceiverSerializer.Compressor = CompressorManager.GetByEncodingType(Config.ResponseOptions?.CompressorEncodingType);
                }

                SenderSerializer = null;

                Core.Log.InfoBasic("Adding queue client listener for {0}, Environment: {1}", Name, Core.EnvironmentName);
                _clientQueues = Config.ClientQueues?.FirstOf(
                    c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                    c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true,
                    c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                    c => c.EnvironmentName.IsNullOrWhitespace());

                if (_clientQueues?.RecvQueue != null)
                {
                    var queueListener = OnCreateQueueServerListener(_clientQueues.RecvQueue, ResponseServer);
                    queueListener.ResponseReceived += QueueListener_ResponseReceived;
                    QueueServerListeners.Add(queueListener);
                }
                else
                {
                    Core.Log.Warning("There aren't any Receiver Queue for the Client Listener. Check the ClientQueues element on the queue config file.");
                }
            }
            else
            {
                ReceiverSerializer = SerializerManager.GetByMimeType(Config.RequestOptions?.SerializerMimeType);
                if (ReceiverSerializer != null && Config.RequestOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true)
                {
                    ReceiverSerializer.Compressor = CompressorManager.GetByEncodingType(Config.RequestOptions?.CompressorEncodingType);
                }

                SenderSerializer = SerializerManager.GetByMimeType(Config.ResponseOptions?.SerializerMimeType);
                if (SenderSerializer != null && Config.ResponseOptions?.CompressorEncodingType.IsNotNullOrEmpty() == true)
                {
                    SenderSerializer.Compressor = CompressorManager.GetByEncodingType(Config.ResponseOptions?.CompressorEncodingType);
                }


                Core.Log.InfoBasic("Adding queue server listeners for {0}, Environment: {1}", Name, Core.EnvironmentName);
                _serverQueues = Config.ServerQueues?.FirstOf(
                    c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                    c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true,
                    c => c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                    c => c.EnvironmentName.IsNullOrWhitespace());

                if (_serverQueues?.RecvQueues?.Any() == true)
                {
                    _serverQueues.RecvQueues.Each(queue =>
                    {
                        var queueListener              = OnCreateQueueServerListener(queue, ResponseServer);
                        queueListener.RequestReceived += QueueListener_RequestReceived;
                        QueueServerListeners.Add(queueListener);
                    });
                }
                else
                {
                    Core.Log.Warning("There aren't any Receiver Queue for the Server Listeners. Check the ServerQueues element on the queue config file.");
                }
            }

            if (QueueServerListeners.Count > 0)
            {
                Core.Log.InfoBasic("Starting queue server listeners for {0}", Name);
                _tokenSource = new CancellationTokenSource();
                _listenerTasks.Clear();

                foreach (var listener in QueueServerListeners)
                {
                    _listenerTasks.Add(InitListener(listener));
                }
            }
            else
            {
                Core.Log.Warning("There are not server listener to start.");
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the cache client connection pool
        /// </summary>
        /// <param name="name">Cache name</param>
        /// <returns>Cache client pool</returns>
        public async Task <CacheClientPoolAsync> GetCacheClientAsync(string name)
        {
            if (Caches?.Contains(name) != true)
            {
                return(null);
            }
            var cacheConfig = Caches[name];
            var cConfig     = cacheConfig.ClientOptionsList?.FirstOf(
                c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true && c.MachineName?.SplitAndTrim(",").Contains(Core.MachineName) == true,
                c => c.EnvironmentName?.SplitAndTrim(",").Contains(Core.EnvironmentName) == true,
                c => c.EnvironmentName.IsNullOrWhitespace());

            if (cConfig?.Pool == null)
            {
                return(null);
            }
            var         pingDelay        = cConfig.Pool.PingDelay.ParseTo(5000);
            var         pingDelayOnError = cConfig.Pool.PingDelayOnError.ParseTo(30000);
            var         readMode         = cConfig.Pool.ReadMode;
            var         writeMode        = cConfig.Pool.WriteMode;
            var         selectionOrder   = cConfig.Pool.SelectionOrder;
            var         forceNetworkItem = cConfig.Pool.ForceAtLeastOneNetworkItemEnabled;
            ISerializer serializer;

            if (cConfig.Pool.SerializerMimeType.IsNotNullOrEmpty())
            {
                serializer = SerializerManager.GetByMimeType(cConfig.Pool.SerializerMimeType);
                Ensure.ReferenceNotNull(serializer, $"The Serializer \"{cConfig.Pool.SerializerMimeType}\" couldn't be loaded.");
                if (cConfig.Pool.CompressorEncoding.IsNotNullOrEmpty())
                {
                    serializer.Compressor = CompressorManager.GetByEncodingType(cConfig.Pool.CompressorEncoding);
                }
            }
            else
            {
                serializer = SerializerManager.DefaultBinarySerializer;
            }
            var ccp = new CacheClientPoolAsync(name, pingDelay, pingDelayOnError, readMode, writeMode, selectionOrder)
            {
                Serializer = serializer,
                ForceAtLeastOneNetworkItemEnabled = forceNetworkItem
            };

            if (cConfig.Pool.Items?.Any() != true)
            {
                return(ccp);
            }

            var idx = 0;

            foreach (var pitem in cConfig.Pool.Items)
            {
                idx++;
                if (!pitem.Enabled)
                {
                    continue;
                }

                var objType = pitem.CreateInstance <object>();
                switch (objType)
                {
                case ITransportClient transport:
                {
                    var hostParam = pitem.Parameters?.FirstOrDefault(p => p.Key == "Host");
                    var portParam = pitem.Parameters?.FirstOrDefault(p => p.Key == "Port");

                    var proxy = await CacheClientProxy.GetClientAsync(transport).ConfigureAwait(false);

                    var cppName = Core.EnvironmentName + "." + Core.MachineName + "." + name + ".Storage(" + transport.GetType().Name + "-" + hostParam?.Value + "-" + portParam?.Value + ")." + idx;
                    ccp.Add(cppName, (IStorageAsync)proxy, pitem.Mode);
                    break;
                }

                case StorageBase sto:
                {
                    var cppName = Core.EnvironmentName + "." + Core.MachineName + "." + name + ".Storage(" + sto.Type + ")." + idx;
                    ccp.Add(cppName, sto);
                    break;
                }
                }
            }
            return(ccp);
        }
Exemplo n.º 14
0
        public T GetPostObject <T>()
        {
            var serializer = SerializerManager.GetByMimeType(ContentType);

            return(serializer != null?serializer.Deserialize <T>(PostData) : default);
Exemplo n.º 15
0
        public object GetPostObject(Type type)
        {
            var serializer = SerializerManager.GetByMimeType(ContentType);

            return(serializer?.Deserialize(PostData, type));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Adds all defined routes on a HttpController type
        /// </summary>
        /// <typeparam name="T">Type of HttpControllerBase</typeparam>
        /// <returns>SimpleHttpServer instance</returns>
        public SimpleHttpServer AddHttpControllerRoutes <T>() where T : HttpControllerBase
        {
            var type    = typeof(T);
            var methods = type.GetRuntimeMethods();

            foreach (var m in methods)
            {
                var routes = m.GetCustomAttributes <HttpRouteAttribute>().ToArray();
                if (routes.Any())
                {
                    foreach (var route in routes)
                    {
                        AddRouteHandler(route.Method, route.Url, async context =>
                        {
                            var ctl     = Activator.CreateInstance <T>();
                            ctl.Context = context;
                            var mParams = m.GetParameters();
                            if (mParams.Length > 0)
                            {
                                ParameterInfo postObjectParam = null;
                                object postObject             = null;
                                var ivkParams = new List <object>();
                                if (context.Request.HasPostObject)
                                {
                                    postObjectParam = mParams.FirstOrDefault(p => p.GetCustomAttribute(typeof(PostObjectAttribute)) != null);
                                    if (postObjectParam is null && mParams.Length == 1)
                                    {
                                        postObjectParam = mParams[0];
                                    }
                                    if (postObjectParam != null)
                                    {
                                        postObject = Try.Do(() => context.Request.GetPostObject(postObjectParam.ParameterType));
                                    }
                                }

                                var dictionary = context.Route.GetRouteParameters(context.Request.Url.AbsolutePath);
                                foreach (var mParam in mParams)
                                {
                                    if (mParam == postObjectParam)
                                    {
                                        ivkParams.Add(postObject);
                                    }
                                    else if (dictionary.ContainsKey(mParam.Name))
                                    {
                                        ivkParams.Add(dictionary[mParam.Name]);
                                    }
                                    else
                                    {
                                        ivkParams.Add(null);
                                    }
                                }

                                var response = m.Invoke(ctl, ivkParams.ToArray());
                                if (response is null)
                                {
                                    return;
                                }
                                var serializer = SerializerManager.GetByMimeType(ctl.Context.Response.ContentType);
                                switch (serializer)
                                {
                                case null when response is string:
                                    await ctl.Context.Response.WriteAsync((string)response).ConfigureAwait(false);
                                    break;

                                case null when response is ValueType:
                                    ctl.Context.Response.Write(response.ToString());
                                    break;

                                case null:
                                    serializer = SerializerManager.GetByMimeType(SerializerMimeTypes.Json);
                                    break;
                                }

                                if (serializer != null)
                                {
                                    Try.Do(() => serializer.Serialize(response, response.GetType(), ctl.Context.Response.OutputStream), ex =>
                                    {
                                        var sEx = new SerializableException(ex);
                                        serializer.Serialize(sEx, sEx.GetType(), ctl.Context.Response.OutputStream);
                                    });
                                    await ctl.Context.Response.OutputStream.FlushAsync().ConfigureAwait(false);
                                }
                            }
                            else
                            {
                                var response = m.Invoke(ctl, new object[0]);
                                if (response is null)
                                {
                                    return;
                                }
                                var serializer = SerializerManager.GetByMimeType(ctl.Context.Response.ContentType);
                                switch (serializer)
                                {
                                case null when response is string:
                                    await ctl.Context.Response.WriteAsync((string)response).ConfigureAwait(false);
                                    break;

                                case null when response is ValueType:
                                    ctl.Context.Response.Write(response.ToString());
                                    break;

                                case null:
                                    serializer = SerializerManager.GetByMimeType(SerializerMimeTypes.Json);
                                    break;
                                }

                                if (serializer != null)
                                {
                                    Try.Do(() => serializer.Serialize(response, response.GetType(), ctl.Context.Response.OutputStream), ex =>
                                    {
                                        var sEx = new SerializableException(ex);
                                        serializer.Serialize(sEx, sEx.GetType(), ctl.Context.Response.OutputStream);
                                    });
                                    await ctl.Context.Response.OutputStream.FlushAsync().ConfigureAwait(false);
                                }
                            }
                        });
                    }
                }
            }
            ;
            return(this);
        }