using System; using System.ComponentModel.Composition.Hosting; using System.IO; using System.Windows.Forms; using SharpShell; using SharpShell.SharpPropertySheet; namespace ServerManager { public static class ServerManagerApi { public static ServerEntry LoadServer(string path) { try { // Create a server entry for the server. var serverEntry = new ServerEntry(); // Set the data. serverEntry.ServerName = Path.GetFileNameWithoutExtension(path); serverEntry.ServerPath = path; // Create an assembly catalog for the assembly and a container from it. var catalog = new AssemblyCatalog(Path.GetFullPath(path)); var container = new CompositionContainer(catalog); // Get the exported server. var server = container.GetExport<ISharpShellServer>().Value; serverEntry.ServerType = server.ServerType; serverEntry.ClassId = server.GetType().GUID; serverEntry.Server = server; return serverEntry; } catch (Exception) { // It's almost certainly not a COM server. MessageBox.Show("The file '" + Path.GetFileName(path) + "' is not a SharpShell Server.", "Warning"); return null; } } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)