Skip to content

Commit f68bb1e

Browse files
authored
Merge pull request #842 from PaitoAnderson/patch-1
Readme Example Code
2 parents 864ede0 + 189a840 commit f68bb1e

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;
@@ -126,16 +125,14 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
126125
aggregateEx.Handle (ex => {
127126

128127
// See what kind of exception it was to further diagnose
129-
if (ex is GcmNotificationException) {
130-
var notificationException = (GcmNotificationException)ex;
128+
if (ex is GcmNotificationException notificationException) {
131129

132130
// Deal with the failed notification
133131
var gcmNotification = notificationException.Notification;
134132
var description = notificationException.Description;
135133

136134
Console.WriteLine ($"{provider} Notification Failed: ID={gcmNotification.MessageId}, Desc={description}");
137-
} else if (ex is GcmMulticastResultException) {
138-
var multicastException = (GcmMulticastResultException)ex;
135+
} else if (ex is GcmMulticastResultException multicastException) {
139136

140137
foreach (var succeededNotification in multicastException.Succeeded) {
141138
Console.WriteLine ($"{provider} Notification Succeeded: ID={succeededNotification.MessageId}");
@@ -148,8 +145,7 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
148145
Console.WriteLine ($"{provider} Notification Failed: ID={n.MessageId}, Desc={e.Description}");
149146
}
150147

151-
} else if (ex is DeviceSubscriptionExpiredException) {
152-
var expiredException = (DeviceSubscriptionExpiredException)ex;
148+
} else if (ex is DeviceSubscriptionExpiredException expiredException) {
153149

154150
var oldId = expiredException.OldSubscriptionId;
155151
var newId = expiredException.NewSubscriptionId;
@@ -160,8 +156,8 @@ gcmBroker.OnNotificationFailed += (notification, aggregateEx) => {
160156
// If this value isn't null, our subscription changed and we should update our database
161157
Console.WriteLine ($"Device RegistrationId Changed To: {newId}");
162158
}
163-
} else if (ex is RetryAfterException) {
164-
var retryException = (RetryAfterException)ex;
159+
} else if (ex is RetryAfterException retryException) {
160+
165161
// If you get rate limited, you should stop sending messages until after the RetryAfterUtc date
166162
Console.WriteLine ($"{provider} Rate Limited, don't send more until after {retryException.RetryAfterUtc}");
167163
} else {
@@ -218,8 +214,7 @@ wnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
218214
aggregateEx.Handle (ex => {
219215

220216
// See what kind of exception it was to further diagnose
221-
if (ex is WnsNotificationException) {
222-
var notificationException = (WnsNotificationException)ex;
217+
if (ex is WnsNotificationException notificationException) {
223218
Console.WriteLine ($"WNS Notification Failed: {notificationException.Message}");
224219
} else {
225220
Console.WriteLine ("WNS Notification Failed for some (Unknown Reason)");

0 commit comments

Comments
 (0)