<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title><![CDATA[鱼之道 - 学习]]></title>
<link>http://blog.buddy.cn/</link>
<description><![CDATA[身体发肤，受之父母，不敢毁伤，孝之始也。立身行道，扬名於后世，以显父母，孝之终也。]]></description>
<language>zh-cn</language>
<copyright><![CDATA[Copyright 2005 PBlog2 v2.4]]></copyright>
<webMaster><![CDATA[yujun.china@gmail.com(余军)]]></webMaster>
<generator>PBlog2 v2.4</generator> 
<image>
	<title>鱼之道</title> 
	<url>http://blog.buddy.cn/images/logos.gif</url> 
	<link>http://blog.buddy.cn/</link> 
	<description>鱼之道</description> 
</image>

			<item>
			<link>http://blog.buddy.cn/default.asp?id=257</link>
			<title><![CDATA[用svcutil.exe为https的wcf写的webservice生成代理类]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Wed,25 Aug 2010 15:41:07 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=257</guid>	
		<description><![CDATA[wcf写的webservice，其默认情况下的WSDL文件都会有一些&lt;import&gt;的语法，貌似如果一旦这个webservice使用https的验证方式的话，svcutil.exe就不能根据wsdl生成代理类了，因为读不到import的那些东东，一般是一些xsd<br/><br/>报错信息：<br/>===================<br/><div class="UBBPanel"><div class="UBBTitle"><img src="http://blog.buddy.cn/images/code.gif" style="margin:0px 2px -3px 0px" alt="程序代码"/> 程序代码</div><div class="UBBContent"><br/>C:\Users\Administrator\Desktop\WSDLs&gt;SvcUtil.exe &#34;TransactionWebService - Copy.wsdl&#34;<br/>Microsoft (R) Service Model Metadata Tool<br/>[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]<br/>Copyright (c) Microsoft Corporation.&nbsp;&nbsp;All rights reserved.<br/><br/>Error: Cannot import wsdl:portType<br/>Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter<br/>Error: Schema with target namespace &#39;urn:schemas.microsoft.com/CommercePlatform/Services/Transaction<br/>Service/2010/01&#39; could not be found.<br/>XPath to Error Source: //wsdl:definitions[@targetNamespace=&#39;urn:schemas.microsoft.com/CommercePlatform/Services/TransactionService/2010/01&#39;]/wsdl:portType[@name=&#39;TransactionService&#39;]<br/><br/><br/>Error: Cannot import wsdl:binding<br/>Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.<br/>XPath to wsdl:portType: //wsdl:definitions[@targetNamespace=&#39;urn:schemas.microsoft.com/CommercePlatform/Services/TransactionService/2010/01&#39;]/wsdl:portType[@name=&#39;TransactionService&#39;]<br/>XPath to Error Source: //wsdl:definitions[@targetNamespace=&#39;urn:schemas.microsoft.com/CommercePlatfo<br/>rm/Services/TransactionService/2010/01&#39;]/wsdl:binding[@name=&#39;TransactionServiceEndPoint&#39;]<br/><br/><br/>Error: Cannot import wsdl:port<br/>Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.<br/>XPath to wsdl:binding: //wsdl:definitions[@targetNamespace=&#39;urn:schemas.microsoft.com/CommercePlatform/Services/TransactionService/2010/01&#39;]/wsdl:binding[@name=&#39;TransactionServiceEndPoint&#39;]<br/>XPath to Error Source: //wsdl:definitions[@targetNamespace=&#39;urn:schemas.microsoft.com/CommercePlatfo<br/>rm/Services/TransactionService/2010/01&#39;]/wsdl:service[@name=&#39;TransactionService&#39;]/wsdl:port[@name=&#39;T<br/>ransactionServiceEndPoint&#39;]<br/><br/><br/>Generating files...<br/>Warning: No code was generated.<br/>If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts o&#114; services<br/>o&#114; because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.<br/><br/>Warning: If you would like to generate data contracts from schemas make sure to use the /dataContrac<br/>tOnly option.</div></div><br/>===================<br/><br/>所以解决方法如下：<br/>1.把wsdl保存到本地<br/>2.把import的xsd也都保存到本地<br/>3.把保存的wsdl里的import的xsd改成保存到本地的xsd<br/>4.再用svcutil.exe根据本地的wsdl和xsd生成代理类<br/><br/>命令：<br/>svcuti.exe &lt;wsdlfilePath&gt; &lt;xsdfilepath1&gt; &lt;xsdfilepath2&gt; ...]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=253</link>
			<title><![CDATA[Convert 250GB dynamic VHD to 40GB fixed size VHD]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Fri,23 Jul 2010 10:54:21 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=253</guid>	
		<description><![CDATA[<div style="TEXT-ALIGN: center; MARGIN: 0in 0in 10pt" align="center"><b><span style="LINE-HEIGHT: 115%; FONT-SIZE: 18pt"><font face="Calibri">Convert 250GB dynamic VHD to 40GB fixed size VHD</font></span></b></div>
<div style="MARGIN: 24pt 0in 0pt"><b><font size="6"><font size="5"><font color="#365f91"><font face="Cambria">Pre-request</font></font></font></font></b></div>
<div style="MARGIN: 0in 0in 10pt"><font face="Calibri">If you want to convert a 250GB dynamic VHD to 40GB fixed size VHD, you have to make sure the used disk space of that 250GB dynamic VHD is less than 40GB.</font>&nbsp;</div>
<div style="MARGIN: 24pt 0in 0pt"><b><font size="6"><font size="5"><font color="#365f91"><font face="Cambria">Glossary</font></font></font></font></b></div>
<div style="MARGIN: 0in 0in 10pt"><font face="Calibri">Source VHD: The 250GB dynamic VHD file</font></div>
<div style="MARGIN: 0in 0in 10pt"><font face="Calibri">Destination VHD: The 40GB fixed size VHD file</font></div>
<div style="MARGIN: 0in 0in 10pt"><font face="Calibri">Local Machine: Machine that hosts Hyper-V</font></div>
<div style="MARGIN: 0in 0in 10pt"><font face="Calibri">VHD Share: The share path that contains the 250GB dynamic VHD file</font>&nbsp;</div>
<div style="MARGIN: 24pt 0in 0pt"><b><font size="6"><font size="5"><font color="#365f91"><font face="Cambria">Steps</font></font></font></font></b></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">1.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Copy the Source VHD to Local Machine from VHD Share</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">2.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Create a VM on Local Machine and attach the Source VHD as its disk</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">3.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Start the VM and logon to OS</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">4.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Open &ldquo;Server Manager&rdquo;, navigate to &ldquo;Storage -&gt; Disk Management&rdquo;</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span style="LINE-HEIGHT: 115%; FONT-SIZE: 18pt"><font face="Calibri"><img alt="" src="http://blog.buddy.cn/attachments/month_1007/t2010723105237.jpg" /></font></span></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">5.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Right click on disk C, select &ldquo;Shrink Volume&hellip;&rdquo;</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><img alt="" src="http://blog.buddy.cn/attachments/month_1007/k2010723105258.jpg" /></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">6.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Enter the amount of space to shrink, make sure the total size after shrink is about 40GB</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><img alt="" src="http://blog.buddy.cn/attachments/month_1007/7201072310536.jpg" /></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">7.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Click &ldquo;Shrink&rdquo; botton</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri"><span style="LINE-HEIGHT: 115%; FONT-SIZE: 18pt"><font face="Calibri"></font></span>8.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">After shrink, you should see that</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri"><span style="LINE-HEIGHT: 115%; FONT-SIZE: 18pt"><font face="Calibri"><img alt="" src="http://blog.buddy.cn/attachments/month_1007/b2010723105333.jpg" /></font></span></font></span></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">9.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><font face="Calibri">Now shut down VM</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">10.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp; </span></span><font face="Calibri">Download &ldquo;VHD Resizer&rdquo; tool at </font><a href="http://vmtoolkit.com/files/folders/converters/entry87.aspx"><font face="Calibri">http://vmtoolkit.com/files/folders/converters/entry87.aspx</font></a><font face="Calibri">, install it</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">11.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp; </span></span><font face="Calibri">Start the VHD Resizer tool, select the Source VHD as its source VHD</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><img alt="" src="http://blog.buddy.cn/attachments/month_1007/42010723105357.jpg" /></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">12.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp; </span></span><font face="Calibri">Input a VHD path as its destination VHD, make sure the destination VHD is not exist</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><img alt="" src="http://blog.buddy.cn/attachments/month_1007/2201072310548.jpg" /></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">13.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp; </span></span><font face="Calibri">Set type to &ldquo;Fixed&rdquo;, and input the new size, the new size should be bigger than the &ldquo;Min&rdquo; value. You can see &ldquo;Min&rdquo; value at below screenshot.</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><img alt="" src="http://blog.buddy.cn/attachments/month_1007/l2010723105418.jpg" /></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in"><span><font face="Calibri">14.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp; </span></span><font face="Calibri">Click &ldquo;resize&rdquo; button and wait. This process need about 1 to 2 hours</font></div>
<div style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in"><span><font face="Calibri">15.</font><span style="FONT: 7pt &quot;Times New Roman&quot;">&nbsp;&nbsp; </span></span><font face="Calibri">After resize, you will see the new VHD with 40GB fixed size now.</font></div>]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=251</link>
			<title><![CDATA[Connect web service with SSL connection]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Mon,05 Jul 2010 13:52:50 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=251</guid>	
		<description><![CDATA[1. Import the cert file<br/>2. Import the pfx file <br/>3. <div class="UBBPanel"><div class="UBBTitle"><img src="http://blog.buddy.cn/images/code.gif" style="margin:0px 2px -3px 0px" alt="程序代码"/> 程序代码</div><div class="UBBContent"><br/>using System;<br/>using System.Collections.Generic;<br/>using System.Linq;<br/>using System.Text;<br/>using System.Net;<br/>using System.Security.Cryptography.X509Certificates;<br/>using System.Net.Security;<br/>using ConsoleApplication1.ScsWebReference;<br/><br/>namespace ConsoleApplication1<br/>{<br/>&nbsp;&nbsp;&nbsp;&nbsp;class Program<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static string ServiceUrl = &#34;<a href="https://172.22.120.154/scs/scsapiwebservice.asmx?wsdl" target="_blank">https://172.22.120.154/scs/scsapiwebservice.asmx?wsdl</a>&#34;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static string CertSerialNumber = &#34;1fcf8092000000002d07&#34;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;static void Main(string[] args)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch || sslPolicyErrors == SslPolicyErrors.None)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bdk scs = new bdk();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scs.Url = ServiceUrl;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scs.ClientCertificates.Add(GetCert(CertSerialNumber));<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string testConnectionOut;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scs.TestConnection(&#34;Scs Test&#34;, out testConnectionOut);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private static X509Certificate GetCert(string serialNumber)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store.Open(OpenFlags.OpenExistingOnly);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (X509Certificate2 cert in store.Certificates)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (cert.GetSerialNumberString().Equals(serialNumber, StringComparison.OrdinalIgnoreCase))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!cert.HasPrivateKey)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new ApplicationException(&#34;The cert (&#34; + serialNumber + &#34;) does not have a private key&#34;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.Write(&#34;Got the cert, serial number:&#34; + serialNumber);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return cert;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw new ApplicationException(&#34;Cannot find cert with SN=&#34; + serialNumber);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finally<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;store.Close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/><br/></div></div>]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=247</link>
			<title><![CDATA[WPF揭秘.pdf]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Mon,28 Jun 2010 11:02:20 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=247</guid>	
		<description><![CDATA[<img src="http://blog.buddy.cn/images/download.gif" alt="下载文件" style="margin:0px 2px -4px 0px"/> <a href="http://blog.buddy.cn/attachments/month_1006/f201062811216.pdf" target="_blank">点击下载此文件</a><br/>]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=231</link>
			<title><![CDATA[关于卸载Operations Manager之后，安装新版本失败的问题]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Mon,18 Jan 2010 10:09:48 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=231</guid>	
		<description><![CDATA[当你卸载一个旧版本的System Center Operations Manager之后，如果想安装它的新版本，可能你会收到如下的报错信息：<br/>---------------------------<br/>&#34;Invalid Management Group name&#34; <br/><br/> <br/><br/>This problem occurs when the Management Group name is:<br/><br/> <br/><br/>-Empty of Null<br/><br/>-Leading o&#114; Trailing spaces<br/><br/> <br/><br/>-Already exists on this computer<br/><br/>-Contains special characters.&nbsp;&nbsp; The Management Group name should not contain following special characters:<br/>^@)~(:!`#%\*+$|,&amp;&amp;=&#39;[&#34;]/&lt;.{;?&gt;}<br/><br/> <br/><br/>To continue setup, go back and change the Management Group name.<br/>---------------------------<br/><br/>这是因为系统在卸载时，没有删除相关的注册表项导致的，解决方法很简单，删掉如下注册表项即可：<br/>HKLM\Software\Microsoft\Microsoft Operations Manager<br/>如果安装目录也没有卸载干净的话，也手动删除一下就好了。]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=230</link>
			<title><![CDATA[获取指定进程的CPU使用率]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Wed,13 Jan 2010 10:29:22 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=230</guid>	
		<description><![CDATA[这些天，碰到一个项目需求，需要做一个小工具用来检测某些指定进程的CPU使用率的总和。具体的说就是有两个进程“HealthService”和“MonitoringHost”，这两个进程会启动一些其他的进程，而被启动的进程又可能启动其他进程，现在的需求就是从这两个最顶端的进程递归寻找到所有子进程，然后计算他们的CPU使用率的综合。<br/><br/>搞了一天，终于搞定，先总结如下。<br/><br/>仅仅用C#的Process类来做貌似比较复杂，而且C#里面貌似获取不到某个进程的父进程ID，所以我基本是用WMI查询来做的，贴部分代码上来，代码写的比较乱，毕竟不是正式的东东，这只是为了测试而写的一个小工具。<br/><br/><div class="UBBPanel"><div class="UBBTitle"><img src="http://blog.buddy.cn/images/code.gif" style="margin:0px 2px -3px 0px" alt="程序代码"/> 程序代码</div><div class="UBBContent"><br/>//这两个类用来获取所有的目标进程，返回值是一个ID和Name的Pair<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;class MOMProcessHelper<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private List&lt;string&gt; topLevelProcessNames;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private List&lt;string&gt; TopLevelProcessNames<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return this.topLevelProcessNames;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ManagementObjectSearcher searcher;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public MOMProcessHelper()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.topLevelProcessNames = new List&lt;string&gt;();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.topLevelProcessNames.Add(&#34;HealthService&#34;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.topLevelProcessNames.Add(&#34;MonitoringHost&#34;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//this.topLevelProcessNames.Add(&#34;System&#34;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//this.topLevelProcessNames.Add(&#34;taskmgr&#34;);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher = new ManagementObjectSearcher();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Scope = new ManagementScope(&#34;root\\CIMV2&#34;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;summary&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// get all mom processes<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;/summary&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;returns&gt;&lt;/returns&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public List&lt;ProcessIdNamePair&gt; GetMOMProcess()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Process[] processes = Process.GetProcesses();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;ProcessIdNamePair&gt; destProcess = new List&lt;ProcessIdNamePair&gt;();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (Process process in processes)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.TopLevelProcessNames.Contains(process.ProcessName))<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessIdNamePair pair = new ProcessIdNamePair();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.Id = process.Id;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.Name = process.ProcessName;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destProcess.Add(pair);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destProcess.AddRange(this.GetChildrenProcess(process.Id));<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = destProcess.Count - 1; i &gt;= 0; i--)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int j = 0; j &lt; i; j++)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (destProcess[i].Id == destProcess[j].Id)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destProcess.RemoveAt(i);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return destProcess;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;summary&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// travelsal to get all children processes<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;/summary&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;param name=&#34;parentProcessId&#34;&gt;&lt;/param&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/// &lt;returns&gt;&lt;/returns&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private List&lt;ProcessIdNamePair&gt; GetChildrenProcess(int parentProcessId)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ObjectQuery q = new ObjectQuery();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;q.QueryString = &#34;Sel&#101;ct Name, ProcessId FROM Win32_Process wh&#101;re ParentProcessId = &#34; + parentProcessId.ToString();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.searcher.Query = q;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;ProcessIdNamePair&gt; childrenProcesses = new List&lt;ProcessIdNamePair&gt;();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (ManagementObject process in this.searcher.Get())<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ProcessIdNamePair pair = new ProcessIdNamePair();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.Name = process.Properties[&#34;Name&#34;].Value.ToString();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pair.Id = Convert.ToInt32(process.Properties[&#34;ProcessId&#34;].Value);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;childrenProcesses.Add(pair);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//travelsal<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;childrenProcesses.AddRange(this.GetChildrenProcess(pair.Id));<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return childrenProcesses;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public class ProcessIdNamePair<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private int id;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private string name;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public int Id<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get { return id; }<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set { id = value; }<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public string Name<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get { return name; }<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set { name = value; }<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public Process ToProcess()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Process p = Process.GetProcessById(this.Id);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return p;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/></div></div><br/><br/><div class="UBBPanel"><div class="UBBTitle"><img src="http://blog.buddy.cn/images/code.gif" style="margin:0px 2px -3px 0px" alt="程序代码"/> 程序代码</div><div class="UBBContent"><br/>//这个类用来获取CPU使用率，需要传递一个进程列表进来作为参数<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;public class CpuUsageHelper<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static Dictionary&lt;string,int&gt; GetProcessorCoreCount()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dictionary&lt;string, int&gt; processorCount = new Dictionary&lt;string, int&gt;();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ManagementObjectSearcher searcher = new ManagementObjectSearcher();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Scope = new ManagementScope(&#34;root\\CIMV2&#34;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Query = new ObjectQuery();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Query.QueryString = &#34;Sel&#101;ct Name,NumberOfCores FROM Win32_Processor&#34;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (ManagementObject obj in searcher.Get())<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string name = obj.Properties[&#34;Name&#34;].Value.ToString();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int numberOfCores = Convert.ToInt32(obj.Properties[&#34;NumberOfCores&#34;].Value);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;processorCount.Add(name, numberOfCores);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return processorCount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//PercentProcessorTime, IDProcess, CreatingProcessId<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static int GetPercentProcessorTime(List&lt;ProcessIdNamePair&gt; processes)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int total = 0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ManagementObjectSearcher searcher = new ManagementObjectSearcher();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Scope = new ManagementScope(&#34;root\\CIMV2&#34;);<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (ProcessIdNamePair process in processes)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//get processor cores<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int coreCount = 0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Query = new ObjectQuery();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Query.QueryString = &#34;Sel&#101;ct NumberOfCores FROM Win32_Processor&#34;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (ManagementObject obj in searcher.Get())<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (obj.Properties[&#34;NumberOfCores&#34;].Value != null)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;coreCount += Convert.ToInt32(obj.Properties[&#34;NumberOfCores&#34;].Value);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;searcher.Query.QueryString = &#34;Sel&#101;ct PercentProcessorTime From Win32_PerfFormattedData_PerfProc_Process wh&#101;re IDProcess = &#34; + process.Id.ToString();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach (ManagementObject obj in searcher.Get())<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (obj.Properties[&#34;PercentProcessorTime&#34;].Value != null)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int usage = Convert.ToInt32(obj.Properties[&#34;PercentProcessorTime&#34;].Value);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;usage /= coreCount;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total += usage;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return total;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static int GetMomCpuUsage(out List&lt;ProcessIdNamePair&gt; momProcesses)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MOMProcessHelper helper = new MOMProcessHelper();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;momProcesses = helper.GetMOMProcess();<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return CpuUsageHelper.GetPercentProcessorTime(momProcesses);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/></div></div><br/><br/>简单的写一下，附件就不上传了，我正在办公室，微软内部貌似不让传文件出去，呵呵。]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=219</link>
			<title><![CDATA[XPath语法介绍]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Fri,13 Nov 2009 10:19:43 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=219</guid>	
		<description><![CDATA[<div class="UBBPanel"><div class="UBBTitle"><img src="http://blog.buddy.cn/images/code.gif" style="margin:0px 2px -3px 0px" alt="程序代码"/> 程序代码</div><div class="UBBContent"><br/>XPath 是XML的查询语言，和SQL的角色很类似。以下面XML为例，介绍XPath 的语法。<br/><br/> <br/>&lt;?xml version=&#34;1.0&#34; encoding=&#34;ISO-8859-1&#34;?&gt;<br/>&lt;catalog&gt;<br/>&nbsp;&nbsp;&lt;cd country=&#34;USA&#34;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Empire Burlesque&lt;/title&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;artist&gt;Bob Dylan&lt;/artist&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;price&gt;10.90&lt;/price&gt;<br/>&nbsp;&nbsp;&lt;/cd&gt;<br/>&nbsp;&nbsp;&lt;cd country=&#34;UK&#34;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Hide your heart&lt;/title&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;artist&gt;Bonnie Tyler&lt;/artist&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;price&gt;9.90&lt;/price&gt;<br/>&nbsp;&nbsp;&lt;/cd&gt;<br/>&nbsp;&nbsp;&lt;cd country=&#34;USA&#34;&gt;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Greatest Hits&lt;/title&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;artist&gt;Dolly Parton&lt;/artist&gt; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&lt;price&gt;9.90&lt;/price&gt; <br/>&nbsp;&nbsp;&lt;/cd&gt;<br/>&lt;/catalog&gt;<br/> <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>定位节点<br/>XML是树状结构，类似档案系统内数据夹的结构，XPath也类似档案系统的路径命名方式。不过XPath 是一种模式(Pattern)，可以选出 XML档案中，路径符合某个模式的所有节点出来。例如要选catalog底下的cd中所有price元素可以用：<br/><br/> <br/>/catalog/cd/price&nbsp;&nbsp;&nbsp;&nbsp; <br/> <br/>如果XPath的开头是一个斜线（/）代表这是绝对路径。如果开头是两个斜线（//）表示文件中所有符合模式的元素都会被选出来，即使是处于树中不同的层级也会被选出来。以下的语法会选出文件中所有叫做cd的元素（在树中的任何层级都会被选出来）：<br/><br/> <br/>//cd<br/> <br/>选择未知的元素<br/>使用星号（Wildcards,＊）可以选择未知的元素。下面这个语法会选出/catalog/cd 的所有子元素：<br/><br/> <br/>/catalog/cd/*<br/> <br/>以下的语法会选出所有catalog的子元素中，包含有price作为子元素的元素。<br/><br/> <br/>/catalog/*/price<br/> <br/>以下的语法会选出有两层父节点，叫做price的所有元素。<br/><br/> <br/>/*/*/price<br/> <br/>以下的语法会选择出文件中的所有元素。<br/><br/> <br/>//*<br/> <br/>要注意的是，想要存取不分层级的元素，XPath语法必须以两个斜线开头(//)，想要存取未知元素才用星号(*)，星号只能代表未知名称的元素，不能代表未知层级的元素。 <br/><br/>选择分支<br/>使用中括号可以选择分支。以下的语法从catalog的子元素中取出第一个叫做cd的元素。XPath的定义中没有第0元素这种东西。<br/><br/> <br/>/catalog/cd[1]<br/> <br/>以下语法选择catalog中的最后一个cd元素：（XPathj并没有定义 first() 这种函式喔，用上例的 [1]就可以取出第一个元素。<br/><br/> <br/>/catalog/cd[last()]<br/> <br/>以下语法选出含有price子元素的所有/catalog/cd元素。<br/><br/> <br/>/catalog/cd[price]<br/> <br/>以下语法选出price元素的值等于10.90的所有/catalog/cd元素<br/><br/> <br/>/catalog/cd[price=10.90]<br/> <br/>以下语法选出price元素的值等于10.90的所有/catalog/cd元素 的price元素<br/><br/> <br/>/catalog/cd[price=10.90]/price<br/> <br/>选择一个以上的路径<br/>使用Or操作数(|)就可以选择一个以上的路径。例如：<br/><br/> <br/>/catalog/cd/title | catalog/cd/artist<br/> <br/>选择所有title以及artist元素<br/><br/> <br/>//title | //artist<br/> <br/>选择所有title以及artist以及price元素<br/><br/> <br/>//title | //artist | //price<br/> <br/>选择属性<br/>在XPath中，除了选择元素以外，也可以选择属性。属性都是以@开头。例如选择文件中所有叫做country的属性：<br/><br/> <br/>//@country<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>选择所有含有country这个属性的cd元素：<br/><br/> <br/>//cd[@country]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>以下语法选择出含有属性的所有cd元素<br/><br/> <br/>//cd[@*]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>以下语法选择出country属性值为UK的cd元素<br/><br/> <br/>//cd[@country=&#39;UK&#39;]<br/> 只要掌握了xpath语法，理论上你就可以访问xml文件中的任意节点和任意值<br/></div></div>]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=218</link>
			<title><![CDATA[用WebRequest向某个http地址发送数据]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Tue,03 Nov 2009 13:45:43 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=218</guid>	
		<description><![CDATA[<div class="UBBPanel"><div class="UBBTitle"><img src="http://blog.buddy.cn/images/code.gif" style="margin:0px 2px -3px 0px" alt="程序代码"/> 程序代码</div><div class="UBBContent"><br/>using System;<br/>using System.IO;<br/>using System.Net;<br/>using System.Text;<br/><br/>namespace Examples.System.Net<br/>{<br/>&nbsp;&nbsp;&nbsp;&nbsp;public class WebRequestPostExample<br/>&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public static void Main ()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Cr&#101;ate a request using a URL that can receive a post. <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WebRequest request = WebRequest.Cr&#101;ate (&#34;<a href="http://www.contoso.com/PostAccepter.aspx" target="_blank">http://www.contoso.com/PostAccepter.aspx</a> &#34;);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Set the Method property of the request to POST.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.Method = &#34;POST&#34;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Cr&#101;ate POST data and convert it to a byte array.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string postData = &#34;This is a test that posts this string to a Web server.&#34;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[] byteArray = Encoding.UTF8.GetBytes (postData);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Set the ContentType property of the WebRequest.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.ContentType = &#34;application/x-www-form-urlencoded&#34;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Set the ContentLength property of the WebRequest.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;request.ContentLength = byteArray.Length;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get the request stream.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stream dataStream = request.GetRequestStream ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Write the data to the request stream.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataStream.Write (byteArray, 0, byteArray.Length);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Close the Stream object.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataStream.Close ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get the response.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WebResponse response = request.GetResponse ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Display the status.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine (((HttpWebResponse)response).StatusDescription);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Get the stream containing content returned by the server.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataStream = response.GetResponseStream ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Open the stream using a StreamReader for easy access.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;StreamReader reader = new StreamReader (dataStream);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Read the content.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string responseFromServer = reader.ReadToEnd ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Display the content.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine (responseFromServer);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Clean up the streams.<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader.Close ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataStream.Close ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.Close ();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;&nbsp;}<br/>}<br/></div></div>]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=217</link>
			<title><![CDATA[查看程序的Trace]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Tue,03 Nov 2009 13:42:46 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=217</guid>	
		<description><![CDATA[有些时候需要查看程序运行的Trace，可以在VS的output窗口中看得到。<br/><br/>可以使用下述方法将字符串写入Trace<br/>Trace.TraceInformation(string message)<br/><br/>]]></description>
		</item>
		
			<item>
			<link>http://blog.buddy.cn/default.asp?id=213</link>
			<title><![CDATA[Managed,Unmanaged,Native:What Kind of Code Is This]]></title>
			<author>yujun.china@gmail.com(Peter)</author>
			<category><![CDATA[学习]]></category>
			<pubDate>Fri,23 Oct 2009 10:06:09 +0800</pubDate>
			<guid>http://blog.buddy.cn/default.asp?id=213</guid>	
		<description><![CDATA[<p>&nbsp;</p>
<h3>What Is Managed Code?</h3>
<p>Managed Code is what Visual Basic .NET and C# compilers create. It compiles to Intermediate Language (IL), not to machine code that could run directly on your computer. The IL is kept in a file called an assembly, along with metadata that describes the classes, methods, and attributes (such as security requirements) of the code you've created. This assembly is the one-stop-shopping unit of deployment in the .NET world. You copy it to another server to deploy the assembly there&mdash;and often that copying is the only step required in the deployment.</p>
<p>Managed code runs in the Common Language Runtime. The runtime offers a wide variety of services to your running code. In the usual course of events, it first loads and verifies the assembly to make sure the IL is okay. Then, just in time, as methods are called, the runtime arranges for them to be compiled to machine code suitable for the machine the assembly is running on, and caches this machine code to be used the next time the method is called. (This is called Just In Time, or JIT compiling, or often just Jitting.) </p>
<p>As the assembly runs, the runtime continues to provide services such as security, memory management, threading, and the like. The application is <em>managed</em> by the runtime.</p>
<p>Visual Basic .NET and C# can produce only managed code. If you're working with those applications, you are making managed code. Visual C++ .NET can produce managed code if you like: When you create a project, select one of the application types whose name starts with .Managed., such as .Managed C++ application..</p>
<h3>What Is Unmanaged Code?</h3>
<p>Unmanaged code is what you use to make before Visual Studio .NET 2002 was released. Visual Basic 6, Visual C++ 6, heck, even that 15-year old C compiler you may still have kicking around on your hard drive all produced unmanaged code. It compiled directly to machine code that ran on the machine where you compiled it&mdash;and on other machines as long as they had the same chip, or nearly the same. It didn't get services such as security or memory management from an invisible runtime; it got them from the operating system. And importantly, it got them from the operating system explicitly, by asking for them, usually by calling an API provided in the Windows SDK. More recent unmanaged applications got operating system services through COM calls.</p>
<p>Unlike the other Microsoft languages in Visual Studio, Visual C++ can create unmanaged applications. When you create a project and select an application type whose name starts with MFC, ATL, or Win32, you're creating an unmanaged application.</p>
<p>This can lead to some confusion: When you create a .Managed C++ application., the build product is an assembly of IL with an .exe extension. When you create an MFC application, the build product is a Windows executable file of native code, also with an .exe extension. The internal layout of the two files is utterly different. You can use the Intermediate Language Disassembler, ildasm, to look inside an assembly and see the metadata and IL. Try pointing ildasm at an unmanaged exe and you'll be told it has no valid CLR (Common Language Runtime) header and can't be disassembled&mdash;Same extension, completely different files.</p>
<h3>What about Native Code?</h3>
<p>The phrase native code is used in two contexts. Many people use it as a synonym for unmanaged code: code built with an older tool, or deliberately chosen in Visual C++, that does not run in the runtime, but instead runs natively on the machine. This might be a complete application, or it might be a COM component or DLL that is being called from managed code using COM Interop or PInvoke, two powerful tools that make sure you can use your old code when you move to the new world. I prefer to say .unmanaged code. for this meaning, because it emphasizes that the code does not get the services of the runtime. For example, Code Access Security in managed code prevents code loaded from another server from performing certain destructive actions. If your application calls out to unmanaged code loaded from another server, you won't get that protection.</p>
<p>The other use of the phrase native code is to describe the output of the JIT compiler, the machine code that actually runs in the runtime. It's managed, but it's not IL, it's machine code. As a result, don't just assume that native = unmanaged.</p>
<h3>Does Managed Code Mean Managed Data?</h3>
<p>Again with Visual Basic and C#, life is simple because you get no choice. When you declare a class in those languages, instances of it are created on the managed heap, and the garbage collector takes care of lifetime issues. But in Visual C++, you get a choice. Even when you're creating a managed application, you decide class by class whether it's a managed type or an unmanaged type. This is an unmanaged type:</p>
<pre>class Foo
{
private:
int x;
public:
Foo(): x(0){}
Foo(int xx): x(xx) {}
};
</pre>
<p>This is a managed type:</p>
<pre>__gc class Bar
{
private:
int x;
public:
Bar(): x(0){}
Bar(int xx): x(xx) {}
};
</pre>
<p>The only difference is the __gc keyword on the definition of Bar. But it makes a huge difference.</p>
<p>Managed types are garbage collected. They must be created with new, never on the stack. So this line is fine:</p>
<pre>Foo f;</pre>
<p>But this line is not allowed:</p>
<pre>Bar b;</pre>
<p>If I do create an instance of Foo on the heap, I must remember to clean it up:</p>
<pre>Foo* pf = new Foo(2);
// . . .
delete pf;
</pre>
<p>The C++ compiler actually uses two heaps, a managed an unmanaged one, and uses operator overloading on new to decide where to allocate memory when you create an instance with new.</p>
<p>If I create an instance of Bar on the heap, I can ignore it. The garbage collector will clean it up some after it becomes clear that no one is using it (no more pointers to it are in scope).</p>
<p>There are restrictions on managed types: They can't use multiple inheritance or inherit from unmanaged types, they can't allow private access with the friend keyword, and they can't implement a copy constructor, to name a few. So, you might not want your classes to be managed classes. But that doesn't mean you don't want your code to be managed code. In Visual C++, you get the choice.</p>]]></description>
		</item>
		
</channel>
</rss>