26 |
*/ |
*/ |
27 |
using System; |
using System; |
28 |
using System.IO; |
using System.IO; |
29 |
|
using DotGNU.DGEE.Protocols.XmlRpc; |
30 |
|
|
31 |
namespace DotGNU.DGEE.Protocols |
namespace DotGNU.DGEE.Protocols |
32 |
{ |
{ |
33 |
public abstract class ProtocolService |
public class ProtocolService |
34 |
{ |
{ |
35 |
static protected IProtocolHandler handler; |
static protected IProtocolHandler handler; |
36 |
|
|
37 |
/// this method is the entry point for the pnetvm |
/// this method is the entry point for the pnetvm |
38 |
public static String DGEE_run( string []args ) |
public static String DGEE_run( String []args ) |
39 |
{ |
{ |
40 |
|
handler = new XmlRpcProtocolHandler(); |
41 |
|
|
42 |
|
Console.Out.WriteLine( String.Format ("Processing XmlRpcRequest: {0}, {1}, {2}, {3}", |
43 |
|
args[0], args[1], args[2], args[3]) ); |
44 |
|
|
45 |
MemoryStream stream = new MemoryStream(); |
MemoryStream stream = new MemoryStream(); |
46 |
StreamWriter writer = new StreamWriter( stream ); |
StreamWriter writer = new StreamWriter( stream ); |
47 |
StreamReader reader = new StreamReader( stream ); |
StreamReader reader = new StreamReader( stream ); |
48 |
|
|
49 |
if( handler == null ) { |
if( handler == null ) { |
50 |
Console.Out.WriteLine( "ERROR: No protocol handler registered" ); |
throw new Exception ( "ERROR: No protocol handler registered" ); |
51 |
} |
} |
|
string s = "<?xml version=\"1.0\"?> |
|
|
<!-- $Id$ --> |
|
|
<methodCall> |
|
|
<methodName>ParameterTest</methodName> |
|
|
<params> |
|
|
<param> |
|
|
<value> |
|
|
<base64>ABI0VqpVw</base64> |
|
|
</value> |
|
|
</param> |
|
|
<param> |
|
|
<value> |
|
|
<i4>1</i4> |
|
|
</value> |
|
|
</param> |
|
|
<param> |
|
|
<value> |
|
|
<int>2</int> |
|
|
</value> |
|
|
</param> |
|
|
<param> |
|
|
<value> |
|
|
<double>2.1</double> |
|
|
</value> |
|
|
</param> |
|
|
<param> |
|
|
<value> |
|
|
<boolean>true</boolean> |
|
|
</value> |
|
|
</param> |
|
|
<param> |
|
|
<value> |
|
|
<boolean>0</boolean> |
|
|
</value> |
|
|
</param> |
|
|
<param> |
|
|
<value> |
|
|
<dateTime.iso8601>2003-07-22T17:17:19</dateTime.iso8601> |
|
|
</value> |
|
|
</param> |
|
|
</params> |
|
|
</methodCall>"; |
|
52 |
|
|
53 |
// Write the request sting to the stream |
// Write the request sting to the stream |
54 |
|
writer.Write( args[3] ); |
|
writer.Write( s ); |
|
55 |
writer.Flush(); |
writer.Flush(); |
56 |
stream.Seek( 0, 0 ); |
stream.Seek( 0, 0 ); |
57 |
|
|
|
// Handle the request to retrieve the method being called |
|
58 |
object method = handler.Request( reader ); |
object method = handler.Request( reader ); |
59 |
long pos = stream.Position; |
long pos = stream.Position; |
60 |
|
|
61 |
|
|
62 |
// Run the method |
// Run the method |
63 |
object result = handler.Invoke( method ); |
object result = handler.Invoke( args[0], method ); |
64 |
|
|
65 |
// Reply back with whatever the protocol expects |
// Reply back with whatever the protocol expects |
66 |
handler.Response( writer, result ); |
handler.Response( writer, result ); |
67 |
stream.Seek( pos, 0 ); |
stream.Seek( pos, 0 ); |
68 |
|
|
69 |
reader = new StreamReader( stream ); |
reader = new StreamReader( stream ); |
70 |
string outputString = reader.ReadToEnd(); |
String outputString = reader.ReadToEnd(); |
71 |
|
|
72 |
// return the resources |
// return the resources |
73 |
writer.Close(); |
writer.Close(); |