예제 #1
0
        private void OnSubscribe(string result)
        {
            var message      = JsonConvert.DeserializeObject <string[]>(result)[0];
            var notification = new Notification(Decrypt(message));

            NotificationEvent?.Invoke(this, new NotificatioEventArgs(notification));
        }
예제 #2
0
 private void showNotification(string msg, bool isError)
 {
     if (NotificationEvent != null)
     {
         NotificationEvent.Invoke(this, msg, isError);
     }
 }
예제 #3
0
        private async Task <bool> Subscribe()
        {
            var temp = await rc.Restapi().Subscription().Post(requestBody);

            subscriptionInfo = JsonConvert.DeserializeObject <SubscriptionInfo>(JsonConvert.SerializeObject(temp));
            var pnConfig = new PNConfiguration();

            pnConfig.SubscribeKey = subscriptionInfo.deliveryMode.subscriberKey;
            pubnub = new Pubnub(pnConfig);
            pubnub.AddListener(new SubscribeCallbackExt(
                                   (pubnubObj, message) => {
                NotificationEvent?.Invoke(this, new NotificatioEventArgs(Decrypt(message.Message.ToString())));
            },
                                   (pubnubObj, presence) => {
                PresenceEvent?.Invoke(this, new SubscriptionEventArgs(presence));
            },
                                   (pubnubObj, status) => {
                StatusEvent?.Invoke(this, new SubscriptionEventArgs(status));
            }
                                   ));
            pubnub.Subscribe <string>().Channels(new string[] {
                subscriptionInfo.deliveryMode.address
            }).Execute();
            return(true);
        }
예제 #4
0
    public static bool Send <TMessage>(
        this NotificationEvent <TMessage> notificationEvent,
        TMessage message)
    {
        var notNull = notificationEvent != null;

        if (notNull)
        {
            notificationEvent.Invoke(message);
        }
        return(notNull);
    }
예제 #5
0
 private void ProcessNotifications()
 {
     while (!Terminating)
     {
         try
         {
             byte NotifByte = NotifSerial.ReadBytes(1)[0];
             if (NotificationEvent != null)
             {
                 NotificationReceived = true;
                 if (!WaitingForNotification)
                 {
                     NotificationEvent.Invoke(new NotificationEventArgs()
                     {
                         NotificationByte = NotifByte
                     }, this);
                 }
             }
         }
         catch
         {
         }
     }
 }
예제 #6
0
파일: Report.cs 프로젝트: regata-jinr/Core
        public static void Notify(Message msg, bool callEvent = false, bool WriteToLog = true, bool NotifyByEmail = false)
        {
            try
            {
                StackTrace st     = new StackTrace();
                StackFrame sf     = st.GetFrame(1);
                var        method = sf.GetMethod();

                var status = Status.Info;

//#if NETFRAMEWORK
                switch (msg.Code / 1000)
                {
                case 3:
                    status = Status.Error;
                    break;

                case 2:
                    status = Status.Warning;
                    break;

                case 1:
                    status = Status.Success;
                    break;
                }
                ;
//#endif
                // NOTE: doesn't work with c# 7.3 thats supports by net48 targetframework
                //var status = (msg.Code / 1000) switch
                //{
                //    3 => Status.Error,
                //    2 => Status.Warning,
                //    1 => Status.Success,
                //    _ => Status.Info
                //};


                msg.Sender  = method.DeclaringType.Name;
                msg.Caption = $"{method.Module}-[{status}]-[{msg.Code}]";
                _nLogger.SetProperty("Sender", msg.Sender);
                _nLogger.SetProperty("Code", msg.Code);
                _nLogger.SetProperty("Assistant", GlobalSettings.User);

                if (WriteToLog)
                {
                    _nLogger?.Log(ExceptionLevel_LogLevel[status], string.Concat(msg.Head, "---", msg.DetailedText));
                }

                if (status == Status.Error && NotifyByEmail)
                {
                    SendMessageByEmail(msg);
                }

                if ((int)GlobalSettings.Verbosity <= (int)status || callEvent)
                {
                    NotificationEvent?.Invoke(msg);
                }
            }
            catch (Exception e)
            {
                if (NotificationEvent == null)
                {
                    return;
                }
                e.Data.Add("Assembly", "Regata.Core.Inform.WriteMessage");
                var tstr = e.ToString();
                if (tstr.Length <= 300)
                {
                    _nLogger.Log(NLog.LogLevel.Error, e.ToString());
                }
                else
                {
                    _nLogger.Log(NLog.LogLevel.Error, e.ToString().Substring(0, 300));
                }
            }
        }
예제 #7
0
 internal void FireNotificationEvent(Notification notif) => NotificationEvent?.Invoke(this, new NotificationEventArgs()
 {
     Notification = notif
 });
 private void NotificationHandle(Notification notification)
 {
     NotificationEvent?.Invoke(this, new NotificationEventArgs(notification));
 }
 protected virtual void Notify(NotificationEventArgs e)
 {
     NotificationEvent?.Invoke(this, e);
 }
예제 #10
0
 protected virtual void OnNotificationEvent(Event e)
 {
     NotificationEvent?.Invoke(this, e);
 }
예제 #11
0
 public void Feedback(string login, string message)
 {
     NotificationEvent?.Invoke(this, new NotificationEventArgs {
         UserName = login, Message = message
     });
 }
 public void Broadcast(Notification notification)
 {
     NotificationEvent?.Invoke(this, notification);
 }
예제 #13
0
        /// <summary>
        /// Called when observable notifies observers
        /// </summary>
        /// <param name="value"></param>
        public void OnNext(Achievement value)
        {
            INotificationData notification = (INotificationData)value;

            OnAchieve?.Invoke(notification);
        }
예제 #14
0
 /// <summary>
 /// 异步发送通知
 /// </summary>
 /// <param name="notification"></param>
 /// <param name="args"></param>
 public void SendAsyncNotification(Notification notification, object[] args) =>
 Task.Run(() => NotificationEvent?.Invoke(notification, args));
예제 #15
0
 /// <summary>
 /// 同步发送通知
 /// </summary>
 /// <param name="notification"></param>
 /// <param name="args"></param>
 public void SendNotification(Notification notification, object[] args) =>
 NotificationEvent?.Invoke(notification, args);