Exemplo n.º 1
0
        public HttpResponseMessage Family(string param)
        {
            try
            {
                var Session = HttpContext.Current.Session;

                CurrentKioskId = ( int )Session["CheckInKioskId"];
                Guid       blockGuid           = ( Guid )Session["BlockGuid"];
                List <int> CheckInGroupTypeIds = (List <int>)Session["CheckInGroupTypeIds"];
                CurrentCheckInState = new CheckInState(CurrentKioskId, null, CheckInGroupTypeIds);
                CurrentCheckInState.CheckIn.UserEnteredSearch   = true;
                CurrentCheckInState.CheckIn.ConfirmSingleFamily = true;
                CurrentCheckInState.CheckIn.SearchType          = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CHECKIN_SEARCH_TYPE_PHONE_NUMBER);
                CurrentCheckInState.CheckIn.SearchValue         = param;

                var    rockContext      = new Rock.Data.RockContext();
                var    block            = BlockCache.Get(blockGuid);
                string workflowActivity = block.GetAttributeValue("WorkflowActivity");
                Guid?  workflowGuid     = block.GetAttributeValue("WorkflowType").AsGuidOrNull();

                List <string> errors;
                var           workflowService = new WorkflowService(rockContext);
                var           workflowType    = WorkflowTypeCache.Get(workflowGuid.Value);

                var CurrentWorkflow = Rock.Model.Workflow.Activate(workflowType, CurrentCheckInState.Kiosk.Device.Name, rockContext);

                var activityType = workflowType.ActivityTypes.Where(a => a.Name == workflowActivity).FirstOrDefault();
                if (activityType != null)
                {
                    WorkflowActivity.Activate(activityType, CurrentWorkflow, rockContext);
                    if (workflowService.Process(CurrentWorkflow, CurrentCheckInState, out errors))
                    {
                        // Keep workflow active for continued processing
                        CurrentWorkflow.CompletedDateTime = null;
                        SaveState(Session);
                        List <CheckInFamily> families = CurrentCheckInState.CheckIn.Families;
                        families = families.OrderBy(f => f.Caption).ToList();
                        return(ControllerContext.Request.CreateResponse(HttpStatusCode.OK, families));
                    }
                }
                else
                {
                    return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, string.Format("Workflow type does not have a '{0}' activity type", workflowActivity)));
                }
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.InternalServerError, String.Join("\n", errors)));
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, HttpContext.Current);
                return(ControllerContext.Request.CreateResponse(HttpStatusCode.Forbidden, "Forbidden"));
            }
        }
Exemplo n.º 2
0
        protected void bntMerge_Click(object sender, EventArgs e)
        {
            PDFWorkflowObject pdfWorkflowObject = new PDFWorkflowObject();

            pdfWorkflowObject.LavaInput = ceLava.Text;

            pdfWorkflowObject.MergeObjects = new Dictionary <string, object>();
            if (cbCurrentPerson.Checked)
            {
                pdfWorkflowObject.MergeObjects.Add("CurrentPerson", CurrentPerson);
            }
            if (cbGlobal.Checked)
            {
                pdfWorkflowObject.MergeObjects.Add("GlobalAttributes", GlobalAttributesCache.Get());
            }


            Guid workflowTypeGuid = Guid.NewGuid();

            if (Guid.TryParse(GetAttributeValue("WorkflowType"), out workflowTypeGuid))
            {
                var workflowRockContext = new RockContext();
                var workflowTypeService = new WorkflowTypeService(workflowRockContext);
                var workflowType        = workflowTypeService.Get(workflowTypeGuid);
                if (workflowType != null)
                {
                    var workflow = Workflow.Activate(WorkflowTypeCache.Get(workflowType.Id), "PDFLavaWorkflow");

                    List <string> workflowErrors;
                    var           workflowService  = new WorkflowService(workflowRockContext);
                    var           workflowActivity = GetAttributeValue("WorkflowActivity");
                    var           activityType     = workflowType.ActivityTypes.Where(a => a.Name == workflowActivity).FirstOrDefault();
                    if (activityType != null)
                    {
                        WorkflowActivity.Activate(WorkflowActivityTypeCache.Get(activityType.Id), workflow, workflowRockContext);
                        if (workflowService.Process(workflow, pdfWorkflowObject, out workflowErrors))
                        {
                            //success
                        }
                    }
                }
            }

            RockContext       rockContext       = new RockContext();
            BinaryFileService binaryFileService = new BinaryFileService(rockContext);

            pdfWorkflowObject.PDF.FileName = "LavaGeneratedPDF.pdf";
            binaryFileService.Add(pdfWorkflowObject.PDF);
            rockContext.SaveChanges();

            Response.Redirect(pdfWorkflowObject.PDF.Path);
        }
        /// <summary>
        /// Handles the SaveClick event of the mdSettings control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void mdSettings_SaveClick(object sender, EventArgs e)
        {
            this.SetAttributeValue("ContentChannel", ddlContentChannel.SelectedValue);
            this.SetAttributeValue("ContentChannelQueryParameter", tbContentChannelQueryParameter.Text);
            this.SetAttributeValue("LavaTemplate", ceLavaTemplate.Text);
            this.SetAttributeValue("OutputCacheDuration", nbOutputCacheDuration.Text);
            this.SetAttributeValue("ItemCacheDuration", nbItemCacheDuration.Text);
            this.SetAttributeValue("CacheTags", cblCacheTags.SelectedValues.AsDelimited(","));
            this.SetAttributeValue("SetPageTitle", cbSetPageTitle.Checked.ToString());
            this.SetAttributeValue("LogInteractions", cbLogInteractions.Checked.ToString());
            this.SetAttributeValue("WriteInteractionOnlyIfIndividualLoggedIn", cbWriteInteractionOnlyIfIndividualLoggedIn.Checked.ToString());
            int? selectedWorkflowTypeId   = wtpWorkflowType.SelectedValueAsId();
            Guid?selectedWorkflowTypeGuid = null;

            if (selectedWorkflowTypeId.HasValue)
            {
                selectedWorkflowTypeGuid = WorkflowTypeCache.Get(selectedWorkflowTypeId.Value).Guid;
            }

            this.SetAttributeValue("WorkflowType", selectedWorkflowTypeGuid.ToString());
            this.SetAttributeValue("LaunchWorkflowOnlyIfIndividualLoggedIn", cbLaunchWorkflowOnlyIfIndividualLoggedIn.Checked.ToString());
            this.SetAttributeValue("LaunchWorkflowCondition", ddlLaunchWorkflowCondition.SelectedValue);
            this.SetAttributeValue("MetaDescriptionAttribute", ddlMetaDescriptionAttribute.SelectedValue);
            this.SetAttributeValue("OpenGraphType", ddlOpenGraphType.SelectedValue);
            this.SetAttributeValue("OpenGraphTitleAttribute", ddlOpenGraphTitleAttribute.SelectedValue);
            this.SetAttributeValue("OpenGraphDescriptionAttribute", ddlOpenGraphDescriptionAttribute.SelectedValue);
            this.SetAttributeValue("OpenGraphImageAttribute", ddlOpenGraphImageAttribute.SelectedValue);
            this.SetAttributeValue("TwitterTitleAttribute", ddlTwitterTitleAttribute.SelectedValue);
            this.SetAttributeValue("TwitterDescriptionAttribute", ddlTwitterDescriptionAttribute.SelectedValue);
            this.SetAttributeValue("TwitterImageAttribute", ddlTwitterImageAttribute.SelectedValue);
            this.SetAttributeValue("TwitterCard", ddlTwitterCard.SelectedValue);

            SaveAttributeValues();

            var cacheKeys = GetCacheItem(CACHEKEYS_CACHE_KEY) as HashSet <string>;

            if (cacheKeys != null)
            {
                foreach (var cacheKey in cacheKeys)
                {
                    RemoveCacheItem(cacheKey);
                }
            }

            RemoveCacheItem(CACHEKEYS_CACHE_KEY);

            mdSettings.Hide();
            pnlSettings.Visible = false;

            // reload the page to make sure we have a clean load
            NavigateToCurrentPageReference();
        }
        protected void BindGrid()
        {
            RockContext                   rockContext                   = new RockContext();
            PersonAliasService            personAliasService            = new PersonAliasService(rockContext);
            WorkflowService               workflowTypeService           = new WorkflowService(rockContext);
            WorkflowService               workflowService               = new WorkflowService(rockContext);
            AttributeService              attributeService              = new AttributeService(rockContext);
            AttributeValueService         attributeValueService         = new AttributeValueService(rockContext);
            RegistrationRegistrantService registrationRegistrantService = new RegistrationRegistrantService(rockContext);

            List <string> workflowTypes   = GetAttributeValues("WorkflowTypes");
            List <string> workflowTypeIds = new List <string>();

            foreach (string workflowTypeGuid in workflowTypes)
            {
                workflowTypeIds.Add(WorkflowTypeCache.Get(workflowTypeGuid.AsGuid()).Id.ToString());
            }

            var attributes   = attributeService.Queryable().Where(a => workflowTypeIds.Contains(a.EntityTypeQualifierValue) && a.EntityTypeQualifierColumn == "WorkflowTypeId");
            var attributeIds = attributes.Select(a => a.Id);

            // Get all the family members
            var familyMembers = personAliasService.Get(PageParameter("PersonAliasId").AsInteger()).Person.GetFamilyMembers(true);

            var familyAliasIds = familyMembers.SelectMany(fm => fm.Person.Aliases.Select(pa => pa.Id)).ToList();

            var discountCodes = registrationRegistrantService.Queryable().Where(rr => rr.PersonAliasId.HasValue && familyAliasIds.Contains(rr.PersonAliasId.Value))
                                .Where(rr => rr.Registration.DiscountCode != null && rr.Registration.DiscountCode != "")
                                .ToDictionary(x => x.Registration.DiscountCode.ToUpper(), x => x.Registration.DiscountAmount);

            var qry = workflowService.Queryable().Where(w => workflowTypeIds.Contains(w.WorkflowTypeId.ToString()))
                      .GroupJoin(attributeValueService.Queryable().Where(av => attributeIds.Contains(av.AttributeId)),
                                 w => w.Id,
                                 av => av.EntityId,
                                 (w, av) => new { Workflow = w, AttributeValues = av })
                      .Where(obj => obj.AttributeValues.Any(av => av.Attribute.Key == "DiscountCode" && discountCodes.Keys.Contains(av.Value)))
                      .ToList()
                      .Select(obj => new {
                Id              = obj.Workflow.Id,
                FirstName       = obj.AttributeValues.Where(av => av.Attribute.Key == "StudentFirstName").Select(av => av.Value).DefaultIfEmpty(obj.AttributeValues.Where(av => av.Attribute.Key == "ParentFirstName").Select(av => av.Value).FirstOrDefault()).FirstOrDefault(),
                LastName        = obj.AttributeValues.Where(av => av.Attribute.Key == "StudentLastName").Select(av => av.Value).DefaultIfEmpty(obj.AttributeValues.Where(av => av.Attribute.Key == "ParentLastName").Select(av => av.Value).FirstOrDefault()).FirstOrDefault(),
                Campus          = obj.AttributeValues.Where(av => av.Attribute.Key == "Campus").Select(av => CampusCache.Get(av.Value.AsGuid())).FirstOrDefault(),
                ApplicationYear = obj.AttributeValues.Where(av => av.Attribute.Key == "ApplicationYear").Select(av => av.Value).DefaultIfEmpty(attributes.Where(a => a.Key == "ApplicationYear").Select(a => a.DefaultValue).FirstOrDefault()).FirstOrDefault(),
                DiscountCode    = obj.AttributeValues.Where(av => av.Attribute.Key == "DiscountCode").Select(av => av.Value).FirstOrDefault(),
                DiscountAmount  = discountCodes.ContainsKey(obj.AttributeValues.Where(av => av.Attribute.Key == "DiscountCode").Select(av => av.Value.ToUpper()).FirstOrDefault()) ?discountCodes[obj.AttributeValues.Where(av => av.Attribute.Key == "DiscountCode").Select(av => av.Value.ToUpper()).FirstOrDefault()]:0,
                Event           = obj.AttributeValues.Where(av => av.Attribute.Key == "EventStudentisAttending").Select(av => av.Value).DefaultIfEmpty(obj.AttributeValues.Where(av => av.Attribute.Key == "EventLeaderisAttending").Select(av => av.Value).FirstOrDefault()).FirstOrDefault(),
                Status          = obj.Workflow.Status
            });

            gFamilyProfile.DataSource = qry.ToList();
            gFamilyProfile.DataBind();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Loads the workflow.
        /// </summary>
        /// <param name="workflowGuid">The workflow identifier.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        private Model.Workflow LoadWorkflow(Guid?workflowGuid, RockContext rockContext)
        {
            if (workflowGuid.HasValue)
            {
                return(new WorkflowService(rockContext).Get(workflowGuid.Value));
            }
            else
            {
                var workflowType = WorkflowTypeCache.Get(GetAttributeValue(AttributeKeys.WorkflowType).AsGuid());

                return(Model.Workflow.Activate(workflowType, $"New {workflowType.Name}"));
            }
        }
        /// <summary>
        /// Adds the person to group.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="person">The person.</param>
        /// <param name="workflowType">Type of the workflow.</param>
        /// <param name="groupMembers">The group members.</param>
        private void AddPersonToGroup(RockContext rockContext, Person person, WorkflowTypeCache workflowType, List <GroupMember> groupMembers)
        {
            if (person != null)
            {
                GroupMember groupMember = null;
                if (!_publishGroup.Group.Members
                    .Any(m =>
                         m.PersonId == person.Id &&
                         m.GroupRoleId == _defaultGroupRole.Id))
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    groupMember                   = new GroupMember();
                    groupMember.PersonId          = person.Id;
                    groupMember.GroupRoleId       = _defaultGroupRole.Id;
                    groupMember.GroupMemberStatus = ( GroupMemberStatus )GetAttributeValue("GroupMemberStatus").AsInteger();
                    groupMember.GroupId           = _publishGroup.Group.Id;
                    groupMemberService.Add(groupMember);
                    rockContext.SaveChanges();
                }
                else
                {
                    GroupMemberStatus status = ( GroupMemberStatus )GetAttributeValue("GroupMemberStatus").AsInteger();
                    groupMember = _publishGroup.Group.Members.Where(m =>
                                                                    m.PersonId == person.Id &&
                                                                    m.GroupRoleId == _defaultGroupRole.Id).FirstOrDefault();
                    if (groupMember.GroupMemberStatus != status)
                    {
                        var groupMemberService = new GroupMemberService(rockContext);

                        // reload this group member in the current context
                        groupMember = groupMemberService.Get(groupMember.Id);
                        groupMember.GroupMemberStatus = status;
                        rockContext.SaveChanges();
                    }
                }

                if (groupMember != null && workflowType != null && (workflowType.IsActive ?? true))
                {
                    try
                    {
                        List <string> workflowErrors;
                        var           workflow = Workflow.Activate(workflowType, person.FullName);
                        new WorkflowService(rockContext).Process(workflow, groupMember, out workflowErrors);
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogService.LogException(ex, this.Context);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Activates and processes a workflow activity.  If the workflow has not yet been activated, it will
        /// also be activated
        /// </summary>
        /// <param name="activityName">Name of the activity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        protected bool ProcessActivity(string activityName, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            Guid?guid = GetAttributeValue("WorkflowType").AsGuidOrNull();

            if (guid.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var workflowService = new WorkflowService(rockContext);

                    var workflowType = WorkflowTypeCache.Get(guid.Value);
                    if (workflowType != null && (workflowType.IsActive ?? true))
                    {
                        if (CurrentWorkflow == null)
                        {
                            CurrentWorkflow = Rock.Model.Workflow.Activate(workflowType, CurrentCheckInState.Kiosk.Device.Name, rockContext);

                            if (IsOverride)
                            {
                                CurrentWorkflow.SetAttributeValue("Override", "True");
                            }
                        }

                        var activityType = workflowType.ActivityTypes.Where(a => a.Name == activityName).FirstOrDefault();
                        if (activityType != null)
                        {
                            WorkflowActivity.Activate(activityType, CurrentWorkflow, rockContext);
                            if (workflowService.Process(CurrentWorkflow, CurrentCheckInState, out errorMessages))
                            {
                                // Keep workflow active for continued processing
                                CurrentWorkflow.CompletedDateTime = null;

                                return(true);
                            }
                        }
                        else
                        {
                            errorMessages.Add(string.Format("Workflow type does not have a '{0}' activity type", activityName));
                        }
                    }
                    else
                    {
                        errorMessages.Add("Invalid Workflow Type");
                    }
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Processes the message that was received from the remote user.
        /// </summary>
        /// <param name="action">The action that contains the configuration for this component.</param>
        /// <param name="message">The message that was received by Rock.</param>
        /// <param name="errorMessage">If there is a problem processing, this should be set</param>
        /// <returns>An SmsMessage that will be sent as the response or null if no response should be sent.</returns>
        public override SmsMessage ProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage)
        {
            errorMessage = string.Empty;

            //
            // Get the list of workflow attributes to set.
            //
            var workflowAttributesSettings = new List <KeyValuePair <string, object> >();
            var workflowAttributes         = action.Attributes["WorkflowAttributes"];

            if (workflowAttributes != null)
            {
                if (workflowAttributes.FieldType.Field is KeyValueListFieldType keyValueField)
                {
                    workflowAttributesSettings = keyValueField.GetValuesFromString(null,
                                                                                   GetAttributeValue(action, "WorkflowAttributes"),
                                                                                   workflowAttributes.QualifierValues,
                                                                                   false);
                }
            }

            var workflowType = WorkflowTypeCache.Get(GetAttributeValue(action, "WorkflowType").AsGuid());

            //
            // Launch the workflow.
            //
            Rock.Utility.TextToWorkflow.LaunchWorkflow(workflowType,
                                                       GetAttributeValue(action, "WorkflowNameTemplate"),
                                                       message.FromPerson,
                                                       message.FromNumber.Replace("+", ""),
                                                       message.ToNumber.Replace("+", ""),
                                                       message.Message,
                                                       message.Attachments,
                                                       workflowAttributesSettings,
                                                       out string response);

            //
            // If there is no response message then return null.
            //
            if (string.IsNullOrWhiteSpace(response))
            {
                return(null);
            }

            return(new SmsMessage
            {
                Message = response.Trim()
            });
        }
Exemplo n.º 9
0
        public static Workflow Activate(WorkflowType workflowType, string name, RockContext rockContext)
        {
            if (workflowType != null)
            {
                var workflowTypeCache = WorkflowTypeCache.Get(workflowType.Id);
                var workflow          = Activate(workflowTypeCache, name, rockContext);
                if (workflow != null)
                {
                    workflow.WorkflowType = workflowType;
                }
                return(workflow);
            }

            return(null);
        }
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="message"></param>
        public override void Execute(Message message)
        {
            var rockContext  = new RockContext();
            var workflowType = WorkflowTypeCache.Get(message.WorkflowTypeId);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                var workflow = Rock.Model.Workflow.Activate(workflowType, message.GroupMemberWorkflowTriggerName);

                if (workflow.AttributeValues != null)
                {
                    if (workflow.AttributeValues.ContainsKey("Group"))
                    {
                        var group = new GroupService(rockContext).Get(message.GroupId.Value);
                        if (group != null)
                        {
                            workflow.AttributeValues["Group"].Value = group.Guid.ToString();
                        }
                    }

                    if (workflow.AttributeValues.ContainsKey("Person"))
                    {
                        var person = new PersonService(rockContext).Get(message.PersonId.Value);
                        if (person != null && person.PrimaryAlias != null)
                        {
                            workflow.AttributeValues["Person"].Value = person.PrimaryAlias.Guid.ToString();
                        }
                    }

                    if (workflow.AttributeValues.ContainsKey("Note"))
                    {
                        workflow.AttributeValues["Note"].Value = message.Note;
                    }

                    // populate any other workflow attributes that match up with the group member's attributes
                    foreach (var attributeKey in message.GroupMemberAttributeValues.Keys)
                    {
                        if (workflow.AttributeValues.ContainsKey(attributeKey))
                        {
                            workflow.AttributeValues[attributeKey].Value = message.GroupMemberAttributeValues[attributeKey];
                        }
                    }
                }

                List <string> workflowErrors;
                new Rock.Model.WorkflowService(rockContext).Process(workflow, out workflowErrors);
            }
        }
Exemplo n.º 11
0
        protected void bntMerge_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();
            //Get the mergefields and pdf
            BinaryFileService           binaryFileService = new BinaryFileService(rockContext);
            Dictionary <string, object> mergeFields       = GetMergeFields();
            BinaryFile pdf = binaryFileService.Get(int.Parse(fpSelectedFile.SelectedValue));

            //Create the object we will need to pass to the workflow
            if (pdf != null && mergeFields.Count > 0)
            {
                var pdfEntity = new PDFWorkflowObject();
                pdfEntity.PDF          = pdf;
                pdfEntity.MergeObjects = mergeFields;

                Guid workflowTypeGuid = Guid.NewGuid();
                if (Guid.TryParse(GetAttributeValue("WorkflowType"), out workflowTypeGuid))
                {
                    var workflowRockContext = new RockContext();
                    var workflowTypeService = new WorkflowTypeService(workflowRockContext);
                    var workflowType        = workflowTypeService.Get(workflowTypeGuid);
                    if (workflowType != null)
                    {
                        var workflow = Workflow.Activate(WorkflowTypeCache.Get(workflowType.Id), pdf.FileName);

                        List <string> workflowErrors;
                        var           workflowService  = new WorkflowService(workflowRockContext);
                        var           workflowActivity = GetAttributeValue("WorkflowActivity");
                        var           activityType     = workflowType.ActivityTypes.Where(a => a.Name == workflowActivity).FirstOrDefault();
                        if (activityType != null)
                        {
                            WorkflowActivity.Activate(WorkflowActivityTypeCache.Get(activityType.Id), workflow, workflowRockContext);
                            if (workflowService.Process(workflow, pdfEntity, out workflowErrors))
                            {
                                //success
                            }
                        }
                    }
                }

                var mergedPDF = pdfEntity.PDF;
                //mergedPDF.Guid = Guid.NewGuid();
                binaryFileService.Add(mergedPDF);
                rockContext.SaveChanges();

                Response.Redirect(mergedPDF.Path);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Launches the workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="workflowTypeId">The workflow type identifier.</param>
        /// <param name="name">The name.</param>
        private void LaunchWorkflow(RockContext rockContext, int workflowTypeId, string name)
        {
            var workflowType = WorkflowTypeCache.Get(workflowTypeId);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                var workflow = Rock.Model.Workflow.Activate(workflowType, name);

                if (workflow.AttributeValues != null)
                {
                    if (workflow.AttributeValues.ContainsKey("Group"))
                    {
                        var group = new GroupService(rockContext).Get(GroupId.Value);
                        if (group != null)
                        {
                            workflow.AttributeValues["Group"].Value = group.Guid.ToString();
                        }
                    }

                    if (workflow.AttributeValues.ContainsKey("Person"))
                    {
                        var person = new PersonService(rockContext).Get(PersonId.Value);
                        if (person != null && person.PrimaryAlias != null)
                        {
                            workflow.AttributeValues["Person"].Value = person.PrimaryAlias.Guid.ToString();
                        }
                    }

                    if (workflow.AttributeValues.ContainsKey("Note"))
                    {
                        workflow.AttributeValues["Note"].Value = Note;
                    }

                    // populate any other workflow attributes that match up with the group member's attributes
                    foreach (var attributeKey in this.GroupMemberAttributeValues.Keys)
                    {
                        if (workflow.AttributeValues.ContainsKey(attributeKey))
                        {
                            workflow.AttributeValues[attributeKey].Value = GroupMemberAttributeValues[attributeKey];
                        }
                    }
                }

                List <string> workflowErrors;
                new Rock.Model.WorkflowService(rockContext).Process(workflow, out workflowErrors);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Binds the workflow type picker.
        /// </summary>
        private void BindWorkflowTypeControls()
        {
            if (_hasLaunched)
            {
                wtpWorkflowType.Visible = false;
                ddlWorkflowType.Visible = false;
                lWorkflowType.Visible   = false;
                return;
            }

            // If a page parameter is set, then it overrides everything else
            var workflowTypeId = PageParameter(PageParameterKey.WorkflowTypeId).AsIntegerOrNull();

            if (workflowTypeId.HasValue)
            {
                var workflowType = WorkflowTypeCache.Get(workflowTypeId.Value);

                if (workflowType != null && workflowType.IsAuthorized(Authorization.VIEW, CurrentPerson))
                {
                    lWorkflowType.Text      = GetLockedWorkflowTypeHtml(workflowType);
                    lWorkflowType.Visible   = true;
                    wtpWorkflowType.Visible = false;
                    ddlWorkflowType.Visible = false;
                    return;
                }
            }

            // If no valid page parameter, then use the block settings
            var workflowTypes = GetAttributeValues(AttributeKey.WorkflowTypes)
                                .Select(WorkflowTypeCache.Get)
                                .ToList();

            wtpWorkflowType.Visible = workflowTypes.Count == 0;
            lWorkflowType.Visible   = workflowTypes.Count == 1;
            ddlWorkflowType.Visible = workflowTypes.Count >= 2;

            if (workflowTypes.Count == 1)
            {
                var workflowType = workflowTypes.Single();
                lWorkflowType.Text = GetLockedWorkflowTypeHtml(workflowType);
            }
            else if (workflowTypes.Any())
            {
                ddlWorkflowType.DataSource = workflowTypes;
                ddlWorkflowType.DataBind();
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Launch the workflow
        /// </summary>
        protected void LaunchTheWorkflow(string workflowName, IJobExecutionContext context)
        {
            Guid workflowTypeGuid = Guid.NewGuid();

            if (Guid.TryParse(workflowName, out workflowTypeGuid))
            {
                var workflowType = WorkflowTypeCache.Get(workflowTypeGuid);
                if (workflowType != null && (workflowType.IsActive ?? true))
                {
                    var workflow = Rock.Model.Workflow.Activate(workflowType, workflowName);

                    List <string> workflowErrors;
                    var           processed = new Rock.Model.WorkflowService(new RockContext()).Process(workflow, out workflowErrors);
                    context.Result = (processed ? "Processed " : "Did not process ") + workflow.ToString();
                }
            }
        }
        protected void StartWorkflow(WorkflowService workflowService, WorkflowTypeCache workflowType, Dictionary <string, string> attributes, string workflowNameSuffix, Person p)
        {
            // launch workflow if configured
            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                var workflow = Rock.Model.Workflow.Activate(workflowType, "UnsubscribeNotice " + workflowNameSuffix);

                // set attributes
                foreach (KeyValuePair <string, string> attribute in attributes)
                {
                    workflow.SetAttributeValue(attribute.Key, attribute.Value);
                }
                // launch workflow
                List <string> workflowErrors;
                workflowService.Process(workflow, p, out workflowErrors);
            }
        }
Exemplo n.º 16
0
        private void LaunchWorkflow(Person person)
        {
            using (var rockContext = new RockContext())
            {
                var workflowType = WorkflowTypeCache.Read(_workflowTypeGuid.Value);
                if (workflowType != null && (workflowType.IsActive ?? true))
                {
                    var workflowService = new WorkflowService(rockContext);
                    var workflow        = Rock.Model.Workflow.Activate(workflowType, person.FullName, rockContext);
                    workflowService.Add(workflow);
                    rockContext.SaveChanges();

                    workflow.SetAttributeValue("Person", person.Guid);
                    workflow.SaveAttributeValues();
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Execute method to write transaction to the database.
        /// </summary>
        public void Execute()
        {
            if (Trigger != null)
            {
                using (var rockContext = new RockContext())
                {
                    var workflowType = WorkflowTypeCache.Get(Trigger.WorkflowTypeId);
                    if (workflowType != null && (workflowType.IsActive ?? true))
                    {
                        var workflow = Rock.Model.Workflow.Activate(workflowType, Trigger.WorkflowName);

                        List <string> workflowErrors;
                        new Rock.Model.WorkflowService(rockContext).Process(workflow, Entity, out workflowErrors);
                    }
                }
            }
        }
Exemplo n.º 18
0
        public virtual void Execute(IJobExecutionContext context)
        {
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            var rockContext     = new RockContext();
            var workflowService = new WorkflowService(rockContext);
            WorkflowTypeCache workflowTypeCache = WorkflowTypeCache.Get(dataMap.GetString("WGuid").AsGuid());

            DataSet data = DbService.GetDataSet(dataMap.GetString("SQLQuery"), CommandType.Text, new Dictionary <string, object>());

            foreach (DataTable tbl in data.Tables)
            {
                foreach (DataRow row in tbl.Rows)
                {
                    Workflow workflow = Workflow.Activate(workflowTypeCache, "New " + workflowTypeCache.WorkTerm);

                    foreach (DataColumn col in tbl.Columns)
                    {
                        workflow.SetAttributeValue(col.ColumnName, row[col].ToString());
                    }

                    if (workflowService.Process(workflow, out List <string> errorMessages))
                    {
                        // If the workflow type is persisted, save the workflow
                        if (workflow.IsPersisted || workflowTypeCache.IsPersisted)
                        {
                            if (workflow.Id == 0)
                            {
                                workflowService.Add(workflow);
                            }

                            rockContext.WrapTransaction(() =>
                            {
                                rockContext.SaveChanges();
                                workflow.SaveAttributeValues(rockContext);
                                foreach (WorkflowActivity activity in workflow.Activities)
                                {
                                    activity.SaveAttributeValues(rockContext);
                                }
                            });
                        }
                    }
                }
            }
        }
        private void LaunchWorkflow(RockContext rockContext, BenevolenceWorkflow benevolenceWorkflow, string name)
        {
            var workflowType = WorkflowTypeCache.Get(benevolenceWorkflow.WorkflowTypeId);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                BenevolenceRequest benevolenceRequest = null;
                if (BenevolenceRequestGuid.HasValue)
                {
                    benevolenceRequest = new BenevolenceRequestService(rockContext).Get(BenevolenceRequestGuid.Value);

                    var workflow = Rock.Model.Workflow.Activate(workflowType, name);

                    List <string> workflowErrors;
                    new WorkflowService(rockContext).Process(workflow, benevolenceRequest, out workflowErrors);
                }
            }
        }
Exemplo n.º 20
0
        private void LaunchWorkflow(RockContext rockContext, ConnectionWorkflow connectionWorkflow, string name, Message message)
        {
            var workflowType = WorkflowTypeCache.Get(connectionWorkflow.WorkflowTypeId.Value);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                ConnectionRequest connectionRequest = null;
                if (message.ConnectionRequestGuid.HasValue)
                {
                    connectionRequest = new ConnectionRequestService(rockContext).Get(message.ConnectionRequestGuid.Value);

                    if (connectionRequest == null)
                    {
                        // If the ConnectionRequest doesn't exist anymore, exit
                        return;
                    }

                    var workflow = Rock.Model.Workflow.Activate(workflowType, name);

                    if (workflow == null)
                    {
                        // if no workflow was created, exit
                        return;
                    }

                    workflow.InitiatorPersonAliasId = message.InitiatorPersonAliasId;

                    List <string> workflowErrors;
                    new WorkflowService(rockContext).Process(workflow, connectionRequest, out workflowErrors);
                    if (workflow.Id != 0)
                    {
                        ConnectionRequestWorkflow connectionRequestWorkflow = new ConnectionRequestWorkflow();
                        connectionRequestWorkflow.ConnectionRequestId  = connectionRequest.Id;
                        connectionRequestWorkflow.WorkflowId           = workflow.Id;
                        connectionRequestWorkflow.ConnectionWorkflowId = connectionWorkflow.Id;
                        connectionRequestWorkflow.TriggerType          = connectionWorkflow.TriggerType;
                        connectionRequestWorkflow.TriggerQualifier     = connectionWorkflow.QualifierValue;
                        new ConnectionRequestWorkflowService(rockContext).Add(connectionRequestWorkflow);
                        rockContext.SaveChanges();
                    }
                }
            }
        }
Exemplo n.º 21
0
        private void LaunchWorkflow(String firstName, String lastName, String email)
        {
            using (var rockContext = new RockContext())
            {
                var workflowType = WorkflowTypeCache.Read(_workflowTypeGuid.Value);
                if (workflowType != null && (workflowType.IsActive ?? true))
                {
                    var workflowService = new WorkflowService(rockContext);
                    var workflow        = Rock.Model.Workflow.Activate(workflowType, string.Format("{0} {1}", firstName, lastName), rockContext);
                    workflowService.Add(workflow);
                    rockContext.SaveChanges();

                    workflow.SetAttributeValue("FirstName", firstName);
                    workflow.SetAttributeValue("LastName", lastName);
                    workflow.SetAttributeValue("Email", email);
                    workflow.SaveAttributeValues();
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Increments the prayer count.
        /// </summary>
        /// <param name="prayerRequestId">The prayer request identifier.</param>
        private void IncrementPrayerCount(int prayerRequestId)
        {
            using (var rockContext = new RockContext())
            {
                var request = new PrayerRequestService(rockContext).Get(prayerRequestId);
                var count   = request.PrayerCount ?? 0;
                request.PrayerCount = (count + 1);
                rockContext.SaveChanges();

                Guid?workflowTypeGuid = GetAttributeValue("PrayerCountWorkflow").AsGuidOrNull();
                if (workflowTypeGuid.HasValue)
                {
                    var workflowType = WorkflowTypeCache.Get(workflowTypeGuid.Value);
                    if (workflowType != null && (workflowType.IsActive ?? true))
                    {
                        if (GetAttributeValue("ProcessWorkflowImmediately").AsBoolean())
                        {
                            try
                            {
                                var           workflow = Workflow.Activate(workflowType, request.Name);
                                List <string> workflowErrors;
                                new WorkflowService(rockContext).Process(workflow, request, out workflowErrors);
                            }
                            catch (Exception ex)
                            {
                                ExceptionLogService.LogException(ex, this.Context);
                            }
                        }
                        else
                        {
                            var workflowDetails = new List <LaunchWorkflowDetails>();
                            workflowDetails.Add(new LaunchWorkflowDetails(request));
                            var transaction = new Rock.Transactions.LaunchWorkflowsTransaction(workflowTypeGuid.Value, workflowDetails);
                            // NOTE: In v8, the initiator will always be null while using delayed start.
                            //transaction.InitiatorPersonAliasId = CurrentPersonAliasId; // available in v9
                            Rock.Transactions.RockQueue.TransactionQueue.Enqueue(transaction);
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
        private void LoadWorkflowType()
        {
            if (_rockContext == null)
            {
                _rockContext = new RockContext();
            }

            if (_workflowService == null)
            {
                _workflowService = new WorkflowService(_rockContext);
            }

            // Get the workflow type id (initial page request)
            if (!WorkflowTypeId.HasValue)
            {
                // Get workflow type set by attribute value
                Guid workflowTypeguid = GetAttributeValue("WorkflowType").AsGuid();
                if (!workflowTypeguid.IsEmpty())
                {
                    _workflowType = WorkflowTypeCache.Get(workflowTypeguid);
                }

                // If an attribute value was not provided, check for query/route value
                if (_workflowType != null)
                {
                    WorkflowTypeId = _workflowType.Id;
                    ConfiguredType = true;
                }
                else
                {
                    WorkflowTypeId = PageParameter("WorkflowTypeId").AsIntegerOrNull();
                    ConfiguredType = false;
                }
            }

            // Get the workflow type
            if (_workflowType == null && WorkflowTypeId.HasValue)
            {
                _workflowType = WorkflowTypeCache.Get(WorkflowTypeId.Value);
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="message"></param>
        public override void Execute(Message message)
        {
            if (message.WorkflowTriggerGuid.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var trigger = new WorkflowTriggerService(rockContext).Get(message.WorkflowTriggerGuid.Value);
                    if (trigger != null)
                    {
                        var workflowType = WorkflowTypeCache.Get(trigger.WorkflowTypeId);
                        if (workflowType != null && (trigger.IsActive ?? true))
                        {
                            var workflow = Rock.Model.Workflow.Activate(workflowType, trigger.WorkflowName);

                            var entity = GetEntity(rockContext, message);
                            new Rock.Model.WorkflowService(rockContext).Process(workflow, entity, out var _);
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
        private void LaunchWorkflow(RockContext rockContext, int workflowTypeId, string name)
        {
            GroupMember groupMember = null;

            if (GroupMemberGuid.HasValue)
            {
                groupMember = new GroupMemberService(rockContext).Get(GroupMemberGuid.Value);
            }

            var workflowType = WorkflowTypeCache.Get(workflowTypeId);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                var workflow = Rock.Model.Workflow.Activate(workflowType, name);

                if (workflow.AttributeValues != null)
                {
                    if (workflow.AttributeValues.ContainsKey("Group"))
                    {
                        var group = new GroupService(rockContext).Get(GroupId.Value);
                        if (group != null)
                        {
                            workflow.AttributeValues["Group"].Value = group.Guid.ToString();
                        }
                    }

                    if (workflow.AttributeValues.ContainsKey("Person"))
                    {
                        var person = new PersonService(rockContext).Get(PersonId.Value);
                        if (person != null)
                        {
                            workflow.AttributeValues["Person"].Value = person.PrimaryAlias.Guid.ToString();
                        }
                    }
                }

                List <string> workflowErrors;
                new Rock.Model.WorkflowService(rockContext).Process(workflow, groupMember, out workflowErrors);
            }
        }
        /// <summary>
        /// Starts the workflow if one was defined in the block setting.
        /// </summary>
        /// <param name="prayerRequest">The prayer request.</param>
        /// <param name="rockContext">The rock context.</param>
        private void StartWorkflow(PrayerRequest prayerRequest, RockContext rockContext)
        {
            Guid?workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull();

            if (workflowTypeGuid.HasValue)
            {
                var workflowType = WorkflowTypeCache.Get(workflowTypeGuid.Value);
                if (workflowType != null && (workflowType.IsActive ?? true))
                {
                    try
                    {
                        var           workflow = Workflow.Activate(workflowType, prayerRequest.Name);
                        List <string> workflowErrors;
                        new WorkflowService(rockContext).Process(workflow, prayerRequest, out workflowErrors);
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogService.LogException(ex, this.Context);
                    }
                }
            }
        }
Exemplo n.º 27
0
        protected void LaunchWorkflow(Guid workflowGuid, Dictionary <string, string> attributes)
        {
            RockContext       _rockContext       = new RockContext();
            WorkflowService   _workflowService   = new WorkflowService(_rockContext);
            WorkflowTypeCache _workflowTypeCache = WorkflowTypeCache.Get(workflowGuid);

            Workflow _workflow = Rock.Model.Workflow.Activate(_workflowTypeCache, "New Test" + _workflowTypeCache.WorkTerm);


            foreach (KeyValuePair <string, string> attribute in attributes)
            {
                _workflow.SetAttributeValue(attribute.Key, attribute.Value);
            }


            List <string> errorMessages;

            if (_workflowService.Process(_workflow, out errorMessages))
            {
                // If the workflow type is persisted, save the workflow
                if (_workflow.IsPersisted || _workflowTypeCache.IsPersisted)
                {
                    if (_workflow.Id == 0)
                    {
                        _workflowService.Add(_workflow);
                    }

                    _rockContext.WrapTransaction(() =>
                    {
                        _rockContext.SaveChanges();
                        _workflow.SaveAttributeValues(_rockContext);
                        foreach (var activity in _workflow.Activities)
                        {
                            activity.SaveAttributeValues(_rockContext);
                        }
                    });
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Executes this instance.
        /// </summary>
        /// <param name="message"></param>
        public override void Execute(Message message)
        {
            if (message.WorkflowDetails != null && message.WorkflowDetails.Any())
            {
                WorkflowTypeCache workflowType = null;
                if (message.WorkflowTypeGuid.HasValue)
                {
                    workflowType = WorkflowTypeCache.Get(message.WorkflowTypeGuid.Value);
                }

                if (workflowType == null && message.WorkflowTypeId.HasValue)
                {
                    workflowType = WorkflowTypeCache.Get(message.WorkflowTypeId.Value);
                }

                if (workflowType != null && (workflowType.IsActive ?? true))
                {
                    foreach (var wfDetail in message.WorkflowDetails)
                    {
                        using (var rockContext = new RockContext())
                        {
                            var workflow = Rock.Model.Workflow.Activate(workflowType, wfDetail.Name);
                            workflow.InitiatorPersonAliasId = message.InitiatorPersonAliasId;

                            if (wfDetail.WorkflowAttributeValues != null)
                            {
                                foreach (var keyVal in wfDetail.WorkflowAttributeValues)
                                {
                                    workflow.SetAttributeValue(keyVal.Key, keyVal.Value);
                                }
                            }

                            var entity = GetEntity(rockContext, wfDetail);
                            new Rock.Model.WorkflowService(rockContext).Process(workflow, entity, out var _);
                        }
                    }
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Launches the workflow.
        /// </summary>
        /// <param name="workflowTypeGuid">The workflow type unique identifier.</param>
        /// <param name="family">The family.</param>
        private void LaunchWorkflow(Guid workflowTypeGuid, Group family)
        {
            int adultRoleId = GroupTypeCache.Get(SystemGuid.GroupType.GROUPTYPE_FAMILY.AsGuid()).Roles.Where(r => r.Guid == SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT.AsGuid()).FirstOrDefault().Id;

            var headOfHouse = family.Members.Where(m => m.GroupRoleId == adultRoleId).OrderBy(m => m.Person.Gender).FirstOrDefault();

            // don't launch a workflow if no adult is present in the family
            if (headOfHouse != null && headOfHouse.Person != null && headOfHouse.Person.PrimaryAlias != null)
            {
                var spouse = family.Members.Where(m => m.GroupRoleId == adultRoleId && m.PersonId != headOfHouse.Person.Id).FirstOrDefault();

                using (var rockContext = new RockContext())
                {
                    var workflowType = WorkflowTypeCache.Get(workflowTypeGuid);
                    if (workflowType != null && (workflowType.IsActive ?? true))
                    {
                        var workflowService = new WorkflowService(rockContext);
                        var workflow        = Rock.Model.Workflow.Activate(workflowType, headOfHouse.Person.FullName, rockContext);
                        workflowService.Add(workflow);
                        rockContext.SaveChanges();

                        workflow.SetAttributeValue("Family", family.Guid);
                        workflow.SetAttributeValue("HeadOfHouse", headOfHouse.Person.PrimaryAlias.Guid);

                        if (family.Campus != null)
                        {
                            workflow.SetAttributeValue("Campus", family.Campus.Guid);
                        }

                        if (spouse != null && spouse.Person != null && spouse.Person.PrimaryAlias != null)
                        {
                            workflow.SetAttributeValue("Spouse", spouse.Person.PrimaryAlias.Guid);
                        }

                        workflow.SaveAttributeValues();
                    }
                }
            }
        }
        private void LaunchWorkflow(RockContext rockContext, int workflowTypeId, string name)
        {
            var workflowType = WorkflowTypeCache.Get(workflowTypeId);

            if (workflowType != null && (workflowType.IsActive ?? true))
            {
                var workflow = Rock.Model.Workflow.Activate(workflowType, name);

                if (workflow.AttributeValues != null)
                {
                    if (workflow.AttributeValues.ContainsKey("Group"))
                    {
                        var group = new GroupService(rockContext).Get(GroupId.Value);
                        if (group != null)
                        {
                            workflow.AttributeValues["Group"].Value = group.Guid.ToString();
                        }
                    }

                    if (workflow.AttributeValues.ContainsKey("Person"))
                    {
                        var personAlias = new PersonAliasService(rockContext).Get(PersonAliasId.Value);
                        if (personAlias != null)
                        {
                            workflow.AttributeValues["Person"].Value = personAlias.Guid.ToString();
                        }
                    }

                    if (AttendanceDateTime.HasValue && workflow.AttributeValues.ContainsKey("AttendanceDateTime"))
                    {
                        workflow.AttributeValues["AttendanceDateTime"].Value = AttendanceDateTime.Value.ToString("o");
                    }
                }

                List <string> workflowErrors;
                new Rock.Model.WorkflowService(rockContext).Process(workflow, null, out workflowErrors);
            }
        }