Ejemplo n.º 1
0
        /// <summary>
        /// Execute the process action.
        /// </summary>
        /// <param name="process"></param>
        /// <param name="openingParticipant"></param>
        private void PerformAction(Entities.Process process, Entities.OpeningParticipant openingParticipant)         // TODO: Create custom syntax and parser for actions.
        {
            // Perform any actions based on the event.
            //oLecture.Actions.Add(new OpeningAction(oLecture, OpeningActionEvent.Accept, "Insert(Participant.Answers, Opening.Tags, Question.Caption=\"Title\");"));
            //oLecture.Actions.Add(new OpeningAction(oLecture, OpeningActionEvent.Unapply, "Delete(Opening.Tags, Tag.Key=\"Title\");"));

            var matches = _regex.Matches(process.Action);
            var opening = process.Opening;

            foreach (Match match in matches)
            {
                var method = match.Groups["method"];
                switch (method.Value)
                {
                case ("Add"):
                {
                    var source      = match.Groups["args"]?.Captures[0]?.Value?.Replace(", ", "");
                    var destination = match.Groups["args"]?.Captures[1]?.Value?.Replace(", ", "");
                    var condition   = match.Groups["args"]?.Captures[2]?.Value?.Replace(")", "");

                    if (source == "Participant.Answers")
                    {
                        if (!String.IsNullOrWhiteSpace(condition))
                        {
                            if (condition.StartsWith("Question.Caption"))
                            {
                                var cval    = condition.Substring(18, condition.Length - 19);
                                var answers = (
                                    from p in this.Context.Processes
                                    join oq in this.Context.OpeningQuestions on p.OpeningId equals oq.OpeningId
                                    join op in this.Context.OpeningParticipants on p.OpeningId equals op.OpeningId
                                    join oan in this.Context.OpeningAnswers on new { p.OpeningId, op.ParticipantId, oq.QuestionId } equals new { oan.OpeningId, oan.ParticipantId, oan.QuestionId }
                                    where p.Id == process.Id &&
                                    op.ParticipantId == openingParticipant.ParticipantId &&
                                    oq.Question.Caption == cval
                                    select oan.Text);

                                answers.ForEach(a =>
                                    {
                                        var tag = new Entities.OpeningTag(opening, cval, a);
                                        opening.Tags.Add(tag);
                                        this.Context.OpeningTags.Add(tag);
                                    });
                            }
                        }
                    }
                }
                break;

                case ("Delete"):
                {
                    var source    = match.Groups["args"]?.Captures[0]?.Value?.Replace(", ", "");
                    var condition = match.Groups["args"]?.Captures[1]?.Value?.Replace(")", "");

                    if (source == "Opening.Tags")
                    {
                        if (!String.IsNullOrWhiteSpace(condition))
                        {
                            if (condition.StartsWith("Tag.Key"))
                            {
                                var cval = condition.Substring(9, condition.Length - 10);
                                var tags = this.Context.OpeningTags.Where(ot => ot.OpeningId == opening.Id && ot.Key == cval).ToArray();

                                tags.ForEach(t => {
                                        opening.Tags.Remove(t);
                                        this.Context.OpeningTags.Remove(t);
                                    });
                            }
                        }
                    }
                }
                break;
                }
                match.NextMatch();
            }
        }
Ejemplo n.º 2
0
        private void PerformAction(Entities.OpeningParticipant openingParticipant, ActionTrigger trigger)
        {
            var processes = this.Context.Processes.Where(oa => oa.OpeningId == openingParticipant.OpeningId && oa.Trigger == trigger).OrderBy(oa => oa.Sequence);

            processes.ForEach(p => this.Source.Actions.Add(new Helpers.OpeningAction(p, openingParticipant)));
        }
Ejemplo n.º 3
0
 public OpeningAction(Entities.Process process, Entities.OpeningParticipant openingParticipant)
 {
     this.Process            = process;
     this.OpeningParticipant = openingParticipant;
 }