Пример #1
0
        public void Publish(MvxMessage message, Type messageType, bool isSticky = false)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            List <BaseSubscription>?toNotify = null;

            lock (_locker)
            {
                if (_subscriptions.TryGetValue(messageType, out Dictionary <Guid, BaseSubscription> messageSubscriptions))
                {
                    toNotify = messageSubscriptions.Values.ToList();
                }
            }

            if (isSticky)
            {
                _messageDictionary[message.GetType()] = message;
            }

            if (toNotify == null || toNotify.Count == 0)
            {
                MvxPluginLog.Instance?.Log(LogLevel.Trace, "Nothing registered for messages of type {0}", messageType.Name);
                return;
            }

            var allSucceeded = true;

            foreach (var subscription in toNotify)
            {
                allSucceeded &= subscription.Invoke(message);
            }

            if (!allSucceeded)
            {
                MvxPluginLog.Instance?.Log(LogLevel.Trace, "One or more listeners failed - purge scheduled");
                SchedulePurge(messageType);
            }
        }
Пример #2
0
 public void Publish(MvxMessage message, bool isSticky = false)
 {
     Publish(message, message.GetType(), isSticky);
 }
Пример #3
0
 public void Publish(MvxMessage message)
 {
     Publish(message, message.GetType());
 }