コード例 #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                var person_id     = pkrPerson.PersonId;
                var group_type_id = Int32.Parse(pkrGroupType.SelectedValue);

                if (person_id != null && group_type_id > 0)
                {
                    var personService        = new Rock.Model.PersonService(_ctx);
                    Rock.Model.Person person = personService.Get((int)person_id);

                    var groupTypeService           = new Rock.Model.GroupTypeService(_ctx);
                    Rock.Model.GroupType groupType = groupTypeService.Get(group_type_id);

                    GroupMatcher groupMatcher = new GroupMatcher(person, groupType, pkrDaysOfWeek.SelectedDaysOfWeek);

                    var matches = groupMatcher.GetMatches();

                    grdMatches.DataSource = matches;
                    grdMatches.DataBind();

                    pnlResults.Visible = true;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes the specified workflow action.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            GroupType        groupType  = GetGroupType(rockContext, action);
            List <DayOfWeek> daysOfWeek = GetDaysOfWeek(rockContext, action);
            Person           person     = GetPerson(rockContext, action);
            int numMatches = GetNumberOfMatches(rockContext, action);

            if (person != null)
            {
                if (groupType != null)
                {
                    if (daysOfWeek != null)
                    {
                        var attrAssignments = GetAttributeValue(action, "AttributeAssignments");
                        var ds = new Deserializer();

                        action.Activity.LoadAttributes();
                        action.Activity.Workflow.LoadAttributes();

                        var groupMatcher = new GroupMatcher(person, groupType, daysOfWeek);
                        groupMatcher.numMatches = numMatches;

                        var matches = groupMatcher.GetMatches();

                        var mergeFields = GetMergeFields(action);
                        mergeFields.Add("Person", person);
                        mergeFields.Add("matches", matches);

                        var attrList = ds.Deserialize <Dictionary <string, string> >(new StringReader(attrAssignments));
                        foreach (string key in attrList.Keys)
                        {
                            if (action.Activity.Attributes.ContainsKey(key))
                            {
                                var lava = attrList[key];
                                try
                                {
                                    var value = lava.ResolveMergeFields(mergeFields);
                                    if (value.Contains("Liquid error"))
                                    {
                                        action.AddLogEntry("Liquid Error: " + value);
                                    }
                                    else
                                    {
                                        action.Activity.SetAttributeValue(key, value);
                                    }
                                }
                                catch (DotLiquid.Exceptions.LiquidException ex)
                                {
                                    action.AddLogEntry("Liquid Error: " + ex.Message);
                                }
                            }
                            else if (action.Activity.Workflow.Attributes.ContainsKey(key))
                            {
                                var lava = attrList[key];
                                try
                                {
                                    var value = lava.ResolveMergeFields(mergeFields);
                                    if (value.Contains("Liquid error"))
                                    {
                                        action.AddLogEntry("Liquid Error: " + value);
                                    }
                                    else
                                    {
                                        action.Activity.Workflow.SetAttributeValue(key, value);
                                    }
                                }
                                catch (DotLiquid.Exceptions.LiquidException ex)
                                {
                                    action.AddLogEntry("Liquid Error: " + ex.Message);
                                }
                            }
                        }

                        return(true);
                    }
                    else
                    {
                        errorMessages.Add("Days of week attribute could not be found");
                    }
                }
                else
                {
                    errorMessages.Add("Group Type could not be found");
                }
            }
            else
            {
                errorMessages.Add("Person could not be found");
            }

            return(false);
        }
         /// <summary>
        /// Executes the specified workflow action.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages )
        {
            errorMessages = new List<string>();

            GroupType groupType = GetGroupType( rockContext, action );
            List<DayOfWeek> daysOfWeek = GetDaysOfWeek( rockContext, action );
            Person person = GetPerson( rockContext, action );
            int numMatches = GetNumberOfMatches( rockContext, action );

            if (person != null)
            {
                if (groupType != null)
                {
                    if (daysOfWeek != null)
                    {
                        var attrAssignments = GetAttributeValue( action, "AttributeAssignments" );
                        var ds = new Deserializer();

                        action.Activity.LoadAttributes();
                        action.Activity.Workflow.LoadAttributes();

                        var groupMatcher = new GroupMatcher(person,groupType,daysOfWeek);
                        groupMatcher.numMatches = numMatches;

                        var matches = groupMatcher.GetMatches();

                        var mergeFields = GetMergeFields( action );
                        mergeFields.Add( "Person", person );
                        mergeFields.Add( "matches", matches );

                        var attrList = ds.Deserialize< Dictionary<string, string> >( new StringReader( attrAssignments ) );
                        foreach(string key in attrList.Keys)
                        {
                            if (action.Activity.Attributes.ContainsKey( key ))
                            {
                                var lava = attrList[key];
                                try
                                {
                                    var value = lava.ResolveMergeFields( mergeFields );
                                    if (value.Contains( "Liquid error" ))
                                    {
                                        action.AddLogEntry( "Liquid Error: " + value );
                                    }
                                    else
                                    {
                                        action.Activity.SetAttributeValue( key, value );
                                    }
                                    
                                }
                                catch (DotLiquid.Exceptions.LiquidException ex)
                                {
                                    action.AddLogEntry( "Liquid Error: " + ex.Message );
                                }
                                
                            }
                            else if(action.Activity.Workflow.Attributes.ContainsKey( key ))
                            {
                                var lava = attrList[key];
                                try
                                {
                                    var value = lava.ResolveMergeFields( mergeFields );
                                    if (value.Contains( "Liquid error" ))
                                    {
                                        action.AddLogEntry( "Liquid Error: " + value );
                                    }
                                    else
                                    {
                                        action.Activity.Workflow.SetAttributeValue( key, value );
                                    }
                                }
                                catch (DotLiquid.Exceptions.LiquidException ex)
                                {
                                    action.AddLogEntry( "Liquid Error: " + ex.Message );
                                }
                                
                            }
                        }

                        return true;

                    }
                    else
                    {
                        errorMessages.Add( "Days of week attribute could not be found" );
                    }
                  
                }
                else
                {
                    errorMessages.Add( "Group Type could not be found" );
                }
            }
            else
            {
                errorMessages.Add( "Person could not be found" );
            }
            
            return false;
        }