using System;
using Fujitsu.Shunsaku;
class SampleUpdate {
static public void Main( string[] args ) {
ShunService service = null;
try {
// ShunService の作成
service = new ShunService();
// ホスト名 ポート番号を指定して Shunsaku に接続
service.Host = "DirSrv1";
service.Port = 33101;
service.Connect();
// ShunSearchRequirement の作成
ShunSearchRequirement req = new ShunSearchRequirement();
// 各種検索条件の設定
req.QueryExpression = "/document/base/name == 'ホテル1'";
req.ReturnExpression = "/document/base/name/text()";
req.ReplyNumber = 1;
req.RequestCount = 30;
// 検索条件を指定して検索を実行
ShunResultSet rs = service.Search( req );
// 更新用 ShunRecordCollection を作成
ShunRecordCollection updateRecords = new ShunRecordCollection();
// 検索条件に該当するレコードを取得
foreach ( ShunRecord record in rs.Records ) {
if ( record.Data == "ホテル1" ) {
// ホテル1の情報について、レコードID、更新データを設定
record.Data = String.Concat(
"<document>",
" <base>",
" <name>ホテル1</name>",
" <prefecture>大阪</prefecture>",
" <address>大阪府大阪市中央区</address>",
" <detail>http://xxxxx.co.jp</detail>",
" <price>8000</price>",
" </base>",
" <information>",
" <date>2006年07月18日</date>",
" </information>",
" <note>バス付 トイレ付 地下鉄 **駅徒歩02分</note>",
"</document>" );
updateRecords.Add( record );
}
}
// データ設定に成功している場合、データを更新
if ( updateRecords.Count > 0 ) {
service.Update( updateRecords );
Console.WriteLine( "更新終了" );
}
// 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 );
}
}
} |