public static void PublishChatMessages(this BahamutPubSubService service, ObjectId senderId, ShareChat chat, ChatMessage msg)
        {
            foreach (var user in chat.UserIds)
            {
                if (user != senderId)
                {

                    var idstr = user.ToString();
                    var cacheModel = new BahamutCacheModel
                    {
                        AppUniqueId = Startup.Appname,
                        CacheDateTime = DateTime.UtcNow,
                        UniqueId = idstr,
                        DeserializableString = msg.Id.ToString(),
                        Type = ChatMessage.NotifyType,
                        ExtraInfo = chat.Id.ToString()
                    };
                    Startup.ServicesProvider.GetBahamutCacheService().PushCacheModelToList(cacheModel);
                    var pbModel = new BahamutPublishModel
                    {
                        NotifyType = "Toronto",
                        ToUser = idstr,
                        CustomCmd = "UsrNewMsg",
                        NotifyInfo = JsonConvert.SerializeObject(new { LocKey = "NEW_MSG_NOTIFICATION" })
                    };
                    Startup.ServicesProvider.GetBahamutPubSubService().PublishBahamutUserNotifyMessage(PublishConstants.NotifyId, pbModel);
                }
            }
        }
 public async Task<bool> RegistDeviceTokenAsync(BahamutPublishModel msgModel)
 {
     dynamic msg = Newtonsoft.Json.JsonConvert.DeserializeObject(msgModel.Info);
     var dt = new DeviceToken
     {
         Token = msg.DeviceToken,
         Type = msg.DeviceType
     };
     string accountid = msg.AccountId;
     LogManager.GetLogger("Info").Info("Regist {0} Device Of Account:{1}",dt.Type, accountid);
     return await ChicagoServer.BahamutPubSubService.RegistUserDeviceAsync(msgModel.ToUser, dt, DeviceTokenExpireTime);
 }
 public static void PublishLinkMessages(this BahamutPubSubService service, string toSharelinkerId, LinkMessage linkMessage)
 {
     var cacheModel = new BahamutCacheModel
     {
         AppUniqueId = Startup.Appname,
         CacheDateTime = DateTime.UtcNow,
         UniqueId = toSharelinkerId,
         DeserializableString = JsonConvert.SerializeObject(linkMessage),
         Type = LinkMessage.NotifyType
     };
     Startup.ServicesProvider.GetBahamutCacheService().PushCacheModelToList(cacheModel);
     var pbModel = new BahamutPublishModel
     {
         NotifyType = "Toronto",
         ToUser = toSharelinkerId,
         CustomCmd = "UsrNewLinkMsg",
         NotifyInfo = JsonConvert.SerializeObject(new { LocKey = "NEW_FRI_MSG_NOTIFICATION" })
     };
     Startup.ServicesProvider.GetBahamutPubSubService().PublishBahamutUserNotifyMessage(PublishConstants.NotifyId, pbModel);
 }
 public static void PublishShareUpdatedMessages(this BahamutPubSubService service, string userId, ShareThingUpdatedMessage updateMsg)
 {
     var cacheModel = new BahamutCacheModel
     {
         AppUniqueId = Startup.Appname,
         CacheDateTime = DateTime.UtcNow,
         UniqueId = userId,
         DeserializableString = JsonConvert.SerializeObject(updateMsg),
         Type = ShareThingUpdatedMessage.NotifyType
     };
     Startup.ServicesProvider.GetBahamutCacheService().PushCacheModelToList(cacheModel);
     var pbModel = new BahamutPublishModel
     {
         NotifyType = "Toronto",
         ToUser = userId,
         CustomCmd = "UsrNewSTMsg",
         NotifyInfo = JsonConvert.SerializeObject(new { LocKey = "NEW_SHARE_NOTIFICATION" })
     };
     Startup.ServicesProvider.GetBahamutPubSubService().PublishBahamutUserNotifyMessage(PublishConstants.NotifyId, pbModel);
 }
 public void PublishBahamutUserNotifyMessage(string appChannel, BahamutPublishModel message)
 {
     if (string.IsNullOrWhiteSpace(appChannel))
     {
         throw new Exception("App Channel Is Empty");
     }
     if (string.IsNullOrWhiteSpace(message.ToUser))
     {
         throw new Exception("To User Is Empty");
     }
     if (string.IsNullOrWhiteSpace(message.NotifyType))
     {
         throw new Exception("Notify Type Is Empty");
     }
     Task.Run(async () =>
     {
         await pubsubRedis.GetDatabase().PublishAsync(AddChannelWithPrefix(appChannel), JsonConvert.SerializeObject(message, Formatting.None));
     });
 }
 private async Task SendBahamutAPNSNotification(string appChannel, string deviceToken, BahamutPublishModel model)
 {
     try
     {
         var umessageModel = UMessageApps[appChannel];
         var umodel = JsonConvert.DeserializeObject<UMengMessageModel>(model.NotifyInfo);
         await UMengPushNotificationUtil.PushAPNSNotifyToUMessage(deviceToken, umessageModel.AppkeyIOS, umessageModel.SecretIOS, umodel);
     }
     catch (Exception)
     {
         LogManager.GetLogger("Warn").Warn("No App Regist:{0}", appChannel);
     }
 }
 private void SendBahamutNotifyCmd(BahamutPublishModel msgModel, BahamutAppUser registedUser)
 {
     var cmd = string.IsNullOrWhiteSpace(msgModel.CustomCmd) ? DEFAULT_NOTIFY_CMD : msgModel.CustomCmd;
     object resObj = null;
     if (msgModel.NotifyType == null && msgModel.Info == null)
     {
         resObj = new { };
     }
     else if (msgModel.Info == null)
     {
         resObj = new { NotificationType = msgModel.NotifyType };
     }
     else if (msgModel.NotifyType == null)
     {
         resObj = new { Info = msgModel.Info };
     }
     else
     {
         resObj = new { NotificationType = msgModel.NotifyType, Info = msgModel.Info };
     }
     this.SendJsonResponse(registedUser.Session, resObj, ExtensionName, cmd);
 }
        private async Task HandleNotificationMessageAsync(string channel, BahamutPublishModel msgModel)
        {
            TypedDeviceTokens token = null;
            if (msgModel.ToUser.Contains(","))
            {
                var userIds = msgModel.ToUser.Split(new char[] { ',' });
                token = await GetMultiUserDeviceTokens(userIds);
            }
            else
            {
                token = await GetSingleUserDeviceToken(msgModel.ToUser);
            }

            if (token == null)
            {
                LogManager.GetLogger("Warn").Warn("App={0}:User Not Regist DeviceToken:{1}", channel, msgModel.ToUser);
            }else
            {
                if (!string.IsNullOrWhiteSpace(token.iOSDeviceTokens))
                {
                    await SendBahamutAPNSNotification(channel, token.iOSDeviceTokens, msgModel);
                }

                if (!string.IsNullOrWhiteSpace(token.AndroidDeviceTokens))
                {
                    await SendAndroidMessageToUMessage(channel, token.AndroidDeviceTokens, msgModel);
                }
            }

        }
 public async Task<bool> RemoveUserAsync(BahamutPublishModel msgModel)
 {
     return await ChicagoServer.BahamutPubSubService.RemoveUserDeviceAsync(msgModel.ToUser);
 }