Imports System
Imports Fujitsu.Shunsaku
Imports System.ComponentModel
Class SampleDirectAccessSearch
Shared Public Function Main( ByVal args() As String ) As Integer
Dim service As ShunService = Nothing
Try
'' ShunService の作成
service = new ShunService()
'' ホスト名 ポート番号を指定して Shunsaku に接続
service.Host = "DirSvr1"
service.Port = 33101
service.ShunsakuFile = "shunsakuFile1"
service.Connect()
'' 検索用の ShunKeyRequirement オブジェクトを作成
Dim keyReq As ShunKeyRequirement = new ShunKeyRequirement()
keyReq.KeyName = "key"
'' 検索対象のキーを追加
keyReq.Records.Add( new ShunRecord() )
keyReq.Records( 0 ).Key = "0001"
'' 検索条件を指定して検索を実行
Dim rs As ShunResultSet = service.SearchByKey( keyReq, "/" )
'' 取得したソース情報のダイレクトアクセスキーを取得
Console.WriteLine( "ヒット件数 = {0}", rs.HitCount )
Dim i As Integer = 0
For Each record As ShunRecord In rs.Records
i += 1
Console.WriteLine( "[結果]{0}件目", i )
Console.WriteLine( "ダイレクトアクセスキー: {0}", record.Key )
Console.WriteLine( "データ :" )
Console.WriteLine( record.Data )
Next
'' Shunsaku から切断
service.Disconnect()
Catch e As ShunContinuousException
'' ShunContinuousExceptionが発生した場合の処理を記述
Try
If Not service Is Nothing And service.State = ShunConnectionState.Open Then
service.Disconnect()
End If
Catch ex As ShunException
Console.WriteLine( "エラーメッセージ : {0}", ex.Message )
End Try
Console.WriteLine( "エラーメッセージ : {0}", e.Message )
Catch e As ShunConnectionTerminatedException
'' ShunConnectionTerminatedExceptionが発生した場合の処理を記述
Console.WriteLine( "エラーメッセージ : {0}", e.Message )
End Try
End Function
End Class |