public async Task ReceiveAsync()
        {
            var result = await Client.ReceiveAsync();

            var endPoint = result.RemoteEndPoint.ToString();

            try
            {
                NotificationPayload payload = _factory.Create(result.Buffer);
                _logger.LogInformation($"Recieve Result: {endPoint} => {payload}");

                switch (payload.Notification)
                {
                case Notifications.Error:
                    _logger.LogWarning($"Error from: {endPoint} => {payload}");
                    break;

                case Notifications.Connect:
                    //Register new Session in storage
                    _repository.GetOrAddSession(endPoint);
                    break;

                case Notifications.Disconnect:
                    //Remove session from storage
                    _repository.Remove(endPoint);
                    break;

                case Notifications.Notify:
                    // Add message to the  queue and Start processing message => ProcessWork()
                    _messageQueue.TryAdd(new KeyValuePair <string, NotificationPayload>(endPoint, payload));
                    break;

                default:
                    break;
                }
            }
            catch (JsonException x)
            {
                _logger.LogError(x, $"{nameof(JsonException)}");
                throw x;
            }
            catch (FormatException x)
            {
                _logger.LogError(x, $"{nameof(FormatException)}");
                throw x;
            }
            catch (InvalidOperationException x)
            {
                throw new InvalidOperationException($"Blocking operations exception - {nameof(ReceiveAsync)}", x);
            }
        }
Exemplo n.º 2
0
        public string Create(string notificationId, NotificationOptions options)
        {
            var notification = notificationFactory.Create(notificationId, options);

            eventAggregator
            .GetEvent <NotificationEvents.AddNotification>()
            .Publish(notification);

            return(notification.NotificationId);
        }
Exemplo n.º 3
0
        private void ShowSample(Position position, int monitorIndex)
        {
            var notificationOneOptions = new NotificationOptions
            {
                BackgroundColor = "ff0000",
                Group           = "one",
                IsPersistent    = true,
                Message         = "This is how an alert will look at this position.",
                Title           = "First Sample Alert",
            };

            var notificationOne = notificationFactory.Create(notificationOneOptions);

            var notificationTwoOptions = new NotificationOptions
            {
                Group        = "two",
                IsPersistent = true,
                Message      = "Alert positioning affects the order.",
                Title        = "Second Sample Alert",
            };

            var notificationTwo = notificationFactory.Create(notificationTwoOptions);

            eventAggregator
            .GetEvent <NotificationEvents.AddNotificationWithPosition>()
            .Publish(new NotificationEvents.AddNotificationArgs
            {
                Notification = notificationOne,
                Position     = position,
                MonitorIndex = monitorIndex
            });

            eventAggregator
            .GetEvent <NotificationEvents.AddNotificationWithPosition>()
            .Publish(new NotificationEvents.AddNotificationArgs
            {
                Notification = notificationTwo,
                Position     = position,
                MonitorIndex = monitorIndex
            });
        }
        public async Task OpenConnectionAsync(Action <NotificationPayload> recieveAction)
        {
            try
            {
                _recieveAction = recieveAction;

                _remoteEndPoint = new IPEndPoint(IPAddress.Parse(_settings.Address), _settings.Port);

                CheckValidClient(_remoteEndPoint);

                await SendMessageAsync(Notifications.Connect); // SEND CONNECTED

                RecieveNotifications();                        // Blocked operation
            }
            catch (Exception x)
            {
                if (!(x is SocketException))
                {
                    await SendMessageAsync(Notifications.Error, x.ToString()); // Errors occurred
                }

                recieveAction?.Invoke(_factory.Create(Notifications.Error, x.ToString()));
            }
        }
        public async Task <IResult <long> > AddAsync(NotificationModel model)
        {
            // var validation = await new AddNotificationModelValidator().ValidationAsync(model);

            // if (validation.Failed)
            // {
            //     return Result<long>.Fail(validation.Message);
            // }

            var targetApp = _notificationFactory.Create(model);

            await _notificationRepository.AddAsync(targetApp);

            await _unitOfWork.SaveChangesAsync();

            return(Result <long> .Success(targetApp.Id));
        }