/// <summary>
 /// Gets a directory representing a root directory.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="path">
 /// The path of the root directory. If this is an absolute path,
 /// then a directory representing the specified path is returned.
 /// If it's a relative path, then it will be combined with the
 /// current root path. If this is <c>null</c> then the base
 /// root directory is returned.
 /// </param>
 /// <returns>A root directory.</returns>
 public static IDirectory GetRootDirectory(this IReadOnlyFileSystem fileSystem, NormalizedPath path)
 {
     _ = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     return(path.IsNull
         ? fileSystem.GetDirectory(fileSystem.RootPath)
         : fileSystem.GetDirectory(fileSystem.RootPath.Combine(path)));
 }
        /// <summary>
        /// Gets matching files based on globbing patterns and/or absolute paths. If any absolute paths
        /// are provided, only those that actually exist are returned.
        /// </summary>
        /// <param name="fileSystem">The file system.</param>
        /// <param name="directory">The directory to search.</param>
        /// <param name="patterns">The globbing patterns and/or absolute paths.</param>
        /// <returns>
        /// All files in the specified directory that match the globbing patterns and/or absolute paths.
        /// </returns>
        public static IEnumerable <IFile> GetFiles(this IReadOnlyFileSystem fileSystem, IDirectory directory, IEnumerable <string> patterns)
        {
            _ = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
            _ = directory ?? throw new ArgumentNullException(nameof(directory));

            IEnumerable <Tuple <IDirectory, string> > directoryPatterns = patterns
                                                                          .Where(x => x != null)
                                                                          .Select(x =>
            {
                bool negated        = x[0] == '!';
                NormalizedPath path = negated ? new NormalizedPath(x.Substring(1)) : new NormalizedPath(x);
                if (path.IsAbsolute)
                {
                    // The globber doesn't support absolute paths, so get the root directory of this path
                    IDirectory rootDirectory    = fileSystem.GetDirectory(path.Root);
                    NormalizedPath relativePath = path.RootRelative;
                    return(Tuple.Create(
                               rootDirectory,
                               negated ? ('!' + relativePath.FullPath) : relativePath.FullPath));
                }
                return(Tuple.Create(directory, x));
            });
            IEnumerable <IGrouping <IDirectory, string> > patternGroups = directoryPatterns
                                                                          .GroupBy(x => x.Item1, x => x.Item2, DirectoryEqualityComparer.Default);

            return(patternGroups.SelectMany(x => Globber.GetFiles(x.Key, x)));
        }
 /// <summary>
 /// Gets a directory representing an input.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="path">
 /// The path of the input directory. If this is an absolute path,
 /// then a directory representing the specified path is returned.
 /// If it's a relative path, then the returned directory will
 /// be a virtual directory that aggregates all input
 /// paths. If this is <c>null</c> then a virtual
 /// directory aggregating all input paths is returned.
 /// </param>
 /// <returns>An input directory.</returns>
 public static IDirectory GetInputDirectory(this IReadOnlyFileSystem fileSystem, NormalizedPath path)
 {
     _ = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     return(path.IsNull
         ? new VirtualInputDirectory(fileSystem, NormalizedPath.Dot)
         : (path.IsRelative ? new VirtualInputDirectory(fileSystem, path) : fileSystem.GetDirectory(path)));
 }
示例#4
0
        internal AssemblyLoader(IReadOnlyFileSystem fileSystem, IAssemblyCollection assemblyCollection, AssemblyResolver assemblyResolver)
        {
            _fileSystem = fileSystem;
            _assemblyCollection = assemblyCollection;
            _assemblyResolver = assemblyResolver;

            // Get the location of the entry assembly
            string entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location;
            DirectoryPath entryAssemblyPath = entryAssemblyLocation == null
                ? new DirectoryPath(Environment.CurrentDirectory)
                : new FilePath(entryAssemblyLocation).Directory;
            _entryAssemblyDirectory = _fileSystem.GetDirectory(entryAssemblyPath);

            // Add the Core modules
            DirectAssemblies.Add(Assembly.GetAssembly(typeof(Engine)));
        }
示例#5
0
        internal AssemblyLoader(IReadOnlyFileSystem fileSystem, AssemblyResolver assemblyResolver)
        {
            _fileSystem       = fileSystem;
            _assemblyResolver = assemblyResolver;

            // Get the location of the entry assembly
            string        entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location;
            DirectoryPath entryAssemblyPath     = entryAssemblyLocation == null
                ? new DirectoryPath(Environment.CurrentDirectory)
                : new FilePath(entryAssemblyLocation).Directory;

            _entryAssemblyDirectory = _fileSystem.GetDirectory(entryAssemblyPath);

            // Add the Core modules
            DirectAssemblies.Add(Assembly.GetAssembly(typeof(Engine)));
        }
示例#6
0
        private void LoadAssembliesByPath()
        {
            // Get path to all assemblies (except those specified by name)
            string        entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location;
            DirectoryPath entryAssemblyPath     = entryAssemblyLocation == null
                ? new DirectoryPath(Environment.CurrentDirectory)
                : new FilePath(entryAssemblyLocation).Directory;
            IDirectory      entryAssemblyDirectory = _fileSystem.GetDirectory(entryAssemblyPath);
            List <FilePath> assemblyPaths          = _fileSystem
                                                     .GetFiles(entryAssemblyDirectory, _patterns)
                                                     .Where(x => x.Path.Extension == ".dll" || x.Path.Extension == ".exe")
                                                     .Select(x => x.Path)
                                                     .ToList();

            // Add all paths to the PrivateBinPath search location (to ensure they load in the default context)
            AppDomain.CurrentDomain.SetupInformation.PrivateBinPath =
                string.Join(";",
                            new[] { AppDomain.CurrentDomain.SetupInformation.PrivateBinPath }
                            .Concat(assemblyPaths.Select(x => x.Directory.FullPath).Distinct())
                            .Distinct());

            foreach (string assemblyPath in assemblyPaths.Select(x => x.FullPath).Distinct())
            {
                try
                {
                    using (Trace.WithIndent().Verbose("Loading assembly file {0}", assemblyPath))
                    {
                        AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
                        Assembly     assembly     = Assembly.Load(assemblyName);
                        if (!_assemblies.Add(assembly))
                        {
                            Trace.Verbose("Skipping assembly file {0} because it was already added", assemblyPath);
                        }
                        else
                        {
                            _moduleAssemblies.Add(assembly);
                            LoadReferencedAssemblies(assembly.GetReferencedAssemblies());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.Verbose("{0} exception while loading assembly file {1}: {2}", ex.GetType().Name, assemblyPath, ex.Message);
                }
            }
        }
 /// <summary>
 /// Gets a directory representing temp files.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="path">
 /// The path of the temp directory. If this is an absolute path,
 /// then a directory representing the specified path is returned.
 /// If it's a relative path, then it will be combined with the
 /// current temp path. If this is <c>null</c> then the base
 /// temp directory is returned.
 /// </param>
 /// <returns>A temp directory.</returns>
 public static IDirectory GetTempDirectory(this IReadOnlyFileSystem fileSystem, NormalizedPath path)
 {
     _ = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     return(fileSystem.GetDirectory(fileSystem.GetTempPath(path)));
 }