using System;
using Fujitsu.Shunsaku;
class SampleDirectAccessSearch {
static public void Main( string[] args ) {
ShunService service = null;
try {
// ShunService の作成
service = new ShunService();
// ホスト名 ポート番号を指定して Shunsaku に接続
service.Host = "DirSvr1";
service.Port = 33101;
service.ShunsakuFile = "shunsakuFile1";
service.Connect();
// 検索用の ShunKeyRequirement オブジェクトを作成
ShunKeyRequirement keyReq = new ShunKeyRequirement();
keyReq.KeyName = "key";
// 検索対象のキーを追加
keyReq.Records.Add( new ShunRecord() );
keyReq.Records[0].Key = "0001";
// 検索条件を指定して検索を実行
ShunResultSet rs = service.SearchByKey( keyReq, "/" );
// 取得したソース情報のダイレクトアクセスキーを取得
Console.WriteLine( "ヒット件数 = {0}", rs.HitCount );
int i = 0;
foreach ( ShunRecord record in rs.Records ) {
++i;
Console.WriteLine( "[結果]{0}件目", i );
Console.WriteLine( "ダイレクトアクセスキー: {0}", record.Key );
Console.WriteLine( "データ :" );
Console.WriteLine( record.Data );
}
// Shunsaku から切断
service.Disconnect();
}
catch ( ShunContinuousException e ) {
// ShunContinuousExceptionが発生した場合の処理を記述
try {
if( service != null && service.State == ShunConnectionState.Open ) {
service.Disconnect();
}
}
catch ( ShunException ex ) {
Console.WriteLine("エラーメッセージ : {0}", ex.Message );
}
Console.WriteLine("エラーメッセージ : {0}", e.Message );
}
catch ( ShunConnectionTerminatedException e ) {
// ShunConnectionTerminatedExceptionが発生した場合の処理を記述
Console.WriteLine("エラーメッセージ : {0}", e.Message );
}
}
} |