Skip to content

Commit ceb9daf

Browse files
💄 Readme Example Code
1 parent a0dc0ac commit ceb9daf

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
3939
aggregateEx.Handle (ex => {
4040

4141
// See what kind of exception it was to further diagnose
42-
if (ex is ApnsNotificationException) {
43-
var notificationException = (ApnsNotificationException)ex;
42+
if (ex is ApnsNotificationException notificationException) {
4443

4544
// Deal with the failed notification
4645
var apnsNotification = notificationException.Notification;
@@ -120,16 +119,14 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
120119
aggregateEx.Handle (ex => {
121120

122121
// See what kind of exception it was to further diagnose
123-
if (ex is GcmNotificationException) {
124-
var notificationException = (GcmNotificationException)ex;
122+
if (ex is GcmNotificationException notificationException) {
125123

126124
// Deal with the failed notification
127125
var gcmNotification = notificationException.Notification;
128126
var description = notificationException.Description;
129127

130128
Console.WriteLine ($"GCM Notification Failed: ID={gcmNotification.MessageId}, Desc={description}");
131-
} else if (ex is GcmMulticastResultException) {
132-
var multicastException = (GcmMulticastResultException)ex;
129+
} else if (ex is GcmMulticastResultException multicastException) {
133130

134131
foreach (var succeededNotification in multicastException.Succeeded) {
135132
Console.WriteLine ($"GCM Notification Succeeded: ID={succeededNotification.MessageId}");
@@ -142,8 +139,7 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
142139
Console.WriteLine ($"GCM Notification Failed: ID={n.MessageId}, Desc={e.Description}");
143140
}
144141

145-
} else if (ex is DeviceSubscriptionExpiredException) {
146-
var expiredException = (DeviceSubscriptionExpiredException)ex;
142+
} else if (ex is DeviceSubscriptionExpiredException expiredException) {
147143

148144
var oldId = expiredException.OldSubscriptionId;
149145
var newId = expiredException.NewSubscriptionId;
@@ -154,8 +150,8 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
154150
// If this value isn't null, our subscription changed and we should update our database
155151
Console.WriteLine ($"Device RegistrationId Changed To: {newId}");
156152
}
157-
} else if (ex is RetryAfterException) {
158-
var retryException = (RetryAfterException)ex;
153+
} else if (ex is RetryAfterException retryException) {
154+
159155
// If you get rate limited, you should stop sending messages until after the RetryAfterUtc date
160156
Console.WriteLine ($"GCM Rate Limited, don't send more until after {retryException.RetryAfterUtc}");
161157
} else {
@@ -212,8 +208,7 @@ wnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
212208
aggregateEx.Handle (ex => {
213209

214210
// See what kind of exception it was to further diagnose
215-
if (ex is WnsNotificationException) {
216-
var notificationException = (WnsNotificationException)ex;
211+
if (ex is WnsNotificationException notificationException) {
217212
Console.WriteLine ($"WNS Notification Failed: {notificationException.Message}");
218213
} else {
219214
Console.WriteLine ("WNS Notification Failed for some (Unknown Reason)");

0 commit comments

Comments
 (0)