OSDN Git Service

AppliStation-all,アセンブリバージョンを1.4.6に
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands / NaGetTaskSet2.cs
index 3a20d18..5d9a848 100644 (file)
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using NaGet.SubCommands.SubTask;
 using NaGet.Tasks;
 
@@ -8,7 +9,7 @@ namespace NaGet.SubCommands
        /// <summary>
        /// NaGetタスク処理のパック
        /// </summary>
-       public abstract class NaGetTaskSet2 : NaGetTaskSet
+       public abstract class NaGetTaskSet2 : Task
        {
                /// <summary>
                /// サブタスクのハンドラ
@@ -16,11 +17,21 @@ namespace NaGet.SubCommands
                public virtual event EventHandler<TaskEventArgs> SubTaskEventRaised;
                
                /// <summary>
+               /// タスク処理中の質問のハンドラ
+               /// </summary>
+               public event NaGetTaskQueryHandler TaskQueryRaised;
+               
+               /// <summary>
                /// サブタスクのリスト
                /// </summary>
                protected IList<NaGetSubTask> subTasks;
                
                /// <summary>
+               /// 文字列で表現した作業一覧リスト
+               /// </summary>
+               protected IList<string> taskSetNames;
+               
+               /// <summary>
                /// 現在実行中のサブタスクのインデックス
                /// </summary>
                private int currentSubTaskIndex = -1;
@@ -75,7 +86,7 @@ namespace NaGet.SubCommands
                        }
                }
                
-               public override int CurrentTaskSetIndex {
+               public virtual int CurrentTaskSetIndex {
                        get { return currentSubTaskIndex; }
                }
                
@@ -87,6 +98,46 @@ namespace NaGet.SubCommands
                        get { return isCancelled; }
                }
                
+               public override bool Running {
+                       get { return CurrentTaskSetIndex >= 0 && !Done; }
+               }
+               
+               /// <summary>
+               /// 文字列で表現した作業一覧リスト
+               /// </summary>
+               public virtual IList<string> TaskSetNames {
+                       get {
+                               return new ReadOnlyCollection<string>(taskSetNames);
+                       }
+               }
+               
+               /// <summary>
+               /// 現在の進捗を戻す。
+               /// </summary>
+               /// <param name="type">作業の状態</param>
+               /// <param name="subTaskProgress">サブタスクの進捗</param>
+               /// <returns>現在の進捗</returns>
+               protected virtual float GetProgressPercent(TaskEventType type, float subTaskProgress)
+               {
+                       if (CurrentTaskSetIndex >= 0) {
+                               if (subTaskProgress >= 0) {
+                                       return (CurrentTaskSetIndex * 100 + subTaskProgress) / taskSetNames.Count;
+                               }
+                               switch (type) {
+                                       case TaskEventType.STARTED:
+                                               return 0;
+                                       case TaskEventType.COMPLETED:
+                                               return 100;
+                                       case TaskEventType.COMPLETED_SUBTASK:
+                                               return ((CurrentTaskSetIndex+1) * 100) / taskSetNames.Count;
+                                       default:
+                                               return (CurrentTaskSetIndex * 100) / taskSetNames.Count;
+                               }
+                       }
+                       
+                       return -1;
+               }
+               
                #region フラグ処理の便利メソッド
                
                /// <summary>
@@ -150,6 +201,37 @@ namespace NaGet.SubCommands
                
                #endregion
                
+               #region TaskEvent便利メソッド
+               
+               protected virtual void RaiseTaskSetEvent(TaskEventType type, string message)
+               {
+                       RaiseTaskSetEvent(type, message, GetProgressPercent(type, -1));
+               }
+               
+               protected virtual void ReceivedErrorData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)
+               {
+                       if (! string.IsNullOrEmpty(e.Data)) {
+                               RaiseTaskSetEvent(TaskEventType.WARNING, e.Data);
+                       }
+               }
+               
+               protected virtual void ReceivedOutputData(object sender, NaGet.Utils.AnyDataEventArgs<string> e)
+               {
+                       if (! string.IsNullOrEmpty(e.Data)) {
+                               RaiseTaskSetEvent(TaskEventType.INFO, e.Data);
+                       }
+               }
+               
+               protected virtual NaGetTaskQueryResult RaiseTaskSetQueryEvent(string message, NaGetTaskQueryResult selection)
+               {
+                       if (TaskQueryRaised != null) {
+                               return TaskQueryRaised(this, new NaGetTaskQueryArgs(message, selection));
+                       }
+                       return NaGetTaskQueryResult.CANCELED_AUTOMATICALLY;
+               }
+                               
+               #endregion
+               
                #region サブタスク初期化・登録便利メソッド
                
                protected void initSubTask()