Exemple #1
0
        public void Update(NotificationKind kind, Peer peer)
        {
            var       newHealthy = new HashSet <IPAddress>(_healthyEndpoints);
            var       newBan     = new HashSet <IPAddress>(_bannedEndpoints);
            IPAddress endpoint   = peer.RpcAddress;

            switch (kind)
            {
            case NotificationKind.Remove:
                if (newHealthy.Remove(endpoint))
                {
                    _healthyEndpoints = newHealthy.OrderBy(e => e, epComparer).ToArray();
                }
                if (newBan.Remove(endpoint))
                {
                    _bannedEndpoints = newBan.ToArray();
                }
                break;

            case NotificationKind.Add:
            case NotificationKind.Update:
                if (!newHealthy.Contains(endpoint) && !newBan.Contains(endpoint))
                {
                    newHealthy.Add(endpoint);
                    _healthyEndpoints = newHealthy.OrderBy(e => e, epComparer).ToArray();
                }
                break;
            }
        }
Exemple #2
0
            public override void OnError(Exception error)
            {
                Dispose();

                _error = error;
                _kind  = NotificationKind.OnError;     // Write last!
            }
Exemple #3
0
        public void Update(NotificationKind kind, Peer peer)
        {
            lock (_lock)
            {
                IPAddress endpoint = peer.RpcAddress;
                switch (kind)
                {
                case NotificationKind.Add:
                    if (!_healthyEndpoints.Contains(endpoint))
                    {
                        _healthyEndpoints.Add(endpoint);
                        _ring.AddOrUpdateNode(peer);
                    }
                    break;

                case NotificationKind.Update:
                    _ring.AddOrUpdateNode(peer);
                    break;

                case NotificationKind.Remove:
                    if (_healthyEndpoints.Contains(endpoint))
                    {
                        _healthyEndpoints.Remove(endpoint);
                        _ring.RemoveNode(endpoint);
                    }
                    break;
                }
            }
        }
 public SubscribedEvent(Guid subscriptionId, NotificationKind kind, string paramUri, Dictionary<string, string> extendedInformation)
 {
     SubscriptionId = subscriptionId;
     Kind = kind;
     ParamUri = paramUri;
     ExtendedInformation = extendedInformation;
 }
 public SubscribeCommand(Guid clientId, Guid subscriptionId, NotificationKind kind, string uri, Dictionary<string, string> extendedInformation)
 {
     ClientId = clientId;
     SubscriptionId = subscriptionId;
     Kind = kind;
     Uri = uri;
     ExtendedInformation = extendedInformation;
 }
Exemple #6
0
 protected void notify(NotificationKind kind, string message)
 {
     if (_notifier != null)
     {
         _notifier.notify(new Notification {
             Kind = kind, Message = message
         });
     }
 }
        private async Task TestCore(NotificationKind notificationKind, string message)
        {
            Assert.AreEqual(notificationKind, mock.NotificationKind);
            Assert.AreEqual(message, mock.Message);
            await Task.Delay(200);

            Assert.IsNull(mock.NotificationKind);
            Assert.IsNull(mock.Message);
        }
Exemple #8
0
            private void ProcessNext()
            {
                object obj = this.actions;

                lock (obj)
                {
                    if (this.actions.Count != 0 && !this.isDisposed)
                    {
                        ObserveOnObservable <T> .ObserveOn.SchedulableAction action = this.actions.First.Value;
                        if (!action.IsScheduled)
                        {
                            action.schedule = this.parent.scheduler.Schedule(delegate()
                            {
                                try
                                {
                                    NotificationKind kind = action.data.Kind;
                                    if (kind != NotificationKind.OnNext)
                                    {
                                        if (kind != NotificationKind.OnError)
                                        {
                                            if (kind == NotificationKind.OnCompleted)
                                            {
                                                this.observer.OnCompleted();
                                            }
                                        }
                                        else
                                        {
                                            this.observer.OnError(action.data.Exception);
                                        }
                                    }
                                    else
                                    {
                                        this.observer.OnNext(action.data.Value);
                                    }
                                }
                                finally
                                {
                                    object obj2 = this.actions;
                                    lock (obj2)
                                    {
                                        action.Dispose();
                                    }
                                    if (action.data.Kind == NotificationKind.OnNext)
                                    {
                                        this.ProcessNext();
                                    }
                                    else
                                    {
                                        this.Dispose();
                                    }
                                }
                            });
                        }
                    }
                }
            }
Exemple #9
0
 public Notification(Guid id, NotificationKind kind, string method, string content, User user)
 {
     Id      = id;
     Kind    = kind;
     Method  = method;
     User    = user;
     UserId  = user.Id;
     Content = content ?? throw SheaftException.Validation("Le contenu de la notification est requis.");
     Unread  = true;
 }
 public void Update(NotificationKind kind, Peer peer)
 {
     lock (_lock)
     {
         IPAddress endpoint = peer.RpcAddress;
         if (!_healthyEndpoints.Contains(endpoint) && !_bannedEndpoints.Contains(endpoint))
         {
             _healthyEndpoints.Add(endpoint);
         }
     }
 }
Exemple #11
0
        private NotificationResponse SendRequest(string subscriptionUri, byte[] notificationMessage, NotificationKind kind)
        {
            HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(subscriptionUri);

            // HTTP POST is the only allowed method to send the notification.
            sendNotificationRequest.Method = "POST";

            // The optional custom header X-MessageID uniquely identifies a notification message. If it is present, the
            // same value is returned in the notification response. It must be a string that contains a UUID.
            sendNotificationRequest.Headers.Add("X-MessageID", Guid.NewGuid().ToString());
            if (kind == NotificationKind.Tile)
            {
                sendNotificationRequest.ContentType = "text/xml";
                sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
            }
            else if (kind == NotificationKind.Toast)
            {
                sendNotificationRequest.ContentType = "text/xml";
                sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
            }

            // TODO Add support for other notification classes
            var notificationClass = ((int)NotificationClass.Immediately) + (int)kind;
            sendNotificationRequest.Headers.Add("X-NotificationClass", notificationClass.ToString());

            // Sets the web request content length.
            sendNotificationRequest.ContentLength = notificationMessage.Length;

            using (Stream requestStream = sendNotificationRequest.GetRequestStream())
            {
                requestStream.Write(notificationMessage, 0, notificationMessage.Length);
            }

            // Sends the notification and make sure we handle the response eventually
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)sendNotificationRequest.GetResponse();
            }
            catch(WebException ex)
            {
                response = ex.Response as HttpWebResponse;
            }

            var notResponse = new NotificationResponse
                                  {
                                      StatusCode = (int)response.StatusCode,
                                      NotificationStatus = response.Headers["X-NotificationStatus"],
                                      SubscriptionStatus = response.Headers["X-SubscriptionStatus"],
                                      DeviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"]
                                  };

            return notResponse;
        }
Exemple #12
0
 public void Update(NotificationKind kind, Peer peer)
 {
     lock (_lock)
     {
         IPAddress endpoint = peer.RpcAddress;
         if (!_healthyEndpoints.Contains(endpoint) && !_bannedEndpoints.Contains(endpoint))
         {
             _healthyEndpoints.Add(endpoint);
         }
     }
 }
Exemple #13
0
        public void Concat2()
        {
            var expected = new NotificationKind [] {
                NotificationKind.OnNext,
                NotificationKind.OnNext,
                NotificationKind.OnError
            };
            var source = Observable.Range(0, 2).Concat(Observable.Throw <int> (new Exception("failure")));
            var arr    = from n in source.Materialize().ToEnumerable() select n.Kind;

            Assert.AreEqual(expected, arr.ToArray(), "#1");
        }
        protected override Task ServerSendAsync(NotificationKind kind, object data)
        {
            var messageKind = GetMessageKind(kind);

            if (messageKind == QbservableProtocolMessageKind.OnCompleted)
            {
                return(SendMessageAsync(new QbservableMessage(messageKind)));
            }
            else
            {
                return(SendMessageAsync(messageKind, data));
            }
        }
Exemple #15
0
            public override void OnNext(TSource value)
            {
                lock (_gate)
                {
                    if (_waiting)
                    {
                        _value = value;
                        _kind  = NotificationKind.OnNext;
                        _semaphore.Release();
                    }

                    _waiting = false;
                }
            }
Exemple #16
0
        public NotificationItem(float lifeTime, NotificationKind notificationKind, string message)
        {
            _spriteFont = GameInstance.Content.Load<SpriteFont>(ResourceNames.Fonts.NotificationFont);
            _backgroundColor = new Color(70, 70, 70);
            _notificationIcons = GameInstance.Content.Load<Texture2D>(ResourceNames.Textures.NotificationIcons);
            NotificationKind = notificationKind;
            Message = message;
            
            var transit = lifeTime*0.125f;
            _remainingLifeTime = lifeTime - 2*transit;

            EnterAnimation = new UiAlphaAnimation(transit, 0,1);
            LeaveAnimation = new UiAlphaAnimation(transit, 1, 0);
        }
Exemple #17
0
        public NotificationItem(float lifeTime, NotificationKind notificationKind, string message)
        {
            _spriteFont        = GameInstance.Content.Load <SpriteFont>(ResourceNames.Fonts.NotificationFont);
            _backgroundColor   = new Color(70, 70, 70);
            _notificationIcons = GameInstance.Content.Load <Texture2D>(ResourceNames.Textures.NotificationIcons);
            NotificationKind   = notificationKind;
            Message            = message;

            var transit = lifeTime * 0.125f;

            _remainingLifeTime = lifeTime - 2 * transit;

            EnterAnimation = new UiAlphaAnimation(transit, 0, 1);
            LeaveAnimation = new UiAlphaAnimation(transit, 1, 0);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Marble" /> class.
        /// </summary>
        /// <param name="streamKey"></param>
        /// <param name="kind">The kind.</param>
        /// <param name="elapsed">The elapsed.</param>
        /// <param name="machineName">Name of the machine.</param>
        internal Marble(
            string streamKey,
            NotificationKind kind,
            TimeSpan elapsed,
            string machineName)
        {
            StreamKey = streamKey;
            Kind      = kind;

            Offset = elapsed;

            DateCreatedUtc = DateTime.UtcNow;

            MachineName = machineName;
        }
        public void HandleNotificationEvent(IUIAutomationElement sender, NotificationKind kind, NotificationProcessing process, string displayString, string activityId)
        {
            var m = EventMessage.GetInstance(this.EventId, sender);

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("NotificationKind", kind.ToString()),
                    new KeyValuePair <string, dynamic>("NotificationProcessing", process.ToString()),
                    new KeyValuePair <string, dynamic>("Display", displayString),
                    new KeyValuePair <string, dynamic>("ActivityId", activityId),
                };
                this.ListenEventMessage(m);
            }
        }
Exemple #20
0
        public void Materialize()
        {
            var expected = new NotificationKind [] {
                NotificationKind.OnNext,
                NotificationKind.OnNext,
                NotificationKind.OnError
            };
            var  source = Observable.Range(0, 2).Concat(Observable.Throw <int> (new Exception("failure")));
            var  l      = new List <NotificationKind> ();
            bool done   = false;
            var  dis    = source.Materialize().Subscribe(v => l.Add(v.Kind), () => done = true);            // test that Materialize() yields OnCompleted event after yielding OnError.

            Assert.IsTrue(SpinWait.SpinUntil(() => done, TimeSpan.FromSeconds(1)), "#1");
            Assert.AreEqual(expected, l.ToArray(), "#3");
            dis.Dispose();
        }
Exemple #21
0
            public override void OnNext(TSource value)
            {
                var lackedValue = false;

                lock (_gate)
                {
                    lackedValue            = !_notificationAvailable;
                    _notificationAvailable = true;
                    _kind  = NotificationKind.OnNext;
                    _value = value;
                }

                if (lackedValue)
                {
                    _semaphore.Release();
                }
            }
        private static QbservableProtocolMessageKind GetMessageKind(NotificationKind kind)
        {
            switch (kind)
            {
            case NotificationKind.OnNext:
                return(QbservableProtocolMessageKind.OnNext);

            case NotificationKind.OnCompleted:
                return(QbservableProtocolMessageKind.OnCompleted);

            case NotificationKind.OnError:
                return(QbservableProtocolMessageKind.OnError);

            default:
                throw new ArgumentOutOfRangeException("kind");
            }
        }
        public void Update(NotificationKind kind, Peer peer)
        {
            lock (_lock)
            {
                bool updated = false;
                IPAddress endpoint = peer.RpcAddress;
                if (!_healthyEndpoints.Contains(endpoint) && !_bannedEndpoints.Contains(endpoint))
                {
                    _healthyEndpoints.Add(endpoint);
                    updated = true;
                }

                if (updated)
                {
                    _healthyEndpoints.Sort((a1, a2) => _snitch.CompareEndpoints(_clientAddress, a1, a2));
                }
            }
        }
Exemple #24
0
        public void Update(NotificationKind kind, Peer peer)
        {
            lock (_lock)
            {
                bool      updated  = false;
                IPAddress endpoint = peer.RpcAddress;
                if (!_healthyEndpoints.Contains(endpoint) && !_bannedEndpoints.Contains(endpoint))
                {
                    _healthyEndpoints.Add(endpoint);
                    updated = true;
                }

                if (updated)
                {
                    _healthyEndpoints.Sort((a1, a2) => _snitch.CompareEndpoints(_clientAddress, a1, a2));
                }
            }
        }
Exemple #25
0
            public override void OnCompleted()
            {
                Dispose();

                var lackedValue = false;

                lock (_gate)
                {
                    lackedValue            = !_notificationAvailable;
                    _notificationAvailable = true;
                    _kind = NotificationKind.OnCompleted;
                }

                if (lackedValue)
                {
                    _semaphore.Release();
                }
            }
Exemple #26
0
        public void Concat3()
        {
            var expected = new NotificationKind [] {
                NotificationKind.OnNext,
                NotificationKind.OnNext,
                NotificationKind.OnNext,
                NotificationKind.OnNext,
                NotificationKind.OnCompleted
            };
            var  scheduler = new HistoricalScheduler();
            var  source    = Observable.Range(1, 3).Concat(Observable.Return(2).Delay(TimeSpan.FromMilliseconds(50), scheduler));
            bool done      = false;
            var  l         = new List <NotificationKind> ();

            source.Materialize().Subscribe(v => l.Add(v.Kind), () => done = true);
            scheduler.AdvanceBy(TimeSpan.FromMilliseconds(50));
            Assert.AreEqual(expected, l.ToArray(), "#1");
            Assert.IsTrue(done, "#2");
        }
Exemple #27
0
 public void PushNotification(NotificationKind notificationKind, string message)
 {
     lock (_lockObject)
     {
         var notificationItem = new NotificationItem(_notificationTime, notificationKind, message)
         {
             Width = _barWidth
         };
         notificationItem.Show();
         _notifications.Add(notificationItem);
         AddChildElement(notificationItem);
         if (_notifications.Count > _maxNotifications)
         {
             RemoveChild(_notifications.First());
             _notifications.RemoveAt(0);
         }
         UpdateIndices();
     }
 }
Exemple #28
0
 public void PushNotification(NotificationKind notificationKind, string message)
 {
     lock (_lockObject)
     {
         var notificationItem = new NotificationItem(_notificationTime, notificationKind, message)
         {
             Width = _barWidth
         };
         notificationItem.Show();
         _notifications.Add(notificationItem);
         AddChildElement(notificationItem);
         if (_notifications.Count > _maxNotifications)
         {
             RemoveChild(_notifications.First());
             _notifications.RemoveAt(0);
         }
         UpdateIndices();
     }
 }
Exemple #29
0
            public override void OnCompleted()
            {
                Dispose();

                lock (_gate)
                {
                    //
                    // BREAKING CHANGE v2 > v1.x - Next doesn't block indefinitely when it reaches the end.
                    //
                    _kind = NotificationKind.OnCompleted;

                    if (_waiting)
                    {
                        _semaphore.Release();
                    }

                    _waiting = false;
                }
            }
Exemple #30
0
            public override void OnError(Exception error)
            {
                Dispose();

                var lackedValue = false;

                lock (_gate)
                {
                    lackedValue            = !_notificationAvailable;
                    _notificationAvailable = true;
                    _kind  = NotificationKind.OnError;
                    _error = error;
                }

                if (lackedValue)
                {
                    _semaphore.Release();
                }
            }
#pragma warning disable CA1725 // Parameter names should match base declaration
        public void HandleNotificationEvent(IUIAutomationElement sender, NotificationKind notificationKind, NotificationProcessing notificationProcessing, string displayString, string activityId)
#pragma warning restore CA1725 // Parameter names should match base declaration
        {
#pragma warning disable CA2000 // Call IDisposable.Dispose()
            var m = EventMessage.GetInstance(this.EventId, sender);
#pragma warning restore CA2000

            if (m != null)
            {
                m.Properties = new List <KeyValuePair <string, dynamic> >
                {
                    new KeyValuePair <string, dynamic>("NotificationKind", notificationKind.ToString()),
                    new KeyValuePair <string, dynamic>("NotificationProcessing", notificationProcessing.ToString()),
                    new KeyValuePair <string, dynamic>("Display", displayString),
                    new KeyValuePair <string, dynamic>("ActivityId", activityId),
                };
                this.ListenEventMessage(m);
            }
        }
Exemple #32
0
            public override void OnError(Exception error)
            {
                base.Dispose();

                lock (_gate)
                {
                    //
                    // BREAKING CHANGE v2 > v1.x - Next doesn't block indefinitely when it reaches the end.
                    //
                    _error = error;
                    _kind  = NotificationKind.OnError;

                    if (_waiting)
                    {
                        _semaphore.Release();
                    }

                    _waiting = false;
                }
            }
Exemple #33
0
        public void Update(NotificationKind kind, Peer peer)
        {
            var       newHealthy = new HashSet <IPAddress>(_healthyEndpoints);
            IPAddress endpoint   = peer.RpcAddress;

            switch (kind)
            {
            case NotificationKind.Add:
                if (!newHealthy.Contains(endpoint))
                {
                    newHealthy.Add(endpoint);
                    _healthyEndpoints = newHealthy.ToArray();
                    lock (_ring)
                    {
                        _ring.AddOrUpdateNode(peer);
                    }
                }
                break;

            case NotificationKind.Update:
                lock (_ring)
                {
                    _ring.AddOrUpdateNode(peer);
                }
                break;

            case NotificationKind.Remove:
                if (newHealthy.Contains(endpoint))
                {
                    newHealthy.Remove(endpoint);
                    _healthyEndpoints = newHealthy.ToArray();
                    lock (_ring)
                    {
                        _ring.RemoveNode(endpoint);
                    }
                }
                break;
            }
        }
Exemple #34
0
        public void CreateNotification(NotificationKind kind, long userId)
        {
            var user = _dbContext.Users.FirstOrDefault(x => x.UserId == userId);

            if (user == null)
            {
                throw new UserException(UserError.DoesNotExist);
            }

            Notification notification = new Notification
            {
                Kind = kind,
                User = user
            };

            _dbContext.Notifications.Add(notification);

            if (_dbContext.SaveChanges() != 1)
            {
                throw new NotificationException(NotificationError.NotCreated);
            }
        }
 public void Update(NotificationKind kind, Peer peer)
 {
     lock (_lock)
     {
         IPAddress endpoint = peer.RpcAddress;
         switch (kind)
         {
             case NotificationKind.Add:
             case NotificationKind.Update:
                 if (!_healthyEndpoints.Contains(endpoint) && !_bannedEndpoints.Contains(endpoint))
                 {
                     _healthyEndpoints.Add(endpoint);
                 }
                 break;
             case NotificationKind.Remove:
                 if (_healthyEndpoints.Contains(endpoint))
                 {
                     _healthyEndpoints.Remove(endpoint);
                 }
                 break;
         }
     }
 }
 /// <summary>
 /// View the details of multiple notifications
 /// </summary>
 /// <param name="kind">The kind of notification (Dashboard, Api, or Automated)</param>
 /// <param name="limit">The number of notifications per page</param>
 /// <param name="offset">The number of notifications to skip</param>
 /// <param name="appId">Optional app id if you want an app id different than what is defined in OneSignalConfiguration</param>
 /// <returns>Paginated list of notifications</returns>
 public ViewNotificationsResponse ViewNotifications(NotificationKind kind, int limit = 50, int offset = 0, string appId = null)
 {
     return(Get <ViewNotificationsResponse>($"notifications?app_id={appId ?? OneSignalConfiguration.GetAppId()}&limit={limit}&offset={offset}&kind={kind}"));
 }
Exemple #37
0
        private void PostNotification(string id, string text, Action clickHandler, NotificationKind kind, string informationUrl = "")
        {
            ToolTipIcon icon = ToolTipIcon.Info;
            switch (kind)
            {
                case NotificationKind.Default:
                    icon = ToolTipIcon.None;
                    break;
                case NotificationKind.Information:
                    icon = ToolTipIcon.Info;
                    break;
                case NotificationKind.Warning:
                    icon = ToolTipIcon.Warning;
                    break;
                case NotificationKind.Danger:
                    icon = ToolTipIcon.Error;
                    break;
            }

            notificationsControl.AddNotification(id, text, clickHandler, kind, informationUrl);

            if (notifyIcon1.Visible)
                ShowBalloonNotification(text, clickHandler, icon);
        }
 public ApplicationMessage(NotificationKind kind)
 {
     NotificationKind = kind;
 }
Exemple #39
0
 protected void notify(NotificationKind kind, string message)
 {
     if (_notifier != null)
         _notifier.notify(new Notification { Kind = kind, Message = message });
 }
 protected void HandleNotificationEvent(SHAutomationElement sender, NotificationKind notificationKind,
                                        NotificationProcessing notificationProcessing, string displaystring, string activityId)
 {
     _callAction(sender, notificationKind, notificationProcessing, displaystring, activityId);
 }
Exemple #41
0
 /// <summary>
 /// Show a confirmation message in the taskbar
 /// </summary>
 protected void ShowConfirmation(string title, string message, NotificationKind notificationKind)
 {
     CDPMessageBus.Current.SendMessage(new TaskbarNotificationEvent(title, message, notificationKind));
 }
Exemple #42
0
 public void Subscribe(Guid subscriptionId, NotificationKind notificationKind, string notificationUri, Dictionary<string, string> extendedInformation)
 {
     PublishEvent(new SubscribedEvent(subscriptionId, notificationKind, notificationUri, extendedInformation));
 }
Exemple #43
0
 public Subscription(Guid subscriptionId, NotificationKind kind, string paramUri)
 {
     SubscriptionId = subscriptionId;
     Kind = kind;
     ParamUri = paramUri;
 }
Exemple #44
0
 public void Update(NotificationKind kind, Peer peer)
 {
     throw new NotImplementedException();
 }
        private void PostNotification(string id, string text, Action clickHandler, NotificationKind kind, string informationUrl)
        {
            NotificationEventArgs notification = new NotificationEventArgs
            {
                Id = id,
                Text = text,
                ClickHandler = clickHandler,
                Kind = kind,
                InformationUrl = informationUrl
            };

            if (NotificationReceived != null) NotificationReceived(this, notification);
        }
 private void PostNotification(string text, NotificationKind icon, string informationUrl = "")
 {
     PostNotification(text, text, () => { }, icon, informationUrl);
 }
 public void QueueMobileMinerNotification(string text, NotificationKind kind)
 {
     Notification notification = new Notification
     {
         NotificationText = text,
         MachineName = Environment.MachineName,
         NotificationKind = kind
     };
     queuedNotifications.Add(notification);
 }
 private void PostNotification(string text, Action clickHandler, NotificationKind icon, string informationUrl = "")
 {
     PostNotification(text, text, clickHandler, icon, informationUrl);
 }