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


C# BufferedStream.Flush方法代码示例

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


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

示例1: ShouldAlwaysFlushUnderlyingStreamIfWritable

        public async Task ShouldAlwaysFlushUnderlyingStreamIfWritable(bool underlyingCanRead, bool underlyingCanSeek)
        {
            var underlying = new DelegateStream(
                canReadFunc: () => underlyingCanRead,
                canWriteFunc: () => true,
                canSeekFunc: () => underlyingCanSeek,
                readFunc: (_, __, ___) => 123,
                writeFunc: (_, __, ___) => { },
                seekFunc: (_, __) => 123L
            );

            var wrapper = new CallTrackingStream(underlying);

            var buffered = new BufferedStream(wrapper);
            
            buffered.Flush();
            Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.Flush)));

            await buffered.FlushAsync();
            Assert.Equal(1, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));

            buffered.WriteByte(0);
            
            buffered.Flush();
            Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.Flush)));

            await buffered.FlushAsync();
            Assert.Equal(2, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:29,代码来源:BufferedStream.FlushTests.cs

示例2: ShouldNotFlushUnderlyingStreamIfReadOnly

        public async Task ShouldNotFlushUnderlyingStreamIfReadOnly(bool underlyingCanSeek)
        {
            var underlying = new DelegateStream(
                canReadFunc: () => true,
                canWriteFunc: () => false,
                canSeekFunc: () => underlyingCanSeek,
                readFunc: (_, __, ___) => 123,
                writeFunc: (_, __, ___) =>
                {
                    throw new NotSupportedException();
                },
                seekFunc: (_, __) => 123L
            );

            var wrapper = new CallTrackingStream(underlying);

            var buffered = new BufferedStream(wrapper);
            buffered.ReadByte();

            buffered.Flush();
            Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.Flush)));

            await buffered.FlushAsync();
            Assert.Equal(0, wrapper.TimesCalled(nameof(wrapper.FlushAsync)));
        }
开发者ID:chcosta,项目名称:corefx,代码行数:25,代码来源:BufferedStream.FlushTests.cs

示例3: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BufferedStream bs2;
         MemoryStream memstr2;
         FileStream fs2;
         StreamWriter sw2;
         if(File.Exists("Co5609Test.tmp"))
             File.Delete("Co5609Test.tmp");
         strLoc = "Loc_9289x";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         iCountTestcases++;
         try 
         {
             bs2.SetLength(-2);
             iCountErrors++;
             printerr( "Error_190x9! Expected exception not thrown");
         } 
         catch (ArgumentOutOfRangeException aexc) 
         {
             printinfo("Info_9199x! Caught expected exception, exc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_t589v! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_27yxc";
         fs2 = new FileStream("Co5609Test.tmp", FileMode.Create);
         bs2 = new BufferedStream(fs2);
         bs2.SetLength(50);
         bs2.Position = 50;
         sw2 = new StreamWriter(bs2);
         Console.WriteLine(bs2.Position);
         for(char c = 'a' ; c < 'f' ; c++) 
             bs2.Write(new Byte[]{(Byte)c}, 0, 1 );
         bs2.Flush();
         fs2.Flush();
         Console.WriteLine(bs2.Position);
         iCountTestcases++;
         if(fs2.Length != 55) 
         {
             iCountErrors++;
             printerr( "Error_389xd! Incorrect stream length=="+fs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 55) 
         {
             iCountErrors++;
             printerr( "Error_3y8t3! Incorrect position=="+bs2.Position);
         }
         bs2.SetLength(30);
         iCountTestcases++;
         if(bs2.Length != 30) 
         {
             iCountErrors++;
             printerr( "Error_28xye! Incorrect length=="+bs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 30) 
         {
             iCountErrors++;
             printerr( "Error_3989a! Incorrect position=="+bs2.Position);
         }
         bs2.SetLength(100);
         bs2.Position = 100;
         iCountTestcases++;
         if(bs2.Length != 100) 
         {
             iCountErrors++;
             printerr( "Error_2090x! Incorrect length=="+bs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 100) 
         {
             iCountErrors++;
             printerr( "Error_1987t! Incorrect position=="+bs2.Position);
         }
         bs2.Flush();
         bs2.SetLength(50);
         iCountTestcases++;
         if(bs2.Length != 50) 
         {
             iCountErrors++;
             printerr( "Error_10x88! Incorrect length=="+bs2.Length);
         }
         iCountTestcases++;
         if(bs2.Position != 50) 
         {
             iCountErrors++;
             printerr( "Error_738gb! Incorrect position=="+bs2.Position);
         }
         bs2.Close();
         strLoc = "Loc_99189";
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5609setlength.cs

示例4: runTest


//.........这里部分代码省略.........
				iCountErrors++;
				printerr( "Error_3444j! Expected exception not thrown");
			} catch (ArgumentException aexc) {
				printinfo("Info_g8777! CAught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_t77gg! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_897yg";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			bs2.Write(new Byte[]{1}, 0, 1);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, 0, 2);
				iCountErrors++;
				printerr( "Error_98y8x! Expected exception not thrown");
			} catch (ArgumentException aexc) {
				printinfo("Info_g58yb! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_ytg78! Incorrect exception thrown, exc=="+exc.ToString());
			}			
			strLoc = "Loc_8g7yb";
			count = 0;
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			bWriteArr = new Byte[100];
			for(int i = 0 ; i < 100 ; i++) 
				bWriteArr[i] = (Byte)i;
			bs2.Write(bWriteArr, 0, 100);
			iCountTestcases++;   
                        bs2.Flush();
			bReadArr = memstr2.ToArray();
			for(int i = 0 ; i < bReadArr.Length ; i++) {
				iCountTestcases++;
				if(bReadArr[i] != bWriteArr[i]) {
					iCountErrors++;
					printerr( "Error_98ybb! Expected=="+bWriteArr[i]+", got=="+bReadArr[i]);
				}
			}
			bs2.Position = 0;
			count = bs2.Read(bReadArr, 0, 100);
			iCountTestcases++;
			if(count != 100) {
				iCountErrors++;
				printerr( "Error_958yv! Incorrect count=="+count);
			}
			for(int i = 0 ; i < bReadArr.Length ; i++) {
				iCountTestcases++;
				if(bReadArr[i] != bWriteArr[i]) {
					iCountErrors++;
					printerr( "Error_98gy8! Expected=="+bWriteArr[i]+", got=="+bReadArr[i]);
				}
			}			
			bs2.Close();
			strLoc = "Loc_g85y7";
			count = 0;
			fs2 = new FileStream("Co5616Test.tmp", FileMode.Create);
			bs2 = new BufferedStream(fs2);
			bWriteArr = new Byte[100];
			for(int i = 0 ; i < 100 ; i++) 
				bWriteArr[i] = (Byte)i;
			bs2.Write(bWriteArr, 0, 100);
			iCountTestcases++;   
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co5616read_barr_i_i.cs

示例5: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		String strValue = String.Empty;
		try
		{
			FileStream fs2;
			MemoryStream ms2;
			BufferedStream bs2;
			String filName = s_strTFAbbrev + "TestFile.tmp";
			Int32 ii = 0;
			Byte[] bytArr;
			Int32 i32;
			bytArr = new Byte[] {
				Byte.MinValue
				,Byte.MaxValue
				,100
				,Byte.MaxValue-100
			};
			if(File.Exists(filName))
				File.Delete(filName);
			strLoc = "Loc_8yfv7";
			fs2 = new FileStream(filName, FileMode.Create);
			bs2 = new BufferedStream(fs2);
			for(ii = 0 ; ii < bytArr.Length ; ii++)
				bs2.WriteByte(bytArr[ii]);		   
			bs2.Flush();
			bs2.Close();
			strLoc = "Loc_987hg";
			fs2 = new FileStream(filName, FileMode.Open);
			bs2 = new BufferedStream(fs2);
			for(ii = 0 ; ii < bytArr.Length ;ii++) {
				iCountTestcases++;
				if((i32 = bs2.ReadByte()) != bytArr[ii]) {
					iCountErrors++;
					printerr( "Error_298hg_"+ii+"! Expected=="+bytArr[ii]+" , got=="+i32);
				}
			}
			i32 = bs2.ReadByte();
			if(i32 != -1) {
				iCountErrors++;
				printerr( "Error_2389! -1 return expected, i32=="+i32);
			} 
			fs2.Close();
			strLoc = "Loc_398yc";
			ms2 = new MemoryStream();
			bs2 = new BufferedStream(ms2);
			for(ii = 0 ; ii < bytArr.Length ; ii++)
				bs2.WriteByte(bytArr[ii]);
			bs2.Flush();
			bs2.Position = 0;
			bs2.Flush();
			for(ii = 0 ; ii < bytArr.Length ; ii++) {
				iCountTestcases++;
				if((i32 = bs2.ReadByte()) != bytArr[ii]) {
					iCountErrors++;
					printerr( "Error_38yv8_"+ii+"! Expected=="+bytArr[ii]+", got=="+i32);
				}
			}
			i32 = bs2.ReadByte();
			if(i32 != -1) {
				iCountErrors++;
				printerr( "Error_238v8! -1 return expected, i32=="+i32);
			}
			bs2.Position = 0;
			for(ii = 0 ; ii < bytArr.Length; ii++)
				bs2.WriteByte(bytArr[ii]);
			if(File.Exists(filName))
				File.Delete(filName);
		} catch (Exception exc_general ) {
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:ArildF,项目名称:masters,代码行数:87,代码来源:co5744readbyte.cs

示例6: Teleport

 public static void Teleport(string address) 
 {
     TcpClient tcpClient = new TcpClient();
     IPEndPoint epSend = null;
     IPAddress sendAddress = IPAddress.Parse(address);			
     epSend = new IPEndPoint(sendAddress, iPortNumber);
     tcpClient.Connect(epSend);
     Stream stream = tcpClient.GetStream();
     BufferedStream bs = new BufferedStream( stream );
     bs.Write(new Byte[]{65,66,67,68,69,70}, 0, 6);
     bs.Flush();			
     StreamReader sr = new StreamReader(stream);
     sr.Close();
 }
开发者ID:ArildF,项目名称:masters,代码行数:14,代码来源:co5605flush.cs

示例7: Teleport

 public static void Teleport(string address) 
 {
     TcpClient tcpClient = new TcpClient();
     IPEndPoint epSend = null;
     IPAddress sendAddress = IPAddress.Parse(address);			
     epSend = new IPEndPoint(sendAddress, iPortNumber);
     tcpClient.Connect(epSend);
     Stream stream = tcpClient.GetStream();
     BufferedStream bs = new BufferedStream( stream);
     for(int iLoop = 0 ; iLoop < 100 ; iLoop++)
         bs.WriteByte( Convert.ToByte( iLoop ));
     bs.Flush();
 }
开发者ID:ArildF,项目名称:masters,代码行数:13,代码来源:co5743writebyte.cs

示例8: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BufferedStream bs2;
         MemoryStream memstr2;
         FileStream fs2;
         Int64 pos;
         if(File.Exists("Co5614Test.tmp"))
             File.Delete("Co5614Test.tmp");
         strLoc = "Loc_95vy8";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         bs2.Write(new Byte[]{1,2,3,4}, 0, 4);
         bs2.Flush();
         iCountTestcases++;
         try 
         {
             bs2.Seek(-2, SeekOrigin.Begin);
             iCountErrors++;
             printerr( "Error_98yvc! Expected exception not thrown");
         } 
         catch (IOException aexc) 
         {
             printinfo("Info_20u90! Caught expected exception, exc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_f3099! Incorrect exception thrown, exc=="+exc.ToString());
         }
         iCountTestcases++;
         if(bs2.Position != 4) 
         {
             iCountErrors++;
             printerr( "Error_298hx! Position set=="+bs2.Position);
         }
         bs2.Position = 1;
         iCountTestcases++;
         try 
         {
             bs2.Seek(-2, SeekOrigin.Begin);
             iCountErrors++;
             printerr( "Error_0190cj! Expected exception not thrown");
         } 
         catch (IOException aexc) 
         {
             printinfo("Info_98yg9! Caught expected exception, exc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_98t8b! Incorrect exception thrown, exc=="+exc.ToString());
         }
         iCountTestcases++;
         if(bs2.Position != 1) 
         {
             iCountErrors++;
             printerr( "Error_29887! Position set=="+bs2.Position);
         }
         bs2.Close();
         strLoc = "Loc_98yvh";
         fs2 = new FileStream("Co5614Test.tmp", FileMode.Create);
         bs2 = new BufferedStream(fs2);
         bs2.Write(new Byte[]{1,2,3,4},0,4);
         bs2.Flush();
         iCountTestcases++;
         try 
         {
             bs2.Seek(-2, SeekOrigin.Begin);
             iCountErrors++;
             printerr( "Error_019uc! Expected exception not thrown");
         } 
         catch (IOException aexc) 
         {
             printinfo("Info_78y7g! Caught expected exception, exc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_099gn! Incorrect exception thrown, exc=="+exc.ToString());
         } 
         iCountTestcases++;
         if(bs2.Position != 4) 
         {
             iCountErrors++;
             printerr( "Error_9t8yb! Position set=="+bs2.Position);
         }
         bs2.Position = 1;
         iCountTestcases++;
         try 
         {
             bs2.Seek(-2, SeekOrigin.Begin);
             iCountErrors++;
             printerr( "Error_98ycn! Expected exception not thrown");
         } 
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5614seek_i64_so.cs

示例9: Page_Load

    //region events
    protected void Page_Load(object sender, EventArgs e)
    {
        //填充交易数据
        serverUrl = Request["serverUrl"];  //submit server url
        key = Request["key"];   //md5 key
        version = Request["version"]; //version
        merchantId = Request["merchantId"];//merchantId
        beginDateTime = Request["beginDateTime"];
        endDateTime = Request["endDateTime"];
        pageNo = Request["pageNo"];
        signType = Request["signType"];

        //生成signMsg
        //1、首先组签名原串 batchQuerySignSrcMsgReq
        StringBuilder bufSignSrc = new StringBuilder();
        appendSignPara(bufSignSrc, "version", version);
        appendSignPara(bufSignSrc, "merchantId", merchantId);
        appendSignPara(bufSignSrc, "beginDateTime", beginDateTime);
        appendSignPara(bufSignSrc, "endDateTime", endDateTime);
        appendSignPara(bufSignSrc, "pageNo", pageNo);
        appendSignPara(bufSignSrc, "signType", signType);
        appendLastSignPara(bufSignSrc, "key", key);

        batchQuerySignSrcMsgReq = bufSignSrc.ToString();

        //2、再对签名原串进行MD5摘要
        batchQuerySignMsgReq = FormsAuthentication.HashPasswordForStoringInConfigFile(batchQuerySignSrcMsgReq, "MD5");

        //发起POST请求到服务端

        postData = HttpUtility.UrlEncode("version") + "=" + HttpUtility.UrlEncode(version)
            + "&" + HttpUtility.UrlEncode("merchantId") + "=" + HttpUtility.UrlEncode(merchantId)
            + "&" + HttpUtility.UrlEncode("beginDateTime") + "=" + HttpUtility.UrlEncode(beginDateTime)
            + "&" + HttpUtility.UrlEncode("endDateTime") + "=" + HttpUtility.UrlEncode(endDateTime)
            + "&" + HttpUtility.UrlEncode("pageNo") + "=" + HttpUtility.UrlEncode(pageNo)
            + "&" + HttpUtility.UrlEncode("signType") + "=" + HttpUtility.UrlEncode(signType)
            + "&" + HttpUtility.UrlEncode("signMsg") + "=" + HttpUtility.UrlEncode(batchQuerySignMsgReq);

        byte[] tRequestMessage = System.Text.ASCIIEncoding.UTF8.GetBytes(postData);
        HttpWebRequest tWebRequest = null;
        BufferedStream tRequestStream = null;
        HttpWebResponse tWebResponse = null;
        Byte[] tResponseByteArray = null;
        try
        {

            #region
            //1、准备连接
            System.Net.ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();

            tWebRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
            tWebRequest.Method = "POST";
            tWebRequest.ProtocolVersion = HttpVersion.Version11;
            tWebRequest.ContentType = "application/x-www-form-urlencoded";

            tWebRequest.KeepAlive = false;
            tWebRequest.ServicePoint.Expect100Continue = false;
            tWebRequest.ReadWriteTimeout = iWebReadWriteTimeout;
            tWebRequest.Timeout = iWebTimeout;

            //2、提交信息
            tWebRequest.ContentLength = tRequestMessage.Length;
            tRequestStream = new BufferedStream(tWebRequest.GetRequestStream());
            if (!tRequestStream.CanWrite)
            {
                //不能连接serverUrl
                throw new Exception("不能建立连接");
            }

            tRequestStream.Write(tRequestMessage, 0, tRequestMessage.Length);
            tRequestStream.Flush();

            //3、接收响应
            tWebResponse = (HttpWebResponse)tWebRequest.GetResponse();
            if (tWebResponse.StatusCode != HttpStatusCode.OK)
            {
                //交易平台未成功处理请求
                throw new Exception("交易平台未成功处理请求");
            }

            Stream tReceiveStream = tWebResponse.GetResponseStream();
            StreamReader tStreamReader = new StreamReader(tReceiveStream);
            String tLine = null;
            String tResponseMessage = "";
            while ((tLine = tStreamReader.ReadLine()) != null)
            {
                tResponseMessage += tLine;
            }
            tResponseByteArray = System.Text.ASCIIEncoding.UTF8.GetBytes(tResponseMessage);

            responseString = System.Text.Encoding.UTF8.GetString(tResponseByteArray);

            /**
             * 返回的批量查询响应报文解析流程
             *  1、对报文base64解码,并转换成utf8编码
             *  2、解析响应报文,将对账明细进行MD5摘要作为签名原串
             *  3、用通联公钥证书进行验签
             * */
            //对响应报文进行base64解码
//.........这里部分代码省略.........
开发者ID:test-lin,项目名称:Utility-class,代码行数:101,代码来源:batchOrderQuery.aspx.cs

示例10: Teleport

 public static void Teleport(string address) 
 {
     TcpClient tcpClient = new TcpClient();
     IPEndPoint epSend = null;
     IPAddress sendAddress = IPAddress.Parse(address);			
     epSend = new IPEndPoint(sendAddress, iPortNumber);
     tcpClient.Connect(epSend);
     Stream stream = tcpClient.GetStream();
     BufferedStream bs = new BufferedStream( stream );
     bs.Write(new Byte[]{0,1,2}, 0, 3);
     bs.Flush();
 }
开发者ID:ArildF,项目名称:masters,代码行数:12,代码来源:co5602ctor_stream.cs

示例11: SetChunkData

    /// <summary>
    /// Sets the chunk data.
    /// </summary>
    /// <param name="x">The x coordinate.</param>
    /// <param name="z">The z coordinate.</param>
    /// <param name="terrainData">Terrain data.</param>
    public void SetChunkData(int x, int y, int z, CubicTerrainData terrainData)
    {
        lock (this.chunkDataLockObject)
        {
            BufferedStream chunkDataStream = new BufferedStream (File.Open (this.chunkDataFile, FileMode.Open));
            ListIndex<int> index = new ListIndex<int>(x,y,z);

            long position = chunkDataStream.Length;
            if (this.chunkLookupTable.ContainsKey(x,y,z))
            {
                // Key already available
                position = this.chunkLookupTable[index];
            }
            else
            {
                // Key not available
                // Update lookup table
                this.chunkLookupTable.Add (x,y,z, chunkDataStream.Length);
                this.WriteLookupTable (x,y,z, chunkDataStream.Length);
            }

            // Write chunk data
            chunkDataStream.Position = position;
            terrainData.SerializeChunk (chunkDataStream);

            chunkDataStream.Flush ();
            chunkDataStream.Close ();
        }
    }
开发者ID:robotpie,项目名称:cubicworld,代码行数:35,代码来源:CubicTerrainFile.cs

示例12: Page_Load

    //region events
    protected void Page_Load(object sender, EventArgs e)
    {
        //填充交易数据
        serverUrl = Request["serverUrl"];  //submit server url
        key = Request["key"];   //md5 key
        version = Request["version"]; //version
        merchantId = Request["merchantId"];//merchantId
        signType = Request["signType"];
        orderNo = Request["orderNo"];
        orderDatetime = Request["orderDatetime"];
        queryDatetime = Request["queryDatetime"];

        //生成signMsg
        //1、首先组签名原串 querySignSrcMsg
        StringBuilder bufSignSrc = new StringBuilder();
        appendSignPara(bufSignSrc, "merchantId", merchantId);
        appendSignPara(bufSignSrc, "version", version);
        appendSignPara(bufSignSrc, "signType", signType);
        appendSignPara(bufSignSrc, "orderNo", orderNo);
        appendSignPara(bufSignSrc, "orderDatetime", orderDatetime);
        appendSignPara(bufSignSrc, "queryDatetime", queryDatetime);
        appendLastSignPara(bufSignSrc, "key", key);

        querySignSrcMsg = bufSignSrc.ToString();
        //2、再对签名原串进行MD5摘要
        querySignMsg = FormsAuthentication.HashPasswordForStoringInConfigFile(querySignSrcMsg, "MD5");

        //发起POST请求到服务端

        postData = HttpUtility.UrlEncode("merchantId") + "=" + HttpUtility.UrlEncode(merchantId)
            + "&" + HttpUtility.UrlEncode("version") + "=" + HttpUtility.UrlEncode(version)
            + "&" + HttpUtility.UrlEncode("signType") + "=" + HttpUtility.UrlEncode(signType)
            + "&" + HttpUtility.UrlEncode("orderNo") + "=" + HttpUtility.UrlEncode(orderNo)
            + "&" + HttpUtility.UrlEncode("orderDatetime") + "=" + HttpUtility.UrlEncode(orderDatetime)
            + "&" + HttpUtility.UrlEncode("queryDatetime") + "=" + HttpUtility.UrlEncode(queryDatetime)
            + "&" + HttpUtility.UrlEncode("signMsg") + "=" + HttpUtility.UrlEncode(querySignMsg);

        byte[] tRequestMessage = System.Text.ASCIIEncoding.UTF8.GetBytes(postData);
        HttpWebRequest tWebRequest = null;
        BufferedStream tRequestStream = null;
        HttpWebResponse tWebResponse = null;
        Byte[] tResponseByteArray = null;
        try
        {

            #region
            //1、准备连接
            System.Net.ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();

            tWebRequest = (HttpWebRequest)WebRequest.Create(serverUrl);
            tWebRequest.Method = "POST";
            tWebRequest.ProtocolVersion = HttpVersion.Version11;
            tWebRequest.ContentType = "application/x-www-form-urlencoded";

            tWebRequest.KeepAlive = false;
            tWebRequest.ServicePoint.Expect100Continue = false;
            tWebRequest.ReadWriteTimeout = iWebReadWriteTimeout;
            tWebRequest.Timeout = iWebTimeout;

            //2、提交信息
            tWebRequest.ContentLength = tRequestMessage.Length;
            tRequestStream = new BufferedStream(tWebRequest.GetRequestStream());
            if (!tRequestStream.CanWrite)
            {
                //不能连接serverUrl
                throw new Exception("不能建立连接");
            }

            tRequestStream.Write(tRequestMessage, 0, tRequestMessage.Length);
            tRequestStream.Flush();

            //3、接收响应
            tWebResponse = (HttpWebResponse)tWebRequest.GetResponse();
            if (tWebResponse.StatusCode != HttpStatusCode.OK)
            {
                //交易平台未成功处理请求
                throw new Exception("交易平台未成功处理请求");
            }

            Stream tReceiveStream = tWebResponse.GetResponseStream();
            StreamReader tStreamReader = new StreamReader(tReceiveStream);
            String tLine = null;
            String tResponseMessage = "";
            while ((tLine = tStreamReader.ReadLine()) != null)
            {
                tResponseMessage += tLine;
            }
            tResponseByteArray = System.Text.ASCIIEncoding.UTF8.GetBytes(tResponseMessage);

            responseString = System.Text.Encoding.UTF8.GetString(tResponseByteArray);

            //解析返回字符串
            string[] parameters = responseString.Split('&');

            foreach (string param in parameters)
            {
                string[] var = param.Split('=');
                if (var.Length == 2)
                {
//.........这里部分代码省略.........
开发者ID:test-lin,项目名称:Utility-class,代码行数:101,代码来源:orderQuery.aspx.cs

示例13: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         MemoryStream ms2, ms3;
         FileStream fs2;
         BufferedStream bs2;
         String filName = s_strTFAbbrev+"Test.tmp";
         Byte[] bytArrRet;
         Byte[] bytArr = new Byte[] {
                                        Byte.MinValue
                                        ,Byte.MaxValue
                                        ,1
                                        ,2
                                        ,3
                                        ,4
                                        ,5
                                        ,6
                                        ,128
                                        ,250
                                    };
         if(File.Exists(filName))
             File.Delete(filName);
         strLoc = "Loc_00001";
         ms2 = new MemoryStream();
         iCountTestcases++;
         try 
         {
             ms2.WriteTo(null);
             iCountErrors++;
             printerr( "Error_00002! Expected exception not thrown");
         } 
         catch (ArgumentNullException aexc) 
         {
             printinfo( "Info_00003! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_00004! Incorrect exception thrown, exc=="+exc.ToString());
         }
         ms2.Close();
         strLoc = "Loc_00005";
         ms2 = new MemoryStream();
         ms2.Write(new Byte[]{1}, 0, 1);
         fs2 = new FileStream(filName, FileMode.OpenOrCreate, FileAccess.Read);
         iCountTestcases++;
         try 
         {
             ms2.WriteTo(fs2);
             iCountErrors++;
             printerr( "Error_00006! Expected exception not thrown");
         } 
         catch (NotSupportedException iexc) 
         {
             printinfo( "Info_00007! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_00008! Incorrect exception thrown, exc=="+exc.ToString());
         }
         ms2.Close();
         fs2.Close();
         strLoc = "Loc_00009";
         ms2 = new MemoryStream();
         fs2 = new FileStream(filName, FileMode.Create);
         fs2.Close();
         iCountTestcases++;
         try 
         {
             ms2.WriteTo(fs2);
             iCountErrors++;
             printerr( "Error_00010! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_00011! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_00012! Incorrect exception thrown, exc=="+exc.ToString());
         }
         ms2.Close();
         strLoc = "Loc_00013";
         ms2 = new MemoryStream();
         ms2.Write(bytArr, 0, bytArr.Length);
         fs2 = new FileStream(filName, FileMode.Create);
         ms2.WriteTo(fs2);
         fs2.Flush();
         fs2.Close();
         fs2 = new FileStream(filName, FileMode.Open);
         bytArrRet = new Byte[(Int32)fs2.Length];
         fs2.Read(bytArrRet, 0, (Int32)fs2.Length);
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5766writeto_strm.cs

示例14: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + "\\" + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue = String.Empty;
     try
     {
         BufferedStream bs2;
         MemoryStream memstr2;
         if(File.Exists("Co5605Test.tmp"))
             File.Delete("Co5605Test.tmp");
         strLoc = "Loc_9g8yg";
         FileStream fs = new FileStream("Co5605Test.tmp", FileMode.Create);
         bs2 = new BufferedStream(fs);
         bs2.Write(new Byte[]{65,66,67,68,69,70}, 0, 6);
         bs2.Flush();			
         StreamReader sr2 = new StreamReader(fs);
         iCountTestcases++;
         bs2.Position = 0;
         if(!sr2.ReadToEnd().Equals("ABCDEF")) 
         {
             iCountErrors++;
             printerr( "Error_19009! Not flushed correctly");
         }
         bs2.Position = 3;
         bs2.Write(new Byte[]{65,66,67}, 0, 3);
         bs2.Flush();
         bs2.Position = 0;
         if(!sr2.ReadToEnd().Equals("ABCABC")) 
         {
             iCountErrors++;
             printerr( "Error_01909! Not flushed correctly");
         }
         sr2.Close();
         strLoc = "Loc_857yv";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         bs2.Write(new Byte[]{1}, 0, 1);
         memstr2.Close();
         iCountTestcases++;
         try 
         {
             bs2.Flush();
             iCountErrors++;
             printerr( "Error_50039! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_0199x! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_298t8! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_20987";
         m_PortSetEvent.Reset();
         Thread tcpListenerThread = new Thread(new ThreadStart(Co5605Flush.StartListeningTcp));
         tcpListenerThread.Start();
         Console.WriteLine("Listening");
         Thread.Sleep( 1000 );
         m_PortSetEvent.WaitOne();
         Teleport("127.0.0.1");
         Thread.Sleep( 1000 );
         if(File.Exists("Co5605Test.tmp"))
             File.Delete("Co5605Test.tmp");
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
         return true;
     }
     else
     {
         Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:84,代码来源:co5605flush.cs

示例15: StartListeningTcp

    public static void StartListeningTcp() 
    {
        TcpThreadListener listener = new TcpThreadListener(0);
        NetworkStream ns = null;
        BufferedStream bs = null;

        try 
        {
            listener.Start();
            IPEndPoint ipe = (IPEndPoint) listener.LocalEndpoint;
            Interlocked.Exchange(ref iPortNumber, ipe.Port);
            Console.WriteLine("Using port: {0}", iPortNumber);
            m_PortSetEvent.Set();

            Socket s = listener.AcceptSocket();
            ns = new NetworkStream(s);
            bs = new BufferedStream( ns );   
            bs.Close();
            try
            {
                bs.Flush();
                iCountErrors++;
                Console.WriteLine( "Error_8989!!! Expected exception not occured");
            } 
            catch (ObjectDisposedException iexc) 
            {
                Console.WriteLine( "Info_9898! Caught expected exception, exc=="+iexc.Message);
            } 
            catch (Exception exc) 
            {
                iCountErrors++;
                Console.WriteLine( "Error_0000! Incorrect exception thrown, exc=="+exc.ToString());
            }
            Console.WriteLine("We are done with the listening");
        }
        catch(Exception e) 
        {
            iCountErrors++ ;
            Console.WriteLine("Exception receiving Teleportation: " + e.Message + Environment.NewLine + e.StackTrace);
            m_PortSetEvent.Set();
        }
        finally
        {
            if (listener != null)
            {
                listener.Stop();
            }
            if (ns != null)
            {
                ns.Close();
            }
            if(bs != null)
            {
                bs.Close();
            }
        } //finally

    }
开发者ID:ArildF,项目名称:masters,代码行数:58,代码来源:co5604close.cs


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