using System;
using Fujitsu.Shunsaku;
class SampleDirectAccessUpdate {
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.ShunsakuFile = "shunsakuFile1";
service.Connect();
// Create ShunKeyRequirement object for updating data
ShunKeyRequirement keyReq = new ShunKeyRequirement();
keyReq.KeyName = "key";
// Add the key to be updated
keyReq.Records.Add( new ShunRecord() );
keyReq.Records[0].Key = "0001";
// Set update data
keyReq.Records[0].Data = String.Concat(
"<course>",
" <id>0001</id>",
" <name>Business negotiation</name>",
" <instructor>",
" <first-name>Max</first-name>",
" <last-name>cameron</last-name>",
" </instructor>",
" <capacity>40</capacity>",
" <current-auditors>31</current-auditors>",
"</course>" );
//Update course information
service.UpdateByKey( keyReq );
Console.WriteLine( "Update 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 );
}
}
} |