Пример #1
0
        public static void Add(this WorkflowExpression expression, Operator.Operands _operator, object UserRefId = null, int applicationId = -1)
        {
            if (expression == null)
                expression = new WorkflowExpression();

      
            //if UserRefId is not Null, its the User  in action
            if (UserRefId == null && _operator != Operator.Operands.USER)
            {
               expression.ExpressionOperandsForView.Add(GetOperatorViewNotation(_operator));
               expression.ExpressionOperandsForEvaluation.Add(GetOperatorNotation(_operator));
            }
            else
            {
                if (applicationId > 0)
                {
                    var _ActorRep = EngineContext.Current.Resolve<IRepository<WorkflowActor, int>>();
                    var theActor = _ActorRep.Table.Where(x => x.ActorRefId == UserRefId.ToString() && x.ApplicationId == applicationId).FirstOrDefault();
                    if (theActor != null)
                    {
                        expression.ExpressionOperandsForView.Add(theActor.Description);
                      //  expression.ExpressionOperandsForEvaluation.Add("{ActorId:" + theActor.Id + "}");

                        expression.ExpressionOperandsForEvaluation.Add("{" + theActor.Id + "}");
                    }
                    else
                        throw new WorkflowGenericError("This User does not exist for the application.");
                }else
                    throw new WorkflowGenericError("Adding users require ApplicationId.");

            }

            
        }
Пример #2
0
        public int AddUserToWorkflowLevel2(WorkflowActor actor, int WorkflowLevelId, bool ActorMustAlwaysApproveInLevel = false)
        {
            //NHibernateHelper.GetCurrentSession().BeginTransaction();
            var wkLevel = _workflowLevels.Get(WorkflowLevelId);
            if (wkLevel != null)
            {
                //try
                //{
                //    NHibernateHelper.GetCurrentSession().BeginTransaction();
                if (!wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.Actor.ActorRefId == actor.ActorRefId &&
                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Count() > 0)
                        throw new WorkflowConfigurationError("User " + actor.Description  + " already exist in the Workflow.");

                }
                var actorId = 0;
                    var _actor = GetActor(actor.ActorRefId, actor.Id);
                    if (_actor != null)
                    {

                        _actor.Description = actor.Description;
                        _actors.Add(_actor);
                        actorId = _actor.Id;

                    }
                    else
                    {

                        actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                        _actors.Add(actor);
                        actorId = actor.Id;

                    }

                    //Save ActorInLevel
                    var _inLevel = GetActorInLevel(actorId, WorkflowLevelId);
                    // var _inLevel = GetActorInLevel(actor.Id, WorkflowLevelId);


                    if (_inLevel == null)
                    {
                        _inLevel = new WorkflowActorInLevel()
                        {
                            WorkflowLevelId = WorkflowLevelId,
                            ActorId = actorId,
                            ActorMustApprove = ActorMustAlwaysApproveInLevel
                        };

                    }
                    else
                        _inLevel.ActorMustApprove = ActorMustAlwaysApproveInLevel;
                    _actorsInLevels.Add(_inLevel);

                    var parametrs =
                        _levelParameters.Table.Where(c => c.WorkflowLevelId == WorkflowLevelId).FirstOrDefault();
                    if (parametrs != null)
                        if (parametrs.MaximumApprovalRequired > 1)
                            return _inLevel.Id;

                    //Build the default Expression
                    var actorsInLevel =
                        _actorsInLevels.Table.Where(x => x.WorkflowLevelId == WorkflowLevelId)
                            .Select(x => x.Actor.ActorRefId.ToString());

                    var _Xpression = new WorkflowExpression();
                    _Xpression.Add(Operator.Operands.OPENED_BRACKET);
                    int count = actorsInLevel.Count();
                    int _count = 0;
                    foreach (string _act in actorsInLevel)
                    {
                        ++_count;

                        _Xpression.Add(Operator.Operands.USER, _act, _inLevel.WorkflowLevel.Workflow.ApplicationId);
                        if (_count != count)
                            _Xpression.Add(Operator.Operands.OR);


                    }
                    _Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                    _Xpression.SaveExpression(WorkflowLevelId, 1);
                    // NHibernateHelper.GetCurrentSession().Transaction.Commit();
                    return _inLevel.Id;
                    //}
                    //catch (Exception ex)
                    //{
                    //    NHibernateHelper.GetCurrentSession().Transaction.Rollback();
                    //    throw new WorkflowGenericError("This User cannot be added to the Workflow level: " + ex.Message);
                    //}
           
            }
            else
            {
                throw new WorkflowConfigurationError("Workflow Level does not exist.");

            }


        }
Пример #3
0
        public int AddUserToLevel(WorkflowActor actor, int workflowLevelId, bool actorMustAlwaysApproveInLevel = false)
        {
          
            var wkLevel = _workflowLevels.Get(workflowLevelId);
            if (wkLevel != null)
            {
                
                if (!wkLevel.Workflow.DisallowSameUserMultiLevel)
                {
                    var _Existing = _actorsInLevels.Table.Where(x => x.Actor.ActorRefId == actor.ActorRefId &&
                                                     x.WorkflowLevel.WorkflowId == wkLevel.WorkflowId);
                    if (_Existing.Count() > 0)
                        throw new WorkflowConfigurationError("User " + actor.Description + " already exist in the Workflow.");

                }
                var actorId = 0;
                var _actor = GetActor(actor.ActorRefId, actor.Id);
                if (_actor != null)
                {

                    _actor.Description = actor.Description;
                    _actors.Add(_actor);
                    actorId = _actor.Id;

                }
                else
                {

                    actor.ApplicationId = wkLevel.Workflow.ApplicationId;
                    _actors.Add(actor);
                    actorId = actor.Id;

                }

                //Save ActorInLevel
                var _inLevel = GetActorInLevel(actorId, workflowLevelId);
                // var _inLevel = GetActorInLevel(actor.Id, WorkflowLevelId);


                if (_inLevel == null)
                {
                    _inLevel = new WorkflowActorInLevel()
                    {
                        WorkflowLevelId = workflowLevelId,
                        ActorId = actorId,
                        ActorMustApprove = actorMustAlwaysApproveInLevel
                    };

                }
                else
                    _inLevel.ActorMustApprove = actorMustAlwaysApproveInLevel;
                _actorsInLevels.Add(_inLevel);

                //1. Get the level Expression
                //2. if null, build a new one with a OR
                //3. If not null, Or d new actor to it.

                var parametrs =
                    _levelParameters.Table.Where(c => c.WorkflowLevelId == workflowLevelId).FirstOrDefault();
                if (parametrs == null)
                {

                    var _Xpression = new WorkflowExpression();
                    _Xpression.Add(Operator.Operands.OPENED_BRACKET);

                    _Xpression.Add(Operator.Operands.USER, _actor.ActorRefId, _inLevel.WorkflowLevel.Workflow.ApplicationId);

                    _Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                    _Xpression.SaveExpression(workflowLevelId, 1);

                    return _inLevel.Id; 
                }
                else
                {
                    if (!string.IsNullOrEmpty(parametrs.Expression.Trim()))
                    {
                        var _exp = parametrs.Expression;
                        var _Xpression = new WorkflowExpression();
                        _Xpression.Add(Operator.Operands.OR);

                        _Xpression.Add(Operator.Operands.OPENED_BRACKET);

                        _Xpression.Add(Operator.Operands.USER, _actor.ActorRefId,
                            _inLevel.WorkflowLevel.Workflow.ApplicationId);

                        _Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                        parametrs.Expression = parametrs.Expression + " " + _Xpression.GetRawLogicalExpresion();
                        parametrs.Parameters = parametrs.Parameters + " " + _Xpression.GetViewerLogicalExpresion();
                        _levelParameters.Add(parametrs);
                        return _inLevel.Id;
                    }
                    else
                    {
                        return _inLevel.Id;
                    }
                }

                //if (parametrs != null)
                //    if (parametrs.MaximumApprovalRequired > 1)
                //        return _inLevel.Id;

                ////Build the default Expression
                //var actorsInLevel =
                //    _actorsInLevels.Table.Where(x => x.WorkflowLevelId == WorkflowLevelId)
                //        .Select(x => x.Actor.ActorRefId.ToString());

                //var _Xpression = new WorkflowExpression();
                //_Xpression.Add(Operator.Operands.OPENED_BRACKET);
                //int count = actorsInLevel.Count();
                //int _count = 0;
                //foreach (string _act in actorsInLevel)
                //{
                //    ++_count;

                //    _Xpression.Add(Operator.Operands.USER, _act, _inLevel.WorkflowLevel.Workflow.ApplicationId);
                //    if (_count != count)
                //        _Xpression.Add(Operator.Operands.OR);


                //}
                //_Xpression.Add(Operator.Operands.CLOSED_BRACKET);

                //_Xpression.SaveExpression(WorkflowLevelId, 1);
               
              
           

            }
            else
            {
                throw new WorkflowConfigurationError("Workflow Level does not exist.");

            }


        }