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


C# BufferedStream.Write方法代码示例

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


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

示例1: Write_Arguments

 public static void Write_Arguments()
 {
     using (BufferedStream stream = new BufferedStream(new MemoryStream()))
     {
         byte[] array = new byte[10];
         Assert.Throws<ArgumentNullException>("array", () => stream.Write(null, 1, 1));
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(array, -1, 1));
         Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(array, 1, -1));
         Assert.Throws<ArgumentException>(() => stream.Write(array, 9, 2));
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:11,代码来源:BufferedStream.InvalidParameters.cs

示例2: CopyToAsyncTest_RequiresAsyncFlushingOfWrites

        public async Task CopyToAsyncTest_RequiresAsyncFlushingOfWrites()
        {
            byte[] data = Enumerable.Range(0, 1000).Select(i => (byte)(i % 256)).ToArray();

            var manualReleaseStream = new ManuallyReleaseAsyncOperationsStream();
            var src = new BufferedStream(manualReleaseStream);
            src.Write(data, 0, data.Length);
            src.Position = 0;

            var dst = new MemoryStream();

            data[0] = 42;
            src.WriteByte(42);
            dst.WriteByte(42);

            Task copyTask = src.CopyToAsync(dst);
            manualReleaseStream.Release();
            await copyTask;

            Assert.Equal(data, dst.ToArray());
        }
开发者ID:dotnet,项目名称:corefx,代码行数:21,代码来源:BufferedStreamTests.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;
         if(File.Exists("Co5604Test.tmp"))
             File.Delete("Co5604Test.tmp");
         strLoc = "Loc_857vi";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         bs2.Write(new Byte[]{65, 66}, 0, 2);
         bs2.Close();
         iCountTestcases++;
         try 
         {
             bs2.Flush();
             iCountErrors++;
             printerr("Error_2yc94! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_298uv! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_9t85y! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_09uf4";
         iCountTestcases++;
         try 
         {
             bs2.Write(new Byte[]{1,2,3}, 0, 3);
             iCountErrors++;
             printerr( "Error_129vc! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_27b99! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "ERror_0901v! Incorrect exception thrown, exc=="+exc.ToString());
         } 
         strLoc = "Loc_2099x";
         iCountTestcases++;
         try 
         {
             bs2.Read(new Byte[3], 0, 3);
             iCountErrors++;
             printerr( "Error_209cx! Expectede exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_t7587! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_20g8j! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_01990";
         iCountTestcases++;
         try 
         {
             bs2.Seek(54, SeekOrigin.Current);
             iCountErrors++;
             printerr( "Error_0190j! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo("Info_g6798! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_2998y! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_0939s";
         iCountTestcases++;
         try 
         {
             bs2.SetLength(100);
             iCountErrors++;
             printerr( "Error_209gb! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_989gh! Caught expected exception, exc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_0190x! Incorrect exception thrown, exc=="+exc.Message);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5604close.cs

示例4: 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 , 3);
     bs.Write(new Byte[]{0,1,2}, 0, 3);
 }
开发者ID:ArildF,项目名称:masters,代码行数:11,代码来源:co5604close.cs

示例5: 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

示例6: 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
		{
			BufferedStream bs2;
			MemoryStream memstr2;
			FileStream fs2;
			Int32 count;
			Byte[] bWriteArr, bReadArr;
			if(File.Exists("Co5616Test.tmp"))
				File.Delete("Co5616Test.tmp");			
			strLoc = "Loc_984yv";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			iCountTestcases++;
			try {
				bs2.Read(null, 0, 0);
				iCountErrors++;
				printerr( "Error_298yv! Expected exception not thrown");
			} catch (ArgumentNullException aexc) {
				printinfo("Info_g98b7! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_t8y78! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_9875g";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, -1, 0);
				iCountErrors++;
				printerr("Error_988bb! Expected exception not thrown");
			} catch (ArgumentOutOfRangeException aexc) {
				printinfo("Info_98yby! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_099hy! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_5g8ys";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, 0, -1);
				iCountErrors++;
				printerr( "Error_9t8yj! Expected exception not thrown");
			} catch (ArgumentOutOfRangeException aexc) {
				printinfo("Info_9488b! Caught expected exception, exc=="+aexc.Message);
			} catch (Exception exc) {
				iCountErrors++;
				printerr( "Error_7687b! Incorrect exception thrown, exc=="+exc.ToString());
			}
			bs2.Close();
			strLoc = "Loc_1228x";
			memstr2 = new MemoryStream();
			bs2 = new BufferedStream(memstr2);
			bs2.Write(new Byte[]{1}, 0, 1);
			iCountTestcases++;
			try {
				bs2.Read(new Byte[]{1}, 2, 0);
				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);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co5616read_barr_i_i.cs

示例7: WriteOnUnwritableStream_Throws_NotSupportedException

 public static void WriteOnUnwritableStream_Throws_NotSupportedException()
 {
     using (WrappedMemoryStream underlying = new WrappedMemoryStream(true, false, true))
     using (BufferedStream stream = new BufferedStream(underlying))
     {
         Assert.Throws<NotSupportedException>(() => stream.Write(new byte[] { 1 }, 0, 1));
     }
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:8,代码来源:BufferedStream.InvalidParameters.cs

示例8: 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

示例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);
     try
     {
         bs.Seek( 1, SeekOrigin.Begin);
         iCountErrors++;
         Console.WriteLine( "Error_8888! Expecte exception not occured ");
     } 
     catch( NotSupportedException iexc) 
     {
         Console.WriteLine("INFO: Expected exception occured, iexc == " + iexc.Message );
     } 
     catch( Exception )
     {
         iCountErrors++;
         Console.WriteLine( "Error_434234! Able to set the Network stream position ");
     } 
 }
开发者ID:ArildF,项目名称:masters,代码行数:26,代码来源:co5614seek_i64_so.cs

示例11: 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

示例12: 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("Co5602Test.tmp"))
             File.Delete("Co5602Test.tmp");
         strLoc = "Loc_98yv7";
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream((Stream)null, 1);
             iCountErrors++;
             printerr( "Error_2yc83! Expected exception not thrown");
         } 
         catch (ArgumentNullException aexc) 
         {
             printinfo("Info_287c7! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_984yv! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_758xy";
         memstr2 = new MemoryStream();
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream(memstr2, 0);
             iCountErrors++;
             printerr( "Error_90838! Expected exception not thrown");
         } 
         catch (ArgumentOutOfRangeException aexc) 
         {
             printinfo( "Info_598by! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_198hg! Incorrect exception thrown, exc=="+exc.ToString());
         }
         memstr2.Close();
         strLoc = "Loc_567g7";
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2, 2);
         bs2.Write(new Byte[]{65,66,67}, 0, 3);
         Byte[] b = new Byte[3];
         bs2.Position = 0;
         bs2.Read(b, 0, 3);
         for(int i = 0 ; i < b.Length ; i++) 
         {
             iCountTestcases++;
             if(b[i] != i+65) 
             {
                 iCountErrors++;
                 printerr( "Error_2958v! Expected=="+i+", got=="+b[i]);
             }
         }
         StreamReader sr2 = new StreamReader(memstr2);
         memstr2.Position = 0;
         iCountTestcases++;
         if(!sr2.ReadToEnd().Equals("ABC")) 
         {
             iCountTestcases++;
             printerr( "ERror_42987! Unexpected string on stream");
         }
         strLoc = "Loc_277gy";
         memstr2 = new MemoryStream();
         memstr2.Close();
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream(memstr2, 10);
             iCountErrors++;
             printerr("Error_2g8yb! Expected exception not thrown");
         } 
         catch (ObjectDisposedException iexc) 
         {
             printinfo( "Info_578yg! Caught expected exception, iexc=="+iexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_3477c! Incorrect exception thrown, exc=="+exc.ToString());
         }
         m_PortSetEvent.Reset();
         Thread tcpListenerThread = new Thread(new ThreadStart(Co5603ctor_stream_i.StartListeningTcp));
         tcpListenerThread.Start();
         Console.WriteLine("Listening");
         Thread.Sleep( 1000 );
         m_PortSetEvent.WaitOne();
         Teleport("127.0.0.1");
         Thread.Sleep( 1000 );
         if(File.Exists("Co5602Test.tmp"))
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co5603ctor_stream_i.cs

示例13: 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("Co5602Test.tmp"))
             File.Delete("Co5602Test.tmp");
         strLoc = "Loc_98yv7";
         iCountTestcases++;
         try 
         {
             bs2 = new BufferedStream((Stream)null);
             iCountErrors++;
             printerr( "Error_2yc83! Expected exception not thrown");
         } 
         catch (ArgumentNullException aexc) 
         {
             printinfo("Info_287c7! Caught expected exception, aexc=="+aexc.Message);
         } 
         catch (Exception exc) 
         {
             iCountErrors++;
             printerr( "Error_984yv! Incorrect exception thrown, exc=="+exc.ToString());
         }
         strLoc = "Loc_567g7";
         iCountTestcases++;
         memstr2 = new MemoryStream();
         bs2 = new BufferedStream(memstr2);
         bs2.Write(new Byte[]{0,1,2}, 0, 3);
         iCountTestcases++;
         Byte[] b = new Byte[3];
         bs2.Position = 0;
         bs2.Read(b, 0, 3);
         for(int i = 0 ; i < b.Length ; i++) 
         {
             iCountTestcases++;
             if(b[i] != i) 
             {
                 iCountErrors++;
                 printerr( "Error_2958v! Expected=="+i+", got=="+b[i]);
             }
         }
         m_PortSetEvent.Reset();
         Thread tcpListenerThread = new Thread(new ThreadStart(Co5602ctor_stream.StartListeningTcp));
         tcpListenerThread.Start();
         Console.WriteLine("Listening");
         Thread.Sleep( 1000 );
         m_PortSetEvent.WaitOne();
         Teleport("127.0.0.1");
         Thread.Sleep( 1000 );
         if(File.Exists("Co5602Test.tmp"))
             File.Delete("Co5602Test.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,代码行数:74,代码来源:co5602ctor_stream.cs

示例14: 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

示例15: 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


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