private async Task<TypedDeviceTokens> GetMultiUserDeviceTokens(string[] userIds) { var result = new TypedDeviceTokens(); try { var iosTokensBuilder = new StringBuilder(); var androidTokensBuilder = new StringBuilder(); var deviceTokens = await ChicagoServer.BahamutPubSubService.GetUserDeviceTokensAsync(userIds); var iosSeparator = ""; var andSeparator = ""; LogManager.GetLogger("Info").Info("Mutil User Notification:{0}", deviceTokens.Count()); foreach (var dt in deviceTokens) { if (dt == null || dt.IsUnValidToken()) { LogManager.GetLogger("Info").Info("UnvalidToken Type Notification"); } else if (dt.IsIOSDevice()) { iosTokensBuilder.Append(iosSeparator); iosTokensBuilder.Append(dt.Token); iosSeparator = ","; } else if (dt.IsAndroidDevice()) { androidTokensBuilder.Append(andSeparator); androidTokensBuilder.Append(dt.Token); andSeparator = ","; } else { LogManager.GetLogger("Info").Info("Unsupport Type Notification:{0}", dt.Token); } } result.iOSDeviceTokens = iosTokensBuilder.ToString(); result.AndroidDeviceTokens = androidTokensBuilder.ToString(); } catch (System.Exception e) { LogManager.GetLogger("Warn").Warn("Mutil Notification Exception:{0}", e.ToString()); return null; } if(string.IsNullOrWhiteSpace(result.AndroidDeviceTokens) && string.IsNullOrWhiteSpace(result.iOSDeviceTokens)) { return null; } return result; }
private async Task<TypedDeviceTokens> GetSingleUserDeviceToken(string toUser) { var result = new TypedDeviceTokens(); var deviceToken = await BahamutUserManager.GetUserDeviceTokenAsync(toUser); if (deviceToken != null) { if (deviceToken.IsIOSDevice()) { result.iOSDeviceTokens = deviceToken.Token; } else if (deviceToken.IsAndroidDevice()) { result.AndroidDeviceTokens = deviceToken.Token; }else { return null; } return result; }else { return null; } }