Imports System
Imports Fujitsu.Shunsaku
Imports System.ComponentModel
Class SampleUpdate
  Shared Public Function Main( ByVal args() As String ) As Integer
    Dim service As ShunService = Nothing
    Try
      '' Create ShunService
      service = new ShunService()
      '' Connect Shunsaku by specifying the host name and port number
      service.Host = "DirSrv1"
      service.Port = 33101
      service.Connect()
      '' Create ShunSearchRequirement
      Dim req As ShunSearchRequirement = new ShunSearchRequirement()
      '' Set each type of search conditions
      req.QueryExpression = "/document/base/name == 'Hotel 1'"
      req.ReturnExpression = "/document/base/name/text()"
      req.ReplyNumber = 1
      req.RequestCount = 30
      '' Specify the search condition and execute the search
      Dim rs As ShunResultSet = service.Search( req )
      '' Create ShunRecordCollection for updating data
      Dim updateRecords As ShunRecordCollection = new ShunRecordCollection()
      '' Obtain the records that correspond to the search conditions
      For Each record As ShunRecord In rs.Records
        If record.Data = "Hotel 1"
          '' Set the record ID and data to update for Hotel 1 information
          record.Data = String.Concat( _
            "<document>", _
            "    <base>", _
            "        <name>Hotel 1</name>", _
            "        <city>Sydney</city>", _
            "        <address>Bondi Beach</address>", _
            "        <detail>http://xxxxx.com.au</detail>", _
            "        <price>300</price>", _
            "    </base>", _
            "    <information>", _
            "        <date>2006/07/18</date>", _
            "    </information>", _
            "    <note>En-suite bathroom and toilet, two minutes' walk to train station XX</note>", _
            "</document>" )
          updateRecords.Add( record )
        End If
      Next
      '' Update the data if the data was set successfully
      If updateRecords.Count > 0
        service.Update( updateRecords )
        Console.WriteLine( "Update complete" )
      End If
      '' Close the connection to Shunsaku
      service.Disconnect()
    
    Catch e As ShunContinuousException
      '' Processing to perform if ShunContinuousException occurs
      Try
        If Not service Is Nothing And service.State = ShunConnectionState.Open Then
          service.Disconnect()
        End If
      Catch ex As ShunException
        Console.WriteLine( "Error message : {0}", ex.Message )
      End Try
      Console.WriteLine( "Error message : {0}", e.Message )
    
    Catch e As ShunConnectionTerminatedException
      '' Processing to perform if ShunConnectionTerminatedException occurs
      Console.WriteLine( "Error message : {0}", e.Message )
    End Try
  End Function
End Class |