using System;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using NaGet.SubCommands.SubTask;
using NaGet.Tasks;
/// <summary>
/// NaGetタスク処理のパック
/// </summary>
- public abstract class NaGetTaskSet2 : NaGetTaskSet
+ public abstract class NaGetTaskSet2 : Task
{
/// <summary>
/// サブタスクのハンドラ
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;
}
}
- public override int CurrentTaskSetIndex {
+ public virtual int CurrentTaskSetIndex {
get { return currentSubTaskIndex; }
}
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>
#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()