Esempio n. 1
0
        public int DisplaceUserInProcess(string processID, string userID, string[] displacingUserIDArray)
        {
            IUser originalUser = OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.Guid, userID).FirstOrDefault();

            OguObjectCollection <IUser> displacingUsers = OguMechanismFactory.GetMechanism().GetObjects <IUser>(SearchOUIDType.Guid, displacingUserIDArray);

            List <IUser> distinctUsers = new List <IUser>();

            foreach (IUser user in displacingUsers)
            {
                if (distinctUsers.Exists(u => u.ID == user.ID) == false)
                {
                    distinctUsers.Add(user);
                }
            }

            IWfProcess process = WfRuntime.GetProcessByProcessID(processID);

            int result = 0;

            foreach (IWfActivity activity in process.Activities)
            {
                bool needReplace = false;

                if (activity.Status != WfActivityStatus.Completed && activity.Status != WfActivityStatus.Aborted)
                {
                    if (activity.Status == WfActivityStatus.Running || activity.Status == WfActivityStatus.Pending)
                    {
                        needReplace = activity.Assignees.Contains(originalUser.ID);
                    }
                    else
                    {
                        needReplace = activity.Candidates.Contains(originalUser.ID);
                    }

                    if (needReplace)
                    {
                        WfReplaceAssigneesExecutor executor = new WfReplaceAssigneesExecutor(null, activity, originalUser, distinctUsers);

                        executor.ExecuteNotPersist();
                        result++;
                    }
                }
            }

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                WfReplaceAssigneesExecutor.DoUserTaskOperations();
                WfRuntime.PersistWorkflows();

                scope.Complete();
            }

            return(result);
        }