/// <summary>
/// An abstract base Http Handler for all your
/// <see cref="IHttpHandler"/> needs.
/// </summary>
/// <remarks>
/// <p>
/// For the most part, classes that inherit from this
/// class do not need to override <see cref="ProcessRequest"/>.
/// Instead implement the abstract methods and
/// properties and put the main business logic
/// in the <see cref="HandleRequest"/>.
/// </p>
/// <p>
/// HandleRequest should respond with a StatusCode of
/// 200 if everything goes well, otherwise use one of
/// the various "Respond" methods to generate an appropriate
/// response code. Or use the HttpStatusCode enumeration
/// if none of these apply.
/// </p>
/// </remarks>
public abstract class BaseHttpHandler : IHttpHandler
{
/// <summary>
/// Creates a new <see cref="BaseHttpHandler"/> instance.
/// </summary>
public BaseHttpHandler() {}
/// <summary>
/// Processs the incoming HTTP request.
/// </summary>
/// <param name="context">Context.</param>
public void ProcessRequest(HttpContext context)
{
SetResponseCachePolicy(context.Response.Cache);
if(!ValidateParameters(context))
{
RespondInternalError(context);
return;
}
if(RequiresAuthentication
&& !context.User.Identity.IsAuthenticated)
{
RespondForbidden(context);
return;
}
context.Response.ContentType = ContentMimeType;
HandleRequest(context);
}
/// <summary>
/// Indicates whether or not this handler can be
/// reused between successive requests.
/// </summary>
/// <remarks>
/// Return true if this handler does not maintain
/// any state (generally a good practice). Otherwise
/// returns false.
/// </remarks>
public bool IsReusable
{
get
{
return true;
}
}
/// <summary>
/// Handles the request. This is where you put your
/// business logic.
/// </summary>
/// <remarks>
/// <p>This method should result in a call to one
/// (or more) of the following methods:</p>
/// <p><code>context.Response.BinaryWrite();</code></p>
/// <p><code>context.Response.Write();</code></p>
/// <p><code>context.Response.WriteFile();</code></p>
/// <p>
/// <code>
/// someStream.Save(context.Response.OutputStream);
/// </code>
/// </p>
/// <p>etc...</p>
/// <p>
/// If you want a download box to show up with a
/// pre-populated filename, add this call here
/// (supplying a real filename).
/// </p>
/// <p>
/// </p>
/// <code>Response.AddHeader("Content-Disposition"
/// , "attachment; filename=\"" + Filename + "\"");</code>
/// </p>
/// </remarks>
/// <param name="context">Context.</param>
public abstract void HandleRequest(HttpContext context);
/// <summary>
/// Validates the parameters. Inheriting classes must
/// implement this and return true if the parameters are
/// valid, otherwise false.
/// </summary>
/// <param name="context">Context.</param>
/// <returns><c>true</c> if the parameters are valid,
/// otherwise <c>false</c></returns>
public abstract bool ValidateParameters(HttpContext context);
/// <summary>
/// Gets a value indicating whether this handler
/// requires users to be authenticated.
/// </summary>
/// <value>
/// <c>true</c> if authentication is required
/// otherwise, <c>false</c>.
/// </value>
public abstract bool RequiresAuthentication {get;}
/// <summary>
/// Gets the content MIME type.
/// </summary>
/// <value></value>
public abstract string ContentMimeType {get;}
/// <summary>
/// Sets the cache policy. Unless a handler overrides
/// this method, handlers will not allow a respons to be
/// cached.
/// </summary>
/// <param name="cache">Cache.</param>
public virtual void SetResponseCachePolicy
(HttpCachePolicy cache)
{
cache.SetCacheability(HttpCacheability.NoCache);
cache.SetNoStore();
cache.SetExpires(DateTime.MinValue);
}
/// <summary>
/// Helper method used to Respond to the request
/// that the file was not found.
/// </summary>
/// <param name="context">Context.</param>
protected void RespondFileNotFound(HttpContext context)
{
context.Response.StatusCode
= (int)HttpStatusCode.NotFound;
context.Response.End();
}
/// <summary>
/// Helper method used to Respond to the request
/// that an error occurred in processing the request.
/// </summary>
/// <param name="context">Context.</param>
protected void RespondInternalError(HttpContext context)
{
// It's really too bad that StatusCode property
// is not of type HttpStatusCode.
context.Response.StatusCode =
(int)HttpStatusCode.InternalServerError;
context.Response.End();
}
/// <summary>
/// Helper method used to Respond to the request
/// that the request in attempting to access a resource
/// that the user does not have access to.
/// </summary>
/// <param name="context">Context.</param>
protected void RespondForbidden(HttpContext context)
{
context.Response.StatusCode
= (int)HttpStatusCode.Forbidden;
context.Response.End();
}
}
2013年1月10日 星期四
BaseHttpHandler
2012年10月4日 星期四
好用的*.resources編輯器
跟同事找了半天的 Resources 編輯器, 正確名稱我不知道, 網路上都是 *DLL, *.Exe 或是 *.Resx *.rc
但是我要找到的是 *.Resources , 用途是什麼別問了, 我有一堆的 *.resources 要打開.
有試過直接改檔型 *.resources 改成 *.resx , 不能用, 還是binary.
找到Bill Sayles 在 codeproject 有分享一個專案, Resource Editor .NET , 還有原始碼, 狀況解除.
忘記我同事找的是哪一套了...
但是我要找到的是 *.Resources , 用途是什麼別問了, 我有一堆的 *.resources 要打開.
有試過直接改檔型 *.resources 改成 *.resx , 不能用, 還是binary.
找到Bill Sayles 在 codeproject 有分享一個專案, Resource Editor .NET , 還有原始碼, 狀況解除.
忘記我同事找的是哪一套了...
VisualStudio開發64位元系統MMC
遇到問題才會知道, 平常不用功, 看的書太少了.
在Win7上開發MMC 3.0 的專案, 按照這個網誌 寫了一支SnapIn 怎麼試都找到SnapIn可以增加...
最後想說該不會權限 or 64位元作業系統的問題吧?! 果然是
用了keyword : "visual studio mmc 64" 馬上找到
在Win7上開發MMC 3.0 的專案, 按照這個網誌 寫了一支SnapIn 怎麼試都找到SnapIn可以增加...
最後想說該不會權限 or 64位元作業系統的問題吧?! 果然是
用了keyword : "visual studio mmc 64" 馬上找到
Debugging SnapIns in 64bit OS
64位元的MMC在
C:\Windows\SysWOW64\mmc.exe
你如果是用 命令列(CMD)去執行 C:\Windows\System32\MMC.EXE -32 也可以找到的你開發的SnapIn, 但是我要在VS2008內Deubg, 但是32的MMC.exe 掛(Attach)不上去, 所以還是用 C:\Windows\SysWOW64\mmc.exe -32的方式, 就能成功Debug了.
2012年9月17日 星期一
Create additional registry keys with DSL Tools Setup Projects
I was trying to solve the Custom Tool property issue with .actiw files in ActiveWriter, as suggested by Bogdan Pietroiu months ago, and spent a clear hour trying to figure how to inject my own registry keys into WiX setup project of DSL Tools. I modified the .vstemplate for .actiw files to include the following:
...
<CustomParameters>
<CustomParameter Name="$itemproperties$" Value="CustomTool" />
<CustomParameter Name="$CustomTool$" Value="ActiveWriterCodeGenerator" />
</CustomParameters>
...
<CustomParameters>
<CustomParameter Name="$itemproperties$" Value="CustomTool" />
<CustomParameter Name="$CustomTool$" Value="ActiveWriterCodeGenerator" />
</CustomParameters>
...
and thought that the file, when added to the project, will have Custom Tool property already set. I was appearently wrong (documentation says it should work).
Bogdan's suggestion was to have a key named after the file extension under Generators\{Language}, and I manually confirmed that it works great. So, how to automate the process of adding this reg key through the setup? WiX Toolkit documentation shows the way, so I copied Registry.wxs to have my own key registered.
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>
<Fragment Id="CustomToolFragment">
<FeatureRef Id="DefaultFeature">
<ComponentRef Id="_ActiveWriterCTReg" />
</FeatureRef>
<DirectoryRef Id="TARGETDIR">
<Component Id="_ActiveWriterCTReg" Guid="{some GUID}">
<Registry Root='HKLM' Key='Software\Microsoft\VisualStudio\8.0\Generators\{164b10b9-b200-11d0-8c61-00a0c91e29d5}\.actiw' Id='{some GUID}' Type='string'Value='ActiveWriterCodeGenerator' />
<Registry Root='HKLM' Key='Software\Microsoft\VisualStudio\8.0\Generators\{fae04ec1-301f-11d3-bf4b-00c04f79efbc}\.actiw' Id='{some GUID}' Type='string'Value='ActiveWriterCodeGenerator' />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>
<Fragment Id="CustomToolFragment">
<FeatureRef Id="DefaultFeature">
<ComponentRef Id="_ActiveWriterCTReg" />
</FeatureRef>
<DirectoryRef Id="TARGETDIR">
<Component Id="_ActiveWriterCTReg" Guid="{some GUID}">
<Registry Root='HKLM' Key='Software\Microsoft\VisualStudio\8.0\Generators\{164b10b9-b200-11d0-8c61-00a0c91e29d5}\.actiw' Id='{some GUID}' Type='string'Value='ActiveWriterCodeGenerator' />
<Registry Root='HKLM' Key='Software\Microsoft\VisualStudio\8.0\Generators\{fae04ec1-301f-11d3-bf4b-00c04f79efbc}\.actiw' Id='{some GUID}' Type='string'Value='ActiveWriterCodeGenerator' />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
<Registry> elements define the key to be added, as you may have guessed. Anyway, although I changed the build action on the .wxs and although it seems that Candle and Light picked up the file, the installer didn't add the registry key. So? Orca to the rescue. You should check Component and Registry tables in .msi file to check if your key slipped in, and Orca shows them quite detailed. In my case, though, it shows the absence of my additions.
Long story (not so) short, it seems that I should examine Registry.tt as the first step, but didn't. To include your ComponentRef in DefaultFeature, you should have your Fragment as FragmentRef in Main.wxs . So, you should add each of your custom fragment in the list defined incustomFragmentIds in InstallerDefinitions.dslsetup as shown below:
<installerDefinitionxmlns="http://schemas.microsoft.com/VisualStudio/2005/DslTools/InstallerDefinitionModel"
...
customFragmentIds="CustomToolFragment">
...
customFragmentIds="CustomToolFragment">
I hope this info helps someone.
2012年9月7日 星期五
新的Lenovo鍵盤
實在不想批評, 但是新的Lenovo T430 島式鍵盤, 實在不好用, 或許是不習慣.
少了許多按鍵就算了(少了 PrtScr, ScrLk, Pause), 反正也少用, 就算了
ps: 前一頁, 下一頁也沒了
請同事幫忙查到
Pause ==> Fn + P
Break ==> Fn + B
ScrLk ==> Fn + C
SysRq(PrtSc) ==> Fn + S
可是我常用的滑鼠右鍵(就是App鍵)的位置, 竟然被 PrtSc取代了!!
快瘋了, 原本的工作可以不用滑鼠只靠鍵盤加快捷鍵就能完成, 現在要拖著滑鼠, 才能用右鍵功能!!
找了兩天, 使用了 日本人 Hirofuml 寫的 RemapKey (包在Win2003的resource kit內), 用 右鍵的Alt鍵替代App鍵(因為它找不到PrtSc鍵).
用了一天還是不習慣, 因為Alt也太常用到了, 左右手都會用到Alt, 實在不能沒有它們.
到這裡, 整個工作速度慢的像烏X(tortoise), 還有專案要完成呀!
還是再找, 終於讓我找到 ShaprKeys 我用的是3.5版.
將 Special: PrtSc(E0_37) 指定到 Special; Application(E0_5D) 就把滑鼠右鍵找回來了!
趕快工作吧 ,沒有藉口了.
2012年8月25日 星期六
NHibernate Query Generator的問題
要了解 NHibernate Query Generator(NHQG) 一定要到這個網站 http://ayende.com/blog
NHQG目前是已經停止開發了, 但是你可以在 https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/deprecated/NHibernate.Query.Generator 取得舊的Source.
一開始我是用Ryan Cromwell 的方法, 但是會找不到NHQG, 我的方法如下:
NHibernate.Query.Generator, NHibernate.Query.Generator.Model, NHibernate.Query.Generator.Tests,
但是經過Build後, Test專案會有一個錯誤, Test專案是用 Model.dll 參考來產生hbm.xml檔, 所以 dll內有一個CS沒有按照 urn:nhibernate-mapping-2.2 的規範, 就會出錯.
System.Xml.Schema.XmlSchemaValidationException: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'.
原因是WierdClass.cs 的 MesajIst 類別沒有 Id ?
我的解決方式, 是把它註解 ?! Test專案也不去測 MesajIst ?!
還沒仔細研究, 先測試過吧.
NHQG目前是已經停止開發了, 但是你可以在 https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/deprecated/NHibernate.Query.Generator 取得舊的Source.
一開始我是用Ryan Cromwell 的方法, 但是會找不到NHQG, 我的方法如下:
上述batch主要是載Rhino-Tools,但我們主要是看NHQG. so, 載完後NHQG有三個專案:echo Offrem set path=%path%;c:\tools\svn-win32-1.4.4\binrem C:\Program Files\CollabNet\Subversion Client\svn.exeecho get Trunk (Non-Recursive)…svn co https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk trunk -q -Necho doneecho get Art…svn co https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk/Art trunk/Art -qecho doneecho get SharedLibs…svn co https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk/SharedLibs trunk/SharedLibs -qecho doneecho get NHQG…rem jk, modifyrem svn co https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/trunk/NHibernate.Query.Generator trunk/NHibernate.Query.Generator -qsvn co https://rhino-tools.svn.sourceforge.net/svnroot/rhino-tools/deprecated/NHibernate.Query.Generatorecho doneecho build NHQG…pushd .cd trunk\NHibernate.Query.Generatorrem jk, modifyrem %windir%\Microsoft.NET\Framework64\v2.0.50727\msbuild.exe default.build%windir%\Microsoft.NET\Framework\v2.0.50727\msbuild.exe default.buildecho doneecho build Installercd NHibernate.Query.Generator.Setup%windir%\Microsoft.NET\Framework\v2.0.50727\msbuild.exe Setup.wixprojecho donepopdPAUSE
NHibernate.Query.Generator, NHibernate.Query.Generator.Model, NHibernate.Query.Generator.Tests,
但是經過Build後, Test專案會有一個錯誤, Test專案是用 Model.dll 參考來產生hbm.xml檔, 所以 dll內有一個CS沒有按照 urn:nhibernate-mapping-2.2 的規範, 就會出錯.
System.Xml.Schema.XmlSchemaValidationException: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id' in namespace 'urn:nhibernate-mapping-2.2'.
原因是WierdClass.cs 的 MesajIst 類別沒有 Id ?
我的解決方式, 是把它註解 ?! Test專案也不去測 MesajIst ?!
還沒仔細研究, 先測試過吧.
2012年8月3日 星期五
Eclipse+SysdeoTomcatPlugin
要記錄一件很X的事件, 花了我一天, 剛好一天!
因為要追 directjngine 的問題, 去載了它1.0的source. 因為看到它的eclipse專案匯入後用到.tomcatplugin, 所以就想說要去載Sysdeo的Plugin來試試看.之前知道這個PlugIn, 只知道它可以啟動tomcat; 看了http://www.eclipsetotale.com/tomcatPlugin.html 的說明, 看到 DevLoader 好像不錯(說明), 因為它可以直接從Eclipse啟動tomcat, 並動態載入class及jar, 按照它的說明,
1.Eclipse安裝了Plugin.
2.設定的tomcat.
3.將eclipse下dropins/com.sysdeo.eclipse.tomcat_3.3.0(我的載3.3.0版)的DevLoader.zip解壓到tomcat/common/classes裡面.(jk, 發現了嗎?紅字的部份)
4.將tomcat啟動(當然是用plugin的方式啟動)
結果, 還沒有作第3步時的錯誤: java.lang.ClassNotFoundException: org.apache.catalina.loader.DevLoader
變成
java.lang.NoClassDefFoundError: org/apache/catalina/loader/WebappLoader
接下來就是花了一天的時間作白工.
專案Properties內Tomcat的DevLoader Classpoath的Active DevLoader要啟動(打勾)
不是專案reloaderable=true的問題.
不是DevLoader.java的問題,我甚到還重新compile了DevLoader.
(DevLoader 繼承自 WebappLoader )
不是Tomcat版本的問題, 雖然網路上說它只支援到Tomcat5.x
是我解錯誤位置了, 應該要將DevLoader.zip 解到 [tomcat]\server\classes
重新啟動tomcat後, 看到console內有
...
[DevLoader] Starting DevLoader
[DevLoader] projectdir=C:\Users\xxx\Documents\JavaProjects\xxx\WebContent
[DevLoader] added file:/C:/Users....
...
就是成功了.
大概是新手才會碰到的問題, 但是還是記錄一下, 免得再浪費一天.
如果是Tomcat6, 請將DevLoader 包成jar檔, 放在Tomcat6\lib下
因為要追 directjngine 的問題, 去載了它1.0的source. 因為看到它的eclipse專案匯入後用到.tomcatplugin, 所以就想說要去載Sysdeo的Plugin來試試看.之前知道這個PlugIn, 只知道它可以啟動tomcat; 看了http://www.eclipsetotale.com/tomcatPlugin.html 的說明, 看到 DevLoader 好像不錯(說明), 因為它可以直接從Eclipse啟動tomcat, 並動態載入class及jar, 按照它的說明,
1.Eclipse安裝了Plugin.
2.設定的tomcat.
3.將eclipse下dropins/com.sysdeo.eclipse.tomcat_3.3.0(我的載3.3.0版)的DevLoader.zip解壓到tomcat/common/classes裡面.(jk, 發現了嗎?紅字的部份)
4.將tomcat啟動(當然是用plugin的方式啟動)
結果, 還沒有作第3步時的錯誤: java.lang.ClassNotFoundException: org.apache.catalina.loader.DevLoader
變成
java.lang.NoClassDefFoundError: org/apache/catalina/loader/WebappLoader
接下來就是花了一天的時間作白工.
專案Properties內Tomcat的DevLoader Classpoath的Active DevLoader要啟動(打勾)
不是專案reloaderable=true的問題.
不是DevLoader.java的問題,我甚到還重新compile了DevLoader.
(DevLoader 繼承自 WebappLoader )
不是Tomcat版本的問題, 雖然網路上說它只支援到Tomcat5.x
是我解錯誤位置了, 應該要將DevLoader.zip 解到 [tomcat]\server\classes
重新啟動tomcat後, 看到console內有
...
[DevLoader] Starting DevLoader
[DevLoader] projectdir=C:\Users\xxx\Documents\JavaProjects\xxx\WebContent
[DevLoader] added file:/C:/Users....
...
就是成功了.
大概是新手才會碰到的問題, 但是還是記錄一下, 免得再浪費一天.
如果是Tomcat6, 請將DevLoader 包成jar檔, 放在Tomcat6\lib下
訂閱:
文章 (Atom)