ICE 3.4.2
[php5-ice-freebsdport.git] / vb / demo / Ice / value / Client.vb
blobf4e4c4407b05739b87c6fb32dccc49e5b5b132e2
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.Diagnostics
12 Imports Demo
14 Module ValueC
15 Class Client
16 Inherits Ice.Application
18 Public Overloads Overrides Function run(ByVal args() As String) As Integer
19 If args.Length > 0 Then
20 Console.Error.WriteLine(appName() & ": too many arguments")
21 Return 1
22 End If
24 Dim initial As InitialPrx = InitialPrxHelper.checkedCast(communicator().propertyToProxy("Value.Initial"))
25 If initial Is Nothing Then
26 Console.Error.WriteLine("invalid object reference")
27 Return 1
28 End If
30 Console.Out.WriteLine()
31 Console.Out.WriteLine("Let's first transfer a simple object, for a class without")
32 Console.Out.WriteLine("operations, and print its contents. No factory is required")
33 Console.Out.WriteLine("for this.")
34 Console.Out.WriteLine("[press enter]")
35 Console.In.ReadLine()
37 Dim simple As simple = initial.getSimple()
38 Console.Out.WriteLine("==> " & simple.message)
40 Console.Out.WriteLine()
41 Console.Out.WriteLine("Yes, this worked. Now let's try to transfer an object for a class")
42 Console.Out.WriteLine("with operations as type Demo.Printer, without installing a factory first.")
43 Console.Out.WriteLine("This should give us a `no factory' exception.")
44 Console.Out.WriteLine("[press enter]")
45 Console.In.ReadLine()
47 Dim printer As printer = Nothing
48 Dim printerProxy As PrinterPrx = Nothing
49 Try
50 initial.getPrinter(printer, printerProxy)
51 Console.Error.WriteLine("Did not get the expected NoObjectFactoryException!")
52 Environment.Exit(1)
53 Catch ex As Ice.NoObjectFactoryException
54 Console.Out.WriteLine("==> " & ex.ToString())
55 End Try
57 Console.Out.WriteLine()
58 Console.Out.WriteLine("Yep, that's what we expected. Now let's try again, but with")
59 Console.Out.WriteLine("installing an appropriate factory first. If successful, we print")
60 Console.Out.WriteLine("the object's content.")
61 Console.Out.WriteLine("[press enter]")
62 Console.In.ReadLine()
64 Dim factory As Ice.ObjectFactory = New ObjectFactory
65 communicator().addObjectFactory(factory, Demo.Printer.ice_staticId())
67 initial.getPrinter(printer, printerProxy)
68 Console.Out.WriteLine("==> " & printer.message)
70 Console.Out.WriteLine()
71 Console.Out.WriteLine("Cool, it worked! Let's try calling the printBackwards() method")
72 Console.Out.WriteLine("on the object we just received locally.")
73 Console.Out.WriteLine("[press enter]")
74 Console.In.ReadLine()
76 Console.Out.Write("==> ")
77 printer.printBackwards()
79 Console.Out.WriteLine()
80 Console.Out.WriteLine("Now we call the same method, but on the remote object. Watch the")
81 Console.Out.WriteLine("server's output.")
82 Console.Out.WriteLine("[press enter]")
83 Console.In.ReadLine()
85 printerProxy.printBackwards()
87 Console.Out.WriteLine()
88 Console.Out.WriteLine("Next, we transfer a derived object from the server as a base")
89 Console.Out.WriteLine("object. Since we haven't yet installed a factory for the derived")
90 Console.Out.WriteLine("class, the derived class (Demo.DerivedPrinter) is sliced")
91 Console.Out.WriteLine("to its base class (Demo.Printer).")
92 Console.Out.WriteLine("[press enter]")
93 Console.In.ReadLine()
95 Dim derivedAsBase As printer = initial.getDerivedPrinter()
96 Console.Out.WriteLine("==> The type ID of the received object is """ & derivedAsBase.ice_id() & """")
97 Debug.Assert(derivedAsBase.ice_id().Equals(Demo.Printer.ice_staticId()))
99 Console.Out.WriteLine()
100 Console.Out.WriteLine("Now we install a factory for the derived class, and try again.")
101 Console.Out.WriteLine("Because we receive the derived object as a base object,")
102 Console.Out.WriteLine("we need to do a class cast to get from the base to the derived object.")
103 Console.Out.WriteLine("[press enter]")
104 Console.In.ReadLine()
106 communicator().addObjectFactory(factory, Demo.DerivedPrinter.ice_staticId())
108 derivedAsBase = initial.getDerivedPrinter()
109 Dim derived As DerivedPrinter = CType(derivedAsBase, DerivedPrinter)
111 Console.Out.WriteLine("==> class cast to derived object succeded")
112 Console.Out.WriteLine("==> The type ID of the received object is """ & derived.ice_id() & """")
114 Console.Out.WriteLine()
115 Console.Out.WriteLine("Let's print the message contained in the derived object, and")
116 Console.Out.WriteLine("call the operation printUppercase() on the derived object")
117 Console.Out.WriteLine("locally.")
118 Console.Out.WriteLine("[press enter]")
119 Console.In.ReadLine()
121 Console.Out.WriteLine("==> " & derived.derivedMessage)
122 Console.Out.Write("==> ")
123 derived.printUppercase()
125 Console.Out.WriteLine()
126 Console.Out.WriteLine("Finally, we try the same again, but instead of returning the")
127 Console.Out.WriteLine("derived object, we throw an exception containing the derived")
128 Console.Out.WriteLine("object.")
129 Console.Out.WriteLine("[press enter]")
130 Console.In.ReadLine()
133 initial.throwDerivedPrinter()
134 Catch ex As DerivedPrinterException
135 derived = ex.derived
136 Debug.Assert(Not derived Is Nothing)
137 End Try
139 Console.Out.WriteLine("==> " & derived.derivedMessage)
140 Console.Out.Write("==> ")
141 derived.printUppercase()
143 Console.Out.WriteLine()
144 Console.Out.WriteLine("That's it for this demo. Have fun with Ice!")
146 initial.shutdown()
148 Return 0
149 End Function
151 End Class
153 Public Sub Main(ByVal args() As String)
154 Dim app As Client = New Client
155 Dim status As Integer = app.main(args, "config.client")
156 System.Environment.Exit(status)
157 End Sub
158 End Module