public async Task <IActionResult> SendAsync([FromBody] SimpleCacheItem model)
        {
            var echo             = $"Echo from server '{model.Id}' '{model.Name}' - {DateTime.Now}";
            var obj              = new { message = echo };
            var webSocketContext = new WebSocketMessageContext {
                Command = WebSocketCommands.DataSend, Value = obj
            };
            await _connectionManager.BroadcastAsync(webSocketContext);

            return(Ok());
        }
Exemple #2
0
        public async Task InvokeAsync(WebSocketMessageContext context)
        {
            if (context.MessageType == WebSocketMessageType.Text)
            {
            }

            if (context.MessageType == WebSocketMessageType.Binary)
            {
                var header = context.Header as Dictionary <string, object>;
                if (header != null)
                {
                    object key = null;
                    if (header.TryGetValue(WebSocketHeaderNames.CacheItemKey, out key))
                    {
                        await Task.Run(() => _cacheProvider.SetObject(key.ToString(),
                                                                      context.Value,
                                                                      new MemoryCacheEntryOptions {
                            Priority = CacheItemPriority.NeverRemove
                        }));
                    }
                }
                var    length = context.Length;
                double size   = (length / 1024f) / 1024f;
                context.Value = $"{size} MB <<binary>>";
            }

            // Sending incoming data from Backend zone to the Clients (Browsers)
            await _connectionManager.BroadcastAsync(context);
        }
 public static async Task WsErrorLog(this IConnectionManager connectionManager, Exception ex)
 {
     await connectionManager.BroadcastAsync(new WebSocketMessageContext
     {
         Command     = WebSocketCommands.DataSend,
         Value       = new { resultState = "error", message = ex.Message },
         MessageType = WebSocketMessageType.Text
     });
 }
 public static async Task WsLogAsync(this IConnectionManager connectionManager, string message)
 {
     await connectionManager.BroadcastAsync(new WebSocketMessageContext
     {
         Command     = WebSocketCommands.DataSend,
         Value       = new { resultState = "success", message },
         MessageType = WebSocketMessageType.Text
     });
 }
Exemple #5
0
        public async Task InvokeAsync(WebSocketMessageContext context)
        {
            if (context.Command == WebSocketCommands.Connect)
            {
            }

            // Sending incoming data from Backend zone to the Clients (Browsers)
            await _connectionManager.BroadcastAsync(context);
        }
 public static async Task WsTransformCompleted(this IConnectionManager connectionManager)
 {
     await connectionManager.BroadcastAsync(new WebSocketMessageContext
     {
         Command     = WebSocketCommands.DataSend,
         Header      = new RouteValueDictionary(new { completed = true }),
         Value       = new { resultState = "completed", message = "Transform completed" },
         MessageType = WebSocketMessageType.Text
     });
 }
        public IActionResult Broadcast([FromBody] BroadcastMessageContext context)
        {
            var messageContext = new WebSocketMessageContext
            {
                Command = WebSocketCommands.DataSend,
                Value   = context
            };

            _connectionManager.BroadcastAsync(messageContext);
            return(Json(messageContext));
        }
Exemple #8
0
        public async Task <ApiResult> BroadcastAsync([FromBody] BroadcastContext context)
        {
            await _connectionManager.BroadcastAsync(new WebSocketMessageContext
            {
                Command     = WebSocketCommands.DataSend,
                MessageType = WebSocketMessageType.Text,
                Value       = context
            });

            return(new ApiResult());
        }
        public async Task InvokeAsync(WebSocketMessageContext context)
        {
            await Task.CompletedTask;

            if (context.MessageType == WebSocketMessageType.Text)
            {
                await _connectionManager.BroadcastAsync(context);

                return;
            }

            if (context.MessageType == WebSocketMessageType.Binary)
            {
            }
        }
        public async Task InvokeAsync(WebSocketMessageContext context)
        {
            if (context.MessageType == WebSocketMessageType.Text)
            {
            }

            if (context.MessageType == WebSocketMessageType.Binary)
            {
                if (context.Header is Dictionary <string, object> stateDictionary)
                {
                }
            }

            await _connectionManager.BroadcastAsync(context);
        }
        public async Task InvokeAsync(WebSocketMessageContext context)
        {
            await Task.CompletedTask;

            if (context.MessageType == WebSocketMessageType.Text)
            {
                await _connectionManager.BroadcastAsync(context);

                return;
            }

            if (context.MessageType == WebSocketMessageType.Binary)
            {
                var stateDictionary = context.Header as Dictionary <string, object>;
                if (stateDictionary != null)
                {
                    object key = null;
                    if (stateDictionary.TryGetValue("Key", out key))
                    {
                        var keyStr     = key.ToString();
                        var descriptor = CacheHelper.GetDescriptor(key.ToString());
                        try
                        {
                            var genericList = descriptor.Type.CreateElementTypeAsGenericList();
                            var value       = context.Value;
                            _cacheProvider.SetObject(keyStr, value, new MemoryCacheEntryOptions {
                                Priority = CacheItemPriority.NeverRemove
                            });

#if DEBUG
                            var length  = context.Length;
                            var message = $"===Sandbox: {Environment.MachineName}===Key: {keyStr}===Length: {length}===";
                            _logger.LogDebug(message);
#endif
                        }
                        catch (Exception ex)
                        {
#if DEBUG
                            var length  = context.Length;
                            var message = $"===Exception: {ex.Message}===Sandbox: {Environment.MachineName}===Key: {keyStr}===Length: {length}===";
                            _logger.LogError(message);
#endif
                        }
                    }
                }
            }
        }
Exemple #12
0
 public async Task InvokeAsync(WebSocketMessageContext context)
 {
     var connection = context.GetConnectionId();
     await _connectionManager.BroadcastAsync(context);
 }
 public async Task InvokeAsync(WebSocketMessageContext context)
 {
     await _connectionManager.BroadcastAsync(context);
 }
Exemple #14
0
 public Task InvokeAsync(WebSocketMessageContext context)
 {
     // Sending incoming data from backend to the Browser(s)
     _connectionManager.BroadcastAsync(context);
     return(Task.CompletedTask);
 }