/* * DotGNU DGEE Protocol Service * * Copyright (C) 2003 DotGNU Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * $Revision: 1.1.4.1 $ $Date: 2003/08/11 16:14:53 $ * * -------------------------------------------------------------------------- * * Authors: * Nicolai P Guba */ using System; using System.IO; using DotGNU.DGEE.Protocols.XmlRpc; namespace DotGNU.DGEE.Protocols { public class ProtocolService { static protected IProtocolHandler handler; /// this method is the entry point for the pnetvm public static String DGEE_run( String []args ) { handler = new XmlRpcProtocolHandler(); Console.Out.WriteLine( String.Format ("Processing XmlRpcRequest: {0}, {1}, {2}, {3}", args[0], args[1], args[2], args[3]) ); MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter( stream ); StreamReader reader = new StreamReader( stream ); if( handler == null ) { throw new Exception ( "ERROR: No protocol handler registered" ); } // Write the request sting to the stream writer.Write( args[3] ); writer.Flush(); stream.Seek( 0, 0 ); object method = handler.Request( reader ); long pos = stream.Position; // Run the method object result = handler.Invoke( args[0], method ); // Reply back with whatever the protocol expects handler.Response( writer, result ); stream.Seek( pos, 0 ); reader = new StreamReader( stream ); String outputString = reader.ReadToEnd(); // return the resources writer.Close(); reader.Close(); stream.Close(); return outputString; } } }