using System;
using Fujitsu.Shunsaku;
class SampleInsert {
static public void Main( string[] args ) {
ShunService service = null;
try {
// Create ShunService
service = new ShunService();
// Connect Shunsaku by specifying the host name and port number
service.Host = "DirSvr1";
service.Port = 33101;
service.Connect();
// Create ShunRecordCollection for adding data
ShunRecordCollection insertRecords = new ShunRecordCollection();
// Create ShunRecord for adding data
ShunRecord record = new ShunRecord();
// Specify data
record.Data = String.Concat(
"<document>",
" <base>",
" <name>Hotel 9</name>",
" <city>Adelaide</city>",
" <address>Belair, Adelaide</address>",
" <detail>http://xxxxx.com.au</detail>",
" <price>150</price>",
" </base>",
" <information>",
" <date>2006/07/18</date>",
" </information>",
"<note>No-smoking room with en-suite bathroom and toilet available, 5 minutes' walk to subway station XX</note>",
"</document>" );
// Add to the collection
insertRecords.Add( record );
// Add data
service.Insert( insertRecords );
Console.WriteLine( "Addition complete" );
// Close the connection to Shunsaku
service.Disconnect();
}
catch ( ShunContinuousException e ) {
// Processing to perform if ShunContinuousException occurs
try {
if( service != null && 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 );
}
}
} |