#using <mscorlib.dll>
#using <system.dll>
#using <Fujitsu.Shunsaku.dll>
using namespace System;
using namespace Fujitsu::Shunsaku;
class SampleDirectAccessSearch {
public:
static void Main( String *args __gc[] ) {
ShunService *service = 0;
try {
// Create ShunService
service = new ShunService();
// Connect Shunsaku by specifying the host name and port number
service->Host = "DirSvr1";
service->Port = 33101;
service->ShunsakuFile = "shunsakuFile1";
service->Connect();
// Create ShunKeyRequirement object for searching data
ShunKeyRequirement *keyReq = new ShunKeyRequirement();
keyReq->KeyName = "key";
// Add the key to be searched
keyReq->Records->Add( new ShunRecord() );
keyReq->Records->get_Item( 0 )->Key = "0001";
// Specify the search condition and execute the search
ShunResultSet *rs = service->SearchByKey( keyReq, "/" );
// Obtain the source information of the direct access key
Console::WriteLine( "Number of hits = {0}", __box( rs->HitCount ) );
int i = 0;
ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator();
while ( enumerator->MoveNext() ) {
ShunRecord *record = enumerator->Current;
++i;
Console::WriteLine( "[Result] Item No. {0}", __box( i ) );
Console::WriteLine( "Direct access key: {0}", record->Key );
Console::WriteLine( "Data :" );
Console::WriteLine( record->Data );
}
// Close the connection to Shunsaku
service->Disconnect();
}
catch ( ShunContinuousException *e ) {
// Processing to perform if ShunContinuousException occurs
try {
if( service != 0 && service->State == ShunConnectionState::Open ) {
service->Disconnect();
}
}
catch ( ShunException *ex ) {
Console::WriteLine( "Error message : {0}", ex->Message );
}
Console::WriteLine( "Error message : {0}", e->Message );
}
catch ( ShunConnectionTerminatedException *e ) {
// Processing to perform if ShunConnectionTerminatedException occurs
Console::WriteLine( "Error message : {0}", e->Message );
}
}
};
int main() {
return
SampleDirectAccessSearch::Main( Environment::GetCommandLineArgs() );
} |