private static int InnerActivityClose(HeContext heContext, int activityId, bool advanceProcess, bool skip, bool skipAll, Action </*id*/ int, /*name*/ string, ActivityKind, /*key*/ string> activityChecks, List <Pair <string, object> > inputs)
        {
            int    userId = heContext.Session.UserId;
            string SSKey;
            string url;
            int    tenantId;
            List <Pair <int, ActivityKind> > nextActIds;

            ActivityKind activityKind;
            string       activityName;
            int          processId;

            BPMRuntime.GetActivityDataForWS(activityId, out processId, out activityKind, out activityName, out SSKey, out url, out tenantId);

            activityChecks(activityId, activityName, activityKind, SSKey);

            using (ActivityHandler activityHandler = new ActivityHandler(url)) {
                string failureMessage;
                bool   success = activityHandler.ExecuteOnClose(SSKey, activityId, processId, tenantId, userId, BuiltInFunction.GetCurrentLocale(), advanceProcess, skip, skipAll, inputs, out failureMessage, out nextActIds);

                if (!success)
                {
                    ProcessBase.ThrowSpecificException(failureMessage);
                }
            }

            if (advanceProcess)
            {
                using (Transaction tran = DatabaseAccess.ForSystemDatabase.GetReadOnlyTransaction()) {
                    return(BPMRuntime.GetNextHumanActivity(heContext, tran, nextActIds, userId));
                }
            }

            return(BuiltInFunction.NullIdentifier());
        }
        public static int ProcessLaunch(HeContext heContext, ObjectKey SSKey, ObjectKey espaceSSKey, int parentActivityId, int parentProcessId, List <Pair <string, object> > inputs, out int nextHumanActivity)
        {
            List <Pair <int, ActivityKind> > nextActIds;

            int newProcessId = ProcessLaunch(heContext, SSKey, espaceSSKey, parentActivityId, parentProcessId, inputs, out nextActIds);

            nextHumanActivity = BuiltInFunction.NullIdentifier();

            return(newProcessId);
        }
        public static void ActivityStart(HeContext heContext, int processId, string activityssKey, string actionName, List <Pair <string, object> > inputs, out int nextHumanActivityId)
        {
            int activityId;

            using (Transaction tran = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) {
                var retries = 0;
                do
                {
                    activityId = DBRuntimePlatform.Instance.GetActiveActivityInProcess(tran, processId, activityssKey, ActivityStatus.Listening);
                    if (activityId == BuiltInFunction.NullIdentifier())
                    {
                        if (Settings.GetBool(Settings.Configs.BPT_ConditionalStartListenersCreatedOnDemand))
                        {
                            using (Transaction priv = DatabaseAccess.ForSystemDatabase.GetCommitableTransaction()) {
                                DBRuntimePlatform.Instance.CreateMissingStartActivityInProcess(priv, processId, activityssKey);
                                activityId = DBRuntimePlatform.Instance.GetActiveActivityInProcess(tran, processId, activityssKey, ActivityStatus.Created);
                                priv.Commit();
                            }
                            // Needed to execute the onready as fast as possible (don't wait for the scheduler)
                            ActivityPushFromCreated(processId, activityssKey, activityId);
                            activityId = DBRuntimePlatform.Instance.GetActiveActivityInProcess(tran, processId, activityssKey, ActivityStatus.Listening);
                        }
                    }
                    retries++;
                    // Wait up to 30 seconds in case the scheduler captured the activity
                    if (activityId != BuiltInFunction.NullIdentifier() ||
                        retries >= Settings.GetInt(Settings.Configs.BPT_StartActivityReadyWaitTimeInSeconds))
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                } while (true);

                if (activityId == BuiltInFunction.NullIdentifier())
                {
                    throw new InvalidOperationException("There is no activity in process #" + processId + " that could be started using " + actionName + ".");
                }
            }

            ActivityStart(heContext, activityId, inputs, out nextHumanActivityId);
        }