OSDN Git Service

na-get-lib,アンインストール処理の中途終了に対応。
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetTaskSet.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Collections.ObjectModel;\r
4 using NaGet.Tasks;\r
5 \r
6 namespace NaGet.SubCommands\r
7 {       \r
8         #region NaGetTaskQueryHandler\8aÖ\98A\r
9         \r
10         public delegate NaGetTaskQueryResult NaGetTaskQueryHandler(object sender, NaGetTaskQueryArgs e);\r
11         \r
12         public class NaGetTaskQueryArgs\r
13         {\r
14                 /// <summary>\r
15                 /// \83^\83X\83N\82Ì\8c»\8bµ\82Ì\83\81\83b\83Z\81[\83W\r
16                 /// </summary>\r
17                 public string Message;\r
18                 \r
19                 /// <summary>\r
20                 /// \89ñ\93\9a\82Ì\8eí\97Þ\82Ì\83t\83\89\83O\r
21                 /// </summary>\r
22                 public NaGetTaskQueryResult SelectionFlag;\r
23                 \r
24                 public NaGetTaskQueryArgs(string message, NaGetTaskQueryResult selectionFlag)\r
25                 {\r
26                         this.Message = message;\r
27                         this.SelectionFlag = selectionFlag;\r
28                 }\r
29         }\r
30         \r
31         /// <summary>\r
32         /// \8e¿\96â\82Ì\93\9a\82¦\r
33         /// </summary>\r
34         [Flags()]\r
35         public enum NaGetTaskQueryResult : uint\r
36         {\r
37                 /// <summary>\r
38                 /// \8cp\91±(=OK)\r
39                 /// </summary>\r
40                 CONTINUE = 0x01,\r
41                 /// <summary>\r
42                 /// \8dÄ\8e\8e\8ds\r
43                 /// </summary>\r
44                 RETRY = 0x02,\r
45                 /// <summary>\r
46                 /// \83L\83\83\83\93\83Z\83\8b\81A\92\86\8e~\r
47                 /// </summary>\r
48                 CANCEL = 0x04,\r
49                 /// <summary>\r
50                 /// \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
51                 /// </summary>\r
52                 CANCELED_AUTOMATICALLY = 0x00,\r
53         }\r
54         \r
55         \r
56         #endregion\r
57         \r
58         /// <summary>\r
59         /// NaGet\83^\83X\83N\8f\88\97\9d\82Ì\83p\83b\83N\r
60         /// </summary>\r
61         public abstract class NaGetTaskSet : Task\r
62         {\r
63                 /// <summary>\r
64                 /// \83^\83X\83N\8f\88\97\9d\92\86\82Ì\8e¿\96â\82Ì\83n\83\93\83h\83\89\r
65                 /// </summary>\r
66                 public event NaGetTaskQueryHandler TaskQueryRaised;\r
67                 \r
68                 /// <summary>\r
69                 /// \95\8e\9a\97ñ\82Å\95\\8c»\82µ\82½\8dì\8bÆ\88ê\97\97\83\8a\83X\83g\r
70                 /// </summary>\r
71                 protected IList<string> taskSetNames;\r
72                 \r
73                 /// <summary>\r
74                 /// \95\8e\9a\97ñ\82Å\95\\8c»\82µ\82½\8dì\8bÆ\88ê\97\97\83\8a\83X\83g\r
75                 /// </summary>\r
76                 public virtual IList<string> TaskSetNames {\r
77                         get {\r
78                                 return new ReadOnlyCollection<string>(taskSetNames);\r
79                         }\r
80                 }\r
81                 \r
82                 /// <summary>\r
83                 /// \8c»\8dÝ\8eÀ\8ds\92\86\82Ì\8dì\8bÆ\94Ô\8d\86\r
84                 /// </summary>\r
85                 public abstract int CurrentTaskSetIndex {\r
86                         get;\r
87                 }\r
88                 \r
89                 /// <summary>\r
90                 /// \8c»\8dÝ\82Ì\90i\92»\82ð\96ß\82·\81B\r
91                 /// </summary>\r
92                 /// <param name="type">\8dì\8bÆ\82Ì\8fó\91Ô</param>\r
93                 /// <param name="subTaskProgress">\83T\83u\83^\83X\83N\82Ì\90i\92»</param>\r
94                 /// <returns>\8c»\8dÝ\82Ì\90i\92»</returns>\r
95                 protected virtual float GetProgressPercent(TaskEventType type, float subTaskProgress)\r
96                 {\r
97                         if (CurrentTaskSetIndex >= 0) {\r
98                                 if (subTaskProgress >= 0) {\r
99                                         return (CurrentTaskSetIndex * 100 + subTaskProgress) / taskSetNames.Count;\r
100                                 }\r
101                                 switch (type) {\r
102                                         case TaskEventType.STARTED:\r
103                                                 return 0;\r
104                                         case TaskEventType.COMPLETED:\r
105                                                 return 100;\r
106                                         case TaskEventType.COMPLETED_SUBTASK:\r
107                                                 return ((CurrentTaskSetIndex+1) * 100) / taskSetNames.Count;\r
108                                         default:\r
109                                                 return (CurrentTaskSetIndex * 100) / taskSetNames.Count;\r
110                                 }\r
111                         }\r
112                         \r
113                         return -1;\r
114                 }\r
115                 \r
116                 #region TaskEvent\95Ö\97\98\83\81\83\\83b\83h\r
117                 \r
118                 protected virtual void RaiseTaskSetEvent(TaskEventType type, string message)\r
119                 {\r
120                         RaiseTaskSetEvent(type, message, GetProgressPercent(type, -1));\r
121                 }\r
122                 \r
123                 protected virtual void ReceivedErrorData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
124                 {\r
125                         if (! string.IsNullOrEmpty(e.Data)) {\r
126                                 RaiseTaskSetEvent(TaskEventType.WARNING, e.Data);\r
127                         }\r
128                 }\r
129                 \r
130                 protected virtual void ReceivedOutputData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)\r
131                 {\r
132                         if (! string.IsNullOrEmpty(e.Data)) {\r
133                                 RaiseTaskSetEvent(TaskEventType.INFO, e.Data);\r
134                         }\r
135                 }\r
136                 \r
137                 #endregion\r
138                 \r
139                 protected virtual NaGetTaskQueryResult RaiseTaskSetQueryEvent(string message, NaGetTaskQueryResult selection)\r
140                 {\r
141                         if (TaskQueryRaised != null) {\r
142                                 return TaskQueryRaised(this, new NaGetTaskQueryArgs(message, selection));\r
143                         }\r
144                         return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;\r
145                 }\r
146                 \r
147                 public override bool Running {\r
148                         get { return CurrentTaskSetIndex >= 0 && !Done; }\r
149                 }\r
150         }\r
151 }\r