public ScriptScope UseFile(string path) {
ContractUtils.RequiresNotEmpty(path, "path");
string extension = Path.GetExtension(path);
ScriptEngine engine;
if (!TryGetEngineByFileExtension(extension, out engine)) {
throw new ArgumentException(string.Format("File extension '{0}' is not associated with any language.", extension));
}
var searchPaths = engine.GetSearchPaths();
if (searchPaths.Count == 0) {
throw new InvalidOperationException(string.Format("No search paths defined for language '{0}'", engine.Setup.DisplayName));
}
// See if the file is already loaded, if so return the scope
foreach (string searchPath in searchPaths) {
string filePath = Path.Combine(searchPath, path);
ScriptScope scope = engine.GetScope(filePath);
if (scope != null) {
return scope;
}
}
// Find the file on disk, then load it
foreach (string searchPath in searchPaths) {
string filePath = Path.Combine(searchPath, path);
if (_manager.Platform.FileExists(filePath)) {
return ExecuteFile(filePath);
}
}
// Didn't find the file, throw
string allPaths = searchPaths.Aggregate((x, y) => x + ", " + y);
throw new FileNotFoundException(string.Format("File '{0}' not found in language's search path: {1}", path, allPaths));
}