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(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(object uninstObj)
70 Uninstallation uninst = (Uninstallation) uninstObj;
72 if (uninst.Installed) {
74 uninst.OutputDataReceived += this.ReceivedOutputData;
75 uninst.ErrorDataReceived += this.ReceivedErrorData;
76 int exitCode = uninst.Uninstall();
78 RaiseTaskSetEvent(TaskEventType.WARNING, "アンインストールが正常に終えていない可能性があります。プロセスの終了コード:"+exitCode);
80 } catch (Exception e) {
81 RaiseTaskSetEvent(TaskEventType.ERROR, e.Message);
85 RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("{0}は既にアンインストールされているか、ソフトの存在を確認できませんでした", uninst));