OSDN Git Service

AppliStation,ハッシュが非整合の時に尋ねるようにした。(all-get.exeにも反映)
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetTaskSet.cs
1 using System;\r
2 \r
3 namespace NaGet.SubCommands\r
4 {\r
5         public class NaGetTaskSetEventArgs : NaGetEventArgs\r
6         {\r
7                 public NaGetTaskSetEventType Type;\r
8                 \r
9                 public NaGetTaskSetEventArgs(NaGetTaskSetEventType type, string message, float processPercent)\r
10                 {\r
11                         this.Type = type;\r
12                         this.TaskMessage = message;\r
13                         this.TaskProgressPercent = processPercent;\r
14                 }\r
15         }\r
16         \r
17         /// <summary>\r
18         /// \83^\83X\83N\82Ì\8eí\97Þ\r
19         /// </summary>\r
20         public enum NaGetTaskSetEventType\r
21         {\r
22                 /// <summary>\r
23                 /// \8aJ\8en\r
24                 /// </summary>\r
25                 STARTED,\r
26                 /// <summary>\r
27                 /// \8a®\97¹\82µ\82½(\82·\82×\82Ä\82ð\8a®\97¹)\r
28                 /// </summary>\r
29                 COMPLETED,\r
30                 /// <summary>\r
31                 /// \8dì\8bÆ\82ª\83L\83\83\83\93\83Z\83\8b\82³\82ê\82½\r
32                 /// </summary>\r
33                 CANCELED,\r
34                 /// <summary>\r
35                 /// \83G\83\89\81[\82ð\94­\90\82µ(\92\86\92f\82µ\82½)\r
36                 /// </summary>\r
37                 ERROR,\r
38                 /// <summary>\r
39                 /// \83G\83\89\81[\82ª\94­\90\82µ\82½\82ª\8cp\91±\r
40                 /// </summary>\r
41                 WARNING,\r
42                 /// <summary>\r
43                 /// \82»\82Ì\82Ù\82©\82Ì\8fî\95ñ\r
44                 /// </summary>\r
45                 INFO,\r
46                 /// <summary>\r
47                 /// \8dì\8bÆ\82ð\8aJ\8en\r
48                 /// </summary>\r
49                 STARTED_TASKSET,\r
50                 /// <summary>\r
51                 /// \8dì\8bÆ\82ð\8fI\97¹\r
52                 /// </summary>\r
53                 COMPLETED_TASKSET,\r
54                 /// <summary>\r
55                 /// \8e¿\96â\r
56                 /// </summary>\r
57                 QUERY,\r
58                 /// <summary>\r
59                 /// \8cx\8d\90\82ð\8aÜ\82Þ\8e¿\96â\r
60                 /// </summary>\r
61                 WARNING_QUERY,\r
62         }\r
63         \r
64         /// <summary>\r
65         /// \8e¿\96â\82Ì\93\9a\82¦\r
66         /// </summary>\r
67         public enum NaGetTaskQueryResult\r
68         {\r
69                 CONTINUE,\r
70                 RETRY,\r
71                 CANCEL,\r
72                 CANCELED_AUTOMATICALLY,\r
73         }\r
74         \r
75         public delegate NaGetTaskQueryResult NaGetTaskQueryHandler(object sender, NaGetTaskSetEventArgs e);\r
76         \r
77         /// <summary>\r
78         /// NaGet\83^\83X\83N\8f\88\97\9d\82Ì\83p\83b\83N\r
79         /// </summary>\r
80         public abstract class NaGetTaskSet : NaGetTask\r
81         {\r
82                 /// <summary>\r
83                 /// \83^\83X\83N\8f\88\97\9d\82Ì\83C\83x\83\93\83g\83n\83\93\83h\83\89\r
84                 /// </summary>\r
85                 public event EventHandler<NaGetTaskSetEventArgs> TaskSetRaised;\r
86                 \r
87                 /// <summary>\r
88                 /// \83^\83X\83N\8f\88\97\9d\92\86\82Ì\8e¿\96â\82Ì\83n\83\93\83h\83\89\r
89                 /// </summary>\r
90                 public event NaGetTaskQueryHandler TaskQueryRaised;\r
91                 \r
92                 /// <summary>\r
93                 /// \95\8e\9a\97ñ\82Å\95\\8c»\82µ\82½\8dì\8bÆ\88ê\97\97\83\8a\83X\83g\r
94                 /// </summary>\r
95                 public string[] TaskSetNames;\r
96                 \r
97                 /// <summary>\r
98                 /// \8c»\8dÝ\8eÀ\8ds\92\86\82Ì\8dì\8bÆ\94Ô\8d\86\r
99                 /// </summary>\r
100                 public abstract int CurrentTaskSetIndex {\r
101                         get;\r
102                 }\r
103                 \r
104                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message)\r
105                 {\r
106                         float percent = (CurrentTaskSetIndex >= 0)? CurrentTaskSetIndex * 100 / TaskSetNames.Length : -1;\r
107                         RaiseTaskSetEvent(type, message, percent);\r
108                 }\r
109                 \r
110                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message, float percent)\r
111                 {\r
112                         if (TaskSetRaised != null) {\r
113                                 TaskSetRaised(this, new NaGetTaskSetEventArgs(type, message, percent));\r
114                         }\r
115                 }\r
116                 \r
117                 protected virtual void ReceivedErrorData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
118                 {\r
119                         if (! string.IsNullOrEmpty(e.Data)) {\r
120                                 RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, e.Data);\r
121                         }\r
122                 }\r
123                 \r
124                 protected virtual void ReceivedOutputData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
125                 {\r
126                         if (! string.IsNullOrEmpty(e.Data)) {\r
127                                 RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, e.Data);\r
128                         }\r
129                 }\r
130                 \r
131                 protected virtual NaGetTaskQueryResult RaiseTaskSetQueryEvent(NaGetTaskSetEventType type, string message)\r
132                 {\r
133                         float percent = (CurrentTaskSetIndex >= 0)? CurrentTaskSetIndex * 100 / TaskSetNames.Length : -1;\r
134                         return RaiseTaskSetQueryEvent(type, message, percent);\r
135                 }\r
136                 \r
137                 protected virtual NaGetTaskQueryResult RaiseTaskSetQueryEvent(NaGetTaskSetEventType type, string message, float percent)\r
138                 {\r
139                         if (TaskQueryRaised != null) {\r
140                                 return TaskQueryRaised(this, new NaGetTaskSetEventArgs(type, message, percent));\r
141                         }\r
142                         return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
143                 }\r
144                 \r
145                 public override bool Running {\r
146                         get { return CurrentTaskSetIndex >= 0 && !Done; }\r
147                 }\r
148         }\r
149 }\r