public override int run(string[] args) { if (args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return(1); } Ice.ObjectPrx obj = communicator().propertyToProxy("Printer.Proxy"); menu(); string line = null; do { try { Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if (line == null) { break; } byte[] outParams; if (line.Equals("1")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.startEncapsulation(); outStream.writeString("The streaming API works!"); outStream.endEncapsulation(); // // Invoke operation. // if (!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if (line.Equals("2")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.startEncapsulation(); string[] arr = { "The", "streaming", "API", "works!" }; Demo.StringSeqHelper.write(outStream, arr); outStream.endEncapsulation(); // // Invoke operation. // if (!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if (line.Equals("3")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.startEncapsulation(); Dictionary <string, string> dict = new Dictionary <string, string>(); dict["The"] = "streaming"; dict["API"] = "works!"; Demo.StringDictHelper.write(outStream, dict); outStream.endEncapsulation(); // // Invoke operation. // if (!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if (line.Equals("4")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.startEncapsulation(); Demo.ColorHelper.write(outStream, Demo.Color.green); outStream.endEncapsulation(); // // Invoke operation. // if (!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if (line.Equals("5")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.startEncapsulation(); Demo.Structure s = new Demo.Structure(); s.name = "red"; s.value = Demo.Color.red; s.ice_write(outStream); outStream.endEncapsulation(); // // Invoke operation. // if (!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if (line.Equals("6")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.startEncapsulation(); Demo.Structure[] arr = new Demo.Structure[3]; arr[0] = new Demo.Structure(); arr[0].name = "red"; arr[0].value = Demo.Color.red; arr[1] = new Demo.Structure(); arr[1].name = "green"; arr[1].value = Demo.Color.green; arr[2] = new Demo.Structure(); arr[2].name = "blue"; arr[2].value = Demo.Color.blue; Demo.StructureSeqHelper.write(outStream, arr); outStream.endEncapsulation(); // // Invoke operation. // if (!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if (line.Equals("7")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.startEncapsulation(); Demo.C c = new Demo.C(); c.s = new Demo.Structure(); c.s.name = "blue"; c.s.value = Demo.Color.blue; Demo.CHelper.write(outStream, c); outStream.writePendingObjects(); outStream.endEncapsulation(); // // Invoke operation. // if (!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if (line.Equals("8")) { // // Invoke operation. // if (!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams)) { Console.Error.WriteLine("Unknown user exception"); continue; } // // Unmarshal the results. // Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); inStream.startEncapsulation(); Demo.CHelper ch = new Demo.CHelper(inStream); ch.read(); String str = inStream.readString(); inStream.readPendingObjects(); inStream.destroy(); Demo.C c = ch.value; Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name + ", s.value=" + c.s.value); } else if (line.Equals("9")) { // // Invoke operation. // if (obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams)) { Console.Error.WriteLine("Expected exception"); continue; } Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); inStream.startEncapsulation(); try { inStream.throwException(); } catch (Demo.PrintFailure) { // Expected. } catch (Ice.UserException) { Console.Error.WriteLine("Unknown user exception"); } inStream.endEncapsulation(); inStream.destroy(); } else if (line.Equals("s")) { obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams); } else if (line.Equals("x")) { // Nothing to do. } else if (line.Equals("?")) { menu(); } else { Console.Error.WriteLine("unknown command `" + line + "'"); menu(); } } catch (Ice.LocalException ex) { Console.Error.WriteLine(ex); } }while(!line.Equals("x")); return(0); }
public override bool ice_invoke(byte[] inParams, out byte[] outParams, Ice.Current current) { outParams = null; Ice.Communicator communicator = current.adapter.getCommunicator(); Ice.InputStream inStream = null; if(inParams.Length > 0) { inStream = Ice.Util.createInputStream(communicator, inParams); inStream.startEncapsulation(); } if(current.operation.Equals("printString")) { string message = inStream.readString(); inStream.endEncapsulation(); inStream.destroy(); Console.WriteLine("Printing string `" + message + "'"); return true; } else if(current.operation.Equals("printStringSequence")) { String[] seq = Demo.StringSeqHelper.read(inStream); inStream.endEncapsulation(); inStream.destroy(); Console.Write("Printing string sequence {"); for(int i = 0; i < seq.Length; ++i) { if(i > 0) { Console.Write(", "); } Console.Write("'" + seq[i] + "'"); } Console.WriteLine("}"); return true; } else if(current.operation.Equals("printDictionary")) { Dictionary<string, string> dict = Demo.StringDictHelper.read(inStream); inStream.endEncapsulation(); inStream.destroy(); Console.Write("Printing dictionary {"); bool first = true; foreach(KeyValuePair<string, string> e in dict) { if(!first) { Console.Write(", "); } first = false; Console.Write(e.Key + "=" + e.Value); } Console.WriteLine("}"); return true; } else if(current.operation.Equals("printEnum")) { Demo.Color c = Demo.ColorHelper.read(inStream); inStream.endEncapsulation(); inStream.destroy(); Console.WriteLine("Printing enum " + c); return true; } else if(current.operation.Equals("printStruct")) { Demo.Structure s = new Demo.Structure(); s.ice_read(inStream); inStream.endEncapsulation(); inStream.destroy(); Console.WriteLine("Printing struct: name=" + s.name + ", value=" + s.value); return true; } else if(current.operation.Equals("printStructSequence")) { Demo.Structure[] seq = Demo.StructureSeqHelper.read(inStream); inStream.endEncapsulation(); inStream.destroy(); Console.Write("Printing struct sequence: {"); for(int i = 0; i < seq.Length; ++i) { if(i > 0) { Console.Write(", "); } Console.Write(seq[i].name + "=" + seq[i].value); } Console.WriteLine("}"); return true; } else if(current.operation.Equals("printClass")) { Demo.CHelper ch = new Demo.CHelper(inStream); ch.read(); inStream.readPendingObjects(); inStream.endEncapsulation(); inStream.destroy(); Demo.C c = ch.value; Console.WriteLine("Printing class: s.name=" + c.s.name + ", s.value=" + c.s.value); return true; } else if(current.operation.Equals("getValues")) { Demo.C c = new Demo.C(); c.s = new Demo.Structure(); c.s.name = "green"; c.s.value = Demo.Color.green; Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); outStream.startEncapsulation(); Demo.CHelper.write(outStream, c); outStream.writeString("hello"); outStream.writePendingObjects(); outStream.endEncapsulation(); outParams = outStream.finished(); return true; } else if(current.operation.Equals("throwPrintFailure")) { Console.WriteLine("Throwing PrintFailure"); Demo.PrintFailure ex = new Demo.PrintFailure(); ex.reason = "paper tray empty"; Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator); outStream.startEncapsulation(); outStream.writeException(ex); outStream.endEncapsulation(); outParams = outStream.finished(); return false; } else if(current.operation.Equals("shutdown")) { current.adapter.getCommunicator().shutdown(); return true; } else { Ice.OperationNotExistException ex = new Ice.OperationNotExistException(); ex.id = current.id; ex.facet = current.facet; ex.operation = current.operation; throw ex; } }
public static void write__(IceInternal.BasicStream os__, Structure v__) { if(v__ == null) { nullMarshalValue__.write__(os__); } else { v__.write__(os__); } }
public static Structure read__(IceInternal.BasicStream is__, Structure v__) { if(v__ == null) { v__ = new Structure(); } v__.read__(is__); return v__; }
public override int run(string[] args) { if(args.Length > 0) { Console.Error.WriteLine(appName() + ": too many arguments"); return 1; } Ice.ObjectPrx obj = communicator().propertyToProxy("Printer.Proxy"); menu(); string line = null; do { try { Console.Write("==> "); Console.Out.Flush(); line = Console.In.ReadLine(); if(line == null) { break; } byte[] outParams; if(line.Equals("1")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); outStream.writeString("The streaming API works!"); // // Invoke operation. // if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if(line.Equals("2")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); string[] arr = { "The", "streaming", "API", "works!" }; Demo.StringSeqHelper.write(outStream, arr); // // Invoke operation. // if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if(line.Equals("3")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Dictionary<string, string> dict = new Dictionary<string, string>(); dict["The"] = "streaming"; dict["API"] = "works!"; Demo.StringDictHelper.write(outStream, dict); // // Invoke operation. // if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if(line.Equals("4")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.ColorHelper.write(outStream, Demo.Color.green); // // Invoke operation. // if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if(line.Equals("5")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.Structure s = new Demo.Structure(); s.name = "red"; s.value = Demo.Color.red; s.ice_write(outStream); // // Invoke operation. // if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if(line.Equals("6")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.Structure[] arr = new Demo.Structure[3]; arr[0] = new Demo.Structure(); arr[0].name = "red"; arr[0].value = Demo.Color.red; arr[1] = new Demo.Structure(); arr[1].name = "green"; arr[1].value = Demo.Color.green; arr[2] = new Demo.Structure(); arr[2].name = "blue"; arr[2].value = Demo.Color.blue; Demo.StructureSeqHelper.write(outStream, arr); // // Invoke operation. // if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if(line.Equals("7")) { // // Marshal the in parameter. // Ice.OutputStream outStream = Ice.Util.createOutputStream(communicator()); Demo.C c = new Demo.C(); c.s = new Demo.Structure(); c.s.name = "blue"; c.s.value = Demo.Color.blue; Demo.CHelper.write(outStream, c); outStream.writePendingObjects(); // // Invoke operation. // if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, outStream.finished(), out outParams)) { Console.Error.WriteLine("Unknown user exception"); } outStream.destroy(); } else if(line.Equals("8")) { // // Invoke operation. // if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, out outParams)) { Console.Error.WriteLine("Unknown user exception"); continue; } // // Unmarshal the results. // Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); Demo.CHelper ch = new Demo.CHelper(inStream); ch.read(); String str = inStream.readString(); inStream.readPendingObjects(); inStream.destroy(); Demo.C c = ch.value; Console.Error.WriteLine("Got string `" + str + "' and class: s.name=" + c.s.name + ", s.value=" + c.s.value); } else if(line.Equals("9")) { // // Invoke operation. // if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, out outParams)) { Console.Error.WriteLine("Expected exception"); continue; } Ice.InputStream inStream = Ice.Util.createInputStream(communicator(), outParams); try { inStream.throwException(); } catch(Demo.PrintFailure) { // Expected. } catch(Ice.UserException) { Console.Error.WriteLine("Unknown user exception"); } inStream.destroy(); } else if(line.Equals("s")) { obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, out outParams); } else if(line.Equals("x")) { // Nothing to do. } else if(line.Equals("?")) { menu(); } else { Console.Error.WriteLine("unknown command `" + line + "'"); menu(); } } catch(Ice.LocalException ex) { Console.Error.WriteLine(ex); } } while(!line.Equals("x")); return 0; }