public DynamicScriptTags(DynamicLanguageConfig langConfig) { RunningScriptTags = false; _LangConfig = langConfig; Code = new List <ScriptCode>(); ZipPackages = new List <Uri>(); }
/// <summary> /// Pre-conditions: langConfig is the set of languages used to detect /// the entry point. /// Post-conditions: Returns the entryPoint's path as a string. /// It may still be null if the entry-point was not /// found. An exception is thrown if multiple entry /// points are found. /// </summary> private static string FindEntryPoint(DynamicLanguageConfig langConfig) { string entryPoint = null; foreach (var lang in langConfig.Languages) { foreach (var ext in lang.Extensions) { var file = Settings.DefaultEntryPoint + ext; var tempStream = BrowserPAL.PAL.VirtualFilesystem.GetFile(file); if (tempStream != null) { if (entryPoint != null) { throw new ApplicationException(string.Format( "Application can only have one entry point, but found two: {0}, {1}", _entryPoint, file )); } entryPoint = file; } } } return(entryPoint); }
/// <summary> /// Given a language config it processes the script-tags on the HTML /// page (see "GetScriptTags"). /// </summary> public DynamicScriptTags(DynamicLanguageConfig langConfig) { RunningScriptTags = false; _LangConfig = langConfig; Code = new List <ScriptCode>(); GetScriptTags(); }
public DynamicScriptTags(DynamicLanguageConfig langConfig) { RunningScriptTags = false; _LangConfig = langConfig; Code = new List<ScriptCode>(); ZipPackages = new List<Uri>(); }
public static void Load(DynamicLanguageConfig langConfig) { foreach (var pair in langConfig.LanguagesUsed) { if (pair.Value) { var lang = langConfig.GetLanguageByName(pair.Key); LanguageTypeExtensions.LoadByExtension(lang.Extensions[0]); } } }
/// <summary> /// Initializes the languages, ScriptRuntime, and entry-point ScriptScope. /// </summary> public DynamicEngine(DynamicLanguageConfig langConfig) { if (langConfig == null) { InitializeLangConfig(); } else { LangConfig = langConfig; } InitializeRuntime(Settings.Debug); InitializeScope(); }
/// <summary> /// Creates a new ScriptRuntimeSetup, given a language config. /// </summary> /// <param name="langConfig">Use this language config to generate the setup</param> /// <param name="debugMode">Tells the setup to generate debuggable code</param> /// <returns>new ScriptRuntimeSetup</returns> public static ScriptRuntimeSetup CreateRuntimeSetup(bool debugMode, DynamicLanguageConfig langConfig) { var setup = langConfig.CreateRuntimeSetup(); setup.HostType = typeof(BrowserScriptHost); setup.Options["SearchPaths"] = new string[] { String.Empty }; setup.DebugMode = debugMode; return(setup); }
/// <summary> /// Initializes the languages, ScriptRuntime, and entry-point ScriptScope. /// </summary> public DynamicEngine(DynamicLanguageConfig langConfig) { RunningEntryPoint = false; if (langConfig == null) { LangConfig = InitializeLangConfig(); } else { LangConfig = langConfig; } Runtime = CreateRuntime(Settings.Debug, LangConfig); Runtime.LoadAssembly(GetType().Assembly); LangConfig.Runtime = Runtime; RuntimeSetup = Runtime.Setup; EntryPointScope = CreateScope(Runtime); }
/// <summary> /// Called by Silverlight host when it instantiates our application /// </summary> public DynamicApplication() { if (_Current != null) { throw new Exception("Only one instance of DynamicApplication can be created"); } _Current = this; _UIThreadId = Thread.CurrentThread.ManagedThreadId; _HtmlPageUri = HtmlPageUri; Settings.ReportUnhandledErrors = true; AppManifest = new DynamicAppManifest(); LanguagesConfig = DynamicLanguageConfig.Create(AppManifest.Assemblies); Startup += new StartupEventHandler(DynamicApplication_Startup); }
/// <summary> /// Loads the configuration from a list of assemblies /// </summary> public static DynamicLanguageConfig LoadFromAssemblies(IEnumerable <Assembly> assemblies) { var dl = new DynamicLanguageConfig(); foreach (var assembly in assemblies) { foreach (DynamicLanguageProviderAttribute attribute in assembly.GetCustomAttributes(typeof(DynamicLanguageProviderAttribute), false)) { dl.Languages.Add(new DynamicLanguageInfo( attribute.Names, attribute.LanguageContextType.AssemblyQualifiedName, new string[] { assembly.ManifestModule.ToString() }, attribute.FileExtensions, null )); } } return(dl); }
/// <summary> /// Gets and validates the entry-point. /// Pre-conditions: entryPoint is the path to validate /// langConfig is the list of languages used to detect /// the entry point. scriptTags track the <script> /// blocks on the HTML page. /// Post-conditions: returns the name of the validated entry-point. The /// return value can be null if no valid entry-point /// exists while there exists a inline script-tag. /// The language of the entry-point is marked as "used" /// in langConfig. /// </summary> private static string GetAndValidateEntryPoint (string entryPoint, DynamicLanguageConfig langConfig, DynamicScriptTags scriptTags) { if (entryPoint == null) { entryPoint = FindEntryPoint(langConfig); } else { var vfs = BrowserPAL.PAL.VirtualFilesystem; var stream = vfs.GetFile(entryPoint); if (stream == null) { throw new ApplicationException( string.Format( "Application expected to have an entry point called {0}, but was not found (check the {1})", entryPoint, BrowserPAL.PAL.VirtualFilesystem.Name())); } } if (entryPoint != null) { var entryPointExt = Path.GetExtension(entryPoint); foreach (var lang in langConfig.Languages) { foreach (var ext in lang.Extensions) { if (entryPointExt == ext) { langConfig.LanguagesUsed[lang.Names[0].ToLower()] = true; break; } } } } return(entryPoint); }
/// <summary> /// Creates a new ScriptRuntimeSetup, given a language config. /// </summary> /// <param name="langConfig">Use this language config to generate the setup</param> /// <param name="debugMode">Tells the setup to generate debuggable code</param> /// <returns>new ScriptRuntimeSetup</returns> public static ScriptRuntimeSetup CreateRuntimeSetup(bool debugMode, DynamicLanguageConfig langConfig) { var setup = langConfig.CreateRuntimeSetup(); setup.HostType = typeof(BrowserScriptHost); setup.Options["SearchPaths"] = new string[] { String.Empty }; setup.DebugMode = debugMode; return setup; }
/// <summary> /// Loads the configuration from the languages config file. /// </summary> public static DynamicLanguageConfig LoadFromConfiguration() { Stream configFile = BrowserPAL.PAL.VirtualFilesystem.GetFile(Settings.LanguagesConfigFile); if (configFile == null) { return(null); } var dl = new DynamicLanguageConfig(); try { XmlReader reader = XmlReader.Create(configFile); reader.MoveToContent(); if (!reader.IsStartElement("Languages")) { throw new ConfigFileException("expected 'Configuration' root element", Settings.LanguagesConfigFile); } while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element || reader.Name != "Language") { continue; } string context = null, asms = null, exts = null, names = null, external = null; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "names": names = reader.Value; break; case "languageContext": context = reader.Value; break; case "assemblies": asms = reader.Value; break; case "extensions": exts = reader.Value; break; case "external": external = reader.Value; break; } } if (context == null || asms == null || exts == null || names == null || external == null) { throw new ConfigFileException("expected 'Language' element to have attributes 'languageContext', 'assemblies', 'extensions', 'names', 'external'", Settings.LanguagesConfigFile); } char[] splitChars = new char[] { ' ', '\t', ',', ';', '\r', '\n' }; string[] assemblies = asms.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); string[] splitNames = names.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); string contextAssembly = assemblies[0].Split('.')[0]; foreach (Assembly asm in DynamicApplication.Current.AppManifest.Assemblies) { if (asm.FullName.Contains(contextAssembly)) { contextAssembly = asm.FullName; break; } } dl.Languages.Add(new DynamicLanguageInfo( splitNames, context + ", " + contextAssembly, assemblies, exts.Split(splitChars, StringSplitOptions.RemoveEmptyEntries), external )); } } catch (ConfigFileException cfe) { throw cfe; } catch (Exception ex) { throw new ConfigFileException(ex.Message, Settings.LanguagesConfigFile, ex); } return(dl); }
/// <summary> /// Loads the configuration from the languages config file. /// </summary> public static DynamicLanguageConfig LoadFromConfiguration() { Stream configFile = BrowserPAL.PAL.VirtualFilesystem.GetFile(Settings.LanguagesConfigFile); if (configFile == null) return null; var dl = new DynamicLanguageConfig(); try { XmlReader reader = XmlReader.Create(configFile); reader.MoveToContent(); if (!reader.IsStartElement("Languages")) { throw new ConfigFileException("expected 'Configuration' root element", Settings.LanguagesConfigFile); } while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element || reader.Name != "Language") { continue; } string context = null, asms = null, exts = null, names = null, external = null; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "names": names = reader.Value; break; case "languageContext": context = reader.Value; break; case "assemblies": asms = reader.Value; break; case "extensions": exts = reader.Value; break; case "external": external = reader.Value; break; } } if (context == null || asms == null || exts == null || names == null || external == null) { throw new ConfigFileException("expected 'Language' element to have attributes 'languageContext', 'assemblies', 'extensions', 'names', 'external'", Settings.LanguagesConfigFile); } char[] splitChars = new char[] { ' ', '\t', ',', ';', '\r', '\n' }; string[] assemblies = asms.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); string[] splitNames = names.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); string contextAssembly = assemblies[0].Split('.')[0]; foreach (Assembly asm in DynamicApplication.Current.AppManifest.Assemblies) { if (asm.FullName.Contains(contextAssembly)) { contextAssembly = asm.FullName; break; } } dl.Languages.Add(new DynamicLanguageInfo( splitNames, context + ", " + contextAssembly, assemblies, exts.Split(splitChars, StringSplitOptions.RemoveEmptyEntries), external )); } } catch (ConfigFileException cfe) { throw cfe; } catch (Exception ex) { throw new ConfigFileException(ex.Message, Settings.LanguagesConfigFile, ex); } return dl; }
/// <summary> /// Loads the configuration from a list of assemblies /// </summary> public static DynamicLanguageConfig LoadFromAssemblies(IEnumerable<Assembly> assemblies) { var dl = new DynamicLanguageConfig(); foreach (var assembly in assemblies) { foreach (DynamicLanguageProviderAttribute attribute in assembly.GetCustomAttributes(typeof(DynamicLanguageProviderAttribute), false)) { dl.Languages.Add(new DynamicLanguageInfo( attribute.Names, attribute.LanguageContextType.AssemblyQualifiedName, new string[] { assembly.ManifestModule.ToString() }, attribute.FileExtensions, null )); } } return dl; }
/// <summary> /// Pre-conditions: langConfig is the set of languages used to detect /// the entry point. /// Post-conditions: Returns the entryPoint's path as a string. /// It may still be null if the entry-point was not /// found. An exception is thrown if multiple entry /// points are found. /// </summary> private static string FindEntryPoint(DynamicLanguageConfig langConfig) { string entryPoint = null; foreach (var lang in langConfig.Languages) { foreach (var ext in lang.Extensions) { var file = Settings.DefaultEntryPoint + ext; var tempStream = BrowserPAL.PAL.VirtualFilesystem.GetFile(file); if (tempStream != null) { if (entryPoint != null) { throw new ApplicationException(string.Format( "Application can only have one entry point, but found two: {0}, {1}", _entryPoint, file )); } entryPoint = file; } } } return entryPoint; }
/// <summary> /// Gets and validates the entry-point. /// Pre-conditions: entryPoint is the path to validate /// langConfig is the list of languages used to detect /// the entry point. scriptTags track the <script> /// blocks on the HTML page. /// Post-conditions: returns the name of the validated entry-point. The /// return value can be null if no valid entry-point /// exists while there exists a inline script-tag. /// The language of the entry-point is marked as "used" /// in langConfig. /// </summary> private static string GetAndValidateEntryPoint (string entryPoint, DynamicLanguageConfig langConfig, DynamicScriptTags scriptTags) { if (entryPoint == null) { entryPoint = FindEntryPoint(langConfig); } else { var vfs = BrowserPAL.PAL.VirtualFilesystem; var stream = vfs.GetFile(entryPoint); if (stream == null) { throw new ApplicationException( string.Format( "Application expected to have an entry point called {0}, but was not found (check the {1})", entryPoint, BrowserPAL.PAL.VirtualFilesystem.Name())); } } if(entryPoint != null) { var entryPointExt = Path.GetExtension(entryPoint); foreach (var lang in langConfig.Languages) { foreach (var ext in lang.Extensions) { if (entryPointExt == ext) { langConfig.LanguagesUsed[lang.Names[0].ToLower()] = true; break; } } } } return entryPoint; }
/// <summary> /// Given a language config it processes the script-tags on the HTML /// page (see "GetScriptTags"). /// </summary> public DynamicScriptTags(DynamicLanguageConfig langConfig) { RunningScriptTags = false; _LangConfig = langConfig; Code = new List<ScriptCode>(); GetScriptTags(); }
public static ScriptRuntime CreateRuntime(bool debugMode, DynamicLanguageConfig langConfig) { return CreateRuntimeHelper(CreateRuntimeSetup(debugMode, langConfig)); }
/// <summary> /// Creates a new ScriptRuntimeSetup, given a list of assemblies. /// </summary> /// <param name="assemblies">List of assemblies to find DLR's language configuration</param> /// <returns>new ScriptRuntimeSetup</returns> public static ScriptRuntimeSetup CreateRuntimeSetup(List <Assembly> assemblies) { return(CreateRuntimeSetup(Settings.Debug, DynamicLanguageConfig.LoadFromAssemblies(assemblies))); }
/// <summary> /// Create a new language config /// </summary> private static DynamicLanguageConfig CreateLangConfig() { return(DynamicLanguageConfig.Create(new DynamicAppManifest().Assemblies)); }
/// <summary> /// Creates a new ScriptRuntimeSetup. /// </summary> /// <param name="debugMode">Tells the setup to generate debuggable code</param> /// <returns>new ScriptRuntimeSetup</returns> public static ScriptRuntimeSetup CreateRuntimeSetup(bool debugMode) { DynamicLanguageConfig langConfig = CreateLangConfig(); return(CreateRuntimeSetup(debugMode, langConfig)); }
public static ScriptRuntime CreateRuntime(bool debugMode, DynamicLanguageConfig langConfig) { return(CreateRuntimeHelper(CreateRuntimeSetup(debugMode, langConfig))); }
/// <summary> /// Given a language config it processes the script-tags on the HTML /// page (see "GetScriptTags"). /// </summary> public DynamicScriptTags(DynamicLanguageConfig langConfig) { _LangConfig = langConfig; Code = new Dictionary<string, Dictionary<bool, ScriptCode>>(); GetScriptTags(); }