OSDN Git Service

df42cd36f2c9d6c7cc4592cccb2b24427c24af6c
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetTaskSet.cs
1 using System;\r
2 \r
3 namespace NaGet.SubCommands\r
4 {\r
5         #region EventHandler<NaGetTaskSetEventArgs>\8aÖ\98A\r
6         \r
7         public class NaGetTaskSetEventArgs : NaGetEventArgs\r
8         {\r
9                 public NaGetTaskSetEventType Type;\r
10                 \r
11                 public NaGetTaskSetEventArgs(NaGetTaskSetEventType type, string message, float processPercent)\r
12                 {\r
13                         this.Type = type;\r
14                         this.TaskMessage = message;\r
15                         this.TaskProgressPercent = processPercent;\r
16                 }\r
17         }\r
18         \r
19         /// <summary>\r
20         /// \83^\83X\83N\82Ì\8eí\97Þ\r
21         /// </summary>\r
22         public enum NaGetTaskSetEventType\r
23         {\r
24                 /// <summary>\r
25                 /// \8aJ\8en\r
26                 /// </summary>\r
27                 STARTED,\r
28                 /// <summary>\r
29                 /// \8a®\97¹\82µ\82½(\82·\82×\82Ä\82ð\8a®\97¹)\r
30                 /// </summary>\r
31                 COMPLETED,\r
32                 /// <summary>\r
33                 /// \8dì\8bÆ\82ª\83L\83\83\83\93\83Z\83\8b\82³\82ê\82½\r
34                 /// </summary>\r
35                 CANCELED,\r
36                 /// <summary>\r
37                 /// \83G\83\89\81[\82ð\94­\90\82µ(\92\86\92f\82µ\82½)\r
38                 /// </summary>\r
39                 ERROR,\r
40                 /// <summary>\r
41                 /// \83G\83\89\81[\82ª\94­\90\82µ\82½\82ª\8cp\91±\r
42                 /// </summary>\r
43                 WARNING,\r
44                 /// <summary>\r
45                 /// \82»\82Ì\82Ù\82©\82Ì\8fî\95ñ\r
46                 /// </summary>\r
47                 INFO,\r
48                 /// <summary>\r
49                 /// \8dì\8bÆ\82ð\8aJ\8en\r
50                 /// </summary>\r
51                 STARTED_TASKSET,\r
52                 /// <summary>\r
53                 /// \8dì\8bÆ\82ð\8fI\97¹\r
54                 /// </summary>\r
55                 COMPLETED_TASKSET,\r
56                 /// <summary>\r
57                 /// \93®\8dì\90i\92»\81E\92Ê\92m\82Ì\82Ý\r
58                 /// </summary>\r
59                 PING,\r
60         }\r
61         \r
62         #endregion\r
63         \r
64         #region NaGetTaskQueryHandler\8aÖ\98A\r
65         \r
66         public delegate NaGetTaskQueryResult NaGetTaskQueryHandler(object sender, NaGetTaskQueryArgs e);\r
67         \r
68         public class NaGetTaskQueryArgs\r
69         {\r
70                 /// <summary>\r
71                 /// \83^\83X\83N\82Ì\8c»\8bµ\82Ì\83\81\83b\83Z\81[\83W\r
72                 /// </summary>\r
73                 public string Message;\r
74                 \r
75                 /// <summary>\r
76                 /// \89ñ\93\9a\82Ì\8eí\97Þ\82Ì\83t\83\89\83O\r
77                 /// </summary>\r
78                 public NaGetTaskQueryResult SelectionFlag;\r
79                 \r
80                 public NaGetTaskQueryArgs(string message, NaGetTaskQueryResult selectionFlag)\r
81                 {\r
82                         this.Message = message;\r
83                         this.SelectionFlag = selectionFlag;\r
84                 }\r
85         }\r
86         \r
87         /// <summary>\r
88         /// \8e¿\96â\82Ì\93\9a\82¦\r
89         /// </summary>\r
90         [Flags()]\r
91         public enum NaGetTaskQueryResult : uint\r
92         {\r
93                 /// <summary>\r
94                 /// \8cp\91±(=OK)\r
95                 /// </summary>\r
96                 CONTINUE = 0x01,\r
97                 /// <summary>\r
98                 /// \8dÄ\8e\8e\8ds\r
99                 /// </summary>\r
100                 RETRY = 0x02,\r
101                 /// <summary>\r
102                 /// \83L\83\83\83\93\83Z\83\8b\81A\92\86\8e~\r
103                 /// </summary>\r
104                 CANCEL = 0x04,\r
105                 /// <summary>\r
106                 /// \8e©\93®\93I\82È\83L\83\83\83\93\83Z\83\8b(\83\86\81[\83U\82Ì\8eè\82Å\82Í\82È\82¢\82à\82Ì)\r
107                 /// </summary>\r
108                 CANCELED_AUTOMATICALLY = 0x00,\r
109         }\r
110         \r
111         \r
112         #endregion\r
113         \r
114         /// <summary>\r
115         /// NaGet\83^\83X\83N\8f\88\97\9d\82Ì\83p\83b\83N\r
116         /// </summary>\r
117         public abstract class NaGetTaskSet : NaGetTask\r
118         {\r
119                 /// <summary>\r
120                 /// \83^\83X\83N\8f\88\97\9d\82Ì\83C\83x\83\93\83g\83n\83\93\83h\83\89\r
121                 /// </summary>\r
122                 public event EventHandler<NaGetTaskSetEventArgs> TaskSetRaised;\r
123                 \r
124                 /// <summary>\r
125                 /// \83^\83X\83N\8f\88\97\9d\92\86\82Ì\8e¿\96â\82Ì\83n\83\93\83h\83\89\r
126                 /// </summary>\r
127                 public event NaGetTaskQueryHandler TaskQueryRaised;\r
128                 \r
129                 /// <summary>\r
130                 /// \95\8e\9a\97ñ\82Å\95\\8c»\82µ\82½\8dì\8bÆ\88ê\97\97\83\8a\83X\83g\r
131                 /// </summary>\r
132                 public string[] TaskSetNames;\r
133                 \r
134                 /// <summary>\r
135                 /// \8c»\8dÝ\8eÀ\8ds\92\86\82Ì\8dì\8bÆ\94Ô\8d\86\r
136                 /// </summary>\r
137                 public abstract int CurrentTaskSetIndex {\r
138                         get;\r
139                 }\r
140                 \r
141                 /// <summary>\r
142                 /// \8c»\8dÝ\82Ì\90i\92»\82ð\96ß\82·\81B\r
143                 /// </summary>\r
144                 /// <param name="type">\8dì\8bÆ\82Ì\8fó\91Ô</param>\r
145                 /// <param name="subTaskProgress">\83T\83u\83^\83X\83N\82Ì\90i\92»</param>\r
146                 /// <returns>\8c»\8dÝ\82Ì\90i\92»</returns>\r
147                 protected virtual float GetProgressPercent(NaGetTaskSetEventType type, float subTaskProgress)\r
148                 {\r
149                         if (CurrentTaskSetIndex >= 0) {\r
150                                 if (subTaskProgress >= 0) {\r
151                                         return (CurrentTaskSetIndex * 100 + subTaskProgress) / TaskSetNames.Length;\r
152                                 }\r
153                                 switch (type) {\r
154                                         case NaGetTaskSetEventType.STARTED:\r
155                                                 return 0;\r
156                                         case NaGetTaskSetEventType.COMPLETED:\r
157                                                 return 100;\r
158                                         case NaGetTaskSetEventType.COMPLETED_TASKSET:\r
159                                                 return ((CurrentTaskSetIndex+1) * 100) / TaskSetNames.Length;\r
160                                         default:\r
161                                                 return (CurrentTaskSetIndex * 100) / TaskSetNames.Length;\r
162                                 }\r
163                         }\r
164                         \r
165                         return -1;\r
166                 }\r
167                 \r
168                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message)\r
169                 {\r
170                         RaiseTaskSetEvent(type, message, GetProgressPercent(type, -1));\r
171                 }\r
172                 \r
173                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message, float percent)\r
174                 {\r
175                         if (TaskSetRaised != null) {\r
176                                 TaskSetRaised(this, new NaGetTaskSetEventArgs(type, message, percent));\r
177                         }\r
178                 }\r
179                 \r
180                 protected virtual void ReceivedErrorData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
181                 {\r
182                         if (! string.IsNullOrEmpty(e.Data)) {\r
183                                 RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, e.Data);\r
184                         }\r
185                 }\r
186                 \r
187                 protected virtual void ReceivedOutputData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
188                 {\r
189                         if (! string.IsNullOrEmpty(e.Data)) {\r
190                                 RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, e.Data);\r
191                         }\r
192                 }\r
193                 \r
194                 protected virtual NaGetTaskQueryResult RaiseTaskSetQueryEvent(string message, NaGetTaskQueryResult selection)\r
195                 {\r
196                         if (TaskQueryRaised != null) {\r
197                                 return TaskQueryRaised(this, new NaGetTaskQueryArgs(message, selection));\r
198                         }\r
199                         return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
200                 }\r
201                 \r
202                 public override bool Running {\r
203                         get { return CurrentTaskSetIndex >= 0 && !Done; }\r
204                 }\r
205         }\r
206 }\r