Ejemplo n.º 1
0
        private string GetEncryptedLocalSession(SiteInfo siteInfo, User user, ServerSession session)
        {
            var lsession   = GetLocalSession(siteInfo, user, session);
            var sessionStr = jsonConvert.Serialize(lsession);

            authEncrypt.Key = siteInfo.EncryptKey;
            authEncrypt.IV  = siteInfo.EncryptSecret;
            return(authEncrypt.Encrypt(sessionStr));
        }
Ejemplo n.º 2
0
        public async void OnEvenAdded(object?sender, EventAddedEventArgs args)
        {
            if (!(sender is Thing thing))
            {
                _logger.LogWarning("The sender is not a Thing, not going to notify.");
                return;
            }

            if (thing.ThingContext.EventsSubscribes[args.EventName].IsEmpty)
            {
                _logger.LogTrace("No subscriber for this event.  [Thing: {thingName}][Event: {eventName}]",
                                 thing.Name, args.EventName);
                return;
            }

            var message = _convert.Serialize(new WebSocketResponse("event",
                                                                   new Dictionary <string, object?>
            {
                [_option.PropertyNamingPolicy.ConvertName(args.EventName)] = args.Event
            }));

            _logger.LogInformation("Going to notify event via Web Socket. [Thing: {thingName}][Event: {eventName}]",
                                   thing.Name, args.EventName);

            foreach (var(_, socket) in thing.ThingContext.EventsSubscribes[args.EventName].ToArray())
            {
                if (socket.State != WebSocketState.Open || socket.CloseStatus.HasValue)
                {
                    _logger.LogInformation("The Web Socket is not open or was requested to close. [Thing: {thingName}][Event: {eventName}]",
                                           thing.Name, args.EventName);
                    return;
                }

                await socket.SendAsync(message, WebSocketMessageType.Text, true, CancellationToken.None)
                .ConfigureAwait(false);
            }
        }