コード例 #1
0
        /// <summary>
        /// 尝试以远程调用的方式处理消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private static bool TryProcessCall(Message msg, RtpData data)
        {
            var requestId = msg.Header.GetValue <Guid>(FieldRtpCallRequestId, Guid.Empty);

            if (requestId == Guid.Empty)
            {
                return(false);
            }

            var error       = msg.Header.GetValue <string>(FieldRtpCallErrorMessage, string.Empty);
            var isCompleted = msg.Header.GetValue <bool>(FieldRtpCallIsCompleted, false);

            var identity = RtpCallManager.GetIdentity(requestId);

            if (identity != null)
            {
                if (!string.IsNullOrEmpty(error))
                {
                    //错误处理
                    identity.Future.SetError(new ApplicationException(error));
                }
                else
                {
                    identity.Process(data, isCompleted);
                }

                if (isCompleted)
                {
                    identity.Future.SetResult(true);
                    RtpCallManager.ReturnIdentity(identity);
                }
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// 远程调用,该调用非常强大,不仅可以同步或异步执行并且获取结果,更可以获取服务器端多次推送的结果
        /// </summary>
        /// <param name="header"></param>
        /// <param name="body"></param>
        /// <param name="future"></param>
        private Future <bool> Call(string eventName, DTObject header, byte[] body, Action <RtpData, bool> process, Action <DTObject> setMessageHeader)
        {
            var identity = RtpCallManager.BorrowIdentity();

            identity.Process = process;

            var rtpData = new RtpData(this.Channel.Participant, header, body);
            var data    = RtpDataAnalyzer.Serialize(rtpData);

            identity.Future.Start();
            Message msg = CreateCallMessage(this.Name, eventName, data, identity.RequestId, setMessageHeader);

            this.Channel.Context.Client.Send(msg);
            return(identity.Future);
        }