Nicolas Joly Tasting

August 23rd, 2015 Phanix

未滿十八歲請勿飲酒,飲酒過量有礙身體健康

Read the rest of this entry / 繼續閱讀 »

Jmeter increase the user defined variable in loop 迴圈中遞增使用者自定變數

August 4th, 2015 Phanix

直接看圖說故事…
Read the rest of this entry / 繼續閱讀 »

Nebbiolo of different maturation processes

July 15th, 2015 Phanix

IMG_20150708_213321_HDR
2015/07/08, @wutong
未滿十八歲請勿飲酒,飲酒過量有礙身體健康
Read the rest of this entry / 繼續閱讀 »

NV Andre Clouet Grande Reserve Brut, Champagne, France

May 16th, 2015 Phanix

未滿18歲請勿飲酒,飲酒過量有礙身體健康
NV Andre Clouet Grande Reserve Brut, Champagne, France
Read the rest of this entry / 繼續閱讀 »

C# stack trace

February 13th, 2015 Phanix
using System.Diagnostics;

[STAThread]
public static void Main()
{
  StackTrace stackTrace = new StackTrace();           // get call stack
  StackFrame[] stackFrames = stackTrace.GetFrames();  // get method calls (frames)

  // write call stack method names
  foreach (StackFrame stackFrame in stackFrames)
  {
    Console.WriteLine(stackFrame.GetMethod().Name);   // write method name
  }
}

Ref: http://www.csharp-examples.net/reflection-callstack/

Using T4 template to read resource files (.resx) and generate multiple output files

February 12th, 2015 Phanix

T4 (Text Template Transformation Toolkit) 可以幫忙訂出 template 並用程式輔助來產生程式碼或文件(比方說不同語言的定義檔)。

使用 T4 之前可以先去下載 T4 Toolbox,安裝之後在 Visual studio 增加新項目時就可以看到有 “T4 Toolbox” 的分類,有 Generator、Script、Template 三種可選
T4Toolbox_01

首先定義template檔案,在這邊用System.Xml去讀取 resource file,同時 include SaveOutput.tt 做輸出用。

<#@ template language="C#" debug="True" #>
<#@ include file="SaveOutput.tt" #>
<#@ include file="T4Toolbox.tt" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Xml" #>
<#
// <copyright file="i18n_js.tt" company="Onelab">
//  Copyright © Onelab. All Rights Reserved.
// </copyright>

string[] files = System.IO.Directory.GetFiles(this.Host.ResolvePath("..\\App_GlobalResources"));
string outputFileLang = "";

foreach (string f in files) {
	if (f.Substring(f.Length-4) != "resx"){
		continue;
	}

	XmlDocument xd = new XmlDocument();
	xd.Load(f);


	if (f.LastIndexOf("Resource") + 8 == f.LastIndexOf(".")) {
		outputFileLang = "en-Us";
	}
	else
	{
		outputFileLang = f.Substring(f.LastIndexOf("Resource") + 9, f.LastIndexOf(".") - f.LastIndexOf("Resource") - 9);
	}


	foreach (XmlNode node in xd.SelectNodes("//data")) {
		try
		{
#>
			<#=node.Attributes[0].Value#> = <#=node.SelectNodes("value")[0].InnerXml#>;
<#
		}
		catch
		{
		}
	}

	SaveOutput("lang\\" + outputFileLang + ".js");
}
#>

另外定義 SaveOutput function於另一個檔案SaveOutput.tt中

<#@ import namespace="System.IO" #>
<#+
  void SaveOutput(string outputFileName)
  {
      string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
      string outputFilePath = Path.Combine(templateDirectory, outputFileName);
      File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString()); 

      this.GenerationEnvironment.Remove(0, this.GenerationEnvironment.Length);
  }
#>

當resource file變動後,必須要執行”Run Custom Tool”才會更新輸出的檔案內容。
T4Toolbox_02

Other resources: Oleg Sych’s article

DOS Batch command file HELP

February 11th, 2015 Phanix

今天工作遇到,記錄一下…

http://stackoverflow.com/questions/112055/what-does-d0-mean-in-a-windows-batch-file
http://www.computerhope.com/forhlp.htm
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

Chateau St. Jean & Stags’ Leap Winery Tasting

December 13th, 2014 Phanix

image_01
2014/12/06
未成年請勿飲酒,飲酒過量有礙身體健康
Read the rest of this entry / 繼續閱讀 »

Datetime format – 顯示非西元的紀年方式

November 17th, 2014 Phanix

例如: 平成XX年

Read the rest of this entry / 繼續閱讀 »

義大利品酒會

November 15th, 2014 Phanix

2014/07/26
image
未滿十八歲請勿飲酒,飲酒過量有礙身體健康
Read the rest of this entry / 繼續閱讀 »