public static bool Scan(IEnumerable <string> directories, IEnumerable <string> workspaceTypeDirectories, out List <string> directoriesWithTypes, out List <string> errors) { bool success = true; AppDomain newDomain = null; errors = null; try { var libraryHelper = new TraceLab.Core.Components.LibraryHelper(workspaceTypeDirectories); newDomain = libraryHelper.CreateDomain("WorkspaceTypeScanner", false); newDomain.Load(Assembly.GetExecutingAssembly().GetName()); // Preload the workspace types so that the component scanner won't barf when a component references a workspace type. libraryHelper.PreloadWorkspaceTypes(newDomain); WorkspaceTypeScanner scanner = (WorkspaceTypeScanner)newDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(WorkspaceTypeScanner).FullName); scanner.Scan(directories); errors = new List <string>(scanner.Errors); foreach (string error in errors) { NLog.LogManager.GetCurrentClassLogger().Warn(error); } // Copy the list so we only get a single AppDomain thunk directoriesWithTypes = new List <string>(scanner.TypeDirectories); } catch (Exception e) { success = false; directoriesWithTypes = new List <string>(); errors = errors ?? new List <string>(); errors.Add(e.Message); } finally { if (newDomain != null) { AppDomain.Unload(newDomain); } } return(success); }
public static bool Scan(IEnumerable<string> directories, IEnumerable<string> workspaceTypeDirectories, out List<string> directoriesWithTypes, out List<string> errors) { bool success = true; AppDomain newDomain = null; errors = null; try { var libraryHelper = new TraceLab.Core.Components.LibraryHelper(workspaceTypeDirectories); newDomain = libraryHelper.CreateDomain("WorkspaceTypeScanner", false); newDomain.Load(Assembly.GetExecutingAssembly().GetName()); // Preload the workspace types so that the component scanner won't barf when a component references a workspace type. libraryHelper.PreloadWorkspaceTypes(newDomain); WorkspaceTypeScanner scanner = (WorkspaceTypeScanner)newDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(WorkspaceTypeScanner).FullName); scanner.Scan(directories); errors = new List<string>(scanner.Errors); foreach (string error in errors) { NLog.LogManager.GetCurrentClassLogger().Warn(error); } // Copy the list so we only get a single AppDomain thunk directoriesWithTypes = new List<string>(scanner.TypeDirectories); } catch (Exception e) { success = false; directoriesWithTypes = new List<string>(); errors = errors ?? new List<string>(); errors.Add(e.Message); } finally { if (newDomain != null) { AppDomain.Unload(newDomain); } } return success; }