コード例 #1
0
        private async void CheckNotClaimedAndNotDeligatedBefore(HttpClient httpClient,
                                                                WorkflowContinueRequest continueRequest)
        {
            if (EngineTask == null)
            {
                EngineTask = await CheckTaskExists(httpClient, continueRequest);
            }

            if (EngineTask.DelegationState == "pending")
            {
                throw new AccessViolationException("این Task به یک نفر دیگر Deligate شده است " + EngineTask.Assignee);
            }

            if (EngineTask.Suspended)
            {
                throw new AccessViolationException("این Task به یک نفر دیگر Suspended شده است " + EngineTask.Assignee);
            }

            if (string.IsNullOrEmpty(EngineTask.Assignee))
            {
                throw new AccessViolationException("باید قبل از انجام این Task ابتدا آن را در وضعیت انحصار قرار دهید");
            }

            if (EngineTask.Assignee != continueRequest.Username)
            {
                throw new AccessViolationException(
                          "این Task توسط یک نفر دیگر در وضعیت انحصار انجام قرار گرفته است یا نام کاربری اشتباه است " +
                          EngineTask.Assignee);
            }
        }
コード例 #2
0
        private async Task <EngineTask> CheckTaskExists(HttpClient httpClient, WorkflowContinueRequest continueRequest)
        {
            var baseUrl = WorkflowSettingSingleTon.WorkflowSetting.BaseUrl;
            var url     = $@"{baseUrl}/runtime/tasks/{continueRequest.TaskId}";
            var resp    = await httpClient.GetAsync(url);

            if ((int)resp.StatusCode == 200)
            {
                return(this.EngineTask = await ActivitiEngineClientHelper.ParseTask(resp));
            }
            else if ((int)resp.StatusCode == 404)
            {
                throw new ActivitiEngineClientException("این Task با TaskId داده شده یافت نشد");
            }
            else
            {
                var errorxml = await resp.Content.ReadAsStringAsync();

                throw new Exception(errorxml);
            }
        }
コード例 #3
0
        public void StartTask(Func <Object?, List <Move>?> fun, Position position)
        {
#if UseTask
            if (CancellationTokenSource is null)
            {
                CancellationToken = getCancellationToken();
            }

            //
            // Start EngineTask to invoke startSearch(), which tests for cancellation
            // via monitorBound() below.
            //
            EngineTask = Task.Factory.StartNew(fun, position, CancellationToken);
            var nTimeoutMS = Bound.MoveTime(ExpectedMovesToGo);

            if (EngineTask.IsCompleted)
            {
                FinishTask = EngineTask;
            }
            else
            {
                //
                // The .Net 4.5 Framework substantially simplifies this by
                // providing a CancelAfter() method for CancellationSource.
                // This explicit apprach allows CancleTimer.Change() to be
                // called in ponderhit() below.
                //
                // Start CancelTimer, which uses the CancellationSource to
                // cancel EngineTask when it expires.
                //
                const Int32 period = Timeout.Infinite;
                CancelTimer = new Timer(state => ((CancellationTokenSource?)state)?.Cancel(),
                                        CancellationTokenSource, nTimeoutMS, period);

                //
                // The FinishTask will clean up when its antecedent EngineTask completes:
                // whether normally or by cancellation.  CancelTimer is then disposed of,
                // whether it fired or not.  FinishTask returns the EngineTask Result as
                // its own.
                //
                Func <Task <List <Move>?>, List <Move>?> fun2 =
                    antecedent => {
                    try {
                        CancelTimer.Dispose();
                        var result = antecedent.Result;
                        return(result);
                    }
                    catch (AggregateException aex) {
                        throw aex.Flatten();
                    }
                    finally {
                        CancelTimer = default;
                    }
                };

                FinishTask = EngineTask.ContinueWith <List <Move>?>(fun2);
            }
#else
            FinishTask = EngineTask = default;
            fun(position);
#endif
        }