public async Task StartShift(string name)
        {
            var picker = _pickerRepository.FindByName(name) ?? new Picker(Context.ConnectionId, name);

            if (picker.InstanceId == null || !await _processClient.IsProcessInstanceRunning(picker.InstanceId))
            {
                var startResponse =
                    await _processClient.CreateProcessInstanceByModelId(ProcessModelId, ProcessStartEvent, picker);

                picker.InstanceId = startResponse.ProcessInstanceId;
                if (_pickerRepository.StartShift(picker))
                {
                    await Clients.Caller.ShiftStartConfirmed();
                }
                else
                {
                    await _processClient.TerminateProcessInstanceById(startResponse.ProcessInstanceId);
                }
            }
            else
            {
                if (_pickerRepository.ResumeShift(picker, Context.ConnectionId))
                {
                    await Clients.Caller.ShiftStartConfirmed();
                }
                else
                {
                    // terminate process
                }
            }
        }
예제 #2
0
        public async Task StartProcess()
        {
            var correlationId = Context.GetUserId();

            var processId = _connectionMapping.GetProcess(correlationId);

            var processInfo = _processInfoProvider.Get(correlationId);

            var isRestarted = true;

            if (processId == null || !await _processClient.IsProcessInstanceRunning(processId))
            {
                var result = await _processClient.CreateProcessInstanceByModelId <string>(
                    correlationId, processInfo, null
                    );

                isRestarted = false;
                _connectionMapping.MapProcess(result.CorrelationId, result.ProcessInstanceId);
            }

            await Clients.Caller.ProcessStartConfirmed(processInfo.ModelId);

            if (isRestarted)
            {
                _processHandlersFactory
                .GetReattachHandler(processInfo.ModelId)?
                .OnReattach();
            }

            _processClient.SubscribeForPendingUserTasks(correlationId, tasks =>
            {
                UserTask handledTaskId = null;
                foreach (var task in tasks)
                {
                    try
                    {
                        var connectionId = _connectionMapping.GetConnection(correlationId);
                        _logger.Log(LogLevel.Debug, $"Exec: Handled task: {correlationId}/{task.Id}");
                        switch (_clientTaskFactory.Create(task))
                        {
                        case { Type: ClientTaskType.Selection } t: