OSDN Git Service

Merge branch 'master' of ttp@git.sourceforge.jp:/gitroot/applistation/AppliStation
[applistation/AppliStation.git] / na-get-lib / NaGet.Packages / RepositoriesList.cs
1 using System;\r
2 using System.ComponentModel;\r
3 using System.Xml.Serialization;\r
4 using System.Collections.Generic;\r
5 \r
6 namespace NaGet.Packages\r
7 {\r
8         /// <summary>\r
9         /// レポジトリのリストを表現するクラス\r
10         /// </summary>\r
11         public class RepositoriesList\r
12         {\r
13                 /// <summary>\r
14                 /// レポジトリの配列\r
15                 /// </summary>\r
16                 public RepositoryInfo[] Repositories = null;\r
17                 \r
18                 /// <summary>\r
19                 /// デフォルトコンストラクタ\r
20                 /// </summary>\r
21                 public RepositoriesList()\r
22                 {\r
23                 }\r
24                 \r
25                 /// <summary>\r
26                 /// 有効なレポジトリの配列を返す\r
27                 /// </summary>\r
28                 [XmlIgnore]\r
29                 public RepositoryInfo[] EnabledRepositories {\r
30                         get {\r
31                                 return Array.FindAll(Repositories, delegate(RepositoryInfo repo) {\r
32                                                         return repo.Enabled;\r
33                                                      });\r
34                         }\r
35                 }\r
36                 \r
37                 /// <summary>\r
38                 /// provider.list.txtから変換してRepositoriesListとして返す\r
39                 /// </summary>\r
40                 /// <param name="path">変換もとのprovider.list.txtのパス</param>\r
41                 /// <returns>変換されたRepositoriesList</returns>\r
42                 public static RepositoriesList MigrateFromProviderListTxt(string path)\r
43                 {\r
44                         List<RepositoryInfo> repos = new List<RepositoryInfo>();\r
45                         using(System.IO.StreamReader reader = new System.IO.StreamReader(path)) {\r
46                                 string line;\r
47                                 while ((line = reader.ReadLine()) != null) {\r
48                                         RepositoryInfo repo = new RepositoryInfo();\r
49                                         repo.Enabled = true;\r
50                                         repo.Url = new LocationEntry(line);\r
51                                         repo.Name = string.Empty;\r
52                                         repos.Add(repo);\r
53                                 }\r
54                         }\r
55                         \r
56                         RepositoriesList repolist = new RepositoriesList();\r
57                         repolist.Repositories = repos.ToArray();\r
58                         return repolist;\r
59                 }\r
60         }\r
61         \r
62         /// <summary>\r
63         /// レポジトリで提供されるソフトリストのフォーマットを返す\r
64         /// </summary>\r
65         public enum RepositoryType : uint\r
66         {\r
67                 /// <summary>\r
68                 /// AppliStation Native XML Format Version 1.0\r
69                 /// </summary>\r
70                 [XmlEnum(Name="ASNATIVEv1.0")]\r
71                 APPLISTATION_NATIVE_XML_1_0 = 0,\r
72         }\r
73         \r
74         /// <summary>\r
75         /// パッケージリストを提供するレポジトリの参照情報を格納するクラス\r
76         /// </summary>\r
77         public class RepositoryInfo\r
78         {\r
79                 /// <summary>\r
80                 /// レポジトリの提供するソフトリストの名称\r
81                 /// </summary>\r
82                 [XmlAttribute]\r
83                 [ReadOnly(true)]\r
84                 public string Name;\r
85                 \r
86                 /// <summary>\r
87                 /// ソフトリストの形式\r
88                 /// </summary>\r
89                 [XmlAttribute]\r
90                 public RepositoryType Type;\r
91                 \r
92                 /// <summary>\r
93                 /// ソフトリストの取得先URL\r
94                 /// </summary>\r
95                 public LocationEntry Url;\r
96                 \r
97                 /// <summary>\r
98                 /// ソフトリストを読み取るか否か(無視するか否か)のフラグ。\r
99                 /// </summary>\r
100                 [XmlAttribute]\r
101                 [DefaultValue(true)]\r
102                 public bool Enabled = true;\r
103         }\r
104 }\r