/// <summary> /// Performs the RefreshAssemblies command. /// </summary> /// <param name="parameter">The RefreshAssemblies command parameter.</param> private void DoRefreshAssembliesCommand(object parameter) { // Clear the assemblies. Assemblies.Clear(); // Set the status text. RefreshAssembliesCommand.ReportProgress( () => { StatusInfo = Resources.Msg_RefreshAssemblies_Progress; }); // Start the enumeration. var timeTaken = ApexBroker.GetModel <IGACManagerModel>().EnumerateAssemblies( assemblyDetails => { // Create an assembly view model from the detials. var viewModel = new GACAssemblyViewModel(); viewModel.FromModel(assemblyDetails); // Add it to the collection. Assemblies.Add(viewModel); }); // Set the resulting status info. RefreshAssembliesCommand.ReportProgress( () => { AssembliesCollectionView = new ListCollectionView(Assemblies.ToList()); AssembliesCollectionView.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending)); AssembliesCollectionView.Filter += Filter; StatusInfo = string.Format(Resources.Msg_RefreshAssemblies_Success, Assemblies.Count, timeTaken.TotalMilliseconds); }); }
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); } }