OSDN Git Service

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