/// <summary> /// Initiate the processing of asynchronous task. /// </summary> /// <param name="parameterValue">asynchronous parameter values</param> public void UOC_Start(ApsParameterValue parameterValue) { // Generates a return value class. // 戻り値クラスを生成する。 ApsReturnValue returnValue = new ApsReturnValue(); this.ReturnValue = returnValue; // Get array data from serialized json string. List <int> listData = JsonConvert.DeserializeObject <List <int> >(parameterValue.Data); // Get command information from database to check for retry. // データベースからコマンド情報を取得して確認する。 ApsUtility.GetCommandValue(parameterValue.TaskId, returnValue, this.GetDam(this.DamKeyforAMT)); if (returnValue.CommandId == (int)AsyncCommand.Stop) { // Retry task: to resume asynchronous process in the middle of the processing. // 再試行タスク:処理の途中で停止された非同期処理を再開する。 ApsUtility.ResumeProcessing(parameterValue.TaskId, returnValue, this.GetDam(this.DamKeyforAMT)); // Updated progress rate will be taken as random number. // 進捗率をインクリメントする。 ProgressRate = this.GenerateProgressRate(ProgressRate); } else { // Otherwise, implement code to initiating a new task. // それ以外の場合は、新しいタスクを開始するコードを実装する。 //... // Hence, initializing progress rate to zero. // したがって、進捗率をゼロに設定する。 ProgressRate = 0; } // Updates the progress rate and handles abnormal termination of the process. // 進捗率をインクリメントしたり、プロセスの異常終了を処理したり。 this.Update(parameterValue.TaskId, returnValue); }
/// <summary> /// Updates the progress rate and handles abnormal termination of the process. /// </summary> /// <param name="taskID">Task ID</param> /// <param name="returnValue">user parameter value</param> private void Update(int taskID, ApsReturnValue returnValue) { // Place the following statements in the loop, till the completion of task. // タスクが完了するまで、ループ内の処理を実行する。 while (true) { // Get command information from database to check for retry. // データベースからコマンド情報を取得して、CommandIdを確認。 ApsUtility.GetCommandValue(taskID, returnValue, this.GetDam(this.DamKeyforAMT)); switch (returnValue.CommandId) { case (int)AsyncCommand.Stop: // If you want to retry, then throw the following exception. // 処理の途中で停止する場合は、次の例外をスロー。 throw new BusinessApplicationException( AsyncErrorMessageID.APSStopCommand.ToString(), GetMessage.GetMessageDescription("CTE0003"), ""); case (int)AsyncCommand.Abort: // Implement code to forcefully Abort the task. // If the task is abnormal terminated, then throw the exception. // 強制的にタスクを中断する場合は、例外をスロー。 throw new BusinessSystemException( AsyncErrorMessageID.APSAbortCommand.ToString(), GetMessage.GetMessageDescription("CTE0004")); default: // Generates new progress rate of the task. // 進捗率をインクリメント ProgressRate = this.GenerateProgressRate(ProgressRate); // Update the progress rate in database. // データベースの進捗率を更新。 ApsUtility.UpdateProgressRate( taskID, returnValue, ProgressRate, this.GetDam(this.DamKeyforAMT)); // 非同期タスクのシミュレーション if (this.Fortune(this.AbortPercentage)) { // Update ABORT command to database // データベースのコマンドをABORTに更新。 ApsUtility.UpdateTaskCommand( taskID, (int)AsyncCommand.Abort, returnValue, this.GetDam(this.DamKeyforAMT)); } else if (this.Fortune(this.StopPercentage)) { // Update STOP command to database // データベースのコマンドをSTOPに更新。 ApsUtility.UpdateTaskCommand( taskID, (int)AsyncCommand.Stop, returnValue, this.GetDam(this.DamKeyforAMT)); } else if (SUCCESS_STATE <= ProgressRate) { // Task is completed sucessfully. // タスクは正常に完了 return; } else { // タスクは継続する。 Thread.Sleep(this.NumberOfSeconds * 1000); } break; } } }