Example #1
0
        private bool internalValidOwner(string target_status_mnemonic)
        {
            string current_status = null;

            if (LatestInstance == null)
            {
                return(true);
            }
            if (target_status_mnemonic.Equals(STATUS_INIT) == false)
            {
                current_status = LatestInstance.task_status;
            }
            User requestor = null;

            switch (target_status_mnemonic)
            {
            case STATUS_INIT:
                if (internalCheckTaskAccessibility())
                {
                    return(true);
                }
                break;

            case STATUS_APPROVAL:
            case STATUS_REJECT:
                //Get Submit Persons
                if (IsSelfApproveEnable == false)
                {
                    requestor = User.GetUser(LatestInstance.entry_author);
                    if (requestor.IsValid && requestor.Equals(CurrentUser))
                    {
                        return(false);
                    }
                }
                foreach (Models.TaskSubmitInformation taskSubmitInformation in GyomuDataAccess.SelectTaskSubmitInformation(LatestInstance))
                {
                    User submit_user = User.GetUser(taskSubmitInformation.submit_to);
                    if (submit_user.IsValid)
                    {
                        if (submit_user.IsGroup == false && submit_user.Equals(CurrentUser))
                        {
                            return(true);
                        }
                        if (submit_user.IsGroup)
                        {
                            if (CurrentUser.IsInGroup(submit_user))
                            {
                                return(true);
                            }
                        }
                    }
                }
                break;

            case STATUS_EXECUTE:
                //If Current Status is not Delegate, it must be equal to Latest instance's user
                if (STATUS_DELEGATE.Equals(current_status) == false)
                {
                    Models.DelegateInformation info = DelegateInformation;
                    if (info.DelegationRequired)
                    {
                        if (Instances.Where(i => i.task_status.Equals(STATUS_DELEGATE) && i.entry_author.Equals(CurrentUser.UserID)).Count() > 0)
                        {
                            return(true);
                        }
                        User previousUser = User.GetUser(LatestInstance.entry_author);
                        if (previousUser.IsValid && previousUser.Equals(CurrentUser))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        User previousUser = User.GetUser(LatestInstance.entry_author);
                        if (previousUser.IsValid && previousUser.Equals(CurrentUser))
                        {
                            return(true);
                        }
                    }
                }
                //Else it must be submit user in the latest instance
                else
                {
                    foreach (Models.TaskSubmitInformation taskSubmitInformation in GyomuDataAccess.SelectTaskSubmitInformation(LatestInstance))
                    {
                        User submit_user = User.GetUser(taskSubmitInformation.submit_to);
                        if (submit_user.IsValid)
                        {
                            if (submit_user.IsGroup == false && submit_user.Equals(CurrentUser))
                            {
                                return(true);
                            }
                            if (submit_user.IsGroup && CurrentUser.IsInGroup(submit_user))
                            {
                                return(true);
                            }
                        }
                    }
                }
                break;

            case STATUS_REQUEST:
                //Approver or Starter
                User starter = User.GetUser(CurrentTask.entry_author);
                if (starter.IsValid && starter.Equals(CurrentUser))
                {
                    return(true);
                }
                if (LatestInstance.task_status.Equals(STATUS_APPROVAL))
                {
                    User approver = User.GetUser(LatestInstance.entry_author);
                    if (approver.IsValid && approver.Equals(CurrentUser))
                    {
                        return(true);
                    }
                }
                break;

            case STATUS_CANCEL:
                //Requester
                requestor = User.GetUser(LatestInstance.entry_author);
                if (requestor.IsValid && requestor.Equals(CurrentUser))
                {
                    return(true);
                }
                break;

            case STATUS_COMPLETE:
                //For Force Success
                if (internalCheckTaskAccessibility() == false)
                {
                    return(false);
                }
                if (current_status.Equals(STATUS_FAIL))
                {
                    return(true);
                }
                break;

            default:
                return(true);
            }
            return(false);
        }
Example #2
0
        private StatusCode executionDecision(string parameter, string comment)
        {
            StatusCode retVal = StatusCode.SUCCEED_STATUS;

            Models.ProposalInformation apply_info = GetProposalInformation;
            if (apply_info.ProposalRequired)
            {
                retVal = sendApply(apply_info, parameter, comment);
            }
            else
            {
                Models.DelegateInformation delegate_info = DelegateInformation;
                if (!retVal.IsSucceeded)
                {
                    return(retVal);
                }
                if (IsAsynchrnous && delegate_info.DelegateUserList.Contains(CurrentUser) == false)
                {
                    //Create New Instance Delegate
                    if (!retVal.IsSucceeded)
                    {
                        return(retVal);
                    }
                    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
                    {
                        retVal = OnDelegate(parameter, comment);
                    }
                    if (!retVal.IsSucceeded)
                    {
                        return(retVal);
                    }
                    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        retVal =
                            createNewInstance(parameter, STATUS_DELEGATE,
                                              delegate_info.DelegateUserList, null, comment);
                        scope.Complete();
                    }
                }
                else
                {
                    if (IsAsynchrnous)
                    {
                        //Create New Instance Executing
                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            retVal =
                                createNewInstance(parameter, STATUS_EXECUTE, null, null, null);
                            scope.Complete();
                        }
                        if (!retVal.IsSucceeded)
                        {
                            return(retVal);
                        }
                        //Create Thread and call OnExec
                        Thread th = new Thread(new ParameterizedThreadStart(this.doAsyncExec));
                        th.Start(parameter);
                        AsyncThread = th;
                    }
                    else
                    {
                        using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                        {
                            retVal =
                                createNewInstance(parameter, STATUS_EXECUTE, null, null, null);

                            scope.Complete();
                        }
                        if (!retVal.IsSucceeded)
                        {
                            return(retVal);
                        }
                        //Call OnExec;
                        retVal = doExec(parameter);
                    }
                }
            }
            return(retVal);
        }