2015年5月15日 星期五

[C#] Auto load x86/x64 SQLite DLL for Platform

  How to Reference Platform Specific (X86/x64) Assemblies in Visual Studio Projects


Unload對想要有此功能之Project,Edit xxx.csproj,新增下方內容


<!--Start Code-->
<choose></choose>
<when condition="$(Platform) == 'x64'"></when>
<itemgroup></itemgroup><br />
<reference include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64"></reference>
<specificversion>False</specificversion>
<hintpath>..SQLiteX64System.Data.SQLite.DLL</hintpath>
<otherwise></otherwise>
<itemgroup></itemgroup>
<reference include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86"></reference>
<specificversion>False</specificversion>
<hintpath>..SQLiteX86System.Data.SQLite.DLL</hintpath>
<!--End Code-->

存檔後關閉,然後Reload此Project,選擇Platform (此時Reference的DLL路徑已經修正成你所選定的平台對應的DLL),Rebuild即可。

2015年4月21日 星期二

[C#] Post-Build event command line

Copy file(s) from one project to another using post build event

Visual Studio provides customized cmd script functions after Building solution.


Project->Property->Build Events->Post-Build event command line:


copy "$(SolutionDir)xxx.xml" "$(TargetDir)xxx.xml"


如上設置,可指定將Solotion Item的檔案一同複製一份至Project out folder

[C#] Set version for all projects in one solution

C# version for all projects in one solution


  1. Create an new "VersionInfo.cs" in solution item
  2. Clear its content
  3. Copy content of  one of your "AssemblyInfo.cs" in your project to "VersionInfo.cs" (Modify the content if you want)
  4. Clear content of all "AssemblyInfo.cs" in all projects
  5. Add Link to the "VersionInfo.cs" in each of your projects

2015年4月15日 星期三

VIM Settings for Visual Studio 2008

Vi Tool

ViEmu (Install-ViEmuVS-3.0.6.exe)

Key Binding
Tool->Option->General->KeyBoard 設定

View.NavigateBackward (Ctrl + T)
Edit.GoToDefinition (Ctrl+])

Theme

Tool->Import and Export Settings 設定

coding-instinct-theme_vs2008.vssettings (網路上找尋自己想要的)

2015年3月4日 星期三

使用PowerShell設定系統變數與ps1範例

以下ps1範例包含系統時間格式、程式(標準/錯誤)輸出重導、外部程式呼叫與ps1變數使用

$datestr = Get-Date -format yyyMMdd
$reporttype = "COMP"
$folder = "D:\reportFolder\"
$toolpath = "D:\scripts\Report.php"

$log = '{0}logs\{1}_{2}.log' -f $folder, $reporttype, $datestr
$err = '{0}logs\{1}_{2}.err' -f $folder, $reporttype, $datestr
php.exe $toolpath type=$reporttype folder=$folder >>$log 2>>$err

PowerShell ps1之語法遠優於舊有的bat,使用上更為便利與靈活、更為易讀。


直接透過PowerShell永久設定系統環境變數之指令
# example of adding a path to PATH
[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";C:\Program Files (x86)\PHP", "Machine")

# creates “myY” of category “User”, and set the value to “"la la"”
[Environment]::SetEnvironmentVariable("myY", "la la", "User")

# removing a env var from registry
[Environment]::SetEnvironmentVariable("myY", $null, "User")

# show value of “path”
$env:path

2014年11月5日 星期三

2014年8月7日 星期四

設定 Powershell Codepage (字碼頁) 為UTF-8

設定 Powershell Codepage (字碼頁) 為UTF-8

打開Powershell,並輸入

chcp 65001

然後在視窗上按右鍵,選擇內容

在字型頁面中,選擇適當的自行後,按確定即可

2014年6月12日 星期四

[Synology] Crontab settings

於Synology DS211j 中增加例行工作

vi /etc/crontab

#minute hour    mday    month   wday    who     command
17      8       *       *       2,5     root    /usr/bin/php -n -d safe_mode_exec_dir='' /usr/syno/bin/autoupdate.php
14      5       *       *       2,5     root    /usr/syno/bin/synopkg chkupgradepkg
0       0       *       *       3       root    /var/packages/AntiVirus/target/bin/synoavscan --all
0       3       *       *       *       root    /usr/syno/bin/syno_poweroff_feasible_check

修改後,儲存離開,並執行下列指令

synoservice -restart crond

2014年6月10日 星期二

[C#] Windows Service Code Debug method

C# service Debug 方法 原始出處

個人採用方法三

只需加一些程式碼判斷與獨立使用即可!


在主要Service程式中獨立的 Start 與 Stop
public void Start(string[] args)
{
    this.OnStart(args);
}

public void Stop()
{
    this.OnStop();
}  

Program.cs中需新增的判斷
 if (Environment.UserInteractive)
 {
     Service1 s = new Service1();
     s.Start(null);
     Console.WriteLine("服務已啟動,請按下 Enter 鍵關閉服務...");
    // 必須要透過 Console.ReadLine(); 先停止程式執行
    // 因為 Windows Service 大多是利用多 Thread 或 Timer 執行長時間的工作
    // 所以雖然主執行緒停止執行了,但服務中的執行緒已經在運行了!
    Console.ReadLine();
    s.Stop();

    Console.WriteLine("服務已關閉");
 }
 else
{
   //原有程式碼
}

最後在專案的property裡設置輸出類型(Output Type),選擇 
Console Application

搜尋此網誌