OSDN Git Service

initial build for opensource
[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         }\r
55         \r
56         /// <summary>\r
57         /// NaGet\83^\83X\83N\8f\88\97\9d\82Ì\83p\83b\83N\r
58         /// </summary>\r
59         public abstract class NaGetTaskSet : NaGetTask\r
60         {\r
61                 /// <summary>\r
62                 /// \83^\83X\83N\8f\88\97\9d\82Ì\83C\83x\83\93\83g\83n\83\93\83h\83\89\r
63                 /// </summary>\r
64                 public event EventHandler<NaGetTaskSetEventArgs> TaskSetRaised;\r
65                 \r
66                 /// <summary>\r
67                 /// \95\8e\9a\97ñ\82Å\95\\8c»\82µ\82½\8dì\8bÆ\88ê\97\97\83\8a\83X\83g\r
68                 /// </summary>\r
69                 public string[] TaskSetNames;\r
70                 \r
71                 /// <summary>\r
72                 /// \8c»\8dÝ\8eÀ\8ds\92\86\82Ì\8dì\8bÆ\94Ô\8d\86\r
73                 /// </summary>\r
74                 public abstract int CurrentTaskSetIndex {\r
75                         get;\r
76                 }\r
77                 \r
78                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message)\r
79                 {\r
80                         float percent = (CurrentTaskSetIndex >= 0)? CurrentTaskSetIndex * 100 / TaskSetNames.Length : -1;\r
81                         RaiseTaskSetEvent(type, message, percent);\r
82                 }\r
83                 \r
84                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message, float percent)\r
85                 {\r
86                         RaiseTaskSetEvent(new NaGetTaskSetEventArgs(type, message, percent));\r
87                 }\r
88                 \r
89                 protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventArgs e)\r
90                 {\r
91                         if (TaskSetRaised != null) {\r
92                                 TaskSetRaised(this, e);\r
93                         }\r
94                 }\r
95                 \r
96                 protected virtual void ReceivedErrorData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
97                 {\r
98                         if (! string.IsNullOrEmpty(e.Data)) {\r
99                                 RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, e.Data);\r
100                         }\r
101                 }\r
102                 \r
103                 protected virtual void ReceivedOutputData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
104                 {\r
105                         if (! string.IsNullOrEmpty(e.Data)) {\r
106                                 RaiseTaskSetEvent(NaGetTaskSetEventType.INFO, e.Data);\r
107                         }\r
108                 }\r
109                 \r
110                 public override bool Running {\r
111                         get { return CurrentTaskSetIndex >= 0 && !Done; }\r
112                 }\r
113         }\r
114 }\r