ICE 3.4.2
[php5-ice-freebsdport.git] / vb / demo / Ice / invoke / PrinterI.vb
blob2041bb7e64b491336ef75881ffc317596b0476ff
1 ' **********************************************************************
3 ' Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 ' This copy of Ice is licensed to you under the terms described in the
6 ' ICE_LICENSE file included in this distribution.
8 ' **********************************************************************
10 Imports System
11 Imports System.Collections.Generic
12 Imports InvokeDemo
14 Public Class PrinterI
15 Inherits Ice.Blobject
17 Public Overrides Function ice_invoke(ByVal inparams As Byte(), ByRef outParams As Byte(), ByVal current As Ice.Current) As Boolean
19 outParams = Nothing
21 Dim communicator As Ice.Communicator = current.adapter.getCommunicator()
23 Dim inStream As Ice.InputStream = Nothing
24 If inparams.Length > 0 Then
25 inStream = Ice.Util.createInputStream(communicator, inparams)
26 End If
28 If current.operation.Equals("printString") Then
29 Dim message As String = inStream.readString()
30 inStream.destroy()
31 Console.WriteLine("Printing string `" & message & "'")
32 Return True
33 ElseIf current.operation.Equals("printStringSequence") Then
34 Dim seq As String() = StringSeqHelper.read(inStream)
35 inStream.destroy()
36 Console.Write("Printing string sequence {")
37 For i As Integer = 0 To seq.Length - 1
38 If i > 0 Then
39 Console.Write(", ")
40 End If
41 Console.Write("'" & seq(i) & "'")
42 Next
43 Console.WriteLine("}")
44 Return True
45 ElseIf current.operation.Equals("printDictionary") Then
46 Dim dict As Dictionary(Of String, String) = StringDictHelper.read(inStream)
47 inStream.destroy()
48 Console.Write("Printing dictionary {")
49 Dim first As Boolean = True
50 For Each e As KeyValuePair(Of String, String) In dict
51 If Not first Then
52 Console.Write(", ")
53 End If
54 first = False
55 Console.Write(e.Key.ToString() & "=" & e.Value.ToString())
56 Next
57 Console.WriteLine("}")
58 Return True
59 ElseIf current.operation.Equals("printEnum") Then
60 Dim c As Color = ColorHelper.read(inStream)
61 inStream.destroy()
62 Console.WriteLine("Printing enum " & c)
63 Return True
64 ElseIf current.operation.Equals("printStruct") Then
65 Dim s As [Structure] = New [Structure]
66 s.ice_read(inStream)
67 inStream.destroy()
68 Console.WriteLine("Printing struct: name=" & s.name & ", value=" & s.value)
69 Return True
70 ElseIf current.operation.Equals("printStructSequence") Then
71 Dim seq As [Structure]() = StructureSeqHelper.read(inStream)
72 inStream.destroy()
73 Console.Write("Printing struct sequence: {")
74 For i As Integer = 0 To seq.Length - 1
75 If i > 0 Then
76 Console.Write(", ")
77 End If
78 Console.Write(seq(i).name & "=" & seq(i).value)
79 Next
80 Console.WriteLine("}")
81 Return True
82 ElseIf current.operation.Equals("printClass") Then
83 Dim ch As CHelper = New CHelper(inStream)
84 ch.read()
85 inStream.readPendingObjects()
86 inStream.destroy()
87 Dim c As InvokeDemo.C = ch.value
88 Console.WriteLine("Printing class: s.name=" & c.s.name & ", s.value=" & c.s.value)
89 Return True
90 ElseIf current.operation.Equals("getValues") Then
91 Dim c As InvokeDemo.C = New InvokeDemo.C
92 c.s = New [Structure]
93 c.s.name = "green"
94 c.s.value = Color.green
95 Dim outStream As Ice.OutputStream = Ice.Util.createOutputStream(communicator)
96 CHelper.write(outStream, c)
97 outStream.writeString("hello")
98 outStream.writePendingObjects()
99 outParams = outStream.finished()
100 Return True
101 ElseIf current.operation.Equals("throwPrintFailure") Then
102 Console.WriteLine("Throwing PrintFailure")
103 Dim ex As PrintFailure = New PrintFailure
104 ex.reason = "paper tray empty"
105 Dim outStream As Ice.OutputStream = Ice.Util.createOutputStream(communicator)
106 outStream.writeException(ex)
107 outParams = outStream.finished()
108 Return False
109 ElseIf current.operation.Equals("shutdown") Then
110 current.adapter.getCommunicator().shutdown()
111 Return True
112 Else
113 Dim ex As Ice.OperationNotExistException = New Ice.OperationNotExistException
114 ex.id = current.id
115 ex.facet = current.facet
116 ex.operation = current.operation
117 Throw ex
118 End If
119 End Function
121 End Class