﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-rex xiang</title><link>http://www.cnblogs.com/xzwplus/</link><description>每天进步一点点.</description><language>zh-cn</language><lastBuildDate>Sat, 26 Jul 2008 09:33:39 GMT</lastBuildDate><pubDate>Sat, 26 Jul 2008 09:33:39 GMT</pubDate><ttl>60</ttl><item><title>asp.net 2.0中实现异步处理任务.</title><link>http://www.cnblogs.com/xzwplus/archive/2008/04/27/1172736.html</link><dc:creator>rex xiang</dc:creator><author>rex xiang</author><pubDate>Sat, 26 Apr 2008 17:56:00 GMT</pubDate><guid>http://www.cnblogs.com/xzwplus/archive/2008/04/27/1172736.html</guid><wfw:comment>http://www.cnblogs.com/xzwplus/comments/1172736.html</wfw:comment><comments>http://www.cnblogs.com/xzwplus/archive/2008/04/27/1172736.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/xzwplus/comments/commentRss/1172736.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/xzwplus/services/trackbacks/1172736.html</trackback:ping><description><![CDATA[<P><FONT size=2>以下内容是在newsgroups中解决一个朋友的问题而写的demo, 留下给自己做个备忘录. </FONT>
<P><FONT size=2>---- </FONT>
<P><FONT size=2>关于PageAsyncTask在MSDN上的参考<BR>ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/fxref_system.web/html/08ffac7a-2c3c-27ee-1445-5284a226be38.htm</FONT></P>
<P><FONT size=2>说明: 此页面中, 在Page_Load方法中, 同时启动4个较耗时的任务(线程), 让它们并行的运行, 然后等待他们都运行完毕或超时.</FONT></P>
<DIV class=csharpcode><PRE class=alt><SPAN class=kwrd>using</SPAN> System;</PRE><PRE><SPAN class=kwrd>using</SPAN> System.Diagnostics;</PRE><PRE class=alt><SPAN class=kwrd>using</SPAN> System.Threading;</PRE><PRE><SPAN class=kwrd>using</SPAN> System.Web.Mvc;</PRE><PRE class=alt><SPAN class=kwrd>using</SPAN> System.Web.UI;</PRE><PRE>&nbsp;</PRE><PRE class=alt><SPAN class=kwrd>namespace</SPAN> Portal.Views.Home</PRE><PRE>{</PRE><PRE class=alt>    <SPAN class=kwrd>public</SPAN> <SPAN class=kwrd>partial</SPAN> <SPAN class=kwrd>class</SPAN> Index : ViewPage</PRE><PRE>    {</PRE><PRE class=alt>        <SPAN class=kwrd>private</SPAN> <SPAN class=kwrd>string</SPAN> _asyncResult;</PRE><PRE>        <SPAN class=kwrd>private</SPAN> AsyncTaskDelegate _asyncTask;</PRE><PRE class=alt>&nbsp;</PRE><PRE>        <SPAN class=kwrd>protected</SPAN> <SPAN class=kwrd>void</SPAN> Page_Load(<SPAN class=kwrd>object</SPAN> sender, EventArgs e)</PRE><PRE class=alt>        {</PRE><PRE>            Stopwatch sw = Stopwatch.StartNew();</PRE><PRE class=alt>&nbsp;</PRE><PRE>            PageAsyncTask task1 =</PRE><PRE class=alt>                <SPAN class=kwrd>new</SPAN> PageAsyncTask(OnTaskBegin, OnTaskEnd, OnTaskTimeout, <SPAN class=str>"A1"</SPAN>, <SPAN class=kwrd>true</SPAN>);</PRE><PRE>            PageAsyncTask task2 =</PRE><PRE class=alt>                <SPAN class=kwrd>new</SPAN> PageAsyncTask(OnTaskBegin, OnTaskEnd, OnTaskTimeout, <SPAN class=str>"B2"</SPAN>, <SPAN class=kwrd>true</SPAN>);</PRE><PRE>            PageAsyncTask task3 =</PRE><PRE class=alt>                <SPAN class=kwrd>new</SPAN> PageAsyncTask(OnTaskBegin, OnTaskEnd, OnTaskTimeout, <SPAN class=str>"C3"</SPAN>, <SPAN class=kwrd>true</SPAN>);</PRE><PRE>            PageAsyncTask task4 =</PRE><PRE class=alt>                <SPAN class=kwrd>new</SPAN> PageAsyncTask(OnTaskBegin, OnTaskEnd, OnTaskTimeout, <SPAN class=str>"D4"</SPAN>, <SPAN class=kwrd>true</SPAN>);</PRE><PRE>&nbsp;</PRE><PRE class=alt>            RegisterAsyncTask(task1);</PRE><PRE>            RegisterAsyncTask(task2);</PRE><PRE class=alt>            RegisterAsyncTask(task3);</PRE><PRE>            RegisterAsyncTask(task4);</PRE><PRE class=alt>&nbsp;</PRE><PRE>            <SPAN class=rem>// By default, an asynchronous task will time out if it has not completed</SPAN></PRE><PRE class=alt>            <SPAN class=rem>// within 45 seconds.</SPAN></PRE><PRE>            AsyncTimeout = TimeSpan.FromSeconds(60);</PRE><PRE class=alt>&nbsp;</PRE><PRE>            ExecuteRegisteredAsyncTasks();</PRE><PRE class=alt>&nbsp;</PRE><PRE>            sw.Stop();</PRE><PRE class=alt>&nbsp;</PRE><PRE>            <SPAN class=rem>// now, we can get the task result here.</SPAN></PRE><PRE class=alt>            Response.Write(_asyncResult);</PRE><PRE>            Response.Write(sw.Elapsed.TotalSeconds);</PRE><PRE class=alt>        }</PRE><PRE>&nbsp;</PRE><PRE class=alt>        <SPAN class=kwrd>private</SPAN> IAsyncResult OnTaskBegin(<SPAN class=kwrd>object</SPAN> sender,</PRE><PRE>                                         EventArgs e,</PRE><PRE class=alt>                                         AsyncCallback callback,</PRE><PRE>                                         <SPAN class=kwrd>object</SPAN> data)</PRE><PRE class=alt>        {</PRE><PRE>            _asyncTask = <SPAN class=kwrd>delegate</SPAN>(<SPAN class=kwrd>string</SPAN> text)</PRE><PRE class=alt>            {</PRE><PRE>                <SPAN class=rem>// TODO: add your async task here.</SPAN></PRE><PRE class=alt>                <SPAN class=kwrd>string</SPAN> response =</PRE><PRE>                    <SPAN class=kwrd>string</SPAN>.Format(<SPAN class=str>"AsyncTask {0} started at: {1}. "</SPAN>, text, DateTime.Now);</PRE><PRE class=alt>                Thread.Sleep(TimeSpan.FromSeconds(10));</PRE><PRE>                response +=</PRE><PRE class=alt>                    <SPAN class=kwrd>string</SPAN>.Format(<SPAN class=str>"AsyncTask {0} ended at: {1}.\n"</SPAN>, text, DateTime.Now);</PRE><PRE>                <SPAN class=kwrd>return</SPAN> response;</PRE><PRE class=alt>            };</PRE><PRE>&nbsp;</PRE><PRE class=alt>            IAsyncResult result = _asyncTask.BeginInvoke((<SPAN class=kwrd>string</SPAN>) data, callback, data);</PRE><PRE>            <SPAN class=kwrd>return</SPAN> result;</PRE><PRE class=alt>        }</PRE><PRE>&nbsp;</PRE><PRE class=alt>        <SPAN class=kwrd>private</SPAN> <SPAN class=kwrd>void</SPAN> OnTaskEnd(IAsyncResult ar)</PRE><PRE>        {</PRE><PRE class=alt>            _asyncResult += _asyncTask.EndInvoke(ar);</PRE><PRE>        }</PRE><PRE class=alt>&nbsp;</PRE><PRE>        <SPAN class=kwrd>private</SPAN> <SPAN class=kwrd>void</SPAN> OnTaskTimeout(IAsyncResult ar)</PRE><PRE class=alt>        {</PRE><PRE>            _asyncResult = <SPAN class=kwrd>string</SPAN>.Format(<SPAN class=str>"AsyncTask {0} is time out."</SPAN>, ar.AsyncState);</PRE><PRE class=alt>        }</PRE><PRE>&nbsp;</PRE><PRE class=alt>        <SPAN class=preproc>#region</SPAN> Nested type: AsyncTaskDelegate</PRE><PRE>&nbsp;</PRE><PRE class=alt>        <SPAN class=kwrd>protected</SPAN> <SPAN class=kwrd>delegate</SPAN> <SPAN class=kwrd>string</SPAN> AsyncTaskDelegate(<SPAN class=kwrd>string</SPAN> text);</PRE><PRE>&nbsp;</PRE><PRE class=alt>        <SPAN class=preproc>#endregion</SPAN></PRE><PRE>    }</PRE><PRE class=alt>}</PRE></DIV>
<STYLE type=text/css>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</STYLE>

<STYLE type=text/css>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</STYLE>
<BR>reference: <A href="http://msdn.microsoft.com/en-us/library/system.web.ui.pageasynctask(zh-cn).aspx">http://msdn.microsoft.com/en-us/library/system.web.ui.pageasynctask(zh-cn).aspx</A><img src ="http://www.cnblogs.com/xzwplus/aggbug/1172736.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41316/" target="_blank">[新闻]腾讯CEO马化腾:中国互联网业准备再过冬</a>]]></description></item><item><title>调试windows service的OnStart事件.</title><link>http://www.cnblogs.com/xzwplus/archive/2008/03/30/1129452.html</link><dc:creator>rex xiang</dc:creator><author>rex xiang</author><pubDate>Sat, 29 Mar 2008 20:02:00 GMT</pubDate><guid>http://www.cnblogs.com/xzwplus/archive/2008/03/30/1129452.html</guid><wfw:comment>http://www.cnblogs.com/xzwplus/comments/1129452.html</wfw:comment><comments>http://www.cnblogs.com/xzwplus/archive/2008/03/30/1129452.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/xzwplus/comments/commentRss/1129452.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/xzwplus/services/trackbacks/1129452.html</trackback:ping><description><![CDATA[<p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; 关于调试windows service, 其实这是一个老生常谈的问题了.</font></p> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; 通常的处理办法是, 在service运行后, 在调试器中选择attach to process.</font></p> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; 然而这种做法也有一定的局限性, 例如在service启动时的OnStart事件中的代码, 基本上很难调试. 往往当attach到我们的service的时候, 这部分代码已经执行过了. 于是, 有人提出, 可以另写一个project来调用这个OnStart方法, 或将OnStart方法中的代码搬到另一个project中测试. 不过, 这些方法终究不是以windows服务的方式调试的, 不能够最真实的反应service运行时的执行状况(如权限问题等环境问题).</font></p> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; 我的做法是, 在OnStart方法的最开始部分加上"<font color="#008080">Debugger</font>.Launch()"的调用, 当service运行到此处时, 将会弹出一个选择调试器的对话框, 同时暂停在当前位置. 这样, 我们就做到了在代码中手动的启动调试器.</font></p> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; 示例代码如下:</font></p> <div class="csharpcode"><pre class="alt"><span class="kwrd">using</span> System.Diagnostics;</pre><pre>&nbsp;</pre><pre class="alt"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> <font color="#008080">MyService</font> : <font color="#008080">ServiceBase</font>{</pre><pre>    <span class="kwrd">public</span> MyService(){</pre><pre class="alt">        InitializeComponent();</pre><pre>    } </pre><pre class="alt">&nbsp;</pre><pre>    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnStart(<span class="kwrd">string</span>[] args){</pre><pre class="alt"><span class="preproc">#if</span> DEBUG</pre><pre>        <font color="#008080">Debugger</font>.Launch();    <span class="rem">//Launches and attaches a debugger to the process.</span></pre><pre class="alt"><span class="preproc">#endif</span></pre><pre>        <span class="rem">// TODO: add your initialize code here.</span></pre><pre class="alt">    } </pre><pre>&nbsp;</pre><pre class="alt">    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnStop(){</pre><pre>    }</pre><pre class="alt">}</pre></div>
<p>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style></p><img src ="http://www.cnblogs.com/xzwplus/aggbug/1129452.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41315/" target="_blank">[新闻]F8 Keynote Speech[多图]</a>]]></description></item><item><title>调试JS时可能会有帮助的事件:OnPropertyChanged</title><link>http://www.cnblogs.com/xzwplus/archive/2008/03/18/1111632.html</link><dc:creator>rex xiang</dc:creator><author>rex xiang</author><pubDate>Tue, 18 Mar 2008 06:59:00 GMT</pubDate><guid>http://www.cnblogs.com/xzwplus/archive/2008/03/18/1111632.html</guid><wfw:comment>http://www.cnblogs.com/xzwplus/comments/1111632.html</wfw:comment><comments>http://www.cnblogs.com/xzwplus/archive/2008/03/18/1111632.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnblogs.com/xzwplus/comments/commentRss/1111632.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/xzwplus/services/trackbacks/1111632.html</trackback:ping><description><![CDATA[<p><font face="Comic Sans MS" size="2"></font></p> <p><font face="Consolas" size="2">今天一位同事遇到JS上的郁闷事情, 现象描述: 在ASPX页面中, 给某个hidden控件赋值后, 在后台CS文件中取到的值与之不符. (也就是说,总会被某个操作悄悄的改变这个hidden的值,此ASPX页面运行在某个OA系统的JS框架下). 为了找出罪魁祸首, 我写了一段测试代码, 来检测当某个控件属性被修改时, 找出是哪个函数在做手脚.</font></p><font face="Comic Sans MS" size="2"> <div class="csharpcode"><pre class="alt">&lt;html&gt;</pre><pre>    &lt;head&gt;</pre><pre class="alt">        &lt;script type=<span class="str">"text/jscript"</span>&gt;</pre><pre>        <span class="kwrd">function</span> controlPropertyChanged(){</pre><pre class="alt">            <span class="kwrd">var</span> name =  <span class="kwrd">event</span>.propertyName;</pre><pre>            <span class="kwrd">if</span>(name != <span class="str">'value'</span>){</pre><pre class="alt">                <span class="kwrd">return</span>;</pre><pre>            }</pre><pre class="alt">            </pre><pre>            <span class="kwrd">var</span> caller = controlPropertyChanged.caller;</pre><pre class="alt">            <span class="kwrd">var</span> callerText = <span class="str">""</span>;</pre><pre>            </pre><pre class="alt">            <span class="kwrd">while</span>(caller != <span class="kwrd">null</span>){</pre><pre>                callerText += <span class="str">"\n--------\n"</span> + caller.toString();</pre><pre class="alt">                caller = caller.caller;</pre><pre>            }</pre><pre class="alt">&nbsp;</pre><pre>            <span class="kwrd">var</span> value = <span class="kwrd">event</span>.srcElement.value;</pre><pre class="alt">            alert(<span class="str">"value = "</span> + value + callerText);</pre><pre>        }</pre><pre class="alt">        &lt;/script&gt;</pre><pre>&nbsp;</pre><pre class="alt">    &lt;/head&gt;</pre><pre>    &lt;body&gt;</pre><pre class="alt">        &lt;form action=<span class="str">""</span>&gt;</pre><pre>        &lt;input id=<span class="str">"ctlAHidden"</span> type=<span class="str">"hidden"</span> value=<span class="str">""</span> onpropertychange=<span class="str">"controlPropertyChanged();"</span> /&gt;</pre><pre class="alt">        </pre><pre>        &lt;input type=<span class="str">"button"</span> value=<span class="str">"change value 1"</span> onclick=<span class="str">"document.all('ctlAHidden').value = 'new value 1';"</span> /&gt;</pre><pre class="alt">        &lt;input type=<span class="str">"button"</span> value=<span class="str">"change value 2"</span> onclick=<span class="str">"document.all('ctlAHidden').value = 'new value 2';"</span> /&gt;</pre><pre>        &lt;/form&gt;</pre><pre class="alt">    &lt;/body&gt;</pre><pre>&lt;/html&gt;</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</font><img src ="http://www.cnblogs.com/xzwplus/aggbug/1111632.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41314/" target="_blank">[新闻]奥运核心资源被分食 搜狐央视网谁忽悠谁？</a>]]></description></item><item><title>LINQ中实现对象Many-To-Many(多对多)的关系映射</title><link>http://www.cnblogs.com/xzwplus/archive/2007/12/27/1017350.html</link><dc:creator>rex xiang</dc:creator><author>rex xiang</author><pubDate>Thu, 27 Dec 2007 10:44:00 GMT</pubDate><guid>http://www.cnblogs.com/xzwplus/archive/2007/12/27/1017350.html</guid><wfw:comment>http://www.cnblogs.com/xzwplus/comments/1017350.html</wfw:comment><comments>http://www.cnblogs.com/xzwplus/archive/2007/12/27/1017350.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnblogs.com/xzwplus/comments/commentRss/1017350.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/xzwplus/services/trackbacks/1017350.html</trackback:ping><description><![CDATA[<p><font face="Comic Sans MS" size="2"><font face="Consolas">前段时间,大概用了一下LINQ to SQL, 发觉O/Rdesigner似乎没有Many-To-Many(多对多)关系的支持,只有自己写代码实现.<br>:( <br><br>提供一下俺的解决办法: <br>例如User和UserGroup的关系,假设保存在UserInGroups表中,这里记录了User和Group的对应关系,那么,需要手动在User/Group类中添加对应的partial属性:</font><br></font></p> <div class="csharpcode"><pre class="alt"><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> User{ </pre><pre>    <font color="#0000ff">piblic</font> <font color="#800000">IEnumerable</font>&lt;<font color="#008080">Groups</font>&gt; Groups </pre><pre class="alt">    { </pre><pre>        <font color="#0000ff">var</font> groups = <font color="#0000ff">from</font> g <span class="kwrd">in</span> db.UserInGroups </pre><pre class="alt">                            <span class="kwrd">where</span> g.UserId = <span class="kwrd">this</span>.UserId </pre><pre>                            <font color="#0000ff">select</font> {g.Groups}; </pre><pre class="alt">        <span class="kwrd">return</span> groups; </pre><pre>    } </pre><pre class="alt">}</pre><pre>&nbsp;</pre><pre class="alt">&nbsp;</pre><pre><span class="kwrd">public</span> <span class="kwrd">partial</span> <span class="kwrd">class</span> Group{ </pre><pre class="alt">    <font color="#0000ff">piblic</font> <font color="#800000">IEnumerable</font>&lt;<font color="#008080">Users</font>&gt; Users </pre><pre>    { </pre><pre class="alt">        <font color="#0000ff">var</font> users = <font color="#0000ff">from</font> u <span class="kwrd">in</span> db.UserInGroups </pre><pre>                            <span class="kwrd">where</span> u.GroupId = <span class="kwrd">this</span>.GroupId </pre><pre class="alt">                            <font color="#0000ff">select</font> {u.Users}; </pre><pre>        <span class="kwrd">return</span> users; </pre><pre class="alt">    } </pre><pre>}</pre></div>
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style><img src ="http://www.cnblogs.com/xzwplus/aggbug/1017350.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41313/" target="_blank">[新闻]微软推新型搜索技术"BrowseRank"挑战谷歌</a>]]></description></item><item><title>visual studio - custom tool 的相关资料</title><link>http://www.cnblogs.com/xzwplus/archive/2007/10/29/941661.html</link><dc:creator>rex xiang</dc:creator><author>rex xiang</author><pubDate>Mon, 29 Oct 2007 08:13:00 GMT</pubDate><guid>http://www.cnblogs.com/xzwplus/archive/2007/10/29/941661.html</guid><wfw:comment>http://www.cnblogs.com/xzwplus/comments/941661.html</wfw:comment><comments>http://www.cnblogs.com/xzwplus/archive/2007/10/29/941661.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/xzwplus/comments/commentRss/941661.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/xzwplus/services/trackbacks/941661.html</trackback:ping><description><![CDATA[<p><font face="Consolas" size="2">&nbsp; 什么是custom tool? 对visual studio比较熟悉的人, 可能都曾经注意到过, 自从VS2002开始, solution explorer中文件的properties中, 都有一个Custom Tool属性.</font></p> <p><font face="Consolas" size="2">&nbsp; 例如, 我们在VS中通过菜单Project -&gt; Add New Item -&gt; Data -&gt; DataSet创建一个DataSet1.xsd文件, 此时, 我们发现DataSet1.xsd文件的properties中的custom tool属性为<font color="#0000ff">MSDataSetGenerator</font>.</font></p> <p><font face="Consolas" size="2">&nbsp; 当我们更改DataSet1.xsd文件时, 仔细观察, 我们发现与之相对应的DataSet1.Designer.cs文件中也会生成做出相应的更新.<br></font><font face="Consolas" size="2">如果我们删除此文件, 再次保存DataSet1.xsd, 将看到DataSet1.Designer.cs又出现了.<br>然后, 我们再次删除DataSet1.Designer.cs文件, 去掉DataSet1.xsd文件properties中的Custom Tool属性, 再次保存, DataSet1.Designer.cs却没有出现了.</font></p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/xzwplus/WindowsLiveWriter/VSCustomTool_2CA8/image_6.png" target="_blank"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="158" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/xzwplus/WindowsLiveWriter/VSCustomTool_2CA8/image_thumb_2.png" width="244" border="0"></a> </p> <p><font face="Consolas" size="2">同样, 具有Custom Tool属性的*dbml文件也有相同的特性.</font></p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/xzwplus/WindowsLiveWriter/VSCustomTool_2CA8/image_4.png" target="_blank"><font face="Consolas" color="#000000" size="2"><a href="http://www.cnblogs.com/images/cnblogs_com/xzwplus/WindowsLiveWriter/VSCustomTool_2CA8/image_4.png" target="_blank"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="160" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/xzwplus/WindowsLiveWriter/VSCustomTool_2CA8/image_thumb_1.png" width="244" border="0"></a></font></a><font face="Consolas" size="2"> </font></p> <p><font face="Consolas" size="2">于是, 我们有理由相信*.Designer.cs文件的出现, 和对应文件的Custom Tool属性有莫大的关系.</font></p> <p><font face="Consolas" size="2">&nbsp; 实际上, Custom Tool属性的作用是, 当具有此属性的文件在保存时, 将调用指定的接口来处理此文件. 例如, 根据DataSet1.xsd文件生成相应的DataSet1.Designer.cs文件. 另一个常见的例子是: 根据wsdl生成WebService代理类.</font></p> <p><font face="Consolas" size="2">&nbsp; 或许, 如果我们合理的利用此接口, 可为我们的工作剩下不少的时间.</font></p> <p><font face="Consolas" size="2"></font>&nbsp;</p> <p><font face="Consolas" size="2">以下是MSDN关于此接口的资料.</font></p> <p><font face="Consolas" size="2">Implementing Single File Generators: <br></font><a href="http://msdn2.microsoft.com/en-us/library/s686w8yb(VS.80).aspx"><font face="Consolas" size="2">http://msdn2.microsoft.com/en-us/library/s686w8yb(VS.80).aspx</font></a><br></p> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; A custom tool — sometimes referred to as a single file generator — can be used to extend the Visual Basic, Visual C#, and Visual J# project systems in Visual Studio. A custom tool is a COM component that implements the </font><a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivssinglefilegenerator.aspx"><font face="Consolas" size="2">IVsSingleFileGenerator</font></a><font face="Consolas" size="2"> interface. Using this interface, a custom tool transforms a single input file into a single output file. The result of the transformation may be source code, or any other output that is useful. Two examples of custom tool-generated code files are code generated in response to changes in a visual designer and files generated using Web Services Description Language (WSDL). </font> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; When a custom tool is loaded, or the input file is saved, the project system calls the </font><a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivssinglefilegenerator.generate.aspx"><font face="Consolas" size="2">Generate</font></a><font face="Consolas" size="2"> method, and passes a reference to a </font><a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsgeneratorprogress.aspx"><font face="Consolas" size="2">IVsGeneratorProgress</font></a><font face="Consolas" size="2"> callback interface, whereby the tool can report its progress to the user. </font> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; The output file that the custom tool generates is added to the project with a dependency on the input file. The project system automatically determines the name of the output file, based on the string returned by the custom tool's implementation of </font><a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivssinglefilegenerator.defaultextension.aspx"><font face="Consolas" size="2">DefaultExtension</font></a><font face="Consolas" size="2">. </font> <p><font face="Consolas" size="2">&nbsp;&nbsp;&nbsp; A custom tool must implement the </font><a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivssinglefilegenerator.aspx"><font face="Consolas" size="2">IVsSingleFileGenerator</font></a><font face="Consolas" size="2"> interface. Optionally, custom tools support the </font><a href="http://msdn2.microsoft.com/en-us/library/microsoft.visualstudio.ole.interop.iobjectwithsite.aspx"><font face="Consolas" size="2">IObjectWithSite</font></a><font face="Consolas" size="2"> interface to retrieve information from sources other than the input file. In any case, before you can use a custom tool, you must register it with the system or in the Visual Studio local registry. For more information on registering custom tools, see </font><a href="http://msdn2.microsoft.com/en-us/library/bb166527.aspx"><font face="Consolas" size="2">Registering Single File Generators</font></a><font face="Consolas" size="2">.</font>  <p><font face="Consolas" size="2"></font>&nbsp;</p> <p><font face="Consolas" size="2">Assembly: Microsoft.VisualStudio.Shell.Interop (in microsoft.visualstudio.shell.interop.dll)</font></p><img src ="http://www.cnblogs.com/xzwplus/aggbug/941661.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/41312/" target="_blank">[新闻]2008年7月26日IT博客精选</a>]]></description></item></channel></rss>