顯示具有 C# 標籤的文章。 顯示所有文章
顯示具有 C# 標籤的文章。 顯示所有文章

2016年11月16日 星期三

Math Editor in C#

When you are acquiring to integrate a math editor into your application in WPF (Windows Presentation Foundation), I recommend you to use this math editor project called OOP in the Real World - Creating an Equation Editor in Code Project platform.

However, the source code put in Code Project is out of date. If you want a new version of the source code and start to program it, I give the instructions for you as follows:

  1. Download the Math_Editor_1.0.6.5.zip from http://www.codeproject.com/KB/architecture/522345/Math_Editor_1.0.6.5.zip  then get ICSharpCode.SharpZipLib.dll after extracting this zip file.
  2. Download the source codes from https://github.com/kashifimran/math-editor/releases. You can choose any relase version. In fact, I have tested the source codes with both versions 1.0.6.5 and 1.0.6.6 and they work.
  3. Extract the source codes and open the project solution.
  4. Put ICSharpCode.SharpZipLib.dll in your project if there’s no library refering to ICSharpCode.SharpZipLib.
  5. Right click on this project then click the item ‘project properties’. 
  6. Click the tab “Signing” then cancel the clickbox called “Sign the assembly”.

Afterall, you will build this project successfully.

2013年12月6日 星期五

I-List: Create Your Own Lists of Links

I-List is a very helpful links share platform to share your collected links.

It provides an user friendly interface to you for sharing some kind of links.

I’ve found that there are two collections which is very helpful for some people whose subjects are for studying and implementation in statistics, accounting and computer science.

1. List of Free Accounting Software : For business/accounting area.

2. List of Free Statistical Software : For statistics area.

2013年6月2日 星期日

Interesting Experiments in SHA3

I’ve tried MD5, SHA256, SHA3-512 algorithms with 1, 10, and 100 million bytes.
In general, SHA3-512 is lower than SHA256 for 3 ~ 10 times. In these cases, MD5 is the fastest algorithm which is faster than SHA256 for 3 times and SHA3-512 for 30~100 times.

image

2013年3月18日 星期一

[Program] The Framework for Auto Updating Programs

I've made up of some frameworks for auto updating program. If you want to make your program with fashion of auto-updating, you can refer to the following table.


Table of Auto Update Program Framework

Name
Tutorials
Platform
License
Dev. Lang.
Click Once
WinFree

.Net Framework
Omaha
WinApache 2.0C/C++
WinSparkle
WinMITC/C++, C#
NETSparkle
WinMITC#
Sparkle
MacMITObject-C/Java
twinkle
N/A
AllLGPLJava

2013年3月11日 星期一

[.NET] 防止反組譯工具

由於.NET程式為了跨平台,導入CLR(Common Language Run-time),讓所有.NET程式編成MSIL(Microsoft Intermediate Language)程式碼,使其在CLR上運作(簡單來說,就是MS版的JVM)。也正因如此,其編譯出來的程式碼,都有一定的規則可以做逆向工程,進行反組譯。

知名的反組譯工具有:.NET Reflector(要錢), ILSpy (筆者測試過,若程式碼不加以防護的話,用這套很容易把程式碼完全還原回來...) 以及Telerik的JustDecompiler

但是,在販賣軟體產品的開發人員,應該不想要讓自己的程式碼被輕易地破解吧?

就目前讀到的參考資料,可將防止反組譯方法分為以下:
1. 混淆保護(Obfuscating) :將程式碼變數命名或是方法做混淆,或是加入無意義的文字,使其無法輕易破解。
    此類工具較為知名的有微軟合作夥伴PreEmptive推出的Dotfuscastor (Community版本內建於Visual Studio,這個版本不用錢;但是Professional版要錢,此二版本功能差異請見此文章)
    若想要使用此工具進行軟體保護的話,可見以下兩篇教學:
    (1) Dotfucscator 使用者入門
    (2) Obfuscation with Dotfuscator with Visual Studio 2010
2. Kernel等級的加密保護:使其無法用MSIL去讀取。代表工具:MaxToCode
3. 硬體鎖:採用硬體鎖的方式,避免程式盜用。(貌似跟反組譯無關)

參考資料
1. .NET反組譯工具:ILSpy, Telerik JustDecompile
2. 使用SuppressIldasmAttribute防止MSIL反組譯工具對組件進行反組譯
3. [.NET Concept][Security].NET程式保護機制概述 (Recommended)
4. MaxToCode

2013年1月27日 星期日

[Windows] Built-in OCR Library in Windows 7/Server 2008

OCR (Optical Character Recognition) is an interesting issue. I've found that some (built-in) libraries in Windows 7/Server 2008. If you want to develop OCR program without extra fee, you should try it.

  1. Window 7 OCR API : In the final answer, you can use thocr.psp.dll ,xocr3.psp.dll, and ximage3b.dll.
  2. Using IFilter in C# : If you want to use IFilter, you should read the following topics: (1) Windows TIFF IFilter Installation and Operations Guide, (2) Implementing Control Panel Items (As you want to write a program to access the Control Panel)
  3. Converting Images to Text using Office 2007 OCR, OpenXML and Speech Recognition: Use MS Office 2007 OCR library to do OCR.


2012年4月20日 星期五

Windows Communication Service (WCF) 開發

微軟從.NET 3.0開始推出了WCF的技術(全名:Windows Communication Foundation)。
WCF整合了Web Service、Remoting(可以開發SOAP, HTTP通訊)、MSMQ(Message Queuing)等微軟分散式元件開發技術,程式設計師只需要開發WCF服務,就可以透過設定的方式,發佈支援不同通訊協定的服務端點。因此,若各位讀者要開發網路服務,統一透過WCF技術框架開發即可。


筆者就WCF程式開發的部分,整理了以下教學資源:
1. 米米貓學開發:WCF服務
2. 史蒂芬筆記:WCF Service
3. [VS2010] WCF 4.0 新功能 (2): REST 服務開發
4. 基本WCF程式設計 (MSDN)
5. 從Web3.0轉移到WCF


相關參考資料
1. Web Service? WCF Service?
2. .Net Remoting
3. Message Queuing 心得分享
4. Wikipedia: Windows Communication Foundation
5. Web應用程式開發-WCF
6. WCF概要 (推薦閱讀)

2011年12月29日 星期四

[ASP.NET] 在 ASP.NET 中使用檔案儲存網站設定 - web.config

在上次的腦殘事件後,經過KK Bruce大哥的指導,才把檔案上傳下載路徑做更動。
就以往的PHP開發的經驗,通常都會有個類似config.inc.php的檔案,於是我想到了
利用web.config來紀錄我的檔案上傳與下載路徑。
但是,C#該怎麼從這邊取值哩? 根據專家Kelp Code的教學文發現,我們只要透過
System.Configuration這個命名空間提供的ConfigurationManager類別所提供的AppSettings屬性,即可取得web.config的設定。例如:

<configuration>
  <appSettings>
    <!--   檔案上傳下載目錄 ,例如放在D:/ -->
    <add key="FileDirectory" value="D:/" />
  </appSettings>
</configuration>
我設定檔案上傳下載目錄如上,那麼,我的檔案上傳路徑便可改為以下:

如此一來,Application_restart的問題就有可能避免。在這邊真的非常感謝KK Bruce大哥的指導:)

在此容我推薦ASP.NET與MVC相關教學網站

  1. KKBruce的MVC, ASP.NET, ADO.NET教學系列集錦
  2. Kelp大大的網站

[轉載] Function Pointer、Delegate和Function Object (C/C++) (template) (.NET) (C#)

Function Pointer(C)、Delegate(C#)和Function Object(C++)這三個是一樣的功能,所以在此一併討論。

詳全文請至:http://www.cnblogs.com/oomusou/archive/2007/05/02/734290.html

2011年12月27日 星期二

[ASP.NET] MVC 3上,Session消失的問題與解決辦法

筆者因工作因素,不得不碰Microsoft MVC 3。雖然開發方便,不過他隱含的一些奇怪的Bug也不少。
身為一個網站開發人員,時常會用到Cookie與Session。奇怪的點就在於MS Visual Studio 2010在開發MVC 3時,有時候會為了某些奇怪因素,重新啟動你開發的Application。
目前普遍知道的重新啟動事件,可能會於以下情形發生:
  1. 從應用程式的 Bin 資料夾中加入、修改或刪除組件。
  2. 從 App_GlobalResources 或 App_LocalResources 資料夾中加入、修改或刪除當地語系化資源。
  3. 加入、修改或刪除應用程式的 Global.asax 檔。
  4. 在 App_Code 目錄中加入、修改或刪除原始程式碼檔。
  5. 加入、修改或刪除設定檔組態。
  6. 在 App_WebReferences 目錄中加入、修改或刪除 Web 服務參考。
  7. 加入、修改或刪除應用程式的 Web.config 檔。
  8. 防毒軟體剛好掃到Webconfig檔
然而,筆者最近發現兩個更奇怪的重新啟動狀況!
  1. Application restarts on directory delete in ASP.net
  2. 檔案上傳後,在該Action內直接return RedirectToAction() ;
開發MVC 3 or ASP.NET網站人員應該都知道,在SessionState為InProc的設定下,任何重新啟動( or Application_start函數的呼叫),將導致Session消失。
很不巧地,筆者剛好遇到上述第2種狀況,導致Session消失,Debug 10個小時才抓到此嚴重錯誤。
其實上面第 2種狀況,應該算是「 Bin 資料夾中加入、修改或刪除組件」,從下面程式碼便可知一二:
public ActionResult Access()
{
    // 取出剛剛上傳的檔名,這邊會發現取不到值
    string fileName = TempData["upfile"].ToString();
    /*                 
     *   處理的程式區段   
     */               
    return View();
}

[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
    //檢查是否有檔案上傳,有的話存檔
    if (file !=null && file.ContentLength > 0)
    {
        //放在執行檔目錄中Upload目錄底下
        string savedName = "./Upload/" + file.FileName;
        file.SaveAs(savedName);
        TempData["upfile"]=file.FileName;
    }            

    return RedirectToAction("Access");
}
從上述可知,由於我在檔案上傳時,"增加"了bin資料夾下的組件,導致Application_start()函數再次啟動,使得我的Session就這麼消失了。

為了避免這個錯誤一再重演,建議將Session State設定為StateServer或是SQL Server模式。
將Session State設定為State Server的方法,可看這篇「如何讓 ASP.NET 使用 Session 資料時不要再自動消失」,主要兩個步驟:
1. 啟動 aspnet_state.exe (ASP.NET State Service)
2. 在Web.config中,加入以下這段設定:

<configuration>
  <system.web>
    <sessionState mode="StateServer"
      stateConnectionString="tcpip=localhost:42424"
      cookieless="false"
      timeout="20"/>
  </system.web>
</configuration>

需要注意設定的Web.config檔案的出處。(不知道為什麼,筆者的View資料夾下剛好也有Web.config,若手誤設定到這個,執行會錯誤喔!)
為了追求開發出來的程式不因Application重新啟動而造成不穩定狀況 (例如:筆者遇到的檔案上傳導致無法儲存Session的問題,也是透過部署的方式,立刻解決!)。
我們通常會需要用到部署,至於設定部署功能,請跟著筆者這樣子做:
  1. 請先安裝好IIS  6/7
  2. 若是使用ASP.NET 4.0,ASP.NET 4.0的安裝程式,不會連同IIS一起設定,因此,請按照此方法設定。
  3. 從IIS中,設定好網站目錄 or 虛擬目錄。
  4. 設定單鍵發行功能,方法請看如何使用 Visual Studio 2010 的「單鍵發行」功能 (MsDeploy)
另一個可能發生的問題,則是在負載平衡的 Web 伺服陣列環境執行 ASP.NET Web 應用程式時,如果使用 SqlServer 或 StateServer 工作階段模式,工作階段狀態可能會遺失。
解決辦法在微軟的「PRB:如果您使用 SqlServer 或 StateServer 工作階段模式,Web 伺服陣列中的工作階段狀態會遺失」,剛好遇到這類問題的使用者,可以看一看。


Reference
  1. [.NET] ASP.NET 狀態管理(State Management):Session
  2. [ASP.NET] Session 遺失 / Session Timeout / Session 設定
  3. 如何讓 ASP.NET 使用 Session 資料時不要再自動消失
  4. IIS虛擬目錄設定
  5. ASP.NET IIS設定工具
  6. ASP.NET 應用程式生命週期概觀
  7. ASP.NET MVC Request Flow (推薦閱讀!)
  8. ASP.NET MVC 3概觀正體中文版 (推薦閱讀!)

2011年12月1日 星期四

[ASP.NET] [網摘] 使用JSON.NET處理動態物件屬性

就如同Json.NET官網的解說:"Json.NET is a popular high-performance JSON framework for .NET"。
而黑暗執行緒 網站也為它介紹了這麼一段話:"一個極為出色的Open Source JSON解決方案,提供了如同JavaScriptSerializer序列化及反序列化JSON字串的功能,甚至支援LINQ式操作,最重要的是它可透過JObject的物件模型支援"動態物件",解決類別屬性不固定的問題。"

因此,若大家有興趣的話,可以到這邊看看,黑暗執行緒網站怎麼以簡單的範例帶我們了解JSON.NET如何支援動態物件吧!

2011年11月12日 星期六

[C#] DotNetZipLib 與 SharpZipLib

SharpZipLib 與 DotNetZipLib的介紹
http://blog.miniasp.com/post/2009/01/11/Introduce-SharpZipLib-and-DotNetZip-Library-for-NET.aspx

DotNetZipLib的Document
http://cheeso.members.winisp.net/DotNetZipHelp/frames.htm

Zip格式與支援程度
http://kikicocopapaya.pixnet.net/blog/post/24538462-zip

[C#] Using 關鍵字的用法

C#有主要兩個用法:

  • 做為指示詞,此時它是用來建立命名空間的別名,或是用來匯入在其他命名空間中定義的型別。
  • 做為陳述式,此時它是用來定義一個範圍,物件會在此範圍結尾處進行處置 (Dispose)

相關教學資源請參考以下:
  1. using 陳述式 (C# 參考)
  2. C# Using Statement Calls Dispose
  3. using 指示詞 (C# 參考)

[C#] C# WriteXml, Dataset與DataTable

  1. Dataset WriteXml方法
  2. Mapping DataSet to XML and backwards
  3. C# DataTable Examples
  4. C# DataTable Select Example
  5. Expression for C# DataTable Select
  6. Limit Rows In DataTable or DataSet
  7. C#: 用XML推論XMLSchema