private void DoInstallAssemblyCommand(object parameter) { // Create an open file dialog. var openFileDialog = new OpenFileDialog { Title = Resources.Prompt_Installation_SelectAssembly, Filter = "Assemblies (*.dll)|*.dll" }; if (openFileDialog.ShowDialog() != true) { return; } // Get the assembly path. var assemblyPath = openFileDialog.FileName; // Install the assembly. try { AssemblyCache.InstallAssembly(assemblyPath, null, AssemblyCommitFlags.Force); // Reload assemblies after proper installation RefreshAssembliesCommand.DoExecute(null); MessageBox.Show(Resources.Msg_InstallationCompleted_Success, Resources.Title_Install); } catch (AssemblyMustBeStronglyNamedException) { MessageBox.Show(Resources.ErrorMsg_InstallationFailed_AssemblyIsNotStrongNamed, Resources.Title_Install); } catch (UnauthorizedAccessException) { MessageBox.Show(Resources.ErrorMsg_InstallationFailed_UnauthorizedError, Resources.Title_Install); } catch { MessageBox.Show(Resources.ErrorMsg_InstallationFailed_GenericError, Resources.Title_Install); } }
/// <summary> /// Performs UninstallAssemblies command /// </summary> /// <param name="parameter">The UninstallAssembliesCommand parameter</param> private void DoUninstallAssembliesCommand(object parameter) { // Check if user is an administrator try { // The parameter must be an assemblies collection. var assemblies = SelectedAssemblies; if (assemblies.Count == 0) { return; } var shouldReload = false; var messages = new List <string>(); foreach (var assemly in assemblies) { // Create an assembly cache. IASSEMBLYCACHE_UNINSTALL_DISPOSITION disposition = IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown; AssemblyCache.UninstallAssembly(assemly.InternalAssemblyDescription.DisplayName, null, out disposition); // Depending on the result, show the appropriate message. string message = string.Empty; switch (disposition) { case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.Unknown: message = string.Format(Resources.ErrorMsg_Uninstall_Unknown, assemly.DisplayName); break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_UNINSTALLED: message = string.Format(Resources.Msg_Uninstall_Success, assemly.DisplayName); // if any removed, reload assemblies shouldReload = true; break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_STILL_IN_USE: message = string.Format(Resources.ErrorMsg_Uninstall_InUse, assemly.DisplayName); break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_ALREADY_UNINSTALLED: message = string.Format(Resources.ErrorMsg_Uninstall_AlreadyUninstalled, assemly.DisplayName); break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_DELETE_PENDING: message = string.Format(Resources.ErrorMsg_Uninstall_Deleting, assemly.DisplayName); break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_HAS_INSTALL_REFERENCES: message = string.Format(Resources.ErrorMsg_Uninstall_PartOfAnotherProduct, assemly.DisplayName); break; case IASSEMBLYCACHE_UNINSTALL_DISPOSITION.IASSEMBLYCACHE_UNINSTALL_DISPOSITION_REFERENCE_NOT_FOUND: message = string.Format(Resources.ErrorMsg_Uninstall_NotFound, assemly.DisplayName); break; } messages.Add(message); // Remove the assembly from the vm. Assemblies.Remove(assemly); } // Reload assemblies if (shouldReload) { RefreshAssembliesCommand.DoExecute(); } // Show the message box. MessageBox.Show(string.Join("\n", messages), Resources.Title_Uninstall); } catch (UnauthorizedAccessException) { MessageBox.Show(Resources.ErrorMsg_Uninstall_UnauthorizedError, Resources.Title_Uninstall); } }