Jacl.NET

by Will Ballard



Listing One



try

{

    System.IO.StreamReader rdr = new System.IO.StreamReader(

            this.GetType().get_Assembly().GetManifestResourceStream(resName));

    eval(rdr.ReadToEnd(), 0);

} catch (Exception e2) {

    throw new TclException(this, "cannot read resource \"" + resName + "\"");

}





Listing Two



static void Main(string[] args)

{

    try

    {

        tcl.lang.Shell.main(args);

    }

    catch (Exception ex)



    {

        System.Console.Error.WriteLine(ex);

    }





Listing Three



public class LogonCommand : tcl.lang.Command

{

    /// <summary>

    /// This holds the connection string once a connection is made.

    /// </summary>

    public static string ConnectionString;

    #region Command Members

    public void cmdProc(tcl.lang.Interp interp, tcl.lang.TclObject[] objv)

    {

        //check argument length

        if (objv.Length == 2) //enough command arguments

        {

            try

            {

                System.Data.SqlClient.SqlConnection conn =

                  new System.Data.SqlClient.SqlConnection(objv[1].ToString());

                conn.Open();

                ConnectionString = conn.ConnectionString;

                conn.Close();

                interp.setResult("Connected");

            }

            catch (Exception ex)

            {

                interp.setResult(ex.Message);

            }

        }

        else

        {

            //standard message for missing arguments

            throw new tcl.lang.TclNumArgsException(interp, 1, 

                                                objv, "connection_string");

        }

    }

    #endregion

} 





Listing Four



class Program

{

    static void Main(string[] args)

    {

        InterpreterService service = new InterpreterService();

        TcpChannel channel = new TcpChannel(55000);

        ChannelServices.RegisterChannel(channel);

        ObjRef mounted = RemotingServices.Marshal(service,"interpreter");

        System.Console.WriteLine("press enter to exit...");

        System.Console.ReadLine();

    }

}



/// <summary>

/// Expose the <see cref="tcl.lang.Interp"/> via remoting.

/// </summary>

public class InterpreterService : MarshalByRefObject

{

    private tcl.lang.Interp _interpreter = new tcl.lang.Interp();



    public InterpreterService()

    {

        tcl.lang.Extension.loadOnDemand(_interpreter, "logon", 

                                             "SampleServer.LogonCommand");

    }

    /// <summary>

    /// Execute a script, returning the evaluated results.

    /// </summary>

    /// <param name="script"></param>

    /// <returns></returns>

    public string RunScript(string script)

    {

        try

        {

            _interpreter.eval(script);

            return _interpreter.getResult().ToString();

        }

        catch (Exception ex)

        {

            return ex.ToString();

        }

    }

} 





Listing Five



Module ClientEntryPoint

Sub Main(ByVal args As String())

    If (args.Length > 0) Then

        Dim chan As New TcpChannel()

        ChannelServices.RegisterChannel(chan)

        RemotingConfiguration.RegisterWellKnownClientType(GetType

                     (SampleServer.InterpreterService), 

                         "tcp://localhost:55000/interpreter")

        Dim remote As New SampleServer.InterpreterService()

        System.Console.WriteLine(remote.RunScript(args(0)))

    End If

End Sub



End Module 











3



