/// <summary> /// The main entry point for the application. /// </summary> private static void Main() { _log = new GorgonLog("FolderFileSystem", "Tape_Worm"); _log.LogStart(); try { Console.WindowHeight = 26.Max(Console.WindowHeight); Console.BufferHeight = Console.WindowHeight; // Create a new file system. _fileSystem = new GorgonFileSystem(_log); // Set the following directory as root on the virtual file system. // To mount a directory we need to put in the trailing slash. // // If we wanted to, we could mount a directory as a sub directory of // the root of the virtual file system. For example, mounting the // directory D:\Dir with Mount(@"D:\Dir", "/VFSDir"); would mount the // contents of the D:\Dir directory under /VFSDir. // // It's also important to point out that the old Gorgon "file system" // would load files from the system into memory when mounting a // directory. While this version only loads directory and file // information when mounting. This is considerably more efficient. string physicalPath = GetResourcePath(@"FolderSystem\"); _fileSystem.Mount(physicalPath); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("This example will mount a physical file system directory as the root of a"); Console.WriteLine("virtual file system. The virtual file system is capable of mounting various"); Console.WriteLine("types of data such as a zip file, a file system folder, etc... as the root or a"); Console.WriteLine("sub directory. You can even mount a zip file as the root, and a physical file"); Console.WriteLine("system directory as a virtual sub directory in the same virtual file system and"); Console.WriteLine("access them as a single unified file system."); Console.Write("\nMounted: "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("'{0}'", physicalPath.Ellipses(Console.WindowWidth - 20, true)); Console.ForegroundColor = ConsoleColor.White; Console.Write(" as "); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("'/'\n"); Console.ForegroundColor = ConsoleColor.White; // Get a count of all sub directories and files under the root directory. IGorgonVirtualDirectory[] directoryList = _fileSystem.FindDirectories("*").ToArray(); // Display directories. Console.WriteLine("Virtual file system contents:"); for (int i = -1; i < directoryList.Length; i++) { IGorgonVirtualDirectory directory = _fileSystem.RootDirectory; // Go into the sub directories under root. if (i > -1) { directory = directoryList[i]; } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("{0}", directory.FullPath); Console.ForegroundColor = ConsoleColor.Yellow; foreach (IGorgonVirtualFile file in directory.Files) { Console.Write(" {0}", file.Name); // Align the size to the same place. Console.CursorLeft = 65; Console.WriteLine("{0}", file.Size.FormatMemory()); } } Console.ResetColor(); Console.WriteLine("\nPress any key to close."); Console.ReadKey(); } catch (Exception ex) { ex.Catch(_ => { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", _.Message, _.StackTrace); Console.ResetColor(); #if DEBUG Console.ReadKey(); #endif }, _log); } finally { _log.LogEnd(); } }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main() { _log = new GorgonLog("FileSystemProviders", "Tape_Worm"); _log.LogStart(); // Create a plugin assembly cache to hold our plugin assemblies. _pluginAssemblies = new GorgonMefPlugInCache(_log); // Create the plugin service. _pluginService = new GorgonMefPlugInService(_pluginAssemblies); try { Console.WriteLine("Gorgon is capable of mounting virtual file systems for file access. A virtual"); Console.WriteLine("file system root can be a folder on a hard drive, a zip file, or any data store"); Console.WriteLine("(assuming there's a provider for it).\n"); Console.WriteLine("In Gorgon, the types of data that can be mounted as a virtual file system are"); Console.WriteLine("managed by objects called providers. By default, the file system has a folder"); Console.WriteLine("provider. This allows a folder to be mounted as the root of a virtual file\nsystem.\n"); Console.WriteLine("This example will show how to load extra providers that can be used in a file\nsystem.\n"); Console.ForegroundColor = ConsoleColor.White; // Get our file system providers. Console.WriteLine("Found {0} external file system plug ins.\n", LoadFileSystemProviders()); // Loop through each provider and print some info. for (int i = 0; i < _providers.Count; ++i) { // Print some info about the file system provider. Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("{0}. {1}", i + 1, _providers[i].Name); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(" Description: {0}", _providers[i].Description); // Gather the preferred extensions. // File system providers that use a file (like a Zip file) as its root // have a list of file extensions that are preferred. For example, the // Zip provider, expects to find *.zip files. These are merely here // for the convenience of the developer and are formatted like a common // dialog file mask so they can be easily dropped into that control. // In this case, we're going to just strip out the relevant part and // concatenate each preferred extension description into a single string. // // Note that a provider may have multiple preferred extensions. string[] extensionList = (from preferred in _providers[i].PreferredExtensions select $"*.{preferred.Extension}").ToArray(); if (extensionList.Length > 0) { Console.WriteLine(" Preferred Extensions: {0}", string.Join(", ", extensionList)); } } Console.ResetColor(); Console.WriteLine("\nPress any key to close."); Console.ReadKey(); } catch (Exception ex) { ex.Catch(_ => { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", _.Message, _.StackTrace); }, _log); Console.ResetColor(); #if DEBUG Console.ReadKey(); #endif } finally { // Always call dispose so we can unload our temporary application domain. _pluginAssemblies.Dispose(); _log.LogEnd(); } }
/// <summary> /// The main entry point for the application. /// </summary> private static void Main() { _log = new GorgonLog("ZipFileSystem", "Tape_Worm"); _log.LogStart(); // Create the plugin assembly cache. _pluginAssemblies = new GorgonMefPlugInCache(_log); // Create the plugin service. _pluginService = new GorgonMefPlugInService(_pluginAssemblies); try { Console.WindowHeight = 28; Console.BufferHeight = Console.WindowHeight; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("This example will mount a zip file as the root of a virtual file system. The"); Console.WriteLine("virtual file system is capable of mounting various types of data such as a zip,"); Console.WriteLine("a file system folder, etc... as the root or a sub directory. You can even"); Console.WriteLine("mount a zip file as the root, and a physical file system directory as a virtual"); Console.WriteLine("sub directory in the same virtual file system and access them as a single"); Console.WriteLine("unified file system."); // Unlike the folder file system example, we need to load // a provider to handle zip files before trying to mount // one. if (!LoadZipProviderPlugIn()) { return; } // Set the following zip file as root on the virtual file system. // // If we wanted to, we could mount a zip file as a sub directory of // the root of the virtual file system. For example, mounting the // directory D:\Dir\zipFile.zip with Mount(@"D:\Dir", "/VFSDir"); would mount // the contents of the D:\Dir\zipFile.zip directory under /VFSDir. // // It's also important to point out that the old Gorgon "file system" // would load files from the system into memory when mounting a // directory. While this version only loads directory and file // information when mounting. This is considerably more efficient. string physicalPath = GetResourcePath(@"FileSystem.zip"); _fileSystem.Mount(physicalPath); Console.Write("\nMounted: "); Console.ForegroundColor = ConsoleColor.Cyan; Console.Write("'{0}'", physicalPath.Ellipses(Console.WindowWidth - 20, true)); Console.ForegroundColor = ConsoleColor.White; Console.Write(" as "); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("'/'\n"); Console.ForegroundColor = ConsoleColor.White; // Get a count of all sub directories and files under the root directory. IGorgonVirtualDirectory[] directoryList = _fileSystem.FindDirectories("*").ToArray(); // Display directories. Console.WriteLine("Virtual file system contents:"); for (int i = -1; i < directoryList.Length; i++) { IGorgonVirtualDirectory directory = _fileSystem.RootDirectory; // Go into the sub directories under root. if (i > -1) { directory = directoryList[i]; } Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("{0}", directory.FullPath); Console.ForegroundColor = ConsoleColor.Yellow; foreach (IGorgonVirtualFile file in directory.Files) { Console.Write(" {0}", file.Name); // Align the size to the same place. Console.CursorLeft = 65; Console.WriteLine("{0}", file.Size.FormatMemory()); } } Console.ResetColor(); Console.WriteLine("\nPress any key to close."); Console.ReadKey(); } catch (Exception ex) { ex.Catch(_ => { Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Exception:\n{0}\n\nStack Trace:{1}", _.Message, _.StackTrace); Console.ResetColor(); #if DEBUG Console.ReadKey(); #endif }); } finally { // Always dispose the cache to clean up the temporary app domain it creates. _pluginAssemblies.Dispose(); _log.LogEnd(); } }