示例#1
0
文件: Log.cs 项目: skaveesh/mediocre
 public static void Dbg(object sender, NotificationReceivedEventArgs e)
 {
     if (Verbose)
     {
         Dbg($"device received: {JsonConvert.SerializeObject(e.Result)}");
     }
 }
示例#2
0
 /// <summary>
 /// Fired when a notification was received
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 public async Task OnNotificationAsync(NotificationReceivedEventArgs e)
 {
     if (NotificationReceived != null)
     {
         await NotificationReceived.Invoke(e);
     }
 }
示例#3
0
        private void OnNotificationReceivedHandler(object sender, NotificationReceivedEventArgs e)
        {
            using var scope = _scopeFactory.CreateScope();

            var notificationHandler = scope.ServiceProvider.GetService <INotificationHandler>();

            notificationHandler.Handle(e.Content);
        }
示例#4
0
 /// <summary>
 /// The notifications handler.
 /// </summary>
 /// <param name="notification">The notification.</param>
 public void NotificationHandler(ZWManager manager, NotificationReceivedEventArgs e)
 {
     // Handle the notification on a thread that can safely
     // modify the form controls without throwing an exception.
     m_notification = e.Notification;
     Invoke(new MethodInvoker(NotificationHandler));
     m_notification = null;
 }
        /// <inheritdoc />
        public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action <UNNotificationPresentationOptions> completionHandler)
        {
            try
            {
                var presentationOptions = UNNotificationPresentationOptions.Alert;
                var notificationContent = notification?.Request.Content;

                if (notificationContent != null)
                {
                    var dictionary = notificationContent.UserInfo;
                    var args       = new NotificationReceivedEventArgs
                    {
                        Title       = notificationContent.Title,
                        Description = notificationContent.Body,
                        Data        = dictionary.ContainsKey(NotificationCenter.ExtraReturnDataIos)
                                        ? dictionary[NotificationCenter.ExtraReturnDataIos].ToString()
                                        : ""
                    };

                    NotificationCenter.Current.OnNotificationReceived(args);

                    if (dictionary.ContainsKey(NotificationCenter.ExtraNotificationReceivedIos))
                    {
                        var customOptions = dictionary[NotificationCenter.ExtraNotificationReceivedIos].ToString()
                                            .ToUpperInvariant();
                        if (customOptions == "TRUE")
                        {
                            presentationOptions = UNNotificationPresentationOptions.None;
                        }
                    }

                    if (dictionary.ContainsKey(NotificationCenter.ExtraSoundInForegroundIos))
                    {
                        var customOptions = dictionary[NotificationCenter.ExtraSoundInForegroundIos].ToString()
                                            .ToUpperInvariant();
                        if (customOptions == "TRUE")
                        {
                            presentationOptions = presentationOptions == UNNotificationPresentationOptions.Alert ?
                                                  UNNotificationPresentationOptions.Sound | UNNotificationPresentationOptions.Alert :
                                                  UNNotificationPresentationOptions.Sound;
                        }
                    }
                }

                if (completionHandler is null)
                {
                    return;
                }

                completionHandler(presentationOptions);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
示例#6
0
        private void ShowCustomAlertFromNotification(NotificationReceivedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(e);

            Device.BeginInvokeOnMainThread(() =>
            {
                if (CustomAlert.IsToggled)
                {
                    DisplayAlert(e.Title, e.Description, "OK");
                }
            });
        }
        /// <summary>
        /// Handles Notifications.
        /// </summary>
        /// <param name="notification">The notification.</param>
        private static void NotificationHandler(ZWManager manager, NotificationReceivedEventArgs e)
        {
            var notification = e.Notification;

            switch (notification.Type)
            {
            case ZWNotificationType.ControllerCommand:
            {
                MyControllerStateChangedHandler((ZWControllerState)notification.Event);
                break;
            }
            }
        }
        /// <summary>
        /// This function receives asynchronous one-way
        /// notification for responses.
        /// </summary>
        /// <remarks>
        /// The response handler's name must be the name of the
        /// function that is given in the SPL Dispatch function
        /// for SIP request async calls.
        /// </remarks>
        /// <param name="sender">not used</param>
        /// <param name="e">the arguments for async call</param>
        public void ResponseNotificationHandler(object sender, NotificationReceivedEventArgs e)
        {
            object[] parameters = e.Parameters;

            // First argument from manifest is SIP response code,
            // use it for statistics

            statistics.Update(Response.GetStatusClass((int)parameters[0]));

            // Last two arguments are From and
            // To user, use it for statistics
            statistics.Update(SipUriParser.GetUserAtHost((string)parameters[1]));

            statistics.Update(SipUriParser.GetUserAtHost((string)parameters[2]));

            // Raise the event finally
            this.StateChangeListeners(e);
        }
        /// <summary>
        /// This function receives asynchronous one-way
        /// notification for requests.
        /// </summary>
        /// <remarks>
        /// The request handler's name must be the name of the
        /// function that is given in the SPL Dispatch function
        /// for SIP request async calls.
        /// </remarks>
        /// <param name="sender">not used</param>
        /// <param name="e">the arguments for async call</param>
        public void RequestNotificationHandler(object sender, NotificationReceivedEventArgs e)
        {
            object[] parameters = e.Parameters;

            // First argument from manifest is SIP Method,
            // use it for statistics

            statistics.Update(Request.GetStandardMethod((string)parameters[0]));

            // Next two arguments are From and To user, use it
            // for statistics
            statistics.Update(SipUriParser.GetUserAtHost((string)parameters[1]));

            statistics.Update(SipUriParser.GetUserAtHost((string)parameters[2]));

            // Raise the event finally
            this.StateChangeListeners(e);
        }
示例#10
0
        /// <summary>
        /// Called when notification is received.
        /// Adds received notification to Notifications collection.
        /// </summary>
        /// <param name="sender"> Sender </param>
        /// <param name="e"> Event arguments </param>
        private void MainPage_NotificationReceived(object sender, NotificationReceivedEventArgs e)
        {
            // parsing action and alertMessage from received message
            string[] val  = e.Message.Split('&');
            string   msg1 = "";
            string   msg2 = "";

            foreach (string temp in val)
            {
                if (temp.Contains("action"))
                {
                    msg1 = temp.Substring(temp.IndexOf("=") + 1);
                }

                if (temp.Contains("alertMessage"))
                {
                    msg2 = temp.Substring(temp.IndexOf("=") + 1);
                }
            }

            var notification = new Notification($"Type: {msg1} / Message: {msg2}", e.ReceivedAt.ToString());

            Notifications.Add(notification);
        }
示例#11
0
        /// <summary>
        /// The notifications handler.
        /// </summary>
        /// <param name="notification">The notification.</param>
        private void OnNodeNotification(ZWManager manager, NotificationReceivedEventArgs e)
        {
            if (Dispatcher == null)
            {
                NotificationHandler(e.Notification);
            }
            else
            {
                // Handle the notification on a thread that can safely
                // modify the controls without throwing an exception.
#if NETFX_CORE
                var _ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
#else
                Dispatcher.BeginInvoke(new Action(() =>
#endif
                {
                    NotificationHandler(e.Notification);
                }
#if !NETFX_CORE
                                            )
#endif
                                            );
            }
        }
示例#12
0
 private static void Device_OnNotificationReceived(object sender, NotificationReceivedEventArgs arg)
 {
     WriteLineWithColor($"Notification received !! value : {JsonConvert.SerializeObject(arg.Result)}", ConsoleColor.DarkGray);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancelBeforeShow"></param>
        protected internal virtual void ShowNow(NotificationRequest request, bool cancelBeforeShow)
        {
            if (cancelBeforeShow)
            {
                Cancel(request.NotificationId);
            }

            if (string.IsNullOrWhiteSpace(request.Android.ChannelId))
            {
                request.Android.ChannelId = NotificationCenter.DefaultChannelId;
            }

            using var builder = new NotificationCompat.Builder(Application.Context, request.Android.ChannelId);
            builder.SetContentTitle(request.Title);
            builder.SetContentText(request.Description);
            using (var bigTextStyle = new NotificationCompat.BigTextStyle())
            {
                var bigText = bigTextStyle.BigText(request.Description);
                builder.SetStyle(bigText);
            }
            builder.SetNumber(request.BadgeNumber);
            builder.SetAutoCancel(request.Android.AutoCancel);
            builder.SetOngoing(request.Android.Ongoing);

            if (string.IsNullOrWhiteSpace(request.Android.Group) == false)
            {
                builder.SetGroup(request.Android.Group);
                if (request.Android.IsGroupSummary)
                {
                    builder.SetGroupSummary(true);
                }
            }

            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                builder.SetPriority((int)request.Android.Priority);

                var soundUri = NotificationCenter.GetSoundUri(request.Sound);
                if (soundUri != null)
                {
                    builder.SetSound(soundUri);
                }
            }

            if (request.Android.VibrationPattern != null)
            {
                builder.SetVibrate(request.Android.VibrationPattern);
            }

            if (request.Android.ProgressBarMax.HasValue &&
                request.Android.ProgressBarProgress.HasValue &&
                request.Android.ProgressBarIndeterminate.HasValue)
            {
                builder.SetProgress(request.Android.ProgressBarMax.Value,
                                    request.Android.ProgressBarProgress.Value,
                                    request.Android.ProgressBarIndeterminate.Value);
            }

            if (request.Android.Color.HasValue)
            {
                builder.SetColor(request.Android.Color.Value);
            }

            builder.SetSmallIcon(GetIcon(request.Android.IconName));
            if (request.Android.TimeoutAfter.HasValue)
            {
                builder.SetTimeoutAfter((long)request.Android.TimeoutAfter.Value.TotalMilliseconds);
            }

            var notificationIntent = Application.Context.PackageManager?.GetLaunchIntentForPackage(Application.Context.PackageName ?? string.Empty);

            if (notificationIntent == null)
            {
                Log($"NotificationServiceImpl.ShowNow: notificationIntent is null");
                return;
            }

            notificationIntent.SetFlags(ActivityFlags.SingleTop);
            notificationIntent.PutExtra(NotificationCenter.ExtraReturnDataAndroid, request.ReturningData);
            var pendingIntent = PendingIntent.GetActivity(Application.Context, request.NotificationId, notificationIntent,
                                                          PendingIntentFlags.CancelCurrent);

            builder.SetContentIntent(pendingIntent);

            var notification = builder.Build();

            if (Build.VERSION.SdkInt < BuildVersionCodes.O &&
                request.Android.LedColor.HasValue)
            {
                notification.LedARGB = request.Android.LedColor.Value;
            }

            if (Build.VERSION.SdkInt < BuildVersionCodes.O &&
                string.IsNullOrWhiteSpace(request.Sound))
            {
                notification.Defaults = NotificationDefaults.All;
            }
            NotificationManager?.Notify(request.NotificationId, notification);

            var args = new NotificationReceivedEventArgs
            {
                Title       = request.Title,
                Description = request.Description,
                Data        = request.ReturningData
            };

            NotificationCenter.Current.OnNotificationReceived(args);
        }
 /// <inheritdoc />
 public void OnNotificationReceived(NotificationReceivedEventArgs e)
 {
     NotificationReceived?.Invoke(e);
 }
 private static void DeviceOnOnNotificationReceived(object sender, NotificationReceivedEventArgs e)
 {
     Console.WriteLine($"[Yeelight] Notification: {JsonConvert.SerializeObject(e.Result)}");
 }
示例#16
0
 private void OnLocalNotificationReceived(NotificationReceivedEventArgs e)
 {
     // your code goes here
 }
示例#17
0
 private static void OnNotification(object sender, NotificationReceivedEventArgs e)
 {
     Console.WriteLine($"Recieved notification: {e.Notification}");
 }
示例#18
0
 /// <summary>
 /// Обработка отправки уведомления уведомления
 /// </summary>
 /// <param name="e">параметры уведомления</param>
 private void OnLocalNotificationReceived(NotificationReceivedEventArgs e)
 {
     if (e != null)
     {
     }
 }
示例#19
0
 private void Device_OnNotificationReceived(object sender, NotificationReceivedEventArgs e)
 {
     //throw new NotImplementedException();
 }