Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FirLib.Core.Patterns.Messaging.FirLibMessenger"/> class.
        /// </summary>
        public FirLibMessenger()
        {
            _globalMessengerName  = string.Empty;
            _hostSyncContext      = null;
            _publishCheckBehavior = FirLibMessengerThreadingBehavior.Ignore;

            _messageSubscriptions     = new Dictionary <Type, List <MessageSubscription> >();
            _messageSubscriptionsLock = new object();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clears all synchronization configuration.
        /// </summary>
        public void DisconnectFromGlobalMessaging()
        {
            if (string.IsNullOrEmpty(_globalMessengerName))
            {
                return;
            }

            s_messengersByName.TryRemove(_globalMessengerName, out _);

            _publishCheckBehavior = FirLibMessengerThreadingBehavior.Ignore;
            _globalMessengerName  = string.Empty;
            _hostSyncContext      = null;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets all required synchronization properties.
        /// </summary>
        /// <param name="checkBehavior">Defines the checking behavior for publish calls.</param>
        /// <param name="messengerName">The name by which this messenger should be registered.</param>
        /// <param name="hostSyncContext">The synchronization context to be used.</param>
        public void ConnectToGlobalMessaging(FirLibMessengerThreadingBehavior checkBehavior, string messengerName, SynchronizationContext?hostSyncContext)
        {
            messengerName.EnsureNotNullOrEmpty(nameof(messengerName));

            if (!string.IsNullOrEmpty(_globalMessengerName))
            {
                throw new FirLibException($"This messenger is already registered as '{_globalMessengerName}'!");
            }
            if (s_messengersByName.ContainsKey(messengerName))
            {
                throw new FirLibException($"The name '{messengerName}' is already in use by another messenger!");
            }

            _globalMessengerName  = messengerName;
            _publishCheckBehavior = checkBehavior;
            _hostSyncContext      = hostSyncContext;

            if (!string.IsNullOrEmpty(messengerName))
            {
                s_messengersByName.TryAdd(messengerName, this);
            }
        }