/// <summary>
        /// Action <code>ActionAddress_CreateOrUpdate</code> that represents the Service Studio user action
        ///  <code>Address_CreateOrUpdate</code> <p> Description: This action creates or updates the give
        /// n address.</p>
        /// </summary>
        public static void ActionAddress_CreateOrUpdate(HeContext heContext, ENAddressEntityRecord inParamAddressR, out long outParamAddressId)
        {
            lcoAddress_CreateOrUpdate result    = new lcoAddress_CreateOrUpdate();
            lcvAddress_CreateOrUpdate localVars = new lcvAddress_CreateOrUpdate(inParamAddressR);

            try {
                // new address?
                if (((localVars.inParamAddressR.ssId == Convert.ToInt64(BuiltInFunction.NullIdentifier()))))
                {
                    // creation info
                    // AddressR.Active = True
                    localVars.inParamAddressR.ssActive = true;
                    // AddressR.CreatedDate = CurrDateTime
                    localVars.inParamAddressR.ssCreatedDate = BuiltInFunction.CurrDateTime();
                    // AddressR.CreatedBy = GetUserId
                    localVars.inParamAddressR.ssCreatedBy = BuiltInFunction.GetUserId();
                }

                // update info
                // AddressR.LastUpdatedDate = CurrDateTime
                localVars.inParamAddressR.ssLastUpdatedDate = BuiltInFunction.CurrDateTime();
                // AddressR.LastUpdatedBy = GetUserId
                localVars.inParamAddressR.ssLastUpdatedBy = BuiltInFunction.GetUserId();
                // CreateOrUpdateAddress
                ExtendedActions.CreateOrUpdateAddress(heContext, localVars.inParamAddressR.ChangedAttributes, (((RCAddressRecord)localVars.inParamAddressR)), out localVars.resCreateOrUpdateAddress_outParamId);

                // AddressId = CreateOrUpdateAddress.Id
                result.outParamAddressId = localVars.resCreateOrUpdateAddress_outParamId;
            }             // try

            finally {
                outParamAddressId = result.outParamAddressId;
            }
        }
Esempio n. 2
0
        public string GetDynamicHtmlInjection(AppInfo app, SessionInfo session, string locale, string data)
        {
            int       userId = (session != null ? session.UserId : 0);
            ObjectKey userProviderEspaceKey = (HttpContext.Current != null ? app.UserProviderEspaceKeyAsKey : null);

            if (userId == BuiltInFunction.NullIdentifier())
            {
                return(string.Empty);
            }

            InboxQueries.PaginationInfo?inboxActivityCount;

            using (Transaction trans = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) {
                // Check if the User Providers are shared between the Inbox and the current eSpace
                if (inboxUserProviderEspaceKey == null)
                {
                    inboxUserProviderEspaceKey = ObjectKey.Parse(DBRuntimePlatform.Instance.GetUserProviderKey(trans, Constants.EPATaskboxESpaceKey));
                }
                if (userProviderEspaceKey != inboxUserProviderEspaceKey)
                {
                    return(string.Empty);
                }

                inboxActivityCount = InboxQueries.GetActivityCount(trans, userId);
            }

            if (!inboxActivityCount.HasValue)
            {
                throw new DataBaseException("No activity data found for userId = " + userId);
            }

            return("<script type='text/javascript'> EPATaskbox.instance = new EPATaskbox(outsystems.internal.$('.EPATaskbox_Container'), " + userId +
                   ", " + inboxActivityCount.Value.Total + ", " + (inboxActivityCount.Value.Unseen > 0 ? "true" : "false") +
                   ", null); </script>");
        }
Esempio n. 3
0
        public static int GetNextHumanActivity(HeContext heContext, Transaction tran, IEnumerable <Pair <int, ActivityKind> > nextActivities, int userId)
        {
            var humanActivitiesIds = nextActivities.Where(pair => pair.Second == ActivityKind.HumanActivity)
                                     .Select(pair => pair.First);

            if (!humanActivitiesIds.IsEmpty())
            {
                return(BPMRuntime.GetAllowedActivities(heContext, tran, humanActivitiesIds, userId).FirstIfSingleOrDefault());
            }
            return(BuiltInFunction.NullIdentifier());
        }
        public int ExecuteProcessDefEvent(string ssKey, int tenantId, string dataId)
        {
            int processId = 0;

            bool res = false;

            res = ExecuteWebService("ProcessImplicitLaunch",
                                    delegate(HeContext heContext) {
                return(ExecuteProcessWebService(heContext, ssKey, tenantId, 0, string.Empty,
                                                delegate(IProcess execObj) {
                    execObj.ProcessImplicitLaunch(heContext, dataId, out processId);
                }));
            }
                                    ,
                                    false);

            return(res ? processId: BuiltInFunction.NullIdentifier());
        }
Esempio n. 5
0
        public static IEnumerable <int> GetAllowedActivities(HeContext heContext, Transaction tran, IEnumerable <int> activityIds, int userId)
        {
            foreach (var nextId in activityIds)
            {
                int            assignedUser;
                ActivityStatus statusId;
                bool           needsPermission = DBRuntimePlatform.Instance.NeedsActivityPermissions(tran, nextId, out assignedUser, out statusId);


                if (assignedUser != BuiltInFunction.NullIdentifier())
                {
                    if (assignedUser != userId)
                    {
                        continue;
                    }
                }
                else
                {
                    if (statusId != ActivityStatus.Ready)
                    {
                        continue;
                    }

                    if (needsPermission)
                    {
                        var roles = DBRuntimePlatform.Instance.GetActivityRoles(tran, nextId);
                        if (!roles.Any(role => GenericExtendedActions.Check(heContext, role.First, userId, role.Second)))
                        {
                            continue;
                        }
                    }
                }

                yield return(nextId);
            }
        }
Esempio n. 6
0
        public static int CreateProcessInstance(HeContext heContext, int tenantId, ObjectKey espaceSSKey, ObjectKey processSSKey, int parentActivityId, int parentProcessId, out Pair <int, ObjectKey> startActivity)
        {
            int       startActivityId;
            ObjectKey activityDefKey;
            int       newProcessId;

            using (Transaction trans = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) {
                int processDefId = 0;
                int topProcessId = 0;
                int createdBy    = 0;

                using (IDataReader reader = DBRuntimePlatform.Instance.GetProcessDefinition(trans, processSSKey, espaceSSKey)) {
                    if (reader.Read())
                    {
                        processDefId = reader.SafeGet <int>("ID");
                    }
                    else
                    {
                        throw new DataBaseException("No process definition exists with key '" + processSSKey + "'.");
                    }
                }


                if (parentActivityId != BuiltInFunction.NullIdentifier())
                {
                    int parentTenantId;
                    parentProcessId = DBRuntimePlatform.Instance.GetParentProcessId(trans, parentActivityId, out parentTenantId);
                }

                if (parentProcessId != BuiltInFunction.NullIdentifier())
                {
                    topProcessId = DBRuntimePlatform.Instance.GetTopProcessId(trans, parentProcessId);
                }
                else
                {
                    // Is not sub-process so we need to set the CreatedBy field
                    createdBy = heContext.Session.UserId;
                }

                newProcessId = DBRuntimePlatform.Instance.CreateProcess(trans, tenantId, BuiltInFunction.CurrDateTime(), createdBy, processDefId, parentProcessId, parentActivityId, topProcessId, ProcessStatus.Active);

                int    activityDefId = 0;
                string activityDefName;

                using (IDataReader reader = DBRuntimePlatform.Instance.GetActivityDefinitionsForKind(trans, newProcessId, ActivityKind.Start)) {
                    if (reader.Read())
                    {
                        activityDefId   = reader.SafeGet <int>("ID");
                        activityDefKey  = ObjectKey.Parse(reader.SafeGet <string>("SS_KEY"));
                        activityDefName = reader.SafeGet <string>("NAME", string.Empty);
                    }
                    else
                    {
                        throw new DataBaseException("No active " + ActivityKind.Start.ToString() + " activity exists for process #" + newProcessId + ".");
                    }
                }

                startActivityId = CreateActivityInstance(heContext, trans, tenantId, activityDefId, newProcessId, activityDefName, 0, null);
            }

            startActivity = Pair.Create(startActivityId, activityDefKey);

            return(newProcessId);
        }
Esempio n. 7
0
        protected void StartActivityExecution(HeContext heContext, int activityId, int processId, ActivityStatus?forInitialStatus, out bool runnable, out ActivityStatus currentStatus, DateTime previousNextRun)
        {
            runnable = false;

            using (Transaction trans = DatabaseAccess.ForSystemDatabase.GetRequestTransaction()) {
                int tenantId = heContext.AppInfo.Tenant.Id;
                int precedentActivityId;
                int precedentActivitySuccessorsCount;
                int rootProcessId;
                if (Debugger.IsRunning)
                {
                    rootProcessId       = DBRuntimePlatform.Instance.GetTopProcessId(trans, processId);
                    precedentActivityId = DBRuntimePlatform.Instance.GetPrecedentActivityId(trans, activityId);
                    if (precedentActivityId == BuiltInFunction.NullIdentifier() && rootProcessId != processId)
                    {
                        // the precendent activity is the activity that launched the subprocess. We need to get
                        // an activity from the same eSpace we're in, because external processes are not executed
                        // in the same web app (contrary to what happens when debugging reference actions, whose code
                        // is all in the consumer eSpace)
                        precedentActivityId = DBRuntimePlatform.Instance.GetAncestorActivityIdInTenant(trans, processId, RunningInfo.TenantId);
                    }

                    precedentActivitySuccessorsCount = DBRuntimePlatform.Instance.GetActivitySuccessorsCount(trans, precedentActivityId);
                }
                else
                {
                    rootProcessId       = 0;
                    precedentActivityId = -1;
                    precedentActivitySuccessorsCount = 0;
                }
                SetCurrentProcessInfo(processId, activityId, precedentActivityId, precedentActivitySuccessorsCount, rootProcessId);

                if (DBRuntimePlatform.Instance.GetProcessStatus(trans, processId) == ProcessStatus.Suspended)
                {
                    throw new InvalidOperationException("Could not execute a built-in/extended action on activity '" + Name + "' (#" + activityId
                                                        + ") because its process is suspended.");
                }

                using (IDataReader reader = DBRuntimePlatform.Instance.GetActivity(trans, tenantId, activityId, true)) {
                    if (reader.Read())
                    {
                        DateTime nextRun = (DateTime)reader.SafeGet <DateTime>("NEXT_RUN");
                        currentStatus = (ActivityStatus)reader.SafeGet <int>("STATUS_ID");

                        DateTime isRunningSince = reader.SafeGet <DateTime>("IS_RUNNING_SINCE", BuiltInFunction.NullDate());

                        runnable = IsRunnableActivity(isRunningSince, forInitialStatus, currentStatus, previousNextRun, nextRun);
                    }
                    else
                    {
                        throw new InvalidOperationException("Could not execute a built-in/extended action on activity '" + Name + "' (#" + activityId
                                                            + ") because the activity does not exist.");
                    }
                }

                if (runnable)
                {
                    DBRuntimePlatform.Instance.UpdateActivity(trans, tenantId, activityId, null, null, null, null, null, null, null, null,
                                                              true, Settings.MachineName, null, null, null, null, null, null, null, null, null);
                }
            }

            DatabaseAccess.CommitAllTransactions();
        }