private MsieJsEngine SetupJsEngine() { var jsEngine = new MsieJsEngine(); try { using (var sr = new StreamReader( typeof(TypeScriptParserTests).Assembly.GetManifestResourceStream( "Serenity.Test.CodeGeneration.TypeScriptParserTests.json2.min.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } using (var sr = new StreamReader( typeof(TypeScriptParserTests).Assembly.GetManifestResourceStream( "Serenity.Test.CodeGeneration.TypeScriptParserTests.typescriptServices.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } using (var sr = new StreamReader( typeof(DtoGenerator).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.tsservices.Serenity.CodeGeneration.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return(jsEngine); } catch { jsEngine.Dispose(); throw; } }
private MsieJsEngine SetupJsEngine() { var jsEngine = new MsieJsEngine(); try { using (var sr = new StreamReader( typeof(TypeScriptParserTests).Assembly.GetManifestResourceStream( "Serenity.Test.CodeGeneration.TypeScriptParserTests.typescriptServices.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } using (var sr = new StreamReader( typeof(DtoGenerator).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.tsservices.Serenity.CodeGeneration.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return jsEngine; } catch { jsEngine.Dispose(); throw; } }
private static MsieJsEngine SetupJsEngine() { MsieJsEngine jsEngine; try { jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.ChakraIeJsRt }); } catch { jsEngine = new MsieJsEngine(); } try { using (var sr = new StreamReader( typeof(ScriptBundleManager).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.optimization.uglifyjs.min.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return(jsEngine); } catch { jsEngine.Dispose(); throw; } }
public virtual void TearDown() { if (_jsEngine != null) { _jsEngine.Dispose(); _jsEngine = null; } }
public void TearDown() { if (_msieJsEngine != null) { _msieJsEngine.Dispose(); _msieJsEngine = null; } }
/// <summary> /// Destroys object /// </summary> /// <param name="disposing">Flag, allowing destruction of /// managed objects contained in fields of class</param> private void Dispose(bool disposing) { if (!_disposed) { _disposed = true; if (_jsEngine != null) { _jsEngine.Dispose(); } } }
private static MsieJsEngine SetupJsEngine() { var jsEngine = new MsieJsEngine(); try { using (var sr = new StreamReader( typeof(ScriptBundleManager).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.optimization.uglifyjs.min.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return jsEngine; } catch { jsEngine.Dispose(); throw; } }
public static void Initialize() { if (isInitialized) { return; } isInitialized = true; isEnabled = false; bundleKeyBySourceUrl = null; bundleByKey = null; MsieJsEngine jsEngine = null; try { var settings = JsonConvert.DeserializeObject <ScriptBundlingSettings>( ConfigurationManager.AppSettings["ScriptBundling"].TrimToNull() ?? "{}", JsonSettings.Tolerant); if (settings == null || settings.Enabled != true) { return; } var bundles = ScriptBundles; if (bundles == null || bundles.Count == 0) { return; } var bundleKeyBySourceUrlNew = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var bundleByKeyNew = new Dictionary <string, ConcatenatedScript>(StringComparer.OrdinalIgnoreCase); bool minimize = settings.Minimize == true; foreach (var pair in bundles) { var sourceFiles = pair.Value; if (sourceFiles == null || sourceFiles.Length == 0) { continue; } var bundleKey = pair.Key; var bundleName = "Bundle." + bundleKey; var bundleParts = new List <Func <string> >(); foreach (var sourceFile in sourceFiles) { if (sourceFile.IsNullOrEmpty()) { continue; } string sourceUrl = ExpandVersionVariable(sourceFile); sourceUrl = VirtualPathUtility.ToAbsolute(sourceUrl); if (sourceUrl.IsNullOrEmpty()) { continue; } bundleKeyBySourceUrlNew[sourceUrl] = bundleKey; bundleParts.Add(() => { if (HttpContext.Current == null) { return(String.Format(errorLines, "Tried to generate script while HttpContext is null")); } var sourcePath = HttpContext.Current.Server.MapPath(sourceUrl); if (!File.Exists(sourcePath)) { return(String.Format(errorLines, String.Format("File {0} is not found!", sourcePath))); } if (minimize) { if (settings.UseMinJS == true) { var minPath = Path.ChangeExtension(sourcePath, ".min.js"); if (File.Exists(minPath)) { sourcePath = minPath; using (StreamReader sr = new StreamReader(sourcePath)) return(sr.ReadToEnd()); } } string code; using (StreamReader sr = new StreamReader(sourcePath)) code = sr.ReadToEnd(); try { return(MinimizeWithUglifyJS(ref jsEngine, code)); } catch (Exception ex) { ex.Log(); return(code); } } using (StreamReader sr = new StreamReader(sourcePath)) return(sr.ReadToEnd()); }); } var bundle = new ConcatenatedScript(bundleParts); DynamicScriptManager.Register(bundleName, bundle); bundleByKeyNew[bundleKey] = bundle; } bundleKeyBySourceUrl = bundleKeyBySourceUrlNew; bundleByKey = bundleByKeyNew; isEnabled = true; } catch (Exception ex) { ex.Log(); } finally { if (jsEngine != null) { jsEngine.Dispose(); } } }
public void Dispose() { _engine.Dispose(); }