Exemplo n.º 1
0
        private BlazeMessageData EncodeNotification(BlazeNotification notification)
        {
            _blazeTypeLookup.TryGetResponseComponentCommand(notification.GetType(), out var component, out var command);

            var header = new BlazeHeader
            {
                Component   = component,
                Command     = command,
                MessageId   = 0, //always 0
                MessageType = BlazeMessageType.Notification,
                ErrorCode   = notification.BlazeErrorCode
            };

            //TODO: remove stream
            var notificationOutput = new MemoryStream();

            _blazeSerializer.Serialize(notificationOutput, notification);
            var messageData = new BlazeMessageData
            {
                Header  = header,
                Payload = new ReadOnlySequence <byte>(notificationOutput.ToArray())
            };

            return(messageData);
        }
Exemplo n.º 2
0
        public Task EnqueueNotification(BlazeNotification notification)
        {
            var currentUserContext = _clientContext as BlazeClientContext;

            if (currentUserContext == null)
            {
                Logger.Warn($"Current User has no context");
                return(Task.CompletedTask);
            }

            var messageData = EncodeNotification(notification);

            currentUserContext.PendingNotifications.Enqueue(messageData);
            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        public Task EnqueueNotification(uint userId, BlazeNotification notification)
        {
            var userContext = _clientManager.GetByUserId(userId) as BlazeClientContext;

            if (userContext == null)
            {
                Logger.Warn($"User {userId} is not connected");
                return(Task.CompletedTask);
            }

            var messageData = EncodeNotification(notification);

            userContext.PendingNotifications.Enqueue(messageData);
            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
        public async Task SendNotification(BlazeNotification notification)
        {
            var currentUserContext = _clientContext as BlazeClientContext;

            if (currentUserContext == null)
            {
                Logger.Warn($"Current User has no context");
                return;
            }

            var messageData = EncodeNotification(notification);

            if (currentUserContext.Writer != null)
            {
                await currentUserContext.Writer.WriteAsync(_protocol, messageData);
            }
        }
Exemplo n.º 5
0
        public async Task SendNotification(uint userId, BlazeNotification notification)
        {
            var userContext = _clientManager.GetByUserId(userId) as BlazeClientContext;

            if (userContext == null)
            {
                Logger.Warn($"User {userId} is not connected");
                return;
            }

            var messageData = EncodeNotification(notification);

            if (userContext.Writer != null)
            {
                await userContext.Writer.WriteAsync(_protocol, messageData);
            }
        }