using System; namespace NaGet.SubCommands { #region EventHandler関連 public class NaGetTaskSetEventArgs : NaGetEventArgs { public NaGetTaskSetEventType Type; public NaGetTaskSetEventArgs(NaGetTaskSetEventType type, string message, float processPercent) { this.Type = type; this.TaskMessage = message; this.TaskProgressPercent = processPercent; } } /// /// タスクの種類 /// public enum NaGetTaskSetEventType { /// /// 開始 /// STARTED, /// /// 完了した(すべてを完了) /// COMPLETED, /// /// 作業がキャンセルされた /// CANCELED, /// /// エラーを発生し(中断した) /// ERROR, /// /// エラーが発生したが継続 /// WARNING, /// /// そのほかの情報 /// INFO, /// /// 作業を開始 /// STARTED_TASKSET, /// /// 作業を終了 /// COMPLETED_TASKSET, } #endregion #region NaGetTaskQueryHandler関連 public delegate NaGetTaskQueryResult NaGetTaskQueryHandler(object sender, NaGetTaskQueryArgs e); public class NaGetTaskQueryArgs { /// /// タスクの現況のメッセージ /// public string Message; /// /// 回答の種類のフラグ /// public NaGetTaskQueryResult SelectionFlag; public NaGetTaskQueryArgs(string message, NaGetTaskQueryResult selectionFlag) { this.Message = message; this.SelectionFlag = selectionFlag; } } /// /// 質問の答え /// [Flags()] public enum NaGetTaskQueryResult : uint { /// /// 継続(=OK) /// CONTINUE = 0x01, /// /// 再試行 /// RETRY = 0x02, /// /// キャンセル、中止 /// CANCEL = 0x04, /// /// 自動的なキャンセル(ユーザの手ではないもの) /// CANCELED_AUTOMATICALLY = 0x00, } #endregion /// /// NaGetタスク処理のパック /// public abstract class NaGetTaskSet : NaGetTask { /// /// タスク処理のイベントハンドラ /// public event EventHandler TaskSetRaised; /// /// タスク処理中の質問のハンドラ /// public event NaGetTaskQueryHandler TaskQueryRaised; /// /// 文字列で表現した作業一覧リスト /// public string[] TaskSetNames; /// /// 現在実行中の作業番号 /// public abstract int CurrentTaskSetIndex { get; } protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message) { float percent = (CurrentTaskSetIndex >= 0)? CurrentTaskSetIndex * 100 / TaskSetNames.Length : -1; RaiseTaskSetEvent(type, message, percent); } protected virtual void RaiseTaskSetEvent(NaGetTaskSetEventType type, string message, float percent) { if (TaskSetRaised != null) { TaskSetRaised(this, new NaGetTaskSetEventArgs(type, message, percent)); } } protected virtual void ReceivedErrorData(object sender, NaGet.Utils.AnyDataEventArgs e) { if (! string.IsNullOrEmpty(e.Data)) { RaiseTaskSetEvent(NaGetTaskSetEventType.WARNING, e.Data); } } protected virtual void ReceivedOutputData(object sender, NaGet.Utils.AnyDataEventArgs e) { if (! string.IsNullOrEmpty(e.Data)) { RaiseTaskSetEvent(NaGetTaskSetEventType.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; } public override bool Running { get { return CurrentTaskSetIndex >= 0 && !Done; } } } }