コード例 #1
0
        /// <summary>
        /// 调用接口
        /// </summary>
        /// <param name="outcoming">请求参数</param>
        /// <param name="stream">正常情况下返回的数据流, 内容是 CSV 格式的数据</param>
        /// <param name="incoming">出错时的返回结果</param>
        /// <returns>正常情况: true, 出错时: false</returns>
        public async Task <bool> Invoke(Outcoming outcoming, AsyncOutParameter <Stream> stream, AsyncOutParameter <Incoming> incoming)
        {
            var url      = Stage.GetApiRootUrl(_sandbox) + "pay/downloadbill";
            var response = await _requester.GetResponse(url, false, outcoming).ConfigureAwait(false);

            var netStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

            var peekStream = new PeekableStream(netStream, 1);
            var buffer     = new byte[1];
            await peekStream.PeekAsync(buffer, 0, 1).ConfigureAwait(false);

            if (buffer[0] != '<')
            {
                stream.SetValue(peekStream);
                return(true);
            }

            using (var reader = new StreamReader(peekStream, Encoding.UTF8))
            {
                var responseBody = await reader.ReadToEndAsync().ConfigureAwait(false);

                incoming.SetValue(_requester.ParseResponse <Incoming, ErrorCode>(responseBody, _checkSignature));
                return(false);
            }
        }
コード例 #2
0
        public void InitUsingByteArray()
        {
            var initial       = "Hello world!";
            var initialBuffer = Encoding.ASCII.GetBytes(initial);
            var stream        = new PeekableStream(initialBuffer, 0, initialBuffer.Length, initialBuffer.Length);

            Assert.Equal(initial.Length, stream.Length);
            Assert.Equal(initial.Length, stream.Capacity);
            Assert.Equal(0, stream.Position);
        }
コード例 #3
0
ファイル: Serializer.cs プロジェクト: anthrax3/Migrant
        /// <summary>
        /// Returns the open stream serializer, which can be used to do consecutive deserializations when
        /// same technique was used to serialize data.
        /// </summary>
        /// <returns>The open stream deserializer.</returns>
        /// <param name="stream">Stream.</param>
        public OpenStreamDeserializer ObtainOpenStreamDeserializer(Stream stream)
        {
            bool preserveReferences;

            ThrowOnWrongResult(TryReadHeader(stream, out preserveReferences));
            if (!settings.UseBuffering)
            {
                stream = new PeekableStream(stream);
            }
            return(new OpenStreamDeserializer(ObtainReader(stream, preserveReferences), settings, stream));
        }
コード例 #4
0
        /// <summary>
        /// Returns the open stream serializer, which can be used to do consecutive deserializations when
        /// same technique was used to serialize data.
        /// </summary>
        /// <returns>The open stream deserializer.</returns>
        /// <param name="stream">Stream.</param>
        public OpenStreamDeserializer ObtainOpenStreamDeserializer(Stream stream)
        {
            bool preserveReferences;
            bool disableStamping;

            ThrowOnWrongResult(TryReadHeader(stream, out preserveReferences, out disableStamping));
            if (!settings.UseBuffering)
            {
                stream = new PeekableStream(stream);
            }
            var result = new OpenStreamDeserializer(CreateReader(stream), settings, stream);

            return(result);
        }
コード例 #5
0
ファイル: ClilocList.cs プロジェクト: Pumpk1ns/RunZHA
        public ClilocList(string language)
        {
            m_Language = language;
            m_Table    = new Hashtable();

            string path = ClilocPath + language;

            if (path == null)
            {
                m_Entries = new ClilocEntry[0];
                return;
            }

            ArrayList list = new ArrayList();

            using (BinaryReader bin = new BinaryReader(new PeekableStream(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))))
            {
                PeekableStream PeekableStream = bin.BaseStream as PeekableStream;
                bin.ReadInt32();
                bin.ReadInt16();

                while (PeekableStream.PeekByte() != -1)
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte();
                    int length = bin.ReadInt16();

                    if (length > m_Buffer.Length)
                    {
                        m_Buffer = new byte[(length + 1023) & ~1023];
                    }

                    bin.Read(m_Buffer, 0, length);
                    string text = Encoding.UTF8.GetString(m_Buffer, 0, length);

                    list.Add(new ClilocEntry(number, text));
                    m_Table[number] = text;
                }
            }

            m_Entries = (ClilocEntry[])list.ToArray(typeof(ClilocEntry));
        }
コード例 #6
0
        public void InitUsingWrittenAndWriteMore()
        {
            var initial  = "Hello world!";
            var addition = "Something more..";
            var buffer   = new byte[65535];
            var text     = Encoding.ASCII.GetBytes(initial);

            Buffer.BlockCopy(text, 0, buffer, 0, text.Length);
            var stream = new PeekableStream(buffer, 0, buffer.Length, text.Length);

            stream.Position = stream.Length;

            var writeable = Encoding.ASCII.GetBytes(addition);

            stream.Write(writeable, 0, writeable.Length);

            stream.Position = 0;
            var reader = new StreamReader(stream);
            var actual = reader.ReadToEnd();

            Assert.Equal(initial + addition, actual);
        }
コード例 #7
0
 public SensorPacketReader(Stream stream)
 {
     this.Stream = new PeekableStream(stream);
 }