.NET to Javascript compiler

C# code   Html page   Start
class BlobRequestApp
{
    readonly static HtmlLazy<BlobRequestApp> instance = new DefaultHtmlLazy<BlobRequestApp>();

    HtmlInputFileElement file = (HtmlInputFileElement)HtmlDocument.Current.GetElementById("file");
    HtmlElement status = HtmlDocument.Current.GetElementById("status");
    HtmlElement statusText = HtmlDocument.Current.GetElementById("statusText");
    HtmlElement length = HtmlDocument.Current.GetElementById("length");
    HtmlElement type = HtmlDocument.Current.GetElementById("type");
    Control response = new Control() { Element = HtmlDocument.Current.GetElementById("response") };

    public BlobRequestApp()
    {
        file.AdviseChange(SendReceiveBlob);
    }

    public static void Start()
    {
        Dummies.Action(instance.Value);
    }

    public static void SendReceiveArrayBuffer()
    {
        instance.Value.SendArrayBuffer(instance.Value.ReceiveArrayBuffer);
    }

    public static void SendReceiveBlob()
    {
        instance.Value.SendBlob(instance.Value.ReceiveBlob);
    }

    public static void SendBlobReceiveString()
    {
        instance.Value.SendBlob(instance.Value.ReceiveString);
    }


    File FetchFile()
    {
        status.InnerText = null;
        statusText.InnerText = null;
        length.InnerText = null;
        type.InnerText = null;
        response.InnerText = null;

        if (this.file.Files == null)
        {
            statusText.InnerText = "Browser does not support file list";
        }
        else if (this.file.Files.Length == 0)
        {
            statusText.InnerText = "Please select file";
        }
        else
        {
            File file = this.file.Files[0];
            statusText.InnerText = string.Format("Sending {0} ..", file.Name);
            length.InnerText = string.Format("Sent {0:N0} bytes", file.Size);
            type.InnerText = file.Type;
            return file;
        }

        return null;
    }

    void ShowError(Exception e)
    {
        WebRequestException wre = (WebRequestException)e.FindKnownException(typeof(WebRequestException));
        string responseText = null;
        if (wre != null)
        {
            status.InnerText = wre.Status.ToString();
            statusText.InnerText = wre.Message;
            responseText = "\r\n" + wre.ResponseText;
        }

        response.InnerText = e.ExtractAllMessages() + responseText;
    }

    void ShowSuccess(IWebResponse response, long size)
    {
        status.InnerText = response.Status.ToString();
        statusText.InnerText = response.StatusText;
        this.response.InnerText = string.Format("Received {0:N0} bytes", size);
    }

    void SendArrayBuffer(Action<WebRequest> sender)
    {

        File file = FetchFile();
        if (file != null)
        {
            if (SupportedHtml5Features.BlobRead)
            {
                file.ReadAsArrayBuffer(
                    delegate (ArrayBuffer arrayBuffer)
                    {
                        ArrayBufferWebRequest request = new ArrayBufferWebRequest()
                        {
                            Body = arrayBuffer
                        };

                        InitRequest(request, file);
                        sender(request);
                    },
                    ShowError);
            }
            else
            {
                ShowError(new NotSupportedException("Browser does not support blob reader"));
            }
        }
    }

    void ReceiveArrayBuffer(WebRequest request)
    {
        if (SupportedHtml5Features.ResponseArrayBuffer)
        {
            request.GetArrayBuffer(
            delegate (IWebResponse<ArrayBuffer> response)
            {
                ShowSuccess(response, response.Response.ByteLength);
            },
            ShowError);
        }
        else
        {
            ShowError(new NotSupportedException("Browser can not reaceive array buffer"));
        }
    }

    void SendBlob(Action<WebRequest> sender)
    {
        File file = FetchFile();
        if (file != null)
        {

            BlobWebRequest request = new BlobWebRequest()
            {
                Body = file
            };

            InitRequest(request, file);
            sender(request);
        }
    }

    void ReceiveBlob(WebRequest request)
    {
        if (SupportedHtml5Features.ResponseBlob)
        {
            request.GetBlob(
                delegate (IWebResponse<Blob> response)
                {
                    ShowSuccess(response, response.Response.Size);
                },
                ShowError);
        }
        else
        {
            ShowError(new NotSupportedException("Browser can not receive blob"));
        }
    }


    void ReceiveString(WebRequest request)
    {
        request.GetString(
            delegate (IWebResponse<string> response)
            {
                status.InnerText = response.Status.ToString();
                statusText.InnerText = response.StatusText;
                this.response.InnerText = response.Response;
            },
            ShowError);
    }

    static void InitRequest(WebRequest request, File file)
    {
        request.Url = "../Services/upload.ashx";
        request.Method = "PUT";
        request.Headers["CONTENT-TYPE"] = file.Type;
    }
}

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <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" />
    <title>BlobRequest.html: Blob transfer by WebpRequest</title>
    <script type="text/javascript" language="javascript" src="js/BlobRequest.js?v2"></script>
</head>
<body onload="javascript:StartScript()">
    BlobRequest.html: Blob transfer by WebpRequest
    <input type="file" id="file" />
    <input type="button" value="Send/Receive ArrayBuffer" onclick="SendReceiveArrayBuffer()" />
    <input type="button" value="Send/Receive Blob" onclick="SendReceiveBlob()" />
    <input type="button" value="Send Blob/Receive String" onclick="SendBlobReceiveString()" />

    <table cellpadding="2" cellspacing="0">
        <tr>
            <th>Status</th>
            <td id="status"></td>
        </tr>
        <tr>
            <th>Status</th>
            <td id="statusText"></td>
        </tr>
        <tr>
            <th>Length</th>
            <td id="length"></td>
        </tr>
        <tr>
            <th>Type</th>
            <td id="type"></td>
        </tr>
        <tr>
            <th>Response</th>
            <td id="response"></td>
        </tr>
    </table>
</body>
</html>
© 2009 JScriptSuite. All rights reserved.