示例#1
0
        protected void Translate(string csCode)
        {
            #if DEBUG
                this.isDebugMode = true;
            #endif

            string json = "{}";

            try
            {
                string bridgeStubLocation = (this.isDebugMode) ? this.context.Server.MapPath("~") + @"..\LiveApp\bin\Debug\LiveApp.dll" : this.context.Server.MapPath(@".\Bridge\Builder\LiveApp.dll");

                LiveTranslator translator =
                    new LiveTranslator(
                        this.context.Server.MapPath(@"."),
                        csCode,
                        false,
                        bridgeStubLocation,
                        HttpContext.Current);

                string jsCode = translator.Translate();

                string hash = jsCode.GetHashCode().ToString();

                json = JsonConvert.SerializeObject(new
                {
                    Success = true,
                    JsCode = jsCode,
                    Hash = hash
                });

                // store emitted javascript to session with its hash as key.
                this.context.Session[hash] = jsCode;
            }
            catch (Exception ex)
            {
                json = JsonConvert.SerializeObject(new
                {
                    Success = false,
                    ErrorMessage = ex.Message
                });
            }
            finally
            {
                this.context.Response.Write(json);
            }
        }
示例#2
0
        protected void Translate(string csCode)
        {
            #if DEBUG
            this.isDebugMode = true;
            #endif

            string json = "{}";

            try
            {
                string bridgeStubLocation = (this.isDebugMode) ? this.context.Server.MapPath("~") + @"..\LiveApp\bin\Debug\LiveApp.dll" : this.context.Server.MapPath(@".\Bridge\Builder\LiveApp.dll");

                LiveTranslator translator =
                    new LiveTranslator(
                        this.context.Server.MapPath(@"."),
                        csCode,
                        false,
                        bridgeStubLocation,
                        HttpContext.Current);

                string jsCode = translator.Translate();

                string hash = jsCode.GetHashCode().ToString();

                json = JsonConvert.SerializeObject(new
                {
                    Success = true,
                    JsCode  = jsCode,
                    Hash    = hash
                });

                // store emitted javascript to session with its hash as key.
                this.context.Session[hash] = jsCode;
            }
            catch (Exception ex)
            {
                json = JsonConvert.SerializeObject(new
                {
                    Success      = false,
                    ErrorMessage = ex.Message
                });
            }
            finally
            {
                this.context.Response.Write(json);
            }
        }