Example #1
0
        /// <summary>
        /// Creates an instance of EventMap.
        /// </summary>
        /// <param name="applicationInstanceIdentity">An instance of IApplicationInstanceIdentity
        /// uniquely identifying the current application instance.</param>
        /// <param name="relayProvider">The underlying transport for the incoming and
        /// outgoing messages. This could be SignalR, and IoT Hub or some type of notification framework.</param>
        /// <param name="eventTarget">A PubSubEvent instance representing the event to be mapped.</param>
        /// <param name="inboundTransformAction">A TransformArgumentDelegate method used to transform the
        /// event arguments before being routed inbound.</param>
        /// <param name="shouldRouteInbound">A ShouldRouteEventDelegate method that determines if the event
        /// should be routed. Note this method is called prior to the transformation.</param>
        /// <param name="outboundTransformAction">A TransformArgumentDelegate method used to transform the
        /// event arguments before being routed outbound.</param>
        /// <param name="shouldRouteOutbound">A ShouldRouteEventDelegate method that determines if the event
        /// should be routed. Note this method is called prior to the transformation.</param>
        public EventRelayMap(IApplicationInstanceIdentity applicationInstanceIdentity,
                             IRelayProviderSender <T> relayProviderSender,
                             IRelayProviderReceiver <T> relayProviderReceiver,
                             PubSubEvent <T> eventTarget,
                             TransformArgumentDelegate <T> inboundTransformAction, ShouldRouteEventDelegate <T> shouldRouteInbound,
                             TransformArgumentDelegate <T> outboundTransformAction, ShouldRouteEventDelegate <T> shouldRouteOutbound)
        {
            this.ApplicationInstanceIdentity = applicationInstanceIdentity;
            this.Event = eventTarget;
            this.InboundTransformAction  = inboundTransformAction;
            this.ShouldRouteInbound      = shouldRouteInbound;
            this.OutboundTransformAction = outboundTransformAction;
            this.ShouldRouteOutbound     = shouldRouteOutbound;
            this.RelayProviderSender     = relayProviderSender;
            this.RelayProviderReceiver   = relayProviderReceiver;

            // ***
            // *** Links an inbound event from the IRelayProvider
            // *** to the external Publish/Subscribe event system.
            // ***
            string eventName = string.Format("On{0}", this.Event.GetType().Name);

            this.RelayProviderReceiver?.SetCallback(eventName, this.OnProcessInboundMessage);

            // ***
            // *** Setup to receive inbound messages and processes them.
            // ***
            _subscriptionToken = this.Event.Subscribe((e) => { this.OnProcessOutboundMessage(e); });
        }
Example #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "T:XmppEventMessage" /> class.
 /// </summary>
 /// <param name = "message">The event.</param>
 internal XmppEventMessage(Message message)
 {
     identifier   = message.ID;
     @from        = message.From;
     to           = message.To;
     eventMessage = (PubSubEvent)message.Items[0];
 }
        public ColorbarViewModel(IRegionManager regionManager,
                                 IEventAggregator eventAggregator,
                                 IAppConfiguration appConfiguration,
                                 ILogger <ColorbarViewModel> logger,
                                 IShell shell,
                                 ISystemInfo systemInfo,
                                 LoginManager loginManager)
        {
            _regionManager                = regionManager;
            _eventAggregator              = eventAggregator;
            _appConfiguration             = appConfiguration;
            _logger                       = logger;
            _shell                        = shell;
            _systemInfo                   = systemInfo;
            _loginManager                 = loginManager;
            StutteringFactor              = _appConfiguration.StutteringFactor;
            SelectWindowSize              = _appConfiguration.MovingAverageWindowSize;
            FpsValuesRoundingDigits       = _appConfiguration.FpsValuesRoundingDigits;
            ScreenshotDirectory           = _appConfiguration.ScreenshotDirectory;
            WindowSizes                   = new List <int>(Enumerable.Range(4, 100 - 4));
            RoundingDigits                = new List <int>(Enumerable.Range(0, 8));
            SelectScreenshotFolderCommand = new DelegateCommand(OnSelectScreenshotFolder);
            OpenScreenshotFolderCommand   = new DelegateCommand(OnOpenScreenshotFolder);
            OptionPopupClosed             = eventAggregator.GetEvent <PubSubEvent <ViewMessages.OptionPopupClosed> >();

            HasCustomInfo = SelectedHardwareInfoSource == EHardwareInfoSource.Custom;
            IsLoggedIn    = _loginManager.State.Token != null;
            SetAggregatorEvents();
            SetHardwareInfoDefaultsFromDatabase();
            SubscribeToUpdateSession();
        }
Example #4
0
        public ColorbarViewModel(IRegionManager regionManager,
                                 IEventAggregator eventAggregator,
                                 IAppConfiguration appConfiguration,
                                 ILogger <ColorbarViewModel> logger,
                                 IShell shell,
                                 ISystemInfo systemInfo,
                                 LoginManager loginManager)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            _regionManager    = regionManager;
            _eventAggregator  = eventAggregator;
            _appConfiguration = appConfiguration;
            _logger           = logger;
            _shell            = shell;
            _systemInfo       = systemInfo;
            _loginManager     = loginManager;

            RoundingDigits = new List <int>(Enumerable.Range(0, 8));
            SelectScreenshotFolderCommand = new DelegateCommand(OnSelectScreenshotFolder);
            OpenScreenshotFolderCommand   = new DelegateCommand(OnOpenScreenshotFolder);
            OptionPopupClosed             = eventAggregator.GetEvent <PubSubEvent <ViewMessages.OptionPopupClosed> >();

            HasCustomInfo = SelectedHardwareInfoSource == EHardwareInfoSource.Custom;
            IsLoggedIn    = _loginManager.State.Token != null;
            SetAggregatorEvents();
            SetHardwareInfoDefaultsFromDatabase();
            SubscribeToUpdateSession();

            stopwatch.Stop();
            _logger.LogInformation(this.GetType().Name + " {initializationTime}s initialization time", Math.Round(stopwatch.ElapsedMilliseconds * 1E-03, 1));
        }
Example #5
0
        public StoragePointViewModel(StoragePoint storagePoint, IEventAggregator eventAggregator) : this()
        {
            _eventAggregator           = eventAggregator;
            Name                       = storagePoint.Name;
            _storagePoint              = storagePoint;
            _insertPartEvent           = _eventAggregator.GetEvent <PubSubEvent <InsertPartEvent> >();
            _insertPartToDeliveryEvent = _eventAggregator.GetEvent <PubSubEvent <InsertPartToDeliveryEvent> >();
            _removePartEvent           = _eventAggregator.GetEvent <PubSubEvent <RemovePartFromStoragePointEvent> >();
            if (Thread.CurrentThread.IsBackground)
            {
                _insertPartEvent.Subscribe(OnInsertPart);
                _removePartEvent.Subscribe(OnRemovePart);
                _insertPartToDeliveryEvent.Subscribe(OnInsertPartToDelivery);
            }
            else
            {
                _insertPartEvent.Subscribe(OnInsertPart, ThreadOption.UIThread);
                _removePartEvent.Subscribe(OnRemovePart, ThreadOption.UIThread);
                _insertPartToDeliveryEvent.Subscribe(OnInsertPartToDelivery, ThreadOption.UIThread);
            }

            foreach (var part in storagePoint.Parts)
            {
                Parts.Add(new PartViewModel(part));
            }
        }
 public CompositePresentationEventObservable(PubSubEvent <TEventArgs> @event)
 {
     if (@event == null)
     {
         throw new ArgumentNullException("event");
     }
     this.@event = @event;
 }
Example #7
0
        /// <summary>
        /// Publish an event to the given topic.
        /// </summary>
        /// <param name="event">event to publish</param>
        public void Publish(PubSubEvent @event)
        {
            string rawTopic   = @event.GetTopic();
            string rawMessage = this.Serializer.Serialize(@event);

            this.Socket.SendMoreFrame(rawTopic);
            this.Socket.SendFrame(rawMessage);
        }
Example #8
0
        public async void OnPlayerJoin(Player player)
        {
            var evnt = new PubSubEvent();

            evnt.EventName = PubSubEventsConstants.DefaultEvents.OnPlayerJoin;
            evnt.Payload.Add(EventPayloadConstants.Player, player);
            await PubSub.Default.PublishAsync(evnt);
        }
 private void SetAggregatorEvents()
 {
     _updateSessionEvent           = _eventAggregator.GetEvent <PubSubEvent <ViewMessages.UpdateSession> >();
     _selectSessionEvent           = _eventAggregator.GetEvent <PubSubEvent <ViewMessages.SelectSession> >();
     _showOverlayEvent             = _eventAggregator.GetEvent <PubSubEvent <ViewMessages.ShowOverlay> >();
     _updateProcessIgnoreListEvent = _eventAggregator.GetEvent <PubSubEvent <ViewMessages.UpdateProcessIgnoreList> >();
     _updateRecordInfosEvent       = _eventAggregator.GetEvent <PubSubEvent <ViewMessages.UpdateRecordInfos> >();
 }
Example #10
0
        public static IMaybe <TReturn> Get <TReturn>(this PubSubEvent <Action <TReturn> > @this)
        {
            var v          = default(TReturn);
            var isCallback = false;
            var callback   = Act.New((TReturn x) => { v = x; isCallback = true; });

            @this.Publish(callback);
            return(v.ToMaybe().Where(_ => isCallback));
        }
        public void UnsubscribeChangeRegionContext(string regionName, Action <object> action)
        {
            PubSubEvent <object> changeRegionContextEvent = GetChangeRegionContextEvent(regionName);

            if (changeRegionContextEvent != null)
            {
                changeRegionContextEvent.Unsubscribe(action);
            }
        }
Example #12
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public MainWindow(IRegionManager regionManager, PubSubEvent hotkeyEvent)
        {
            InitializeComponent();

            this.regionManager = regionManager;
            this.hotkeyEvent   = hotkeyEvent;

            HotkeyCommand.InputGestures.Add(new KeyGesture(Key.Escape));
        }
Example #13
0
        /// <summary>
        /// Subscribe to the given topic with a handler function.
        /// </summary>
        /// <param name="topic">pub-sub topic</param>
        public void Subscribe <T>(PubSubEventHandler <T> handler) where T : PubSubEvent
        {
            string topic = PubSubEvent.GetTopicForEventType(typeof(T));

            MessageHandlers.Add(topic, new MessageHandler <T>(handler, this.Serializer));

            string topicString = topic.ToString();

            this.Socket.Subscribe(topicString);
        }
Example #14
0
        public OverlayViewModel(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;

            AcceptEditingDialogCommand = new DelegateCommand(OnAcceptEditingDialog);
            CancelEditingDialogCommand = new DelegateCommand(OnCancelEditingDialog);

            _hideOverlayEvent = _eventAggregator.GetEvent <PubSubEvent <ViewMessages.HideOverlay> >();
            SubscribeToUpdateSession();
        }
Example #15
0
        private static void Navigate(PubSubEvent <NavigateOrder> @this, string viewName, IDictionary <string, object> prms)
        {
            var order = new NavigateOrder
            {
                ViewName = viewName,
                Prms     = prms,
            };

            @this.Publish(order);
        }
Example #16
0
        public ModulesViewModel(IMazeRestClient restClient, IWindowService windowService) : base(Tx.T("Modules"), PackIconFontAwesomeKind.PuzzlePieceSolid)
        {
            _restClient    = restClient;
            _windowService = windowService;

            _tabViewModels = new List <IModuleTabViewModel> {
                new BrowseTabViewModel(), new InstalledTabViewModel(), new UpdatesTabViewModel()
            };
            BrowseLoaded = new PubSubEvent();
        }
Example #17
0
        public static void Publish <T, With>(this PubSubEvent <AddOrder <T, With> > @this, T model, With with)
        {
            var order = new AddOrder <T, With>
            {
                Model  = model,
                WithIn = with,
            };

            @this.Publish(order);
        }
        public ComparisonRecordInfoWrapper(ComparisonRecordInfo info, ComparisonViewModel viewModel)
        {
            WrappedRecordInfo = info;
            _viewModel        = viewModel;

            _setFileRecordInfoExternalEvent =
                viewModel.EventAggregator.GetEvent <PubSubEvent <ViewMessages.SetFileRecordInfoExternal> >();

            RemoveCommand    = new DelegateCommand(OnRemove);
            MouseDownCommand = new DelegateCommand(OnMouseDown);
        }
 private void SetAggregatorEvents()
 {
     _updateObservedFolder = _eventAggregator.GetEvent <PubSubEvent <AppMessages.UpdateObservedDirectory> >();
     _openLoginWindow      = _eventAggregator.GetEvent <PubSubEvent <AppMessages.OpenLoginWindow> >();
     _logout = _eventAggregator.GetEvent <PubSubEvent <AppMessages.LoginState> >();
     _eventAggregator.GetEvent <PubSubEvent <AppMessages.LoginState> >().Subscribe(state =>
     {
         IsLoggedIn = state.IsLoggedIn;
         RaisePropertyChanged(nameof(IsLoggedIn));
     });
 }
Example #20
0
        public async void OnResourceStart()
        {
            var config = ParseConfig("s_config.toml");

            Context.Init(config);
            var evnt = new PubSubEvent();

            evnt.EventName = PubSubEventsConstants.DefaultEvents.OnServerStart;
            await PubSub.Default.PublishAsync(evnt);

            NAPI.Util.ConsoleOutput("Wayland Project server started!");
        }
Example #21
0
        public BenchmarkDotNetRun()
        {
            var provider = new ServiceCollection().AddMessagePipe().BuildServiceProvider();

            prism       = new Prism.Events.EventAggregator().GetEvent <Message>();
            prismStrong = new Prism.Events.EventAggregator().GetEvent <Message>();

            var mdiatr = new ServiceCollection().AddMediatR(typeof(PublishOps).Assembly).BuildServiceProvider();

            medi = mdiatr.GetRequiredService <IMediator>();


            p = provider.GetRequiredService <IPublisher <Message> >();
            var s = provider.GetRequiredService <ISubscriber <Message> >();

            keyed = provider.GetRequiredService <IPublisher <Guid, Message> >();
            var keyedS = provider.GetRequiredService <ISubscriber <Guid, Message> >();

            hub = Hub.Default;

            m       = new Message();
            subject = new Subject <Message>();

            signalBus  = SetupZenject();
            easyMsgHub = new MessageHub();

            for (int i = 0; i < 8; i++)
            {
                s.Subscribe(new EmptyMessageHandler());
                prism.Subscribe(_ => { });
                prismStrong.Subscribe(_ => { }, true);
                ev += _ => { };
                subject.Subscribe(_ => { });
                hub.Subscribe <Message>(_ => { });



                keyedS.Subscribe(key, _ => { });


                easyMsgHub.Subscribe <Message>(_ => { });
            }

            signalBus.Subscribe <Message>(m => { });
            signalBus.Subscribe <Message>(m => { });
            signalBus.Subscribe <Message>(m => { });
            signalBus.Subscribe <Message>(m => { });
            signalBus.Subscribe <Message>(m => { });
            signalBus.Subscribe <Message>(m => { });
            signalBus.Subscribe <Message>(m => { });
            signalBus.Subscribe <Message>(m => { });
        }
Example #22
0
        /// <summary>
        /// Return a value that iundicates whether a pubsub event is an activity event
        /// </summary>
        /// <param name="xmppevent"></param>
        /// <returns></returns>
        public static bool IsActivityEvent(PubSubEvent xmppevent)
        {
            var items = xmppevent.Item as PubSubEventItems;

            if (items != null && items.Items.Count == 1)
            {
                var item = items.Items[0] as PubSubItem;

                return(item.Item is Tune || item.Item is Mood);
            }

            return(false);
        }
Example #23
0
        public static IUser Get(this PubSubEvent <AuthOrder> @this, IUser authUser)
        {
            var v        = null as IUser;
            var callback = Act.New((IUser x) => { v = x; });
            var order    = new AuthOrder
            {
                AuthUser = authUser,
                Callback = callback,
            };

            @this.Publish(order);
            return(v);
        }
Example #24
0
        public LoginManager(ILogger <LoginManager> logger, IEventAggregator eventAggregator)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            _logger          = logger;
            _loginStateEvent = eventAggregator.GetEvent <PubSubEvent <AppMessages.LoginState> >();
            Initialize();

            stopwatch.Stop();
            _logger.LogInformation(this.GetType().Name + " {initializationTime}s initialization time", Math.Round(stopwatch.ElapsedMilliseconds * 1E-03, 1));
        }
Example #25
0
        public void TestTopicUniqueness()
        {
            // Gather list of all PubSubEvent sub-classes.
            IEnumerable <Type> pubSubEventTypes = typeof(PubSubEvent).GetTypeInfo().Assembly.GetTypes()
                                                  .Where(type => typeof(PubSubEvent).IsAssignableFrom(type) && type != typeof(PubSubEvent));

            // Ensure all PubSubEvents have unique topics.
            HashSet <string> topics = new HashSet <string>();

            foreach (Type eventType in pubSubEventTypes)
            {
                string topic = PubSubEvent.GetTopicForEventType(eventType);
                Assert.True(topics.Add(topic));
            }
        }
        public async Task Publish(T @event, CancellationToken cancellationToken)
        {
            _logger.LogInformation($"Publishing integration event to database");
            var message = new PubSubEvent
            {
                DateCreated = DateTime.Now,
                Id = Guid.NewGuid(),
                MessageType = @event.GetType().Name,
                Message = @event,
                Topic = _topic
            };

            await _repository.InsertAsync(message);
            _logger.LogInformation($"Integration event saved to database");
        }
Example #27
0
        /// <summary>
        ///   Return a value that iundicates wheter a pubsub event is an activity event
        /// </summary>
        /// <param name = "xmppevent"></param>
        /// <returns></returns>
        public static bool IsActivityEvent(PubSubEvent xmppevent)
        {
            if (xmppevent.Item is PubSubEventItems)
            {
                var items = (PubSubEventItems)xmppevent.Item;

                if (items.Items.Count == 1)
                {
                    var item = (PubSubItem)items.Items[0];

                    return(item.Item is Tune || item.Item is Mood);
                }
            }

            return(false);
        }
Example #28
0
        public CloudViewModel(IStatisticProvider statisticProvider, IRecordManager recordManager,
                              IEventAggregator eventAggregator, IAppConfiguration appConfiguration, ILogger <CloudViewModel> logger, IAppVersionProvider appVersionProvider, LoginManager loginManager)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            _statisticProvider  = statisticProvider;
            _recordManager      = recordManager;
            _eventAggregator    = eventAggregator;
            _appConfiguration   = appConfiguration;
            _logger             = logger;
            _appVersionProvider = appVersionProvider;
            _loginManager       = loginManager;
            ClearTableCommand   = new DelegateCommand(OnClearTable);
            CopyURLCommand      = new DelegateCommand(() => Clipboard.SetText(_shareUrl));
            SwitchToDownloadDirectoryCommand = new DelegateCommand(OnSwitchToDownloadDirectory);
            _cloudFolderChanged  = eventAggregator.GetEvent <PubSubEvent <AppMessages.CloudFolderChanged> >();
            _selectCloudFolder   = eventAggregator.GetEvent <PubSubEvent <AppMessages.SelectCloudFolder> >();
            UploadRecordsCommand = new DelegateCommand(async() =>
            {
                await UploadRecords();
                OnClearTable();
            });

            DownloadRecordsCommand = new DelegateCommand(async() =>
            {
                await DownloadCaptureCollection(DownloadIDString);
            });


            SubscribeToUpdateSession();

            CloudEntries.CollectionChanged += new NotifyCollectionChangedEventHandler
                                                  ((sender, eventArg) => OnCloudEntriesChanged());

            IsLoggedIn = loginManager.State.Token != null;

            _eventAggregator.GetEvent <PubSubEvent <AppMessages.LoginState> >().Subscribe(state =>
            {
                IsLoggedIn = state.IsLoggedIn;
                RaisePropertyChanged(nameof(IsLoggedIn));
            });

            stopwatch.Stop();
            _logger.LogInformation(this.GetType().Name + " {initializationTime}s initialization time", Math.Round(stopwatch.ElapsedMilliseconds * 1E-03, 1));
        }
        public CompositePresentationEventSubscription(PubSubEvent <TEventArgs> @event,
                                                      IObserver <TEventArgs> observer)
        {
            if (@event == null)
            {
                throw new ArgumentNullException("event");
            }
            if (observer == null)
            {
                throw new ArgumentNullException("observer");
            }

            this.@event   = @event;
            this.observer = observer;

            @event.Subscribe(observer.OnNext, true);
        }
Example #30
0
        private void m_stream_OnProtocol(object sender, XmlElement rp)
        {
            if (rp.Name != "message")
            {
                return;
            }
            PubSubEvent evt = rp["event", URI.PUBSUB_EVENT] as PubSubEvent;

            if (evt == null)
            {
                return;
            }

            EventItems items = evt.GetChildElement <EventItems>();

            if (items == null)
            {
                return;
            }
            if (items.Node != m_node)
            {
                return;
            }

            // OK, it's for us.  Might be a new one or a retraction.
            // Shrug, even if we're sent a mix, it shouldn't hurt anything.

            /*
             * <message from='pubsub.shakespeare.lit' to='*****@*****.**' id='bar'>
             * <event xmlns='http://jabber.org/protocol/pubsub#event'>
             *  <items node='princely_musings'>
             *    <retract id='ae890ac52d0df67ed7cfdf51b644e901'/>
             *  </items>
             * </event>
             * </message>
             */
            foreach (string id in items.GetRetractions())
            {
                m_items.RemoveId(id);
            }

            foreach (PubSubItem item in items.GetItems())
            {
                m_items.Add(item);
            }
        }