コード例 #1
0
        public void Publish(UserLoggedInMessage userLoggedInMessage)
        {
            ConnectionFactory connectionFactory = new ConnectionFactory();

            connectionFactory.Uri      = new Uri("amqp://*****:*****@rabbitmq:5672");
            connectionFactory.UserName = "******";
            connectionFactory.Password = "******";
            connectionFactory.AutomaticRecoveryEnabled = true;
            connectionFactory.NetworkRecoveryInterval  = TimeSpan.FromSeconds(10);
            using (var connection = connectionFactory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "customerloggin", type: "fanout");
                    channel.QueueDeclare(queue: "customerlogginqueue",
                                         durable: true,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);
                    channel.QueueBind("customerlogginqueue", "customerloggin", "");

                    var message    = JsonConvert.SerializeObject(userLoggedInMessage);
                    var body       = Encoding.UTF8.GetBytes(message);
                    var properties = channel.CreateBasicProperties();
                    properties.Persistent = true;
                    channel.BasicPublish(exchange: "customerloggin",
                                         routingKey: "",
                                         basicProperties: null,
                                         body: body);
                    Debug.WriteLine(" [x] Sent {0}", message);
                }
        }
コード例 #2
0
 public async Task RegisterUser(string userId)
 {
     UserLoggedInMessage userLoggedInMessage = new UserLoggedInMessage()
     {
         UserId = userId,
     };
     //TODO: ToString be tested later
     // _userLoggedInRedisPublisher.Publish(userLoggedInMessage);
     await Groups.AddToGroupAsync(Context.ConnectionId, userId);
 }
コード例 #3
0
 private void OnUserLoggedIn(UserLoggedInMessage userMessage)
 {
     if (userMessage != null && userMessage.CurrentUser != null && !string.IsNullOrWhiteSpace(userMessage.CurrentUser.Username))
     {
         CurrentUserName = userMessage.CurrentUser.Username;
         IsLoggedIn      = true;
     }
     else
     {
         CurrentUserName = string.Empty;
         IsLoggedIn      = false;
     }
 }
コード例 #4
0
        private void OnUserLoggedIn(UserLoggedInMessage message)
        {
            bool loggedIn = message.CurrentUser != null && message.CurrentUser.Username != null;

            if (loggedIn)
            {
                loginItemText = "switch user / logout";
            }
            else
            {
                loginItemText = "login";
            }
        }
コード例 #5
0
        private async void OnUserLoggedIn(UserLoggedInMessage message)
        {
            bool wasLoggedIn = LoggedIn;

            LoggedIn = message.CurrentUser != null && message.CurrentUser.Me != null;
            if (wasLoggedIn != _loggedIn)
            {
                if (PivotItems.Count > 0 && PivotItems[0] != null && PivotItems[0] is RedditViewModel)
                {
                    (PivotItems[0] as RedditViewModel).RefreshLinks();
                }
            }

            if (_initialLoad)
            {
                await LoadSubreddits();

                _initialLoad = false;
            }
        }
コード例 #6
0
        public void EventAggregatorSimpleTest()
        {
            var eventAggregator     = new EventAggregator.Simple.EventAggregator();
            var mockSubscriberAlpha = new Moq.Mock <ISubscriberAlpha>();
            var mockSubscriberBeta  = new Moq.Mock <ISubscriberBeta>();
            var subscriberAlpha     = mockSubscriberAlpha.Object;
            var subscriberBeta      = mockSubscriberBeta.Object;

            eventAggregator.Subscribe <UserLoggedInMessage>(subscriberAlpha, subscriberAlpha.Invoke);
            eventAggregator.Subscribe <UserLoggedInMessage>(subscriberBeta, subscriberBeta.InvokeBetaHandler);
            eventAggregator.Subscribe <UserLoggedOutMessage>(subscriberAlpha, subscriberAlpha.Invoke);
            eventAggregator.Subscribe <UserLoggedOutMessage>(subscriberBeta, subscriberBeta.InvokeBetaHandler);

            Assert.AreEqual(2, eventAggregator.SubscriptionCount <UserLoggedInMessage>());
            Assert.AreEqual(2, eventAggregator.SubscriptionCount <UserLoggedOutMessage>());

            var loggedInMessage = new UserLoggedInMessage("Tom", this);

            eventAggregator.Publish(loggedInMessage);


            mockSubscriberAlpha.Verify(x => x.Invoke(loggedInMessage), Times.Once);
            mockSubscriberBeta.Verify(x => x.InvokeBetaHandler(loggedInMessage), Times.Once);

            mockSubscriberAlpha.Invocations.Clear();
            mockSubscriberBeta.Invocations.Clear();

            eventAggregator.Unsubscribe <UserLoggedInMessage>(subscriberAlpha);
            Assert.AreEqual(1, eventAggregator.SubscriptionCount <UserLoggedInMessage>());
            Assert.AreEqual(2, eventAggregator.SubscriptionCount <UserLoggedOutMessage>());
            eventAggregator.Publish(loggedInMessage);

            mockSubscriberAlpha.Verify(x => x.Invoke(loggedInMessage), Times.Never);
            mockSubscriberBeta.Verify(x => x.InvokeBetaHandler(loggedInMessage), Times.Once);

            eventAggregator.Unsubscribe(subscriberAlpha);
            eventAggregator.Unsubscribe(subscriberBeta);

            Assert.AreEqual(0, eventAggregator.SubscriptionCount <UserLoggedInMessage>());
            Assert.AreEqual(0, eventAggregator.SubscriptionCount <UserLoggedOutMessage>());
        }
コード例 #7
0
 public void Invoke(UserLoggedInMessage message)
 {
     Console.WriteLine($"Recieved Message in {nameof(SubscriberAlpha)}");
 }
コード例 #8
0
 private void OnUserLoggedIn(UserLoggedInMessage message)
 {
     LoggedIn = message.CurrentUser != null && message.CurrentUser.Me != null;
 }
コード例 #9
0
 public void Handle(UserLoggedInMessage message)
 {
     MenuItems = InitializeMenuItems();
     NotifyOfPropertyChange(nameof(MenuItems));
     // Navbar = IoC.Get<NavbarControl>().ViewModel;
 }
コード例 #10
0
 public void Invoke(UserLoggedInMessage message)
 {
 }
コード例 #11
0
 public void InvokeBetaHandler(UserLoggedInMessage message)
 {
     Console.WriteLine($"Recieved Message in {nameof(SubscriberBeta)}");
 }