public void Test_93_2()
        {
            string text = "9300CNLoginUserID|COLoginPassword|CPLocationCode|AY5AZEC78";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as Login_93;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_25()
        {
            string text = "2519980723    094240AOCertification Institute ID|AAPatronID|AY4AZEBF1";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as PatronEnable_25;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_98_1()
        {
            string text = "98YYYNYN01000319960214    1447001.00AOID_21|AMCentral Library|ANtty30|AFScreen Message|AGPrint Message|AY1AZDA74";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as ACSStatus_98;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_63()
        {
            string text = "6300119980723    091905Y         AOInstitutionID|AAPatronID|BP00001|BQ00005|AY1AZEA83";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as PatronInformation_63;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_18()
        {
            string text = "1808000119980723    115615CF00000|ABItemBook|AJTitle For Item Book|CK003|AQPermanent location|APCurrent Location|CHFree-form text|AY0AZC05B";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as ItemInformationResponse_18;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_23()
        {
            string text = "2300119960212    100239AOid_21|AA104000000105|AC|AD|AY2AZF400";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as PatronStatusRequest_23;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_24()
        {
            string text = "24              00119960212    100239AO|AA104000000105|AEJohn Doe|AFScreen Message|AGCheck Print message|AY2AZDFC4";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as PatronStatusResponse_24;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_96()
        {
            string text = "96";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as RequestSCResend_96;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_93_1()
        {
            string text = "9300CNzizhu_test@instance5|CO1234567|CPzizhu_test@instance5|AY1AZEAE5";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as Login_93;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_98_2()
        {
            string text = "98YYYYYN01000320170623    1537532.00AOdp2Library|AMdp2Library|BXYYYYYYYYYYYYYYYY|AF连接成功!|AY4AZ3EFC";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as ACSStatus_98;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_17()
        {
            string text = "1719980723    100000AOCertification Institute ID|ABItemBook|AY1AZEBEB";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as ItemInformation_17;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_26()
        {
            string text = "26              00119980723    111413AOInstitutionID for PatronID|AAPatronID|AEPatron Name|BLY|AFScreenMessage 0 for PatronID, Language 1|AFScreen Message 1 for PatronID, Language 1 |AGPrint Line 0 for PatronID, Language 1|AY7AZ8EA6";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as PatronEnableResponse_26;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_20()
        {
            //20	1-char	18-char	AB	AJ	CH	AF	AG
            string text = "20020170630    144410AB001|AJ001中国|CH|AF002美国|AGtest|AY4AZ3CAD";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as ItemStatusUpdateResponse_20;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_16()
        {
            //16  1-char  1-char  18-char  BW  BR  BS  AO  AA  AB AJ  AF  AG
            string text = "160120170630    144410BW20170630    144410|BR|BS|AOdp2Library|AA001|AB|AJ001中国|AF002美国|AF003德国|AGtest|AY4AZ3CAD";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as HoldResponse_16;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_19()
        {
            //19	18-char	AO	AB	AC	CH
            string text = "1920170630    144419AOdp2Library|AB905071|CH";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as ItemStatusUpdate_19;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_15()
        {
            //15 1-char 18-char BW BS BY AO AA AD AB AJ AC BO
            string text = "15+20170630    144419BW20170630    144419|BS|BY|AOdp2Library|AAL905071|AD|AB|AJ|AC|BON";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as Hold_15;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_66()
        {
            //66	1-char	4-char	4-char	18-char	AO	BM	BN	AF	AG
            string text = "6601234123420170630    144410AOdp2Library|BM001|BN002|BN003|AF001中国|AF002美国|AF003德国|AGtest|AY4AZ3CAD";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as RenewAllResponse_66;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_65()
        {
            //65	18-char	AO	AA	AD	AC	BO
            string text = "6520170630    144419AOdp2Library|AAL905071|AD|AC|BON";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as RenewAll_65;

            Assert.IsTrue(request != null); // 检查解析对象

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        public void Test_10_1()
        {
            string text = "101YNN20170630    141632AOdp2Library|AB510102|AQ综合图书库|AJ《奔放西班牙餐》|AAL905071|CK001|CHProperties|CLsort bin A1|AF图书《奔放西班牙餐》还回处理成功!2017-06-30|AG图书《奔放西班牙餐》-- 510102已于2017-06-30归还!|AY4AZ4E37";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet); // 检查返回值

            var request = message as CheckinResponse_10;

            Assert.IsTrue(request != null); // 检查解析对象

            // 2020/8/16注意这个例子把CL排在了AA了后面,但SIP2.0中,CL字段是在AA之前的
            // 所以这个例子输出的字符串与原始字符串中字段位置有差别,但也是正确的,所以改为判断字符串长度是否
            string retText = request.ToText();

            Assert.AreEqual(text.Length, retText.Length); // 检查原始字符串和转成对象后输出字符串是否一致
        }
        // 重复AU,AF,AG
        public void Test_64_2()
        {
            string text = "64              00119980723    104009000100000002000100020000AOInstitutionID for PatronID|AAPatronID|AEPatron Name|BZ0002|CA0003|CB0010|BLY|ASItemID1 for PatronID |AUChargeItem1|AUChargeItem2|BDHome Address|BEE Mail Address|BFHome Phone for PatronID|AFScreenMessage 0 for PatronID, Language 1|AFScreen Message 1 for PatronID, Language 1|AFScreen Message 2 for PatronID, Language 1|AGPrint Line 0 for PatronID, Language 1|AGPrint Line 1 for PatronID, Language 1|AGPrint Line 2 for PatronID, language 1|AY4AZ608F";
            // return:
            //      -1  出错
            //      0   成功
            int nRet = SIPUtility.ParseMessage(text,
                                               out BaseMessage message,
                                               out string error);

            Assert.AreEqual(0, nRet);

            var request = message as PatronInformationResponse_64;

            Assert.IsTrue(request != null);

            Assert.AreEqual(2, request.AU_ChargedItems_o.Count);// 检查解析出来的AU数量是否正确

            string retText = request.ToText();

            Assert.AreEqual(text, retText); // 检查原始字符串和转成对象后输出字符串是否一致
        }
Beispiel #21
0
        // 发送消息,接收消息
        public async Task <SendAndRecvResult> SendAndRecvAsync(string requestText)
        {
            string error = "";
            int    nRet  = 0;

            int redo_count = 0;

            // 校验消息
            BaseMessage request = null;

            nRet = SIPUtility.ParseMessage(requestText, out request, out error);
            if (nRet == -1)
            {
                SipChannelUtil.TryDetectSipNetwork();

                return(new SendAndRecvResult
                {
                    Value = -1,
                    ErrorInfo = "校验发送消息异常:" + error
                });
            }

REDO_SEND:
            // 发送消息
            var send_result = await SendMessageAsync(requestText);

            if (send_result.Value == -1)
            {
                if (send_result.ErrorCode == "ConnectionAborted" &&
                    String.IsNullOrEmpty(this.SIPServerAddr) == false &&
                    redo_count < 2)
                {
                    var connect_result = await ConnectAndLoginAsync(null, -1, null, null);

                    if (connect_result.Value != -1)
                    {
                        redo_count++;
                        goto REDO_SEND;
                    }
                }

                SipChannelUtil.TryDetectSipNetwork();

                return(new SendAndRecvResult(send_result));
            }

            // 接收消息
            var recv_result = await RecvMessageAsync();

            if (recv_result.Value == -1)
            {
                if (recv_result.ErrorCode == "ConnectionAborted" &&
                    String.IsNullOrEmpty(this.SIPServerAddr) == false &&
                    redo_count < 2)
                {
                    var connect_result = await ConnectAndLoginAsync(null, -1, null, null);

                    if (connect_result.Value != -1)
                    {
                        redo_count++;
                        goto REDO_SEND;
                    }
                }

                SipChannelUtil.TryDetectSipNetwork();
                return(new SendAndRecvResult(recv_result));
            }

            //解析返回的消息
            nRet = SIPUtility.ParseMessage(recv_result.RecvMsg, out BaseMessage response, out error);
            if (nRet == -1)
            {
                try
                {
                    dynamic p = response;
                    if (string.IsNullOrEmpty(p.AF_ScreenMessage_o) == false)
                    {
                        return new SendAndRecvResult
                               {
                                   RecvMsg   = recv_result.RecvMsg,
                                   Response  = response,
                                   Value     = -1,
                                   ErrorInfo = p.AF_ScreenMessage_o,
                                   ErrorCode = "sipError",
                               }
                    }
                    ;
                }
                catch
                {
                }

                return(new SendAndRecvResult
                {
                    RecvMsg = recv_result.RecvMsg,
                    Response = response,
                    Value = -1,
                    ErrorInfo = "解析返回的消息异常:" + error + "\r\n" + recv_result.RecvMsg,
                    ErrorCode = "parseError"
                });
            }

            return(new SendAndRecvResult
            {
                Value = 0,
                RecvMsg = recv_result.RecvMsg,
                Response = response
            });
        }