3 using System.Collections.Generic;
6 using NaGet.Packages.Install;
8 using NaGet.SubCommands;
9 using NaGet.SubCommands.SubTask;
12 namespace NaGet.SubCommands
17 public class NaGetUpdate2 : NaGetTaskSet2
19 private PackageListsManager pkgListMan = null;
21 private bool downloadPackageLists = true;
23 private RepositoriesList repoList = null;
25 private IList<string> tempRepoFiles = null;
27 public NaGetUpdate2(PackageListsManager pkgListMan)
28 : this(pkgListMan, true)
35 /// <param name="pkgMan">参照パッケージマネージャ</param>
36 /// <param name="downloadPackageListsFlag">リストをダウンロードするか?</param>
37 public NaGetUpdate2(PackageListsManager pkgMan, bool downloadPackageListsFlag)
39 this.pkgListMan = pkgMan;
40 this.downloadPackageLists = downloadPackageListsFlag;
44 if (this.downloadPackageLists) {
45 // repos.list.xmlがあるとき、そこからよみとる。
46 repoList = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
47 tempRepoFiles = new List<string>();
49 foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
50 string filepath = Path.GetTempFileName();
52 tempRepoFiles.Add(filepath);
53 registSubTask(string.Format("リスト取得: {0}", repo.Url.Href),
54 new DownloadSubTask(repo.Url.Href, filepath));
56 registSubTask(string.Format("リスト更新: {0}", NaGet.Env.PackageListFile),
57 new FunctionalSubTask(runUpdatePackageListFile, null));
59 registSubTask("インストール済みのソフトリスト更新",
60 new LocalUpdateSubTask(this.pkgListMan));
63 public override void Run()
66 RaiseTaskSetEvent(TaskEventType.STARTED, string.Empty);
69 while (hasMoreSubTask) {
70 RaiseTaskSetEvent(TaskEventType.STARTED_SUBTASK, currentSubTaskName);
72 RaiseTaskSetEvent(TaskEventType.COMPLETED_SUBTASK, currentSubTaskName);
74 NotifyGoToNextSubTask();
76 } catch (TaskCanceledException) {
78 } catch (Exception e) {
79 RaiseTaskSetEvent(TaskEventType.ERROR, e.Message);
86 RaiseTaskSetEvent(TaskEventType.CANCELED, "キャンセルされました");
89 RaiseTaskSetEvent(TaskEventType.COMPLETED, string.Empty);
93 private void runUpdatePackageListFile(object dummy)
96 PackageList<Package> avaiablePackageList = new PackageList<Package>();
98 // かならず常にrepositoryリストに書き込む。
99 NaGet.Utils.PutSerializeObject(NaGet.Env.RepositoriesListFile, repoList);
101 foreach (RepositoryInfo repo in repoList.EnabledRepositories) {
102 if (repo.Type == RepositoryType.APPLISTATION_NATIVE_XML_1_0) {
104 string tmpfileName = tempRepoFiles[i];
105 PackageList<Package> pkgList = NaGet.Utils.GetDeserializedObject<PackageList<Package>>(tmpfileName);
106 pkgList.FixPackageListName(); // PackageListNameとの紐付けを行う
108 // RepositoryReferenceの名前を読み込む
109 repo.Name = (string.IsNullOrEmpty(pkgList.Name))? repo.Name : pkgList.Name;
111 avaiablePackageList.AddPackages(pkgList);
112 } catch (InvalidOperationException) {
113 RaiseTaskSetEvent(TaskEventType.ERROR, string.Format("レポジトリ'{0}'はAppliStation Native XML softlist形式ではありません。", repo.Name ?? repo.Url.Href));
116 RaiseTaskSetEvent(TaskEventType.WARNING, string.Format("レポジトリ'{0}'の設定が不正です。", repo.Name ?? repo.Url.Href));
121 pkgListMan.availablePkgList = avaiablePackageList; // Mediatorのリストを更新
122 pkgListMan.SaveAvailablePackageList();
125 private void runDeleteTempFiles()
127 if (tempRepoFiles != null) {
128 foreach (string file in tempRepoFiles) {
129 if (File.Exists(file)) {
136 public override bool Cancelable {
138 return !cancelCalled && Running && isDuringDownloading;
142 private bool isDuringDownloading {
144 return Running && (currentSubTask is DownloadSubTask);