public Task SendAsync(DispatchArgs args, CancellationToken cancellation = default) { if (args == null) { throw new ArgumentNullException(nameof(args)); } cancellation.ThrowIfCancellationRequested(); args.From = this.Instance; args.AppletId = this.AppletId; if (CanSend(args.IntentId)) { return(this.BroadcastAsync(args, cancellation)); } var intentName = _appInfo.GetIntentName(args.IntentId); throw new InvalidOperationException( new StringBuilder($"The specified outgoing message intent is forbidden for this applet.") .Append($" Sender applet: {AppletName} ({AppletId}).") .Append($" Message intent: {intentName} ({args.IntentId}).") .Append($" See {_appInfo.GetType()} type constructor.") .ToString() ); }
public IObservable <IDeliveryArgs> GetResponses(DispatchArgs args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } if (false == args.HasCorrelationId) { throw new ArgumentException($"{nameof(args)}.{nameof(args.CorrelationId)} is missing."); } if (0 == Interlocked.CompareExchange(ref _privateResponsesConnected, 1, 0)) { _privateResponses.Connect(); } return(Observable .Create <IDeliveryArgs>(Subscribe) .SubscribeOn(_privateEventLoopScheduler) .Do(InspectAndLog) .Where(IsIntentPermitted) .ObserveOn(_privateEventLoopScheduler)); IDisposable Subscribe(IObserver <IDeliveryArgs> observer) { observer = observer.NotifyOn(TaskPoolScheduler.Default); var subscription = Disposable.Create(() => _privateResponseObserversByCorrelationId.Remove(args.CorrelationId)); try { _privateResponseObserversByCorrelationId.TryAdd(args.CorrelationId, observer); SendAsync(args); return(subscription); } catch { subscription.Dispose(); throw; } } bool IsIntentPermitted(IDeliveryArgs reply) => _appInfo.IsExpectedReply(AppletId, args.IntentId, reply.IntentId); void InspectAndLog(IDeliveryArgs reply) { if (false == IsIntentPermitted(reply)) { Trace.TraceError(new StringBuilder("Unexpected Fan-Out response.") .Append($" Initiating applet: {AppletName}.") .Append($" Fan-Out request: {_appInfo.GetIntentName(args.IntentId)}.") .Append($" Fan-Out response: {reply.IntentName}.") .ToString() ); } } }
public bool CanSend(DispatchArgs args) { if (args == null) { throw new ArgumentNullException(nameof(args)); } return(CanSend(args.IntentId)); }
protected DeliveryArgs(DispatchArgs dispatchArgs, IAppletChannel channel) { if (dispatchArgs == null) { throw new ArgumentNullException(nameof(dispatchArgs)); } Body = dispatchArgs.Body ?? throw new NullReferenceException(nameof(dispatchArgs.Body)); Channel = channel ?? throw new ArgumentNullException(nameof(channel)); _appInfo = Channel.GetAppInfo() ?? throw new NullReferenceException($"{nameof(channel)}.{nameof(Channel.GetAppInfo)} returned null"); IntentId = dispatchArgs.IntentId; CorrelationId = dispatchArgs.CorrelationId; From = dispatchArgs.From; DataContractId = dispatchArgs.DataContractId; AppletId = dispatchArgs.AppletId; }
public Task ReplyWithAsync(DispatchArgs reply, CancellationToken cancellation) { if (reply == null) { throw new ArgumentNullException(nameof(reply)); } if (reply.CorrelationId == Guid.Empty) { reply.CorrelationId = this.CorrelationId; } if (reply.To == Guid.Empty) { reply.To = this.From; } if (reply.IntentId == Guid.Empty) { reply.IntentId = reply.DataContractId; } return(Channel.SendAsync(reply, cancellation)); }
/// <summary>底层回调函数</summary> /// <param name="nCategory"></param> /// <param name="notify"></param> /// <param name="hInstance"></param> private void cllBack(TalkSDK.LINE_MESSAGE_CATEGORY nCategory, TalkSDK.MBox_Notify notify, IntPtr hInstance) { //System.Console.WriteLine("开始-----------------------------"); lock (this) { #region MyRegion switch (nCategory) { case TalkSDK.LINE_MESSAGE_CATEGORY.CATEGORY_SUBSTATUS_NOTIFY: //unsigned int uEventTimeStamp; //时间帧未实现 UserStateArgs ua = new UserStateArgs(); ua.UserNumber = notify.lSubscriberNumber; ua.PeerPartNumber = notify.lPeerPartNumber; ua.UserLineStatus = (EnumUserLineStatus)notify.uSubscriberStatus; ua.RecordStatus = (EnumRecordStatus)notify.uRecordingStatus; ua.UserHookStatus = (EnumUserHookStatus)notify.uHookOffStatus; ua.ConfID = notify.uDispatchConfId; ua.EventAdditionalInfo = Encoding.Default.GetString(notify.chEventAdditionalInfo); ua.FapIP = Encoding.Default.GetString(notify.chfapIpAddr); int i = ua.FapIP.IndexOf("\0"); if (i>0) { ua.FapIP = ua.FapIP.Substring(0, i); } // Console.WriteLine(ua.ToString()); if (OnMemberStateChanged != null) { if (ua.UserLineStatus == EnumUserLineStatus.Busy && ua.PeerPartNumber == 0 && ua.ConfID == 0)//防止没用的信息 { return; } //if (ua.UserLineStatus == EnumUserLineStatus.Busy && ua.PeerPartNumber == 0 && ua.RecordStatus== EnumRecordStatus.ON)//防止没用的信息 //{ // return; //} OnMemberStateChanged(this, ua); } break; case TalkSDK.LINE_MESSAGE_CATEGORY.CATEGORY_WAITINGQUEUESTATUS_NOTIFY: //unsigned int uEventTimeStamp; //时间帧 WaitingQueensAgs args = new WaitingQueensAgs(); args.WaitingUserNumber = notify.lWaitingUserNumber; args.WaitingUserStatus = (EnumWaitingUserStatus)notify.uWaitingUserStatus; args.EventAdditionalInfo = Encoding.Default.GetString(notify.chEventAdditionalInfo); // Console.WriteLine(args.ToString()); if (OnWaitingQueensChanged != null) { OnWaitingQueensChanged(this, args); } break; case TalkSDK.LINE_MESSAGE_CATEGORY.CATEGORY_DISPATCHSTATUS_NOTIFY: DispatchArgs ss = new DispatchArgs(); ss.DispatchStatus = (EnumDispatchStatus)notify.uDispatchStatus; CurrentMeetingID = notify.uDispatchConfId; ss.MainIP = Encoding.Default.GetString(notify.chDispatchCmdHost); ss.EventAdditionalInfo = Encoding.Default.GetString(notify.chEventAdditionalInfo); //ss.FromNumber = notify.lDispatchedUser; //ss.ToNumber = notify.lPeerPartNumber; ss.FromNumber = notify.lDispatchCmdDispatcher; ss.ToNumber = notify.lDispatchedUser; ss.DispatchCmdType = (TalkSDK.LINE_MESSAGE_CATEGORY)notify.uDispatchCmdType; ss.DispatchCmdSubType = (EnumDispatchCmdType)notify.uDispatchCmdSubType; ss.DispatchCmdTransactionId = notify.uDispatchCmdTransactionId; ss.DispatchErrorCause = (EnumuDispatchErrorCause)notify.uDispatchErrorCause; ss.ConfID = notify.uDispatchConfId; if (OnDispatchStateChanged != null) { OnDispatchStateChanged(this, ss); } // Console.WriteLine(ss.ToString()); //unsigned int uDispatchedUserOld; //保留 //unsigned int uEventTimeStamp; //时间帧 break; case TalkSDK.LINE_MESSAGE_CATEGORY.CATEGORY_LEMCQUEUESTATUS_NOTIFY: //unsigned int uEventTimeStamp; //时间帧 LemcQueensArgs a = new LemcQueensArgs(); a.UserNumber = notify.lLemcCallingNumber; a.LemcNumber = notify.lLemcCalledNumber; a.LemcStatus = (EnumLemcStatus)notify.uLemcStatus; int not = notify.lEventTimeStamp; a.EventAdditionalInfo = Encoding.Default.GetString(notify.chEventAdditionalInfo); if (OnLemcQueensChanged != null) { OnLemcQueensChanged(this, a); } // Console.WriteLine(a.ToString()); break; case TalkSDK.LINE_MESSAGE_CATEGORY.CATEGORY_REDUNDANCYSTATUS_NOTIFY: HotStandbyArgs arg = new HotStandbyArgs(); arg.StandyHostActiveIP = Encoding.Default.GetString(notify.chStandyHostActiveIP); arg.StandyHostNMSIP = Encoding.Default.GetString(notify.chStandyHostNMSIP); arg.RedUndancyWorkMode = notify.RedUndancyWorkMode; arg.RedUndancyNMSStatus = notify.RedUndancyNMSStatus; if (OnHotStandbyChanged!=null) { OnHotStandbyChanged(this, arg); } break; default: break; } #endregion } //System.Console.WriteLine("结束-----------------------------"); }
public InMemoryDeliveryArgs(DispatchArgs dispatchArgs, IAppletChannel channel) : base(dispatchArgs, channel) { }
protected override Task BroadcastAsync(DispatchArgs args, CancellationToken cancellation) { _topic.OnNext(args); return(Task.CompletedTask); }
protected abstract Task BroadcastAsync(DispatchArgs args, CancellationToken cancellation);