コード例 #1
0
        private void AddServerEntryToList(ServerEntry serverEntry)
        {
            var listItem = new ListViewItem(
                new[]
                    {
                        serverEntry.ServerName,
                        serverEntry.ServerType.ToString(),
                        serverEntry.ClassId.ToString()
                    }) {Tag = serverEntry};

            switch (serverEntry.ServerType)
            {
                case ServerType.ShellContextMenu:
                    listItem.ImageIndex = 0;
                    break;
                case ServerType.ShellPropertySheet:
                    listItem.ImageIndex = 2;
                    break;
                case ServerType.ShellIconHandler:
                    listItem.ImageIndex = 1;
                    break;
                    case ServerType.ShellInfoTipHandler:
                    listItem.ImageIndex = 3;
                    break;
                case ServerType.ShellIconOverlayHandler:
                    listItem.ImageIndex = 4;
                    break;
                default:
                    listItem.ImageIndex = 0;
                    break;
            }
            listViewServers.Items.Add(listItem);

        }
コード例 #2
0
        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;
            }
        }