ランタイム・ファイルの作成

関連:API テスト のみ

注: DLL のコンパイルには,Framework 4.0 のターゲット・フレームワークを使用してください。

using ステートメントの追加

ランタイム・ファイルで,必須の using ステートメントを指定します。.dll ファイルへの参照も追加する必要があります。.dll ファイルは製品のインストール先の /bin フォルダに格納されています。HP.ST.Fwk.RunTimeFWK.dll への参照を必ず追加してください。内部ログ機能を使用する場合は,log4net.dll への参照も追加する必要があります。

次の例は,サンプルの .cs ファイルの using ステートメントです。

using HP.ST.Fwk.RunTimeFWK;
// If you need to implement Internal Logging
using log4net;

先頭に戻る

名前空間とクラスの指定

名前空間を定義し,アクティビティの実行時コードを指定します。カスタム・アクティビティ用に定義するクラスは,STActivityBase クラスを継承する必要があります。次に例を示します。

namespace ReportMessageActivitySample
{
[Serializable]
public class ReportMessageActivitySample : STActivityBase
{

先頭に戻る

内部ログの設定

組み込みのロガー・マネージャの設定により,アクティビティは実行時に内部ログを作成します。この例では,入力プロパティのプロパティ値を取得し,出力を実行結果のみに送信,または実行結果と出力ウィンドウの両方に送信します。次に例を示します。

/// <summary> /// 内部ログ
/// </summary>
private static readonly ILog log = 
LogManager.GetLogger(typeof(ReportMessageActivitySample)); const string runResults = "Run Results"; const string runResultsAndOutputWindow = "Run Results and Output Window";

その他のログ・オプションの詳細については,Assert オブジェクトを参照してください。

先頭に戻る

プロパティの初期化

署名ファイルで指定したユーザ定義の入出力プロパティを初期化します。次の例では,StatusMessageDestination という 3 つの入力プロパティを初期化します。次に例を示します。

/// <summary>
/// プロパティの初期化
/// </summary>
/// <param name="ctx">The runtime context</param>
public ReportMessageActivitySample(ISTRunTimeContext ctx, string name)
: base(ctx, name)
{
this.Status = String.Empty; 
this.Message = String.Empty; 
this.Destination = String.Empty; 
}

先頭に戻る

プロパティ値の取得

ここでは,入力プロパティの値を取得または設定します。次に例を示します。

/// <summary>
/// レポートするメッセージのステータスを取得または設定
/// </summary>
public string Status { get; set; }
/// <summary>
/// レポートするメッセージの詳細を取得または設定
/// </summary>
public string Message { get; set; }
/// <summary>
/// メッセージの送信先を取得または設定
/// </summary>
public string Destination { get; set; }

スキーマで記述されていない配列型のプロパティがある場合(キーと値のペアなど),すべてのアレイ要素を明示的に初期化し,実際の要素数を指定する必要があります。

次の例では,MyArrayName プロパティを構成する 40 の要素を初期化しています。この配列には,キーと値のペアが 40 含まれています。

this. MyArrayName = new MyPair[40]; 
for (int i=0; i<40; i++)
{
this. MyArrayName [i] = new MyPair(); 
}
public MyPair[] MyArrayName; 
public class MyPair
{
string Key; 
string Value; 
}

配列がスキーマまたは WSDL で定義されている場合,標準の[リンク元の選択]ダイアログ・ボックス(API テスト)でアレイ要素に直接リンクできます。

先頭に戻る

イベントの定義

カスタム・イベントを 1 つまたは複数定義します。定義したイベントは,後で起動できます。次に例を示します。

public event EventHandler CustomerEvent; 
private void InvokeCustomerEvent(EventArgs MyArg)
{
EventHandler handler = this.CustomerEvent; 
if (handler != null)
{
handler(this, MyArg); 
}
}

先頭に戻る

ステップの実行

ステップを実行し,実行時情報をログに送信します。STActivityBase クラスで定義されている STExecutionResult データ型とその ExecuteStep 関数を使用します。次に例を示します。

protected override STExecutionResult ExecuteStep()
{
string DetailsReport; 
if (this.Destination == runResultsAndOutputWindow)
{
LogInfo("\n" + this.Message.Replace("\\n", "\n")); 
}
/// <summary>
/// テスト結果と出力ウィンドウにメッセージを送信
/// </summary>
// 改行を置換することで,レポートで複数行の印刷が可能
	DetailsReport = this.Message; 
	DetailsReport = DetailsReport.Replace("\\n", "<BR>"); 	
	DetailsReport = DetailsReport.Replace("\n", "<BR>"); 
	this.Report("Message", DetailsReport);

カスタム・イベントを定義した場合,ExecuteStep の呼び出しの後に起動します。

...
protected override STExecutionResult ExecuteStep()
{
InvokeCustomerEvent(); 
}

先頭に戻る

ステータスの設定

テスト実行のステータスを設定します。サンプルの ReportMessageActivitySample.cs ファイルは,列挙を使用して,STExecutionResult 値に基づいてステータスを設定します。次に例を示します。

switch (this.Status)
{
case "Done": 
this.Report(ReportKeywords.StatusKeywordTag, ReportKeywords.DoneValueTag); 
return new STExecutionResult(STExecutionStatus.Success); 
case "Pass": 
this.Report(ReportKeywords.StatusKeywordTag, ReportKeywords.SuccessValueTag); 
return new STExecutionResult(STExecutionStatus.Success); 
case "Fail": 
this.Report(ReportKeywords.StatusKeywordTag, ReportKeywords.FailureValueTag); 
return new STExecutionResult(STExecutionStatus.Success); 
default: 
return new STExecutionResult(STExecutionStatus.Success); 
}

先頭に戻る

ランタイム・ファイルのコンパイル

コードのカスタマイズが完了したら,.dll をコンパイルします。.dll 名は,アドイン・ファイルと同じ名前を指定します。たとえば,ランタイム・ファイルが ReportMessageActivitySample.dll の場合,アドイン・ファイルの名前は ReportMessageActivitySample.addin になります。

開発環境でランタイム・ファイルを作成したら,署名ファイルから .dll を参照し,アドイン・ファイルから署名ファイルを参照します。

先頭に戻る