From 1590c6d6f63d6f8abe09c1480481bd8e836c422e Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 27 Feb 2019 13:37:50 -0600 Subject: [PATCH 1/2] SPARK-2076 Sounds crash (Dan 1.5) --- src/client/spark/Notifications/INotificationService.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/client/spark/Notifications/INotificationService.cs b/src/client/spark/Notifications/INotificationService.cs index eb3823cc7..20cdc7659 100644 --- a/src/client/spark/Notifications/INotificationService.cs +++ b/src/client/spark/Notifications/INotificationService.cs @@ -25,14 +25,20 @@ namespace bts.shell { } static class NotificationServiceExtensions { + /// TODO: remove this extension and force callers to use the appropriate 'link' method in (it is smelly, and is NOT ACTUALLY STRONGLY TYPED) public static IDisposable link(this INotificationService notification_service, IPredicate predicate, SoundNotification sound) { if (predicate is IPredicate orp) return notification_service.link_to_order(orp, sound); + if (predicate is IPredicate osp) { + // Note: watch out for implicit types as generic type arguments (although OrderSecurity can be implicitly cast to OrderTuple, IPredicate CANNOT be implicitly cast to IPredicate) + return notification_service.link_to_order(PredicateBuilder.create(ot => osp.trigger(new OrderSecurity(ot.Item1, ot.Item2))), sound); + } if (predicate is IPredicate ap) return notification_service.link_to_activity(ap, sound); throw new ArgumentException(nameof(predicate)); } + /// TODO: remove this extension and force callers to use the appropriate 'link' method in (it is smelly, and is NOT ACTUALLY STRONGLY TYPED) public static IDisposable link(this INotificationService notification_service, INotificationPredicate toast_notification_predicate) { if (toast_notification_predicate is INotificationPredicate orp) return notification_service.link_to_order(orp); From 9864d18a60c338e2ed1e1e2dc28f8d97c0668c55 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Wed, 27 Feb 2019 14:37:53 -0600 Subject: [PATCH 2/2] SPARK-2076 [pr edit] log error instead of throwing an exception (when unable to link predicate). --- src/client/spark/Notifications/INotificationService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/spark/Notifications/INotificationService.cs b/src/client/spark/Notifications/INotificationService.cs index 20cdc7659..282fcd3ca 100644 --- a/src/client/spark/Notifications/INotificationService.cs +++ b/src/client/spark/Notifications/INotificationService.cs @@ -35,7 +35,8 @@ namespace bts.shell { } if (predicate is IPredicate ap) return notification_service.link_to_activity(ap, sound); - throw new ArgumentException(nameof(predicate)); + Log.Ui.error($"Unable to activate sound-trigger (unrecognized predicate type '{typeof(T)}')."); + return Disposable.empty; } /// TODO: remove this extension and force callers to use the appropriate 'link' method in (it is smelly, and is NOT ACTUALLY STRONGLY TYPED) @@ -44,7 +45,8 @@ namespace bts.shell { return notification_service.link_to_order(orp); if (toast_notification_predicate is INotificationPredicate ap) return notification_service.link_to_activity(ap); - throw new ArgumentException(nameof(toast_notification_predicate)); + Log.Ui.error($"Unable to activate toast-notification-trigger (unrecognized predicate type '{typeof(T)}')."); + return Disposable.empty; } }