/// <inheritdoc/>
        public Task Publish <T>(BusEvent <T> message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (string.IsNullOrWhiteSpace(message.Name))
            {
                throw new ArgumentException(nameof(message));
            }

            // publish event back to Salesforce
            return(_forceClient.CreateRecordAsync <T>(message.Name, message.Data));
        }
        private void RemoteEventBus_EventBroadcasted(BusEvent e)
        {
            if (SelectedTarget == null)
            {
                if (_handler.OnlineClients.Count == 0)
                {
                    return;
                }

                SelectedTarget = _handler.OnlineClients[0]; //TODO: temp
            }

            var eData = e.DataAs <RemoteEvent>();
            var seri  = _eventSerializer.Serialize(eData);

            Connection.SendAsync(nameof(IRelayHub.RelayMessage), SelectedTarget, seri);
        }
        public async Task SendMessageChunk_ShouldCleanMessageJSon()
        {
            var uncleanedTestMessage = new BusEvent
            {
                Event   = "topic4",
                Message =
                    "{\"Plant\" : \"PCS$HF_LNG\",\"Parameter\":\"En \t\r\n\fstreng\" }"
            };
            var expectedWashedMessage = "{\"Plant\" : \"PCS$HF_LNG\",\"Parameter\":\"En streng\" }";

            _busEventRepository.Setup(b => b.GetEarliestUnProcessedEventChunk()).Returns(() => Task.FromResult(new List <BusEvent> {
                uncleanedTestMessage
            }));

            await _dut.SendMessageChunk();

            Assert.AreEqual(expectedWashedMessage, _messageBodyOnTopicClient4);
        }
Example #4
0
        public void Setup()
        {
            _earliestEvent = new BusEvent {
                Created = DateTime.Now.AddMinutes(-105), Event = "T", Sent = Status.UnProcessed, Id = 7, Message = "Message 105 minutes ago not sent"
            };
            _latestEvent = new BusEvent {
                Created = DateTime.Now.AddMinutes(-1), Event = "T", Sent = Status.UnProcessed, Id = 2, Message = "Message 1 minutes ago not sent"
            };
            _secondToLatestEvent = new BusEvent {
                Created = DateTime.Now.AddMinutes(-2), Event = "T", Sent = Status.UnProcessed, Id = 3, Message = "Message 2 minutes ago not sent"
            };

            _busEvents = new List <BusEvent>
            {
                new BusEvent {
                    Created = DateTime.Now.AddMinutes(-10), Event = "T", Sent = Status.UnProcessed, Id = 1, Message = "Message 10 minutes ago not sent"
                },
                _latestEvent,
                _secondToLatestEvent,
                new BusEvent {
                    Created = DateTime.Now.AddMinutes(-100), Event = "T", Sent = Status.UnProcessed, Id = 4, Message = "Message 100 minutes ago not sent"
                },
                new BusEvent {
                    Created = DateTime.Now.AddMinutes(-80), Event = "T", Sent = Status.Failed, Id = 5, Message = "Message 80 minutes ago sent"
                },
                new BusEvent {
                    Created = DateTime.Now.AddMinutes(-30), Event = "T", Sent = Status.UnProcessed, Id = 6, Message = "Message 30 minutes ago not sent"
                },
                _earliestEvent,
            };

            _busEventSetMock = _busEvents.AsQueryable().BuildMockDbSet();

            ContextHelper
            .ContextMock
            .Setup(x => x.BusEvents)
            .Returns(_busEventSetMock.Object);

            var configuration = new Mock <IConfiguration>();

            configuration.Setup(c => c["MessageChunkSize"]).Returns("5");
            _dut = new BusEventRepository(ContextHelper.ContextMock.Object, configuration.Object);
        }
Example #5
0
        public void Publish(string queueName, BusEvent message)
        {
            var subscribers = this.busSubscribers.FindAll(bs => bs.TopicName == queueName);

            var busContext = new BusContext(this);
            var busMessage = new BusMessage
            {
                Payload   = message.Payload,
                TopicName = message.TopicName
            };

            try
            {
                Task.WaitAll(subscribers.Select(busHandler => Task.Run(() => busHandler.Handler(busContext, busMessage))).Cast <Task>().ToArray());
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }
        }
        /// <inheritdoc/>
        public Task Unsubscribe <T>(BusEvent <T> eventMessage) where T : class
        {
            if (eventMessage == null)
            {
                throw new ArgumentNullException(nameof(eventMessage));
            }

            var @event = (eventMessage is PlatformEvent <T>) ?
                         eventMessage as PlatformEvent <T> :
                         throw new ArgumentException($"{nameof(eventMessage)} must be type of {nameof(PlatformEvent<T>)}");

            if (!typeof(IMessageListener).IsAssignableFrom(typeof(T)))
            {
                throw new InvalidOperationException("Type parameter must be an IMessageListener");
            }

            var eventName = eventMessage.Name;

            if (string.IsNullOrWhiteSpace(eventName))
            {
                throw new ArgumentException($"EventName of {nameof(eventMessage)} cannot be empty");
            }

            var key = new SubscriptionInfo(eventName, @event.ReplayId, typeof(T));

            if (!_subscriptions.ContainsKey(key))
            {
                return(Task.CompletedTask);
            }

            // build channel segment
            var topicName = GetEventOrTopicName(eventMessage.Name);

            var handler = _subscriptions[key];

            _streamingClient.UnsubscribeTopic(topicName, handler as IMessageListener, @event.ReplayId);

            _subscriptions.TryRemove(key, out var val);

            return(Task.CompletedTask);
        }
Example #7
0
        protected override void SelectedMenuItemBus_EventBroadcasted(BusEvent e)
        {
            if (e.DataObject is ContentItemViewModel cvi && cvi.Type != ContentItemType.MenuItem)
            {
                if (_workspace.WindowDataSource.Contains(cvi))
                {
                    if (cvi.IsSingleton)
                    {
                        BringItemToFront(cvi);
                        return;
                    }
                    else
                    {
                        cvi = cvi.Clone();
                    }
                }

                if (cvi.PublishRemoteEvents)
                {
                    _remoteBus.Publish(new RemoteEvent(RemoteEventType.MenuItemSelected, cvi.Model), this);
                }

                if (e.OriginalSource is Menu.Menu)
                {
                    _workspace.WindowDataSource.Clear();
                }

                _workspace.WindowDataSource.Add(cvi);

                var cont = (ListViewItem)_workspace.PART_ItemsHost.ContainerFromItem(cvi);

                if (cont == null)
                {
                    return;
                }

                cont.Width  = _workspace.PART_ItemsHost.ActualWidth;
                cont.Height = _workspace.PART_ItemsHost.ActualHeight;
            }
        }
Example #8
0
 internal void Stop(Bus bus)
 {
     BusEvent?.Invoke(bus);
 }
Example #9
0
 protected virtual void RemoteWindowOperationsBus_EventBroadcasted(BusEvent e)
 {
 }
Example #10
0
 protected abstract void SelectedMenuItemBus_EventBroadcasted(BusEvent e);
Example #11
0
        protected async override void SelectedMenuItemBus_EventBroadcasted(BusEvent e)
        {
            var dsp = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;

            if (!dsp.HasThreadAccess)
            {
                await dsp.RunAsync(CoreDispatcherPriority.Normal, () => SelectedMenuItemBus_EventBroadcasted(e));

                return;
            }

            if (e.DataObject == null)
            {
                _workspace.WindowDataSource.Clear();
                return;
            }

            if (e.DataObject is ContentItemViewModel cvi && cvi.Type != ContentItemType.MenuItem)
            {
                if (_rootConfigVm.HostType != Core.HostType.Tablet && cvi.Type == ContentItemType.Gallery && e.EventFilter == "remote")
                {
                    return;
                }


                if (_workspace.WindowDataSource.Contains(cvi))
                {
                    if (cvi.IsSingleton)
                    {
                        BringItemToFront(cvi);
                        return;
                    }
                    else
                    {
                        cvi = cvi.Clone();
                    }
                }


                _workspace.WindowDataSource.Add(cvi);

                if (cvi.PublishRemoteEvents && e.EventFilter == null)
                {
                    _remoteBus.Publish(new RemoteEvent(RemoteEventType.MenuItemSelected, cvi.Model), this);
                }

                var cont = (ListViewItem)_workspace.PART_ItemsHost.ContainerFromItem(cvi);

                if (cont == null)
                {
                    return;
                }

                if (!cvi.WindowSettings.ShrinkToContent)
                {
                    cont.Width  = cvi.WindowSettings.DefaultWidth;
                    cont.Height = cvi.WindowSettings.DefaultHeight;
                }
                else
                {
                    cont.MaxWidth  = cvi.WindowSettings.DefaultWidth;
                    cont.MaxHeight = cvi.WindowSettings.DefaultHeight;
                }
            }
        }