.NET to Javascript compiler

C# code   Html page   Start
class GenericServiceApp
{
    readonly static string serviceUrl = "Services/WebService.asmx";
    readonly static HtmlLazy<GenericServiceApp> instance = new HtmlLazy<GenericServiceApp>(delegate() { return new GenericServiceApp(); });

    readonly Person[] request;
    readonly Grid<Person> grid;
    readonly HtmlElement error;

    GenericServiceApp()
    {
        request = new Person[]
        {
            new Person() { FirstName = "Alice", LastName = "Cooper", Birthday = new JDate(2000, 1, 1)  },
            new Person() { FirstName = "Bob", LastName = "Silver", Birthday = new JDate(1992, 4, 5)  },
            new Person() { FirstName = "Sue", LastName = "Barnaby" }
        };

        grid = new Grid<Person>() { 
            Element = HtmlDocument.Current.GetElementById("grid"),
            Columns =
            {
                CreateColumn("First Name", delegate(Person person) { return person.FirstName; }),
                CreateColumn("Last Name", delegate(Person person) { return person.LastName; }),
                CreateColumn("Full Name", delegate(Person person) { return person.FullName; }),
                CreateColumn("Birtday", delegate(Person person) { return string.Format("{0:d}", person.Birthday); })
            },
            ClassName = "grid"
        };

        error = HtmlDocument.Current.GetElementById("error");
        HtmlWindow.Current.AdviseResize(Resize);
        Resize();
    }

    void Resize()
    {
        HtmlRect rc = grid.Element.GetBoundingClientRect();
        grid.Element.Style.Height = Math.Max(50, HtmlWindow.Current.InnerHeight - rc.Top - 70) + "px";
        grid.Element.Style.Width = Math.Max(50, HtmlWindow.Current.InnerWidth - 2 * rc.Left) + "px";
    }

    static GridColumn<Person> CreateColumn(string title, Func<Person, string> accessor)
    {
        return new GridColumn<Person>()
        {
            Width = 100,
            AllowResize = true,
            Header = new SortableTextColumnHeader() { Text = title },
            Renderer = delegate(HtmlElement outer, Person person, object state)
            {
                string text = person != null ? accessor(person) : null;
                if (text != state as string)
                {
                    outer.InnerText = text;
                }
                return text;
            }
        };

    }

    async void _ReceiveTypedArray()
    {
        try
        {
            ShowResult(new ObservableList<Person>(await CreateClient().GetPersons(request)), null);
        }
        catch(Exception e)
        {
            ShowResult(null, e);
        }
    }

    void _ReceiveTypedList()
    {
        CreateClient().GetPersons(request,
            delegate(ObservableList<Person> response)
            {
                ShowResult(response, null);
            },
            delegate(Exception e) { ShowResult(null, e); });
    }

    void ShowResult(IObservableList response, Exception e)
    {
        if (e == null)
        {
            error.Style.Display = StyleDisplay.None;
            grid.Element.Style.Display = StyleDisplay.Default;
            grid.DataSource = response;
        }
        else
        {
            error.Style.Display = StyleDisplay.Default;
            grid.Element.Style.Display = StyleDisplay.None;
            error.InnerText = e.ExtractAllMessages();

        }
    }

    static IServiceClient CreateClient()
    {
        if (((HtmlRadioButton)HtmlGlobal.document.GetElementById("soap11")).Checked)
        {
            return new Soap11Service<IServiceClient>() { Url = serviceUrl }.Proxy; 
        }

        if (((HtmlRadioButton)HtmlGlobal.document.GetElementById("soap12")).Checked)
        {
            return new Soap12Service<IServiceClient>() { Url = serviceUrl }.Proxy;
        }

        return new JsonService<IServiceClient>() { Url = serviceUrl }.Proxy;
    }

    public static void ReceiveTypedArray()
    {
        instance.Value._ReceiveTypedArray();
    }

    public static void ReceiveTypedList()
    {
        instance.Value._ReceiveTypedList();
    }

    public interface IServiceClient : IServiceClient<ObservableList<Person>, Person> { }
}

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow:hidden;width:100%;height:100%">
<head>
    <title>
        GenericService.html: Communication with service without DTOs.
    </title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="x-ua-compatible" content="IE=11;IE=10;IE=9;IE=8;IE=7" />
    <link rel="stylesheet" href="styles/grid.css" type="text/css" />
    <link rel="stylesheet" href="styles/summary.css" type="text/css" />
    <script type="text/javascript" language="javascript" src="js/GenericService.js?v4"></script>
</head>
<body scroll="no" style="overflow:hidden; margin-top:0 0 0 0;width:100%;height:100%">
    GenericService.html: Communication with service without DTOs. 
    <br />
    <input type="radio" id="soap11" name="protocol" /> <label for="soap11">Soap 1.1</label>
    <input type="radio" id="soap12" name="protocol" /> <label for="soap12">Soap 1.2</label>
    <input type="radio" id="json" name="protocol" checked="checked" /> <label for="json">Json</label>
    <input type="button" value="Receive typed array (await)" onclick="ReceiveTypedArray()" />
    <input type="button" value="Receive typed list" onclick="ReceiveTypedList()" />
    <div id="grid" class="gridOuter" style="overflow:hidden;width:100%;height:200px"></div>
    <div id="error" style="width:100%; overflow:hidden;display:none"></div>
</body>
</html>
© 2009 JScriptSuite. All rights reserved.