2 using System.Collections.Generic;
4 using NaGet.Packages.Install;
5 using NaGet.SubCommands;
6 using NaGet.SubCommands.SubTask;
9 namespace NaGet.SubCommands
14 public class NaGetUninstall2 : NaGetTaskSet2
17 private IList<Uninstallation> uninsts;
19 public NaGetUninstall2(PackageListsManager pkgMan, IList<InstalledPackage> pkgs)
21 uninsts = new List<Uninstallation>(pkgs.Count);
22 foreach (InstalledPackage instPkg in pkgs) {
23 uninsts.Add(new Uninstallation(instPkg));
28 foreach (Uninstallation uninst in uninsts) {
29 registSubTask(string.Format("アンインストール: {0}", uninst.ToString()),
30 new FunctionalSubTask<Uninstallation>(runUninstall, uninst));
32 registSubTask("インストール済みのソフトリスト更新",
33 new LocalUpdateSubTask(pkgMan));
36 public override void Run()
39 RaiseTaskSetEvent(TaskEventType.STARTED, string.Empty);
42 while (hasMoreSubTask) {
43 RaiseTaskSetEvent(TaskEventType.STARTED_SUBTASK, currentSubTaskName);
45 RaiseTaskSetEvent(TaskEventType.COMPLETED_SUBTASK, currentSubTaskName);
48 throw new TaskCanceledException("cancel is called");
51 NotifyGoToNextSubTask();
53 } catch (TaskCanceledException) {
55 } catch (Exception e) {
56 RaiseTaskSetEvent(TaskEventType.ERROR, e.Message);
61 RaiseTaskSetEvent(TaskEventType.CANCELED, "キャンセルされました");
64 RaiseTaskSetEvent(TaskEventType.COMPLETED, string.Empty);
68 private void runUninstall(Uninstallation uninst)
70 if (uninst.Installed) {
72 uninst.OutputDataReceived += this.ReceivedOutputData;
73 uninst.ErrorDataReceived += this.ReceivedErrorData;
74 int exitCode = uninst.Uninstall();
76 RaiseTaskSetEvent(TaskEventType.WARNING, "アンインストールが正常に終えていない可能性があります。プロセスの終了コード:"+exitCode);
78 } catch (Exception e) {
79 RaiseTaskSetEvent(TaskEventType.ERROR, e.Message);
83 RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0}は既にアンインストールされているか、ソフトの存在を確認できませんでした", uninst));
87 public override bool Cancelable {
89 return !cancelCalled && Running && isDuringUninstalling;
93 private bool isDuringUninstalling {
95 return currentSubTask is LocalUpdateSubTask;