#using <mscorlib.dll>
#using <system.dll>
#using <Fujitsu.Shunsaku.dll>
using namespace System;
using namespace Fujitsu::Shunsaku;
class SampleDirectAccessUpdate {
public:
static void Main( String *args __gc[] ) {
ShunService *service = 0;
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->get_Item( 0 )->Key = "0001";
// 更新データを設定
keyReq->Records->get_Item( 0 )->Data = String::Concat(
S"<course>",
S" <id>0001</id>",
S" <name>Business negotiation</name>",
S" <instructor>",
S" <first-name>Max</first-name>",
S" <last-name>cameron</last-name>",
S" </instructor>",
S" <capacity>40</capacity>",
S" <current-auditors>31</current-auditors>",
S"</course>" );
//コース情報の更新
service->UpdateByKey( keyReq );
Console::WriteLine( "更新終了" );
// Shunsaku から切断
service->Disconnect();
}
catch ( ShunContinuousException *e ) {
// ShunContinuousExceptionが発生した場合の処理を記述
try {
if( service != 0 && 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 );
}
}
};
int main() {
return
SampleDirectAccessUpdate::Main( Environment::GetCommandLineArgs() );
} |