public void ParseListenerAttributes( INotificationListener Instance )
        {
            Type instanceType 			= Instance.GetType();
            Type listenerAttributeType 	= typeof( NotificationListenerAttribute );
            INotifier notifier 			= Notifier.getInstance( Instance.Context );

            foreach( MethodInfo method in instanceType.GetMethods( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ) )
            {
                foreach( Attribute attribute in method.GetCustomAttributes( listenerAttributeType, false ) )
                {
                    Console.WriteLine( "\t" + this + ".ParseListenerAttributes()\n\tAdding InterestListener: " + ( attribute as NotificationListenerAttribute ).Name );
                    MethodInfo scopeMethod = method;
                    notifier.Add(
                        new NotificationInterestListener(
                            ( attribute as NotificationListenerAttribute ).Type,
                            Instance.Context,
                            delegate( Object Sender, INotification Notification )
                            {
                                scopeMethod.Invoke( Instance, new Object[]{ Sender, Notification } );
                            }
                        )
                    );
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NotificationHostViewModel" /> class.
        /// </summary>
        /// <param name="notificationListener">Object which is listening for occuring notifications.</param>
        public NotificationHostViewModel(INotificationListener notificationListener = null)
        {
            _notificationListener = notificationListener ?? Locator.Current.GetService <INotificationListener>();

            var notificationSource  = new SourceList <Notification>();
            var notificationChanges = notificationSource.Connect();

            this.WhenActivated(d =>
            {
                _notificationListener.Notifications
                .ObserveOn(RxApp.TaskpoolScheduler)
                .Subscribe(x => notificationSource.Add(x))
                .DisposeWith(d);

                // Add new received notifications as viewmodels to our internal collection.
                notificationChanges
                .Transform(x => new NotificationViewModel(x))
                .ObserveOn(RxApp.MainThreadScheduler)
                .Bind(out _notifications)
                .Subscribe()
                .DisposeWith(d);

                // Listen for notification close requests.
                notificationChanges
                .Throttle(TimeSpan.FromMilliseconds(100), RxApp.TaskpoolScheduler)
                .Select(_ => Notifications.Select(x => x.Close).Merge())
                .Switch()
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(x => notificationSource.Remove(x.Notification))
                .DisposeWith(d);
            });
        }
        public void Init(NotificationsSettings settings, INotificationListener listener)
        {
            // Store the settings for later references.
            mSettings = settings;

            // Convert category groups to JSON. Invalid groups (empty name or ID) will be
            // automatically ignored in native side.
            var categoryGroupJson = AndroidNotificationHelper.ToJson(settings.CategoryGroups);

            // Convert categories to JSON.
            var categories = new List <NotificationCategory>();

            categories.Add(settings.DefaultCategory);

            if (settings.UserCategories != null)
            {
                categories.AddRange(settings.UserCategories);
            }

            var categoriesJson = AndroidNotificationHelper.ToJson(categories.ToArray());

            // Listener info
            var name = listener.Name;
            var backgroundNotificationMethod = Helper.GetMethodName(listener.NativeNotificationFromBackgroundHandler);
            var foregroundNotificationMethod = Helper.GetMethodName(listener.NativeNotificationFromForegroundHandler);

            // Initialize native Android client, which may send some launch notification data during the process.
            AndroidNotificationNative._InitNativeClient(categoryGroupJson, categoriesJson, name, backgroundNotificationMethod, foregroundNotificationMethod);

            mIsInitialized = true;
        }
 public void RedeliverTo_WhenNotificationWasNotDelivered_DoesNotTouchDecreasesDeliveryCount(
     INotificationListener listener,
     EventStreamUpdated notification,
     EventStreamReaderId consumerId)
 {
     Assert.Equal(0, notification.RedeliverTo(listener).DeliveryCount);
 }
 public void IsAddressedTo_WhenNotificationWasNotAddressed_Throws(
     INotificationListener listener,
     EventStreamUpdated notification,
     EventStreamReaderId consumerId)
 {
     Assert.Throws <InvalidOperationException>(() => notification.IsAddressedTo(listener));
 }
        // TODO: onDispose remove logic integrieren
        public void ParseDelegateInterestAttributes( INotificationListener Instance )
        {
            Type InstanceType 			= Instance.GetType();
            Type ListenerAttributeType 	= typeof( NotificationDelegateAttribute );

            foreach( MethodInfo method in InstanceType.GetMethods( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance ) )
            {
                foreach( Attribute attribute in method.GetCustomAttributes( ListenerAttributeType, false ) )
                {
                    #if DEBUG
                    Debug.WriteLine( this + ".ParseDelegateInterestAttributes()\n\tNoteType: " + ( attribute as NotificationDelegateAttribute ).NoteType + "\n\tNotificationDelegateInterest: " + ( attribute as NotificationDelegateAttribute ).Name + "\n---" );
                    #endif

                    MethodInfo scopeMethod = method;
                    // adding handler methods to the NotificationListenerList
                    Instance.NotificationListenerList.Add(
                        new NotificationDelegateInterest(
                            ( attribute as NotificationDelegateAttribute ).NoteType,
                            Instance.Context,
                            delegate( Object Sender, INotification Notification )
                            {
                                scopeMethod.Invoke( Instance, new Object[]{ Sender, Notification } );
                            }
                        )
                    );
                }
            }
        }
示例#7
0
 public NotifyControl(INotificationListener notificationService, IUserSession userSession)
 {
     InitializeComponent();
     notificationService.NotificationRecieved += notificationService_OnNotification;
     ApplicationCommands.LoginSucceeded.RegisterCommand(new DelegateCommand <object>(Update));
     ApplicationCommands.UserLoggedOut.RegisterCommand(new DelegateCommand <object>(Update));
     _userSession = userSession;
 }
        public void NotificationsSubscriber_WhenProcessingIsNotEnabled_AddsListenerToCollection(
            INotificationListener listener,
            EventStoreConnectionConfiguration connectionConfiguration)
        {
            connectionConfiguration.Notifications.Subscribe(listener);

            Assert.DoesNotContain(listener, connectionConfiguration.NotificationListeners);
        }
        public bool IsAddressedTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            Ensure.True(m_recipient != null, "Notification was not addressed.");

            return(m_recipient.Equals(listener.GetType().FullName));
        }
示例#10
0
 public StandardMBean(object impl, Type intfType)
 {
     _internalInfo = MBeanInternalInfo.GetCached(intfType);
      _info = _internalInfo.MBeanInfo;//CreateMBeanInfo(impl, intfType);
      _impl = impl;
      _registration = impl as IMBeanRegistration;
      _notifListener = impl as INotificationListener;
      _notifEmitter = impl as INotificationEmitter;
 }
        /// <summary>
        /// Remove Notification listener.
        /// </summary>
        /// <param name="listener"></param>
        public void RemoveListener(INotificationListener listener)
        {
            _listeners.Remove(listener);

            if (_config.EnableConsoleLogging)
            {
                Debug.Log("[Countly NotificationsCallbackService] RemoveListener: " + listener);
            }
        }
示例#12
0
 public StandardMBean(object impl, Type intfType)
 {
     _internalInfo  = MBeanInternalInfo.GetCached(intfType);
     _info          = _internalInfo.MBeanInfo;//CreateMBeanInfo(impl, intfType);
     _impl          = impl;
     _registration  = impl as IMBeanRegistration;
     _notifListener = impl as INotificationListener;
     _notifEmitter  = impl as INotificationEmitter;
 }
        public void RedeliverTo_DecreasesDeliveryCount(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            SaveAndRestore(notification);

            Assert.Equal(0, notification.RedeliverTo(listener).DeliveryCount);
        }
 public void IsAddressedTo_WhenRecipientSpecifiedDirectly_ReturnsTrue(
     INotificationListener listener,
     EventStreamUpdated notification,
     EventStreamReaderId consumerId)
 {
     Assert.True(notification
                 .SendTo(listener)
                 .IsAddressedTo(listener));
 }
        public void SendTo_WhenMessagHasBeenAddressedToTheSameConsumer_ReturnsItself(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            var addressedNotification = notification.SendTo(listener);

            Assert.Same(addressedNotification, addressedNotification.SendTo(listener));
        }
        public void SendTo_ChangesNotificationId(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            var addressedNotification = notification.SendTo(listener);

            Assert.NotEqual(notification.NotificationId, addressedNotification.NotificationId);
        }
示例#17
0
        internal static iOSNotificationListenerInfo ToIOSNotificationListenerInfo(INotificationListener listener)
        {
            var iOSListenerInfo = new iOSNotificationListenerInfo();

            iOSListenerInfo.name = listener.Name;
            iOSListenerInfo.backgroundNotificationMethod = Helper.GetMethodName(listener.NativeNotificationFromBackgroundHandler);
            iOSListenerInfo.foregroundNotificationMethod = Helper.GetMethodName(listener.NativeNotificationFromForegroundHandler);

            return(iOSListenerInfo);
        }
示例#18
0
        public NotificationListenerSubscription(
            INotificationsChannel notificationsChannel,
            INotificationListener listener)
        {
            Require.NotNull(notificationsChannel, "notificationsChannel");
            Require.NotNull(listener, "listener");

            m_notificationsChannel = notificationsChannel;
            m_listener             = listener;
            m_processingCountdown  = new CountdownEvent(0);
        }
示例#19
0
        private INotificationListener GetListenerMBean(ObjectName name, out IDynamicMBean bean)
        {
            bean = GetMBean(name);
            INotificationListener listner = bean as INotificationListener;

            if (listner != null)
            {
                return(listner);
            }
            throw new OperationsException(string.Format("Bean \"{0}\" is not a notification listener.", name));
        }
        public void SendTo_WhenMessagHasBeenAddressedToTheSameConsumer_SavesId(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            var addressedNotification = notification.SendTo(listener);

            Assert.Equal(
                addressedNotification.NotificationId,
                addressedNotification.SendTo(listener).NotificationId);
        }
示例#21
0
        public IEventStoreConnectionConfiguration Subscribe(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            if (m_enabled)
            {
                m_listeners.Add(listener);
            }

            return(m_connection);
        }
示例#22
0
    // PUBLIC METHODS
    // -------------------------------------------------------------------------

    public void Subscribe(Notification.Type type, INotificationListener listener)
    {
        if (!m_types.ContainsKey(type))
        {
            m_types[type] = new List <INotificationListener>();
        }

        if (!m_types[type].Contains(listener))
        {
            m_types[type].Add(listener);
        }
    }
示例#23
0
        public void RemoveNotificationListener(ObjectName name, ObjectName listener)
        {
            name     = GetNameWithDomain(name);
            listener = GetNameWithDomain(listener);
            IDynamicMBean        bean;
            INotificationEmitter emitter = GetEmitterMBean(name, out bean);

            TestPermissions(bean.GetMBeanInfo().ClassName, null, name, MBeanPermissionAction.RemoveNotificationListener);
            INotificationListener listenerBean = GetListenerMBean(listener, out bean);
            NotificationCallback  callback     = new NotificationCallback(listenerBean.HandleNotification);

            emitter.RemoveNotificationListener(callback);
        }
示例#24
0
        public void HandleNotification(ApplicationSettingsBase settings, string pathToNotificationFile, INotificationListener listener)
        {
            Settings = settings;
            PathToNotificationFile = pathToNotificationFile;
            Listener = listener;

            // Setup a worker to process the notification in the background to avoid locking up the
            // application
            var notificationWorker = new BackgroundWorker();

            notificationWorker.DoWork += new DoWorkEventHandler(FetchNotifications);
            notificationWorker.RunWorkerAsync(this);
        }
        public void SendTo_PreservesNotificationPropertiesValues(
            INotificationListener listener,
            EventStreamUpdated notification,
            EventStreamReaderId consumerId)
        {
            var addressedNotification = (EventStreamUpdated)notification.SendTo(listener);

            Assert.Equal(notification.StreamName, addressedNotification.StreamName);
            Assert.Equal(notification.FromVersion, addressedNotification.FromVersion);
            Assert.Equal(notification.ToVersion, addressedNotification.ToVersion);
            Assert.Equal(notification.NotificationType, addressedNotification.NotificationType);
            Assert.Equal(notification.DeliveryCount, addressedNotification.DeliveryCount);
        }
        /// <summary>
        /// Add Notification listener.
        /// </summary>
        /// <param name="listener"></param>
        public void AddListener(INotificationListener listener)
        {
            if (_listeners.Contains(listener))
            {
                return;
            }

            _listeners.Add(listener);

            if (_config.EnableConsoleLogging)
            {
                Debug.Log("[Countly NotificationsCallbackService] AddListener: " + listener);
            }
        }
示例#27
0
    public void Unsubscribe(Notification.Type type, INotificationListener listener)
    {
        if (!m_types.ContainsKey(type))
        {
            return;
        }

        if (!m_types[type].Contains(listener))
        {
            return;
        }

        m_types[type].Remove(listener);
    }
示例#28
0
        public INotification SendTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            if (IsAddressed && IsAddressedTo(listener))
            {
                return(this);
            }

            return(CopyAndUpdate(properties =>
            {
                properties[NotificationPropertyKeys.Common.NOTIFICATION_ID] = NotificationId.Create().ToString();
                properties[NotificationPropertyKeys.Common.RECIPIENT] = listener.GetType().FullName;
            }));
        }
示例#29
0
        public INotification RedeliverTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            return(CopyAndUpdate(properties =>
            {
                properties[NotificationPropertyKeys.Common.NOTIFICATION_ID] = Guid.NewGuid().ToString("N");
                properties[NotificationPropertyKeys.Common.RECIPIENT] = listener.GetType().FullName;

                if (m_deliveryCount > 0)
                {
                    properties[NotificationPropertyKeys.Common.DELIVERY_COUNT] = (m_deliveryCount - 1).ToInvariantString();
                }
            }));
        }
示例#30
0
        public void AddNotificationListener(INotificationListener listener)
        {
            if (listener == null)
            {
                return;
            }
            if (Listeners == null)
            {
                Listeners = new List <INotificationListener>();
            }

            if (!Listeners.Contains(listener))
            {
                Listeners.Add(listener);
            }
        }
示例#31
0
        public void RemoveNotificationListener(INotificationListener listener)
        {
            if (listener == null)
            {
                return;
            }
            if (Listeners == null)
            {
                return;
            }

            if (Listeners.Contains(listener))
            {
                Listeners.Remove(listener);
            }
        }
        public async Task DefferNotificationAsync_SendAddressedNotification(
            [Frozen] Mock <INotificationsChannel> channelMock,
            [Frozen] Mock <INotification> receivedNotificationMock,
            INotification deferredNotification,
            IEventStoreConnection connection,
            INotificationListener listener,
            NotificationListenerSubscription subscription)
        {
            receivedNotificationMock
            .Setup(self => self.SendTo(listener))
            .Returns(deferredNotification);

            subscription.Start(connection);

            await subscription.RetryNotificationProcessingAsync(receivedNotificationMock.Object);

            channelMock
            .Verify(self => self.SendAsync(
                        deferredNotification,
                        It.Is <TimeSpan>(v => TimeSpan.FromSeconds(deferredNotification.DeliveryCount * 2) == v)));
        }
示例#33
0
        /// <summary>
        /// Initializes the notification service.
        /// </summary>
        public static void Init()
        {
            // Get the listener.
            sListener = GetNotificationListener();

            // Subscibe to internal notification events.
            if (sListener != null)
            {
                sListener.LocalNotificationOpened  += InternalOnLocalNotificationOpened;
                sListener.RemoteNotificationOpened += InternalOnRemoteNotificationOpened;
            }

            // Initialize remote notification service.
            // On iOS, OneSignal's NotificationReceived & NotificationOpened will not really fire,
            // because all notification events are handled by us from native side.
            if (EM_Settings.Notifications.PushNotificationService == PushNotificationProvider.OneSignal)
            {
                #if EM_ONESIGNAL
                // The only required method you need to call to setup OneSignal to recieve push notifications.
                // Call before using any other methods on OneSignal.
                // Should only be called once when your game is loaded.
                OneSignal.StartInit(EM_Settings.Notifications.OneSignalAppId)
                .HandleNotificationReceived(sListener.OnOneSignalNotificationReceived)
                .HandleNotificationOpened(sListener.OnOneSignalNotificationOpened)
                .InFocusDisplaying(OneSignal.OSInFocusDisplayOption.None)
                .EndInit();
                #else
                Debug.LogError("SDK missing. Please import OneSignal plugin for Unity.");
                #endif
            }

            // Initialize local notification client.
            // We may need to override some configuration done by the initialization
            // of the remote notification service, so this should be done later.
            LocalNotificationClient.Init(EM_Settings.Notifications, sListener);
        }