/// <summary> /// 发送给指定商户 /// </summary> /// <param name="businessmanCodes">商户号组</param> public static void SendMsgByBuyerCodes(string[] businessmanCodes, EnumPushCommands command, string content, bool isRepeatSend = false, params object[] param) { foreach (var item in businessmanCodes) { Send(item, command, content, isRepeatSend, param); } }
/// <summary> /// 给商户发送消息 /// </summary> /// <param name="code">商户号</param> /// <param name="command">命令</param> /// <param name="content">消息内容</param> public static void Send(string code, EnumPushCommands command, string content, bool isRepeatSend = false, params object[] param) { var list = PushList.Where(p => string.Equals(p.Value.Code, code, StringComparison.InvariantCultureIgnoreCase)).ToList(); bool isSend = false; //当前商户是否有用户在线 if (list != null && list.Count > 0) { list.ForEach(p => { ICommunicationObject obj = (ICommunicationObject)p.Value.Callback; if (obj.State == CommunicationState.Opened) { p.Value.Callback.Notify(command, content, param); isSend = true; } }); } //保存离线消息 if (!isSend && isRepeatSend) { AddOffLine(new OffLineMessage { Code = code, Account = string.Empty, Command = command, MessageContent = content, SendDate = DateTime.Now }); } }
/// <summary> /// 发送给指定的运营商 /// </summary> /// <param name="carrierCodes"></param> /// <param name="command"></param> /// <param name="content"></param> /// <param name="isRepeatSend"></param> /// <param name="param"></param> public static void SendByCarrier(string[] carrierCodes, EnumPushCommands command, string content, bool isRepeatSend = false, params object[] param) { IBusinessmanRepository _repository = StructureMap.ObjectFactory.GetInstance<IBusinessmanRepository>(); //获取发送商户 var sendArray = _repository.FindAll().OfType<Buyer>().Where(p => carrierCodes.Contains(p.CarrierCode)).Select(p => p.Code).ToArray(); SendMsgByBuyerCodes(sendArray, command, content, isRepeatSend, param); }
/// <summary> /// 执行客户端命令 /// </summary> /// <param name="command">The command.</param> /// <param name="param">The parameter.</param> public static void InvokeCommand(EnumPushCommands command, params object[] param) { //if (importer.ClientCommands == null) // return; //foreach (var item in importer.ClientCommands.Where(item => item.Metadata.CommandKey == command)) // { // item.Value.Invoke(param); // return; // } //UIManager.ShowMessage("没有找到目标模块"); var items = PluginManager.ClientCommandModules; if (items == null) { return; } foreach (var item in items.Where(item => (EnumPushCommands)item.Value.Command == command)) { item.Key.Invoke(param); return; } //UIManager.ShowMessage("没有找到目标模块"); }
/// <summary> /// 发送所有客户端[Buyer] /// </summary> public static void SendAll(EnumPushCommands command, string content, bool isRepeatSend = false, params object[] param) { IBusinessmanRepository _repository = StructureMap.ObjectFactory.GetInstance<IBusinessmanRepository>(); //获取所有商户信息 var sendArray = _repository.FindAll().OfType<Buyer>().Select(p => p.Code).ToArray(); foreach (var item in sendArray) { Send(item, command, content, isRepeatSend, param); } }
//public PublishCallback() //{ //} public void Notify(EnumPushCommands pushCommand, string content, params object[] param) { try { UIManager.InvokeCommand(pushCommand, content, param); } catch (Exception e) { Logger.WriteLog(LogType.ERROR, "回调处理异常", e); } }
public static void Send(string code, string account, EnumPushCommands command, string content, params object[] param) { try { PushList.Where(p => p.Value.Code == code && p.Value.Account == account).ToList().ForEach(p => { ICommunicationObject obj = (ICommunicationObject)p.Value.Callback; if (obj.State == CommunicationState.Opened) p.Value.Callback.Notify(command, content, param); else { PushInfo info = null; PushList.TryRemove(p.Key, out info); } }); } catch (Exception e) { JoveZhao.Framework.Logger.WriteLog(JoveZhao.Framework.LogType.ERROR, "发送消息错误", e); } }
/// <summary> /// 发送方法 /// </summary> /// <param name="pushInfo"></param> /// <param name="title">标题</param> /// <param name="command">命令</param> /// <param name="IsRepeatSend">发送失败是否保存消息下次发送</param> /// <param name="content">内容</param> /// <param name="param">附加参数</param> public static void Send(KeyValuePair<Guid, PushInfo> keyValuePair, EnumPushCommands command, string content, bool IsRepeatSend = false, params object[] param) { try { keyValuePair.Value.Callback.Notify(command, content, param); } catch (CommunicationException) { UnSubscriber(keyValuePair.Key); if (IsRepeatSend) AddOffLine(new OffLineMessage { Code = keyValuePair.Value.Code, Account = keyValuePair.Value.Account, Command = command, MessageContent = content, SendDate = DateTime.Now }); } catch (Exception e) { JoveZhao.Framework.Logger.WriteLog(JoveZhao.Framework.LogType.ERROR, "发送消息出现异常", e); } }