public Rock.Model.Workflow WorkflowEntry(int workflowTypeId) { var rockContext = new Rock.Data.RockContext(); var workflowType = WorkflowTypeCache.Get(workflowTypeId); if (workflowType != null && (workflowType.IsActive ?? true)) { var workflow = Rock.Model.Workflow.Activate(workflowType, "Workflow From REST"); // set workflow attributes from querystring foreach (var parm in Request.GetQueryStrings()) { workflow.SetAttributeValue(parm.Key, parm.Value); } // save -> run workflow List <string> workflowErrors; new Rock.Model.WorkflowService(rockContext).Process(workflow, out workflowErrors); var response = ControllerContext.Request.CreateResponse(HttpStatusCode.Created); return(workflow); } else { var response = ControllerContext.Request.CreateResponse(HttpStatusCode.NotFound); } return(null); }
/// <summary> /// Executes this instance. /// </summary> /// <param name="message"></param> public override void Execute(Message message) { using (var rockContext = new RockContext()) { 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)) { var workflow = Rock.Model.Workflow.Activate(workflowType, message.WorkflowName); workflow.InitiatorPersonAliasId = message.InitiatorPersonAliasId; if (message.WorkflowAttributeValues != null) { foreach (var keyVal in message.WorkflowAttributeValues) { workflow.SetAttributeValue(keyVal.Key, keyVal.Value); } } var entity = GetEntity(rockContext, message); new WorkflowService(rockContext).Process(workflow, entity, out var _); } } }
/// <summary> /// Launches the workflow. /// </summary> /// <param name="fromPersonAliasId">From person alias identifier.</param> /// <param name="fromPhone">From phone.</param> /// <param name="message">The message.</param> /// <param name="toPersonAliasId">To person alias identifier.</param> /// <param name="rockSmsFromPhoneDv">The rock SMS from phone DefinedValue.</param> private void LaunchWorkflow(int?fromPersonAliasId, string fromPhone, string message, int?toPersonAliasId, DefinedValueCache rockSmsFromPhoneDv) { var workflowTypeGuid = rockSmsFromPhoneDv.GetAttributeValue("LaunchWorkflowOnResponseReceived"); var workflowType = WorkflowTypeCache.Get(workflowTypeGuid); if (workflowType == null || (workflowType.IsActive != true)) { return; } var personAliasService = new PersonAliasService(new RockContext()); var workflowAttributeValues = new Dictionary <string, string>(); workflowAttributeValues.Add("FromPhone", fromPhone); workflowAttributeValues.Add("Message", message); workflowAttributeValues.Add("SMSFromDefinedValue", rockSmsFromPhoneDv.Guid.ToString()); if (fromPersonAliasId != null) { workflowAttributeValues.Add("FromPerson", personAliasService.Get(fromPersonAliasId.Value).Guid.ToString() ?? string.Empty); } if (toPersonAliasId != null) { workflowAttributeValues.Add("ToPerson", personAliasService.Get(toPersonAliasId.Value).Guid.ToString() ?? string.Empty); } var launchWorkflowTransaction = new Rock.Transactions.LaunchWorkflowTransaction(workflowType.Id); launchWorkflowTransaction.WorkflowAttributeValues = workflowAttributeValues; launchWorkflowTransaction.Enqueue(); }
/// <summary> /// Checks the attributes for this component and determines if the message /// should be processed. /// </summary> /// <param name="action">The action that contains the configuration for this component.</param> /// <param name="message">The message that is to be checked.</param> /// <param name="errorMessage">If there is a problem processing, this should be set</param> /// <returns> /// <c>true</c> if the message should be processed. /// </returns> public override bool ShouldProcessMessage(SmsActionCache action, SmsMessage message, out string errorMessage) { // // Give the base class a chance to check it's own settings to see if we // should process this message. // if (!base.ShouldProcessMessage(action, message, out errorMessage)) { return(false); } // // Check if we have a valid workflow type. // var workflowType = WorkflowTypeCache.Get(GetAttributeValue(action, AttributeKey.WorkflowType).AsGuid()); if (workflowType == null) { return(false); } // // Get the filter expression for the message body. // var attribute = action.Attributes.ContainsKey(AttributeKey.Message) ? action.Attributes[AttributeKey.Message] : null; var msg = GetAttributeValue(action, AttributeKey.Message); var filter = ValueFilterFieldType.GetFilterExpression(attribute?.QualifierValues, msg); // // Evaluate the message against the filter and return the match state. // return(filter != null?filter.Evaluate(message, AttributeKey.Message) : true); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { bbtnLaunch.Enabled = false; Guid?entityTypeGuid = GetAttributeValue("EntityType").AsGuidOrNull(); Guid?workflowGuid = GetAttributeValue("WorkflowType").AsGuidOrNull(); int? entityId = PageParameter("EntityId").AsIntegerOrNull(); if (!workflowGuid.HasValue || !entityTypeGuid.HasValue) { nbInformation.Text = "Please configure the block before using it.<br />"; nbInformation.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger; } else if (!entityId.HasValue || entityId <= 0) { nbInformation.Text += "Please pass the EntityId as a page parameter.<br />"; nbInformation.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Danger; } else { var entity = getEntity(); var workflowType = WorkflowTypeCache.Get(workflowGuid.Value); nbInformation.Text = string.Format("Clicking \"Launch\" below will start a new instance of <i>{0}</i> for <i>{1}</i> (ID: {2:d}).", workflowType.Name, entity.ToString(), entityId.Value); nbInformation.NotificationBoxType = Rock.Web.UI.Controls.NotificationBoxType.Info; bbtnLaunch.Enabled = true; } } }
/// <summary> /// Gets the selected workflow type identifier. /// </summary> /// <returns></returns> private WorkflowTypeCache GetSelectedWorkflowType() { var workflowTypeId = PageParameter(PageParameterKey.WorkflowTypeId).AsIntegerOrNull(); if (workflowTypeId.HasValue) { return(WorkflowTypeCache.Get(workflowTypeId.Value)); } var workflowTypes = GetAttributeValues(AttributeKey.WorkflowTypes) .Select(WorkflowTypeCache.Get) .ToList(); if (workflowTypes.Count == 1) { var workflowType = workflowTypes.Single(); return(workflowType); } workflowTypeId = workflowTypes.Any() ? ddlWorkflowType.SelectedValueAsInt() : wtpWorkflowType.SelectedValueAsInt(); return(WorkflowTypeCache.Get(workflowTypeId ?? 0)); }
/// <summary> /// Launches a workflow in response to a prayer request flagged action. /// </summary> /// <param name="prayerRequest">The prayer request that was flagged.</param> /// <param name="workflowTypeGuid">The workflow type unique identifier to be launched.</param> /// <param name="currentPerson">The person that flagged the request.</param> public static void LaunchFlaggedWorkflow(PrayerRequest prayerRequest, Guid workflowTypeGuid, Person currentPerson) { var workflowType = WorkflowTypeCache.Get(workflowTypeGuid); if (workflowType != null && (workflowType.IsActive ?? true)) { try { // Create parameters var parameters = new Dictionary <string, string>(); parameters.Add("EntityGuid", prayerRequest.Guid.ToString()); if (currentPerson != null) { parameters.Add("FlaggedByPerson", currentPerson.PrimaryAlias.Guid.ToString()); parameters.Add("FlaggedByPersonAliasGuid", currentPerson.PrimaryAlias.Guid.ToString()); } prayerRequest.LaunchWorkflow(workflowTypeGuid, prayerRequest.Name, parameters, currentPerson.PrimaryAliasId); } catch (Exception ex) { ExceptionLogService.LogException(ex); } } }
public void LaunchWorkflow() { Guid?workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull(); if (workflowTypeGuid.HasValue) { var workflowType = WorkflowTypeCache.Get(workflowTypeGuid.Value); if (workflowType != null && (workflowType.IsActive ?? true)) { Person person = null; int? groupMemberId = null; GroupMember groupMember = null; if (gmpGroupMember.SelectedValueAsId().HasValue) { groupMemberId = gmpGroupMember.SelectedValueAsId(); if (groupMemberId.HasValue) { groupMember = new GroupMemberService(_rockContext).Get(groupMemberId.Value); person = groupMember.Person; } } if (ppPerson.SelectedValue.HasValue) { person = new PersonService(_rockContext).Get(ppPerson.PersonId.Value); } try { var workflowEntity = GetAttributeValue("WorkflowEntity"); if (workflowEntity.Equals("Note") && _noteId.HasValue) { var noteRequest = new NoteService(_rockContext).Get(_noteId.Value); if (noteRequest != null) { var workflow = Workflow.Activate(workflowType, person.FullName); List <string> workflowErrors; new WorkflowService(_rockContext).Process(workflow, noteRequest, out workflowErrors); } } else if (workflowEntity.Equals("GroupMember") && groupMemberId.HasValue && groupMember != null) { var workflow = Workflow.Activate(workflowType, person.FullName); List <string> workflowErrors; new WorkflowService(_rockContext).Process(workflow, groupMember, out workflowErrors); } else { var workflow = Workflow.Activate(workflowType, person.FullName); List <string> workflowErrors; new WorkflowService(_rockContext).Process(workflow, person, out workflowErrors); } } catch (Exception ex) { ExceptionLogService.LogException(ex, this.Context); } } } }
/// <summary> /// Executes this instance. /// </summary> public void Execute() { using (var rockContext = new RockContext()) { WorkflowTypeCache workflowType = null; if (WorkflowTypeGuid.HasValue) { workflowType = WorkflowTypeCache.Get(WorkflowTypeGuid.Value); } if (workflowType == null && WorkflowTypeId.HasValue) { workflowType = WorkflowTypeCache.Get(WorkflowTypeId.Value); } if (workflowType != null && (workflowType.IsActive ?? true)) { var workflow = Rock.Model.Workflow.Activate(workflowType, WorkflowName); workflow.InitiatorPersonAliasId = InitiatorPersonAliasId; foreach (var keyVal in WorkflowAttributeValues) { workflow.SetAttributeValue(keyVal.Key, keyVal.Value); } List <string> workflowErrors; new Rock.Model.WorkflowService(rockContext).Process(workflow, GetEntity(), out workflowErrors); } } }
/// <summary> /// Launches the workflow. /// </summary> private void LaunchWorkflow() { var rockContext = new RockContext(); var attendanceService = new AttendanceService(rockContext); var attendanceInfo = attendanceService.GetSelect( this.AttendanceId, s => new { Attendance = s, GroupGuid = s.Occurrence.Group.Guid, s.PersonAlias.Person, s.Occurrence.Group.GroupType.ScheduleCancellationWorkflowTypeId }); var attendance = attendanceInfo?.Attendance; var person = attendanceInfo?.Person; var groupGuid = attendanceInfo?.GroupGuid; if (attendanceInfo?.ScheduleCancellationWorkflowTypeId == null) { // either attendance record doesn't exist, or it doesn't have a ScheduleCancellationWorkflowType defined, so nothing to do return; } if (!attendance.IsScheduledPersonDeclined()) { // attendance record wasn't actually canceled, or isn't canceled anymore, so nothing to do } var workflowType = WorkflowTypeCache.Get(attendanceInfo.ScheduleCancellationWorkflowTypeId.Value); if (workflowType != null && (workflowType.IsActive ?? true)) { var workflow = Rock.Model.Workflow.Activate(workflowType, attendanceInfo.Person?.FullName); if (workflow.AttributeValues != null) { if (workflow.AttributeValues.ContainsKey("Group")) { workflow.AttributeValues["Group"].Value = groupGuid.ToString(); } if (workflow.AttributeValues.ContainsKey("Attendance")) { workflow.AttributeValues["Attendance"].Value = attendance.Guid.ToString(); } if (workflow.AttributeValues.ContainsKey("Person")) { if (person != null) { workflow.AttributeValues["Person"].Value = person.PrimaryAlias?.Guid.ToString(); } } } List <string> workflowErrors; new Rock.Model.WorkflowService(rockContext).Process(workflow, attendance, out workflowErrors); } }
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); var workflow = Rock.Model.Workflow.Activate(workflowType, name); 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(); } } } }
/// <summary> /// Processes the specified <see cref="Rock.Model.Workflow" /> /// </summary> /// <param name="workflow">The <see cref="Rock.Model.Workflow" /> instance to process.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">A <see cref="System.Collections.Generic.List{String}" /> that contains any error messages that were returned while processing the <see cref="Rock.Model.Workflow" />.</param> /// <returns></returns> public bool Process(Workflow workflow, object entity, out List <string> errorMessages) { var workflowType = WorkflowTypeCache.Get(workflow.WorkflowTypeId); if (workflowType != null && (workflowType.IsActive ?? true)) { var rockContext = (RockContext)this.Context; if (workflow.IsPersisted) { workflow.IsProcessing = true; rockContext.SaveChanges(); } bool result = workflow.ProcessActivities(rockContext, entity, out errorMessages); if (workflow.Status == "DeleteWorkflowNow") { if (workflow.Id > 0) { rockContext.SaveChanges(); Delete(workflow); rockContext.SaveChanges(); } result = true; } else { if (workflow.IsPersisted || workflowType.IsPersisted) { if (workflow.Id == 0) { Add(workflow); } rockContext.SaveChanges(); workflow.SaveAttributeValues(rockContext); foreach (var activity in workflow.Activities) { activity.SaveAttributeValues(rockContext); } workflow.IsProcessing = false; rockContext.SaveChanges(); } } return(result); } else { errorMessages = new List <string> { "Workflow Type is invalid or not active!" }; return(false); } }
/// <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("Status", cblStatus.SelectedValuesAsInt.AsDelimited(",")); var ppFieldType = new PageReferenceFieldType(); this.SetAttributeValue("DetailPage", ppFieldType.GetEditValue(ppDetailPage, null)); 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("MergeContent", cbMergeContent.Checked.ToString()); 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(); }
/// <summary> /// Create and launch a new instance of a workflow for the specified trigger. /// </summary> /// <param name="dataContext">The data context.</param> /// <param name="workflowTypeId">The workflow type identifier.</param> /// <param name="triggerId">The trigger identifier.</param> /// <param name="name">The name.</param> private void LaunchWorkflow(RockContext dataContext, int workflowTypeId, int triggerId, string name) { // Get the Workflow Type associated with this trigger. var workflowType = WorkflowTypeCache.Get(workflowTypeId); if (workflowType == null) { ExceptionLogService.LogException($"EntityChangeTransaction failed. Workflow Type does not exist [WorkflowTypeId={ workflowTypeId }]."); return; } if (!(workflowType.IsActive ?? true)) { return; } // TODO: Extend IService interface to include Get(guid) method? // Then we could eliminate the need for the GetTargetEntity callback, and just do this: // var entityService = Reflection.GetServiceForEntityType( typeof( TEntity ), rockContext ); // var targetEntity = entityService.Get( this.EntityGuid.GetValueOrDefault() ); var targetEntity = this.GetTargetEntity(dataContext, _EntityGuid.GetValueOrDefault()); if (targetEntity == null) { ExceptionLogService.LogException($"EntityChangeTransaction failed. Target entity does not exist [Guid={ _EntityGuid }]."); return; } // Create and process a new Workflow of the specified Workflow Type for the target Entity. var workflow = Rock.Model.Workflow.Activate(workflowType, name); var workflowService = new WorkflowService(dataContext); List <string> workflowErrors; workflowService.Process(workflow, targetEntity, out workflowErrors); if (workflow.Id == 0) { ExceptionLogService.LogException($"EntityChangeTransaction failed. Workflow instance could not be created [WorkflowName={ name }]."); return; } if (workflowErrors.Any()) { ExceptionLogService.LogException($"EntityChangeTransaction failed. Workflow execution failed with errors [WorkflowName={ name }].\n{ workflowErrors.AsDelimited( "\n" )}"); return; } // Create a new EntityWorkflow instance to track the association between the target entity and the workflow. // TODO: Create an interface IEntityWorkflowInstance(EntityId, WorkflowId, TriggerId) to allow the instance object to be created here using a generic implementation? this.CreateWorkflowInstanceEntity(dataContext, targetEntity.Id, workflow.Id, triggerId); dataContext.SaveChanges(); }
public HttpResponseMessage Family(string param) { try { var Session = HttpContext.Current.Session; var localDeviceConfigCookie = HttpContext.Current.Request.Cookies[CheckInCookieKey.LocalDeviceConfig].Value; var localDevice = localDeviceConfigCookie.FromJsonOrNull <LocalDeviceConfiguration>(); CurrentKioskId = localDevice.CurrentKioskId.Value; Guid blockGuid = ( Guid )Session["BlockGuid"]; CurrentCheckInState = new CheckInState(CurrentKioskId, localDevice.CurrentCheckinTypeId, localDevice.CurrentGroupTypeIds); 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")); } }
protected void gReleventPeople_RowSelected(object sender, RowEventArgs e) { var attendance = new AttendanceService(rockContext).Get(SelectedAttendanceGuid); var selectedPlegePersonAlias = new PersonAliasService(rockContext).Get(( Guid )e.RowKeyValue); var workflowTypeCache = WorkflowTypeCache.Get(GetAttributeValue("WorkflowType").AsGuid()); if (attendance != null && selectedPlegePersonAlias != null) { LaunchWorkflow(rockContext, attendance, selectedPlegePersonAlias, workflowTypeCache); } }
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(); }
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> /// 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> /// 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); }
/// <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() }); }
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); } }
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); } }
/// <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(); } }
/// <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); } }
/// <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); } } } }
/// <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(); } } }
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); } } }