当前位置: 首页>>代码示例>>C#>>正文


C# Response.Add方法代码示例

本文整理汇总了C#中Response.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Response.Add方法的具体用法?C# Response.Add怎么用?C# Response.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Response的用法示例。


在下文中一共展示了Response.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Summary

        public Response Summary()
        {
            Response response = new Response();
              //  response.Add("AccountTests", accountService.GetAccountTestSummary());
              response.Add("CardSummary", summaryService.GetMasterDataSummary<Card>(card => card.Class));
              //response.Add("EquipSummary", summaryService.GetMasterDataSummary<Equip>());
              //response.Add("AreaSummary", summaryService.GetMasterDataSummary<Area>());

              return response;
        }
开发者ID:huytrongnguyen,项目名称:MoonlightGarden,代码行数:10,代码来源:SystemController.cs

示例2: Transmit

        /// <summary>Transmits the specified command APDU.</summary>
        /// <param name="commandApdu">The command APDU.</param>
        /// <returns>A response containing one ore more <see cref="ResponseApdu" />.</returns>
        public virtual Response Transmit(CommandApdu commandApdu) {
            if (commandApdu == null) {
                throw new ArgumentNullException("commandApdu");
            }

            // prepare send buffer (Check Command APDU and convert it to an byte array)
            byte[] sendBuffer;
            try {
                sendBuffer = commandApdu.ToArray();
            } catch (InvalidOperationException exception) {
                throw new InvalidApduException("Invalid APDU.", commandApdu, exception);
            }

            // create Response object
            var response = new Response();

            // prepare receive buffer (Response APDU)
            var receiveBufferLength = commandApdu.ExpectedResponseLength; // expected size that shall be returned
            var receiveBuffer = new byte[receiveBufferLength];

            var receivePci = new SCardPCI();

            var responseApdu = SimpleTransmit(
                sendBuffer,
                sendBuffer.Length,
                commandApdu.Case, // ISO case used by the Command APDU
                commandApdu.Protocol, // Protocol used by the Command APDU
                receivePci,
                ref receiveBuffer,
                ref receiveBufferLength);

            /* Check status word SW1SW2:
             * 
             * 1. 0x6cxx -> Set response buffer size Le <- SW2
             * 2. AND/OR 0x61xx -> More data can be read with GET RESPONSE
             */

            if (responseApdu.SW1 == (byte) SW1Code.ErrorP3Incorrect) {
                // Case 1: SW1=0x6c, Previous Le/P3 not accepted -> Set le = SW2
                var resendCmdApdu = (CommandApdu) commandApdu.Clone();
                if (responseApdu.SW2 == 0) {
                    resendCmdApdu.Le = 0; // 256
                    receiveBufferLength = 256 + 2; // 2 bytes for status word
                } else {
                    resendCmdApdu.Le = responseApdu.SW2;
                    receiveBufferLength = responseApdu.SW2 + 2; // 2 bytes for status word
                }

                receiveBuffer = new byte[receiveBufferLength];
                receivePci = new SCardPCI();

                try {
                    sendBuffer = resendCmdApdu.ToArray();

                    // Shall we wait until we re-send we APDU/TPDU?
                    if (RetransmitWaitTime > 0) {
                        Thread.Sleep(RetransmitWaitTime);
                    }

                    // send Command APDU again with new Le value
                    responseApdu = SimpleTransmit(
                        sendBuffer,
                        sendBuffer.Length,
                        resendCmdApdu.Case,
                        resendCmdApdu.Protocol,
                        receivePci,
                        ref receiveBuffer,
                        ref receiveBufferLength);
                } catch (InvalidOperationException ex) {
                    throw new InvalidApduException("Got SW1=0x6c. Retransmission failed because of an invalid APDU.",
                        resendCmdApdu, ex);
                }
            }

            if (responseApdu.SW1 == (byte) SW1Code.NormalDataResponse) {
                // Case 2: SW1=0x61, More data available -> GET RESPONSE

                /* The transmission system shall issue a GET RESPONSE command APDU (or TPDU)
                 * to the card by assigning the minimum of SW2 and Le to parameter Le (or P3)). 
                 * Le = min(Le,SW2) 
                 */
                var le = (commandApdu.Le < responseApdu.SW2)
                    ? commandApdu.Le
                    : responseApdu.SW2;

                do {
                    // add the last ResponseAPDU to the Response object
                    response.Add(responseApdu);
                    response.Add(receivePci);

                    var getResponseApdu = ConstructGetResponseApdu(ref le);

                    if (le == 0) {
                        receiveBufferLength = 256 + 2; // 2 bytes for status word
                    } else {
                        receiveBufferLength = le + 2; // 2 bytes for status word
                    }
//.........这里部分代码省略.........
开发者ID:thiti-y,项目名称:pcsc-sharp,代码行数:101,代码来源:IsoReader.cs


注:本文中的Response.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。