3 using System.Collections.Generic;
6 using NaGet.Packages.Install;
7 using NaGet.SubCommands;
8 using NaGet.SubCommands.SubTask;
11 namespace NaGet.SubCommands
16 public class NaGetUpdate2 : NaGetTaskSet2
18 private PackageListsManager pkgListMan = null;
20 private bool downloadPackageLists = true;
22 private RepositoriesList repoList = null;
24 private IList<string> tempRepoFiles = null;
26 public NaGetUpdate2(PackageListsManager pkgListMan)
27 : this(pkgListMan, true)
34 /// <param name="pkgMan">参照パッケージマネージャ</param>
35 /// <param name="downloadPackageListsFlag">リストをダウンロードするか?</param>
36 public NaGetUpdate2(PackageListsManager pkgMan, bool downloadPackageListsFlag)
38 this.pkgListMan = pkgMan;
39 this.downloadPackageLists = downloadPackageListsFlag;
43 registSubTask("セキュリティプロトコル設定の確認",
44 new SecurityProtocolConfigSubTask());
45 if (this.downloadPackageLists) {
46 // repos.list.xmlがあるとき、そこからよみとる。
47 repoList = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
48 tempRepoFiles = new List<string>();
50 foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
51 string filepath = Path.GetTempFileName();
53 tempRepoFiles.Add(filepath);
54 registSubTask(string.Format("リスト取得: {0}", repo.Url.Href),
55 new DownloadSubTask(repo.Url.Href, filepath));
57 registSubTask(string.Format("リスト更新: {0}", NaGet.Env.PackageListFile),
58 new FunctionalSubTask<object>(runUpdatePackageListFile, null));
60 registSubTask("インストール済みのソフトリスト更新",
61 new LocalUpdateSubTask(this.pkgListMan));
64 public override void Run()
67 RaiseTaskSetEvent(TaskEventType.STARTED, string.Empty);
70 while (hasMoreSubTask) {
71 RaiseTaskSetEvent(TaskEventType.STARTED_SUBTASK, currentSubTaskName);
73 RaiseTaskSetEvent(TaskEventType.COMPLETED_SUBTASK, currentSubTaskName);
75 NotifyGoToNextSubTask();
77 } catch (TaskCanceledException) {
79 } catch (Exception e) {
80 RaiseTaskSetEvent(TaskEventType.ERROR, e.Message);
87 RaiseTaskSetEvent(TaskEventType.CANCELED, "キャンセルされました");
90 RaiseTaskSetEvent(TaskEventType.COMPLETED, string.Empty);
94 private void runUpdatePackageListFile(object dummy)
97 PackageList<Package> avaiablePackageList = new PackageList<Package>();
99 // かならず常にrepositoryリストに書き込む。
100 NaGet.Utils.PutSerializeObject(NaGet.Env.RepositoriesListFile, repoList);
102 foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
103 if (repo.Type == RepositoryType.APPLISTATION_NATIVE_XML_1_0) {
105 string tmpfileName = tempRepoFiles[i];
106 PackageList<Package> pkgList = NaGet.Utils.GetDeserializedObject<PackageList<Package>>(tmpfileName);
107 pkgList.FixPackageListName(); // PackageListNameとの紐付けを行う
109 // RepositoryReferenceの名前を読み込む
110 repo.Name = (string.IsNullOrEmpty(pkgList.Name))? repo.Name : pkgList.Name;
112 avaiablePackageList.AddPackages(pkgList);
113 } catch (InvalidOperationException) {
114 RaiseTaskSetEvent(TaskEventType.ERROR, string.Format("レポジトリ'{0}'はAppliStation Native XML softlist形式ではありません。", repo.Name ?? repo.Url.Href));
117 RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("レポジトリ'{0}'の設定が不正です。", repo.Name ?? repo.Url.Href));
122 pkgListMan.availablePkgList = avaiablePackageList; // Mediatorのリストを更新
123 pkgListMan.SaveAvailablePackageList();
126 private void runDeleteTempFiles()
128 if (tempRepoFiles != null) {
129 foreach (string file in tempRepoFiles) {
130 if (File.Exists(file)) {
137 public override bool Cancelable {
139 return !cancelCalled && Running && isDuringDownloading;
143 private bool isDuringDownloading {
145 return Running && (currentSubTask is DownloadSubTask);