Ejemplo n.º 1
0
        /// <summary>
        ///     采用命名通道发送消息
        /// </summary>
        /// <param name="strMsg">参数</param>
        /// <param name="flag">标记</param>
        /// <returns>是否成功</returns>
        public bool SendMessage(string[] strMsg, CommniucationFlag flag)
        {
            bool result = true;

            try
            {
                if (strMsg == null)
                {
                    return(false);
                }

                //组织发送实体
                var gm = new GenericMessage
                {
                    MessageId       = Guid.NewGuid(),
                    Recipient       = "TellerSystem",
                    Originator      = "ExamSystem",
                    MessageFlag     = flag,
                    MessageDateTime = DateTime.Now,
                    Payload         = Encoding.UTF8.GetBytes(strMsg.Aggregate((c1, c2) => c1 + "!@" + c2))
                };

                byte[] b = MessageSerializers.SerializeMessage(gm);
                pipeClient.SendMessage(b);
            }
            catch (Exception)
            {
                result = false;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     收到前段传来的消息处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void pipeServer_MessageReceived(object sender, MessageEventArgs args)
        {
            IMessage msg = MessageSerializers.DeserializeMessage(args.Message);

            if (msg.MessageFlag == CommniucationFlag.A ||
                msg.MessageFlag == CommniucationFlag.B ||
                msg.MessageFlag == CommniucationFlag.C ||
                msg.MessageFlag == CommniucationFlag.D)
            {
                string   data   = Encoding.UTF8.GetString(msg.Payload);
                string[] strMsg = data.Split(new[] { "!@" }, StringSplitOptions.RemoveEmptyEntries);

                //string[] p = ReaderString();
                WriteString(new[] { "istrue" });

                if (ReceiveMessage != null)
                {
                    ReceiveMessage(msg.MessageFlag, strMsg);
                }
            }
        }