Contents tagged with CLR

  • Integrating .NET and Erlang using OTP.NET


    Summary:
    A simple example using OTP.NET to connect a .NET node to an erlang node. I have decided to write this after reading the article on "Integrating Java and Erlang" on ServerSide.com so I highly recommend that you read that article before continuing here as there are many things which are already described there which I'm not going to repeat.

     

    OTP.NET is a port to the Jinterface that the author used in the serverside article.  Here, I'll use the same process to integrate erlang code with a C# application.

     

    [I found OTP.NET while browsing through the Jungerl code repository. Jungerl contains miscellanous utilities for erlang programmers]

     

    The source code for the erlang mathserver application is also listed here. I've changed it to do multiplcation instead of addition and made it simpler by removing the send/receive code.

     

    File: Mathserver.erl


    -module(mathserver).

    -compile(export_all).

     

    multiply(First, Second) ->

    First * Second.

     

    Now, you can try this code in an erlang shell to see if it is working

     

    (1) >> werl.exe -sname servernode -setcookie cookie

    (2) (servernode@apollo)3> c(mathserver).

    {ok,mathserver}

    (3) (servernode@apollo)7> mathserver:multiply(10, 3).

    30

     

    (1) starts an erlang shell in a window using servernode as the short node name. The cookie is also required for security and you can see how we will use it in the client.

    (2) & (3) we then compile our application and call the exposed method to get the result back.

     

    Before starting to write a C# Sharp application, we can quickly start another erlang shell to see if we can connect to our server node from a new node.

    >> werl.exe -sname clientnode -setcookie cookie

    >> (clientnode@apollo)3> rpc:call(servernode@apollo, mathserver, multiply, [10, 2]).

    20

     

    Once we are confident that the erlang application is working, we can close the client node shell and start devenv.exe and a new project .

     

    The first thing we need to do is to include the reference to the OTP.dll file. You can either compile it yourself by downloading the source code from jungerl[sourceforge] or just download the sample application(sample download link). Please note that I've only included the dll in the sample and not the full source code.

     

    Now you can add the following code to the main method.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Otp;
    
    namespace ErsharpClient 
    {
        class Program
        {
            static void Main(string[] a)
            {
                OtpSelf cNode = new OtpSelf("clientnode", "cookie");
                OtpPeer sNode = new OtpPeer("servernode@apollo");
                OtpConnection connection = cNode.connect(sNode);
    
                Otp.Erlang.Object[] args = new Otp.Erlang.Object[] { 
                    new Otp.Erlang.Long(1), new Otp.Erlang.Long(4)
                }; 
                connection.sendRPC("mathserver", "multiply", args);
    
                Otp.Erlang.Long sum = (Otp.Erlang.Long)connection.receiveRPC();
                Console.WriteLine("Return Value:" + sum.ToString());
            }
        }
    }

    This is exactly similar to the code described in the article therefore I'm not going to duplicate that information.

     

    Download Sample Application 

     

    Other Links:

    [ServerSide Article] http://www.theserverside.com/tt/articles/article.tss?l=IntegratingJavaandErlang

    [JInterface] http://www.erlang.org/doc/apps/jinterface/index.html

    [OTP.NET Announcement] http://www.erlang.org/pipermail/erlang-questions/2004-May/012313.html

    [Jungerl] http://jungerl.sourceforge.net/

    [OTP.NET] http://jungerl.cvs.sourceforge.net/jungerl/jungerl/lib/otp.net/

     

    So, Java comes to rescue .NET again and OTP.NET makes inter node communication between erlang and .NET possible :)

    Read more...

  • SequenceViz 0.3 :: Namespaces and Pie Chart

    With the help of Mike and Steve, finally there are few visitors coming to the site looking for SequenceViz. For those new visitors and the existing loyal readers (if there are any :)), here is another version of SequenceViz.

     

    If you like SequenceViz or not, Spread it by Kicking It @ DotnetKicks or Digging It @ Digg.com. And subscribe to RSS to get any new releases.

     

    A quick screenshot first.

     

     

     New Additions:

     

    1) Namespace Supports:

    Now you can see in the assembly tree that the classes are grouped under namespaces.

     

    2) Assembly Pie Chart:

     

    In this version, I put a Tab control to easily add multiple views of the assembly data.

     

     

    Assembly Stats is a new view where you can see the size of assemblies and namespaces. It works when you either select Assembly or Namespace in the left hand pane and switch to Assembly Stats tab.

     

    If you have selected an assembly then the pie charts shows the different namespaces within the assembly. The size of each pie is proportional to the size of classes in each namespace. For eg. Here is a nice view of log4net assembly. You can see that the classes are nicely distributed among namespaces.

     

     

    The view changes when you select a namespace as shown below. Now it shows the different classes in the selected namespace . Similarly, the size of the pie in this case is proportional to the size of methods in each class.

     

     

    I was initially thinking about adding the chart to show the number of IL count for each method. In the end, I decided not to go along that path because IL doesn't reflect the true number of lines in a higher level language and can give an incorrect picture.

     

    Finally, a big thanks to ZedGraph for building a wonderful open source chart package which comes with excellent document even though it is really really simple to use.

     

    The Future:

    I'm trying to setup a CodePlex project so that SequenceViz can get its own home, but currently there are few areas of that website not working so I'll to wait until that get fixed.  In the meantime, if you would like to see anything in the next release then please leave your comments. The main theme of SequenceViz is to use visualization to help people understanding an existing project.

     

    For comments on putting this as Reflector Plugin:

    I would like to control the shell and now as I am getting comfortable with using Cecil therefore I am sorry that I won't be able to integrate this in Reflector any time soon. In addition there are some features that I want to see in SequenceViz which would not be possible without controlling the shell application.

     

    Download

    SequenceViz 0.3 (Source + Binaries)

     

    Read more...

  • Method Tree Visualizer :: Fun with IronPython, Cecil and Netron Graph - Part III

    As I said in the last post, the output from Microsoft GLEE looked but not ideal and as the method tree gets bigger with more relationships, the diagram gets out of control. Disappointed with that, my further search takes me to the Netron Project, which is a diagramming and graph layout toolkit for Microsoft .NET Framework.    

    Read more...