發表文章

目前顯示的是 2012的文章

[WPF] – Debugging DataBindings

圖片
最近從頭開始學習 WPF 其 DataBinding,那其如何 Dbugging DataBindings 的部份是我之前並沒有接觸過的,那記錄一下以後有需要時就可以拿來使用,以防跟之前一樣都是用土法鍊鋼的方式一直測試到 Binding 成功為止,也不知道那裡有問題. 按照上面所述的部份做設定即可 Debugging DataBindings 了.

[Windows] – Registering an Application to a URL Protocol

有些應用程式可以在 Web 按下 Hyper Link 後會開啟應用程式並傳入參數, 那此部份是如何達成的呢?在此記錄一下, 以防以後有需要時還要再重新找尋資料. Registering the Application Handling the Custom Protocol To register an application to handle a particular URL protocol, add a new key, along with the appropriate subkeys and values, to HKEY_CLASSES_ROOT. The root key must match the protocol scheme that is being added. For instance, to add an "alert:" protocol, add an alert key to HKEY_CLASSES_ROOT, as follows: HKEY_CLASSES_ROOT alert URL Protocol = "" Under this new key, the URL Protocol string value indicates that this key declares a custom protocol handler. Without this key, the handler application will not launch. The value should be an empty string. Keys should also be added for DefaultIcon and shell . The Default string value of the DefaultIcon key must be the file name to use as an icon for this new URL protocol. The string takes the form "path, iconindex" with a maximum length of MAX_PATH. The name of the firs

[MVVM] 初步認識 MVVM 設計模式

圖片
View :其實就是XAML檔,也就是使用者介面,使用者介面設計人員只需要在Blend中進行對它的編輯,並透過Binding來和ViewModel溝通(將DataContext指定為某個ViewModel,以更進一步的與其中的屬性進行Binding)。 ViewModel :顧名思義,ViewModel就是供View使用的Model,透過公開的屬性(public property)給View進行Binding,供其使用。 Model :用來描述資料實體(Entity)的簡單類別(Class),也可以在這邊實作商業邏輯以及與資料庫溝通等資料存取相關的功能。 *注意:上圖中的箭頭是有意義的,上層的物件可以向下存取,但是下層的物件並不會知道上層的東西長什麼樣子,透過此原則,才得以做到乾淨的分層與鬆散藕合。 而這個設計模式能幫我們帶來什麼好處呢? 對程式設計人員(Developer)來說: 1. 程式的階層切分更為乾淨、簡潔 2. 相對減少透過程式進行與使用者介面的互動 3. 可以根據設計期/執行期決定不同的資料來源 4. 程式的撰寫可以完全的與使用者介面上的控制項脫鉤,不需再撰寫使用者控制項的Event Handler 5. 可以完全將設計的重心著重在資料流和商業邏輯,而不需要花費心思在使用者介面和流程   對使用者介面設計人員(Designer)來說: 1. 只需要將心思著重在使用者介面操作的流程使用者介面的呈現方式 2. 可以藉由程式設計人員提供的設計時期資料製作更接近現實的使用者介面 3. 更輕鬆的透過Binding、Behavior和Action就可以實作出整個使用者介面 4. 與控制項的互動一樣只需要透過Binding進行設定,不需要費心在Event Handler上 5. 更輕鬆的透過Blend就進行完所有使用者介面的設計,並輕鬆和程式進行結合   轉貼至 : http://www.dotblogs.com.tw/ouch1978/archive/2011/04/23/introducing-mvvm.aspx

Flex – working with session on BlazeDS

when applying BlazeDS, you might notice that in web.xml, a listener named "flex.messaging.HttpFlexSession" should be inserted. It is how BlazeDS can work with session data. BlazeDS provide several classes which is useful for get access to the session and the HTTP pieces of the session, such as the HTTP servlet request and response. This lets you access HTTP data when you use a Flex application in the context of a larger web application where other classes, such as JSPs or Struts actions, might have stored information. flex.messaging.FlexContext flex.messaging.FlexSession The following example shows a Java class that calls FlexContext.getHttpRequest() to get an HTTPServletRequest object and calls FlexContext.getFlexSession() to get a FlexSession object. By exposing this class as a remote object, you can make it accessible to a Flex client application; you place the compiled class in the WEB_INF/classes directory package myROPackage; import flex.messaging.*; import java.io

.NET – Distinct SQL Statement of NHibernate’s QueryOver

圖片
NHibernate 中提供 QueryOver 的方式來產生 SQL Statements, 當需 distinct 時又需如何使用呢? Session.QueryOver<Contact>()     .Select(         Projections.Distinct(             Projections.ProjectionList()                 .Add(Projections.Property<Constact>(x => x.Id).As(“ConstactId”)         )     )     .TransformUsing(Transformers.AliasToBean<Contact>()); 產生 SQL 如下所示 :

.NET – NHibenate & log4net 的配置

圖片
如果你只想要顯示 NHibernate 在 unit test 在查詢 database 時使用 SQL 時, 只需在 NHibernate configuration file 中加入 show_sql key 即可. 現在, 當在執行任何 unit test 時, NHibernate 產生 SQL queries 時, NHibernate 將會記錄至 output window. 那如果想使用 log4net 來收集 NHibernate 產生的 logging information 時在 config file 中加入一些必要的 configuration. 最後需通知 application 要使用 log4net(ex: 如建立 web application 時就放至 “ Global.asax ”) 最後在 output window 會顯示如下相同的訊息. NHibernate 定義二個不同的 loggers NHibernate   和 NHibernate.SQL .第一個接收所有 NHibernate 產生的 logging.第二個只接收 NHibernate 產生 SQL Statements.

NHibernate – 各個 Property 的定義.

圖片
    最近在入門 NHibernate, 下面的 diagram 可以很清楚的知道 NHibernate 的運作原理.及各個 Property 的定義為何?在些做個記錄.

Flex – Pure MVC Framework Review

之前在寫 Flex 真的是很隨便的在 Coding, 並沒有使用什麼架構,最近在重新 review 時覺得很亂, 雖然會動手翻掉的機率不大, 但還是要了解一下是不是有什麼好的架構可以在 Flex 上來實作, 看來 Pure MVC Framework 不錯的樣子, 記錄一下其一些 Demo 的文章, 方便以後可以在 re-engineer 時可以拿來參考. 1. [PureMVC]初學者入門教學 前言 - PureMVC簡介與參考資料 2. [PureMVC]初學者入門教學Part.1 Application與Facde   3. [PureMVC]初學者入門教學Part.2 Component(View)與Mediator 4. [PureMVC]初學者入門教學Part.3 Commmand 5. [PureMVC]初學者入門教學Part.4 Proxy and 範例Demo 6. [PureMVC]初學者入門教學Part.5 新增功能!? & 範例DEMO 此部份是簡單的 Sample 可以很快速的入門 PureMVC Framework.

.NET - Windows 2008 Server 中 ASP.NET 使用 Office Application Component 的設定.

圖片
這一二天在 deploy ASP.NET 至 windows 2008 R2 時,因使用 Office Application Component,一直在 deploy 時發生 IIS 7 COMException (0x80004005) 的問題,故在此做個記錄以防之後有類似的情形發生. 因 install Office 為 32 bit ,但在 Server 2008 R2 中的 Component Services 預設是 64 bit 的,看不到 32 bit component,請故在 run 中打入  “ mmc comexp.msc /32 ” 來執行 32 bit 版本的 Component Services. 修改所需的 Permissions 後,即可在 ASP.NET 中呼叫 Office Component 來使用.

C# – NetOffice 產生 Powerpoint 的初體驗

圖片
目前在 .NET 中產生 Powerpoint 並沒有什麼 free library 可用,如需產生 Powerpoint 時只能呼叫 Office Applicaiton 或是自行使用 OpenXML SDK 來產生,之前在 codeplex 中發生有個叫 NetOffice 的 Library ,雖然它也是要依賴 Office Applicaiton ,但它是透過 COM Proxies 的方式來呼叫 Office Applicaiton,已簡化很多的部份並幫解決 Memory Leak 的部份,算是不錯的 solution 之一了. 那在此提供一個簡單的 Sample ,記錄一下如何使用此 component … 1. Reference Library . 2. Source Code using (PowerPoint.Application app = new PowerPoint.Application()) { PowerPoint.Presentation presentation = app.Presentations.Add(MsoTriState.msoFalse); presentation.Slides.Add(1, PpSlideLayout.ppLayoutClipArtAndVerticalText); string filename = string.Format(@"c:\1.pptx"); presentation.SaveAs(filename); app.Quit(); app.Dispose(); } 結果如下所示: 如需其它的 Demo 請參考 NetOffice PowerPoint Examples .

jQuery – File Download plugin

在作 Web 時 Download File 的功能一直都有,但又如何在 User 按下 Download Button 時,出現提示 server 回覆才又隱藏提示呢?這一部份在網路上有很多的 Sample,這裡提個一個還不錯的 jQuery Plugin : jQuery File Download , 癈話不多說請看 Demo .

Configure Project for 32 bit and 64 bit

圖片
最近接了一個 Project ,在 32 bit 上做開發及測試都正常,但拿到 Winodow 2008 R2 (64 bit) 上 Run 就是會有 Exception,那在此記錄一下解決方法. 1. 開啟 Configuration Manager dialog,選取使用中的方案平台. 2. 選取新增, 選取 X64 的 platform 後按下確定 Button.   3. 最後在 Debug / Release 時選取所需的 Platform 已可.

IIS7 – Running 32-bit and 64-bit ASP.NET versions at the same time on different worker process (轉貼)

圖片
In IIS6, this was a pain area. On a 64-bit Windows 2003 Server, you cannot run worker processes in both 32-bit mode and as well as 64 bit mode. Either only one of them was possible. This was possible by the below Metabase Key which would be applied to the W3SVC/AppPools node. W3SVC/AppPools/enable32BitAppOnWin64 : true | false Read more how to do this in IIS 6.0 here . But, in IIS7, you can run 32-bit and 64-bit worker processes simultaneously. Let’s see how to do it. You have the same enable32BitAppOnWin64 property for the applicationPools in the applicationHost.config. Now, you can set this for individual application pools. Below is my sample configuration: <applicationPools> <add name="MyAppPool32bit" autoStart="true" enable32BitAppOnWin64="true" /> <add name="MyAppPool64bit" autoStart="true" enable32BitAppOnWin64="false" /> <applicationPoolDefaults> <processModel identityType="Ne

ASP.NET – Deploy MVC3 web application

圖片
當 ASP.NET MVC3 web application release to production environment,但 production environment 沒有安裝 ASP.NET MVC3,當需 release to production environment 時需收入那些 Library 至 web application bin 中呢? System.Web.Mvc System.Web.Heplers System.Web.Razor System.Web.WebPages System.Web.WebPages.Deployment System.Web.WebPages.Razor Microsoft.Web.Infrastructure Add library to reference 時,執行下面步驟設定 Library 會 copy to local.

ASP.NET MVC In-Depth: The Life of an ASP.NET MVC Request

雖然這是一篇舊的文章,但確能了解 ASP.NET MVC 它的 Life Cycle 為何? The purpose of this blog entry is to describe, in painful detail, each step in the life of an ASP.NET MVC request from birth to death. I want to understand everything that happens when you type a URL in a browser and hit the enter key when requesting a page from an ASP.NET MVC website. Why do I care? There are two reasons. First, one of the promises of ASP.NET MVC is that it will be a very extensible framework. For example, you’ll be able to plug in different view engines to control how your website content is rendered. You also will be able to manipulate how controllers get generated and assigned to particular requests. I want to walk through the steps involved in an ASP.NET MVC page request because I want to discover any and all of these extensibility points. Second, I’m interested in Test-Driven Development. In order to write unit tests for controllers, I need to understand all of the controller dependencies. When writing my tests, I n

.NET – 在 ASP.NET MVC 3 中使用 Microsoft Chart Controls Library

圖片
Microsoft 提供了免費的 Chart Controls Library,其提供的範例都是 ASP.NET Web Form 的部份,需在 ASP.NET MVC 中使用的話又需使何設定呢?在此提供一個簡單的範例. 1. 在你的 MVC Web Project 中加入 System.Web.DataVisualization Library 2. 在 Web.config 中加入 assembly, httpHandlers 及 handlers. <?xml version="1.0" encoding="utf-8"?> <!-- For more information on how to configure your ASP.NET application, please visit http://go.microsoft.com/fwlink/?LinkId=152368 --> <configuration> <connectionStrings> <add name="xx" connectionString="user id=userId;data source=DBName;password=pwd;" /> </connectionStrings> <appSettings> <add key="webpages:Version" value="1.0.0.0" /> <add key="ClientValidationEnabled" value="true" /> <add key="UnobtrusiveJavaScriptEnabled" value="true" /> </appSettings> <system.web> <compilation debug="true" targetFr

Flex – Simple Animating Preloader

圖片
在 Flex 4 中並不提供 Busy Indicator Component 於 Application 中. 那在此提供一 Simple Preloader Component 以供參考. Source URL : http://flexdevtips.blogspot.tw/2011/05/simple-animating-preloader-and.html 1. Create Component 2. 在 MXML 中加入下面的程式碼 3. 在 creationComplete Handler 中加入下面二行程式碼 最後此 Component 提供 start(), stop() 二個 Method 讓此 Component Animating.

[轉貼]The Life Cycle of a Servlet

The Life Cycle of a Servlet This tutorial explains the Servlet interface and Servlet life cycle . A servlet example is given at the end which demonstrates the life cycle of a servlet. Servlets are managed components. They are managed by web container. Of the various responsibilities of web container, servlet life cycle management is the most important one. A servlet is managed through a well defined life cycle that defines how it is loaded, instantiated ad initialized, handles requests from clients and how it is taken out of service. The servlet life cycle methods are defined in the javax.servlet.Servlet interface of the Servlet API that all Servlets must implement directly or indirectly by extending GenericServlet or HttpServlet abstract classes. Most of the servlet you develop will implement it by extending HttpServlet class. The servlet life cycle methods defined in Servlet interface are init(), service() and destroy() . The life cycle starts when container instantiates the objec

[轉貼]Understanding Servlet request

Understanding Servlet request ServletRequest Is one of the most important Interface of Servlet API. This tutorial explains the basics of ServletRequest interface and the most widely used methods defined in it. What is servlet request Servlets are designed to receive client request and generate responce to send to client. Though servlets are protocol independent, they are most widely used wih HTTP protocol to generate the dynamic response. The servlet request interface represents the request sent by the client (Browser in our case) . Whenever a web container receives a request from the browser, it creates a servlet request, and identifies which servlet needs to be invoked based on the URL mapping, calls the service method of the servlet and passes the servlet request object as parameter. The servlet request object contains information like request parameters, request headers etc. which is used by Servlet when generating the response. Javax.servlet.ServletRequest ServletRequest is an

[轉貼] Servlet File Upload Example

Java Servlet file upload example This Servlet File Upload tutorial explains how to handle the file upload in Servlets. This tutorial explains Handling file upload using apache commons-file file upload API. Handling file upload using commons file upload API The commons File Upload package makes it easy to add robust, high performance, file upload capacity to your Servlets and web applications. Download and install Commons File Upload package First of all, download the latest version of commons file upload package from here. FileUpload depends on Commons IO package, so download the version mentioned on the FileUpload dependency page. t the time of writing this tutorial, the latest version of Commons File Upload is 1.2.1 which depends on Commons IO version 1.3.2. Installation is very easy. Extract both of the downloaded zip files and put commons-fileupload-1.2.1.jar and commons-io-1.3.2.jar jar files into the WEB-INF/lib folded of your web application. The next step is to create t

@MultipartConfig : Servlet 3.0 File Upload Example

@MultipartConfig : Servlet 3.0 File Upload Example Up to now Servlet API did not provide any built in support for handling file upload. we used various open source libraries like Commons file upload and COS multipart parser. However supporting file upload is so common requirement for any web application that Servlet 3.0 Specification supports it out of the box. Web container itself can parse the multipart request and make mime attachments available through HttpServletRequest object. A new annotation @MultiPartConfig has been introduced. When @MultiPartConfig is present on any servlet, it indicates that the servlet expects request of type multipart. @MultipartConfig annotation @MultipartConfig supports following attributes location - An absolute path to a directory on file system. It is important to remember that location doesnt support a path relative to application context. (I too don't know, why specification doesnt support context relative URLs). This location will be use

讓所有 IE 支持 HTML5

自從 HTML 5能為我們的新網頁帶來更高效潔淨的code而得到更多關注,然而唯一能讓 IE 識別那些新元素則使用 html5.js 來解決 IE 支持 HTML5 的關題. html5.js 讓所有的 IE 支持 HTML5, html5.js 必須在頁面 head 元素內調用(因為 IE 必須在元素解析前知道這個元素,所以這個 js 文件不能在頁面底部調用). 你可以使用 IE 信件注釋來調用這個 js 文件,這樣像 FireFox 等非 IE 瀏覽器就會忽視這段 code。 <!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> < ![endif]-->

EasyUI – datebox 中如何自定日期格式化

在 datebox 中提供了二個 method ,一個為 formatter,另一個為 parser,這二個 method 是用來自定日期格式化的. formatter 是在顯示時如何選擇日期後將其格式化為所需的格式. parser 是在選擇好日期後告訴控件如何去解析自定義的格式. 將日期格式化為 yyyy-mm-dd 的格式如下所示: $('$dd').datebox({ formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate(); }, parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/"))); } });

Hibernate – 呼叫 Stored Procedure 回傳 Cursor 時 Mapping Class Model

圖片
Hibernate 提供了強大的 OR Mapping 的功能,那如果呼叫 Stroed Procedure 回傳 Cursor 時,要如何使用 Hibernate 來 Mapping 至 Class Model 呢?下面提供一種方式已供參考. 1. 在 .hbm.xml 中定義 sql-query 的 name query’s name,然后就可以像調用一個命名的 HQL 查詢一樣直接調用命名 SQL 查詢.(Stored procedures are supported if the callable attribute is set) 2. 建立 mapping 的 Class Model 的 .hbm.xml 3. 在 Java 的程式碼就可以使用 getNamedQuery Method 指定 sql-query’s name 來取得所設定的 SQL,其 return cursor 時, Hibernate 則會自動的 Mapping 至 Class Model 中.

JavaScript – Date 提供 addDays 的 Method

在 JavaScript 中使用 Date Class 時,此部份並沒有提供 addDays 的 Method,那我們可以自行擴充 Custom Method,那在此提供一個簡單的 addDays Method 的擴充方法. 使用 prototype 的方式來擴充 Date 的 custom method,故即可在 Date Class 使用此 method. Date.prototype.addDays = function(days) { var dat = new Date(this.valueOf()); dat.setDate(dat.getDate() + days); return dat; };