public void WorkflowTriggerCollectionAddNew()
 {
     var sut = new WorkflowTriggerCollection<string>();
     var t = new WorkflowTrigger<string>("trigger1");
     sut.Add(t);
     sut.Count.ShouldBe(1);
 }
        /// <summary>
        /// Shows the qualifier values in the correct fields using the given
        /// workflow trigger if available.
        /// </summary>
        /// <param name="workflowTrigger">The workflow trigger.</param>
        private void ShowQualifierValues(WorkflowTrigger workflowTrigger)
        {
            bool showPreSave = false;

            if (workflowTrigger != null)
            {
                showPreSave = (workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PreSave);
                if (showPreSave &&
                    !string.IsNullOrEmpty(workflowTrigger.EntityTypeQualifierValue) &&
                    workflowTrigger.EntityTypeQualifierValue != workflowTrigger.EntityTypeQualifierValuePrevious)
                {
                    tbQualifierValueAlt.Text      = workflowTrigger.EntityTypeQualifierValue;
                    tbPreviousQualifierValue.Text = workflowTrigger.EntityTypeQualifierValuePrevious;
                }
                else
                {
                    tbQualifierValue.Text = workflowTrigger.EntityTypeQualifierValue;
                }
            }

            if (rblTriggerType.SelectedValue == ((int)WorkflowTriggerType.PreSave).ToStringSafe() || showPreSave)
            {
                tbQualifierValue.Label           = "Or value is";
                tbPreviousQualifierValue.Visible = true;
                tbQualifierValueAlt.Visible      = true;
            }
            else
            {
                tbQualifierValue.Label           = "Value is";
                tbPreviousQualifierValue.Visible = false;
                tbQualifierValueAlt.Visible      = false;
            }
        }
 private void ValidateTrigger(WorkflowTrigger actual)
 {
     Assert.Equal(Constants.DefaultTriggerName, actual.Name);
     Assert.Equal("Succeeded", actual.ProvisioningState);
     Assert.Equal("Enabled", actual.State);
     Assert.NotNull(actual.CreatedTime);
     Assert.NotNull(actual.ChangedTime);
 }
Exemple #4
0
 /// <summary>
 /// Construct a transition.
 /// </summary>
 /// <param name="fromState"></param>
 /// <param name="toState"></param>
 /// <param name="triggeredBy"></param>
 /// <param name="isReentry"></param>
 /// <param name="guardCondition"></param>
 /// <returns></returns>
 public WorkflowTransition(WorkflowState <T, TContext> fromState,
                           WorkflowState <T, TContext> toState,
                           WorkflowTrigger <T> triggeredBy,
                           bool isReentry = false,
                           IWorkflowGuard <T, TContext> guardCondition = null)
 {
     FromState      = fromState;
     ToState        = toState;
     TriggeredBy    = triggeredBy;
     IsReentry      = isReentry;
     GuardCondition = guardCondition;
 }
Exemple #5
0
        /// <summary>
        /// Shows the qualifier values in the correct fields using the given
        /// workflow trigger if available.
        /// </summary>
        /// <param name="workflowTrigger">The workflow trigger.</param>
        private void ShowQualifierValues(WorkflowTrigger workflowTrigger)
        {
            bool usePreviousValue  = false;
            bool showPreviousField = false;

            if (workflowTrigger != null)
            {
                if (workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PreSave ||
                    workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PostSave ||
                    workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.ImmediatePostSave)
                {
                    usePreviousValue = true;
                }

                if (usePreviousValue &&
                    (!string.IsNullOrEmpty(workflowTrigger.EntityTypeQualifierValue) || !string.IsNullOrEmpty(workflowTrigger.EntityTypeQualifierValuePrevious)) &&
                    workflowTrigger.WorkflowTriggerValueChangeType == WorkflowTriggerValueChangeType.ChangeFromTo
                    )
                {
                    tbQualifierValueAlt.Text      = workflowTrigger.EntityTypeQualifierValue;
                    tbPreviousQualifierValue.Text = workflowTrigger.EntityTypeQualifierValuePrevious;
                }
                else
                {
                    tbQualifierValue.Text = workflowTrigger.EntityTypeQualifierValue;
                }
            }

            if (rblTriggerType.SelectedValue == (( int )WorkflowTriggerType.PreSave).ToStringSafe() ||
                rblTriggerType.SelectedValue == (( int )WorkflowTriggerType.PostSave).ToStringSafe() ||
                rblTriggerType.SelectedValue == (( int )WorkflowTriggerType.ImmediatePostSave).ToStringSafe())
            {
                showPreviousField = true;
            }

            if (showPreviousField || usePreviousValue)
            {
                tbQualifierValue.Label           = "Or value is";
                tbPreviousQualifierValue.Visible = true;
                tbQualifierValueAlt.Visible      = true;
            }
            else
            {
                tbQualifierValue.Label           = "Value is";
                tbPreviousQualifierValue.Visible = false;
                tbQualifierValueAlt.Visible      = false;
            }
        }
        private void onStateTransition(WorkflowState <string, Customer> source,
                                       WorkflowState <string, Customer> destination,
                                       WorkflowTrigger <string> trigger, bool reentry)
        {
            if (source is WorkflowStartState <string, Customer> )
            {
                output.WriteLine("Workflow started");
            }

            if (destination is WorkflowEndState <string, Customer> )
            {
                output.WriteLine("Workflow completed");
            }

            output.WriteLine($"{DateTime.Now.ToShortTimeString()}: State changed from {source} to {destination} because of trigger {trigger}.");
        }
Exemple #7
0
        private void ValidateTrigger1(WorkflowTrigger trigger)
        {
            Assert.True(this.ValidateIdFormat(id: trigger.Id, entityTypeName: "workflows", entitySubtypeName: "triggers"));
            Assert.Equal("tName", trigger.Name);
            Assert.Equal("Microsoft.Logic/workflows/triggers", trigger.Type);

            Assert.Equal(2015, trigger.CreatedTime.Value.Year);
            Assert.Equal(06, trigger.CreatedTime.Value.Month);
            Assert.Equal(23, trigger.CreatedTime.Value.Day);
            Assert.Equal(21, trigger.CreatedTime.Value.Hour);
            Assert.Equal(47, trigger.CreatedTime.Value.Minute);
            Assert.Equal(00, trigger.CreatedTime.Value.Second);
            Assert.Equal(DateTimeKind.Utc, trigger.CreatedTime.Value.Kind);

            Assert.Equal(2015, trigger.ChangedTime.Value.Year);
            Assert.Equal(06, trigger.ChangedTime.Value.Month);
            Assert.Equal(23, trigger.ChangedTime.Value.Day);
            Assert.Equal(21, trigger.ChangedTime.Value.Hour);
            Assert.Equal(47, trigger.ChangedTime.Value.Minute);
            Assert.Equal(30, trigger.ChangedTime.Value.Second);
            Assert.Equal(DateTimeKind.Utc, trigger.ChangedTime.Value.Kind);

            Assert.Equal(WorkflowState.Enabled, trigger.State);
            Assert.Equal(WorkflowStatus.Waiting, trigger.Status);

            Assert.Equal(2015, trigger.LastExecutionTime.Value.Year);
            Assert.Equal(1, trigger.LastExecutionTime.Value.Month);
            Assert.Equal(1, trigger.LastExecutionTime.Value.Day);
            Assert.Equal(1, trigger.LastExecutionTime.Value.Hour);
            Assert.Equal(1, trigger.LastExecutionTime.Value.Minute);
            Assert.Equal(1, trigger.LastExecutionTime.Value.Second);
            Assert.Equal(DateTimeKind.Utc, trigger.LastExecutionTime.Value.Kind);

            Assert.Equal(2015, trigger.NextExecutionTime.Value.Year);
            Assert.Equal(1, trigger.NextExecutionTime.Value.Month);
            Assert.Equal(1, trigger.NextExecutionTime.Value.Day);
            Assert.Equal(2, trigger.NextExecutionTime.Value.Hour);
            Assert.Equal(1, trigger.NextExecutionTime.Value.Minute);
            Assert.Equal(1, trigger.NextExecutionTime.Value.Second);
            Assert.Equal(DateTimeKind.Utc, trigger.NextExecutionTime.Value.Kind);

            Assert.Equal(RecurrenceFrequency.Hour, trigger.Recurrence.Frequency);
            Assert.Equal(1, trigger.Recurrence.Interval);
            Assert.Equal("/subscriptions/66666666-6666-6666-6666-666666666666/resourceGroups/rgName/providers/Microsoft.Logic/workflows/wfName/versions/08587692632149400005", trigger.Workflow.Id);
            Assert.Equal("wfName/08587692632149400005", trigger.Workflow.Name);
            Assert.Equal("Microsoft.Logic/workflows/versions", trigger.Workflow.Type);
        }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            WorkflowTrigger        WorkflowTrigger;
            var                    rockContext            = new RockContext();
            WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService(rockContext);
            AttributeService       attributeService       = new AttributeService(rockContext);

            int WorkflowTriggerId = int.Parse(hfWorkflowTriggerId.Value);

            if (WorkflowTriggerId == 0)
            {
                WorkflowTrigger = new WorkflowTrigger();
                WorkflowTriggerService.Add(WorkflowTrigger);
            }
            else
            {
                WorkflowTrigger = WorkflowTriggerService.Get(WorkflowTriggerId);
            }

            WorkflowTrigger.EntityTypeId = ddlEntityType.SelectedValueAsInt().Value;
            WorkflowTrigger.EntityTypeQualifierColumn = ddlQualifierColumn.SelectedValue;
            WorkflowTrigger.EntityTypeQualifierValue  = tbQualifierValue.Text;
            WorkflowTrigger.WorkflowTypeId            = ddlWorkflowType.SelectedValueAsInt().Value;
            WorkflowTrigger.WorkflowTriggerType       = (WorkflowTriggerType)System.Enum.Parse(typeof(WorkflowTriggerType), rblTriggerType.SelectedValue);
            WorkflowTrigger.IsActive = cbIsActive.Checked;
            if (string.IsNullOrWhiteSpace(tbWorkflowName.Text))
            {
                WorkflowTrigger.WorkflowName = null;
            }
            else
            {
                WorkflowTrigger.WorkflowName = tbWorkflowName.Text;
            }

            if (!WorkflowTrigger.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            Rock.Workflow.TriggerCache.Refresh();

            NavigateToParentPage();
        }
        /// <summary>
        /// Get a formatted string that represents the qualifier value of the workflow trigger.
        /// </summary>
        /// <param name="workflowTrigger">The workflow trigger object.</param>
        /// <returns>A formatted string that represents the qualifier value of the workflow trigger.</returns>
        private string GetFormattedQualifierValue(WorkflowTrigger workflowTrigger)
        {
            bool   usePreviousValue = false;
            string value;

            if (workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PreSave ||
                workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PostSave ||
                workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.ImmediatePostSave)
            {
                usePreviousValue = true;
            }

            if (usePreviousValue &&
                (!string.IsNullOrEmpty(workflowTrigger.EntityTypeQualifierValue) || !string.IsNullOrEmpty(workflowTrigger.EntityTypeQualifierValuePrevious)))
            {
                if (!string.IsNullOrWhiteSpace(workflowTrigger.EntityTypeQualifierValuePrevious))
                {
                    value = workflowTrigger.EntityTypeQualifierValuePrevious.EncodeHtml();
                }
                else
                {
                    value = "<i>Any value</i>";
                }

                if (workflowTrigger.WorkflowTriggerValueChangeType == WorkflowTriggerValueChangeType.ChangeFromTo)
                {
                    value += " <i class='fa fa-angle-double-right'></i> ";

                    if (!string.IsNullOrWhiteSpace(workflowTrigger.EntityTypeQualifierValue))
                    {
                        value += workflowTrigger.EntityTypeQualifierValue.EncodeHtml();
                    }
                    else
                    {
                        value += "<i>Any value</i>";
                    }
                }
            }
            else
            {
                value = workflowTrigger.EntityTypeQualifierValue.EncodeHtml();
            }

            return(value);
        }
Exemple #10
0
    private async Task <HttpEndpointDescriptor> GetHttpEndpointDescriptor(
        WorkflowExecutionContext workflowExecutionContext,
        WorkflowTrigger workflowTrigger,
        ICreatesActivityExecutionContextForActivityBlueprint activityExecutionContextFactory)
    {
        var activityId                   = workflowTrigger.ActivityId;
        var httpEndpointActivity         = workflowExecutionContext.WorkflowBlueprint.GetActivity(activityId) !;
        var httpEndpointBookmark         = (HttpEndpointBookmark)workflowTrigger.Bookmark;
        var activityExecutionContext     = activityExecutionContextFactory.CreateActivityExecutionContext(httpEndpointActivity, workflowExecutionContext, CancellationToken.None);
        var httpEndpointActivityAccessor = new ActivityBlueprintWrapper <HttpEndpoint>(activityExecutionContext);
        var displayName                  = httpEndpointActivity.DisplayName;
        var description                  = httpEndpointActivity.Description;
        var path       = httpEndpointBookmark.Path;
        var method     = httpEndpointBookmark.Method !;
        var targetType = await httpEndpointActivityAccessor.EvaluatePropertyValueAsync(x => x.TargetType);

        var schema = await httpEndpointActivityAccessor.EvaluatePropertyValueAsync(x => x.Schema);

        return(new HttpEndpointDescriptor(activityId, path, method, displayName, description, targetType, schema));
    }
Exemple #11
0
        /// <summary>
        /// Handles the Delete event of the gWorkflowTrigger control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gWorkflowTrigger_Delete(object sender, RowEventArgs e)
        {
            var rockContext = new RockContext();
            WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService(rockContext);
            WorkflowTrigger        WorkflowTrigger        = WorkflowTriggerService.Get(e.RowKeyId);

            if (WorkflowTrigger != null)
            {
                string errorMessage;
                if (!WorkflowTriggerService.CanDelete(WorkflowTrigger, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                WorkflowTriggerService.Delete(WorkflowTrigger);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Exemple #12
0
        /// <summary>
        /// Handles the Delete event of the gWorkflowTrigger control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gWorkflowTrigger_Delete(object sender, RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService();
                WorkflowTrigger WorkflowTrigger = WorkflowTriggerService.Get((int)e.RowKeyValue);

                if (WorkflowTrigger != null)
                {
                    string errorMessage;
                    if (!WorkflowTriggerService.CanDelete(WorkflowTrigger, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    WorkflowTriggerService.Delete(WorkflowTrigger, CurrentPersonId);
                    WorkflowTriggerService.Save(WorkflowTrigger, CurrentPersonId);
                }
            });

            BindGrid();
        }
Exemple #13
0
        /// <summary>
        /// Determines whether the entity matches the current and/or previous qualifier values.
        /// If 
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="trigger">The trigger.</param>
        /// <returns>true if matches; false otherwise</returns>
        private static bool IsQualifierMatch( ContextItem item, Dictionary<string, PropertyInfo> properties, WorkflowTrigger trigger )
        {
            bool match = false;
            var dbEntity = item.DbEntityEntry;

            // Now attempt to find a match taking into account the EntityTypeQualifierValue and/or EntityTypeQualifierValuePrevious
            if ( properties.ContainsKey( trigger.EntityTypeQualifierColumn.ToLower() ) )
            {
                var propertyInfo = properties[trigger.EntityTypeQualifierColumn.ToLower()];

                bool hasPrevious = !string.IsNullOrEmpty( trigger.EntityTypeQualifierValuePrevious );
                bool hasCurrent = !string.IsNullOrEmpty( trigger.EntityTypeQualifierValue );

                // it's apparently not possible to interrogate the dbEntity of virtual properties
                // so it's illegal if they somehow selected one of these; and it's not a match.
                if ( propertyInfo.GetGetMethod().IsVirtual )
                {
                    // TODO: log a silent exception?
                    return false;
                }

                var currentProperty = propertyInfo.GetValue( item.Entity, null );
                var currentValue = currentProperty != null ? currentProperty.ToString() : string.Empty;
                var previousValue = string.Empty;

                var dbPropertyEntry = dbEntity.Property( propertyInfo.Name );
                if ( dbPropertyEntry != null )
                {
                    previousValue = dbEntity.State == EntityState.Added ? string.Empty : dbPropertyEntry.OriginalValue.ToStringSafe();
                }

                if ( trigger.WorkflowTriggerType == WorkflowTriggerType.PreDelete ||
                    trigger.WorkflowTriggerType == WorkflowTriggerType.PostDelete )
                {
                    match = ( previousValue == trigger.EntityTypeQualifierValue );
                }
                else if ( hasCurrent && !hasPrevious )
                {
                    // ...and previous cannot be the same as the current (must be a change)
                    match = ( currentValue == trigger.EntityTypeQualifierValue &&
                        currentValue != previousValue );
                }
                else if ( !hasCurrent && hasPrevious )
                {
                    // ...and previous cannot be the same as the current (must be a change)
                    match = ( previousValue == trigger.EntityTypeQualifierValuePrevious &&
                        previousValue != currentValue );
                }
                else if ( hasCurrent && hasPrevious )
                {
                    match = ( currentValue == trigger.EntityTypeQualifierValue &&
                        previousValue == trigger.EntityTypeQualifierValuePrevious );
                }
                else if ( !hasCurrent && !hasPrevious )
                {
                    // If they used an entity type qualifier column, at least one qualifier value is required.
                    // TODO: log as silent exception?
                }
            }
            return match;
        }
Exemple #14
0
        /// <summary>
        /// Shows the qualifier values in the correct fields using the given 
        /// workflow trigger if available.
        /// </summary>
        /// <param name="workflowTrigger">The workflow trigger.</param>
        private void ShowQualifierValues( WorkflowTrigger workflowTrigger )
        {
            bool showPreSave = false;
            if ( workflowTrigger != null )
            {
                showPreSave = ( workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PreSave );
                if ( showPreSave
                    && ! string.IsNullOrEmpty( workflowTrigger.EntityTypeQualifierValue )
                    && workflowTrigger.EntityTypeQualifierValue != workflowTrigger.EntityTypeQualifierValuePrevious )
                {
                    tbQualifierValueAlt.Text = workflowTrigger.EntityTypeQualifierValue;
                    tbPreviousQualifierValue.Text = workflowTrigger.EntityTypeQualifierValuePrevious;
                }
                else
                {
                    tbQualifierValue.Text = workflowTrigger.EntityTypeQualifierValue;
                }
            }

            if ( rblTriggerType.SelectedValue == ( (int)WorkflowTriggerType.PreSave ).ToStringSafe() || showPreSave )
            {
                tbQualifierValue.Label = "Or value is";
                tbPreviousQualifierValue.Visible = true;
                tbQualifierValueAlt.Visible = true;
            }
            else
            {
                tbQualifierValue.Label = "Value is";
                tbPreviousQualifierValue.Visible = false;
                tbQualifierValueAlt.Visible = false;
            }
        }
Exemple #15
0
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
        {
            WorkflowTrigger workflowTrigger;
            var rockContext = new RockContext();
            WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService( rockContext );
            AttributeService attributeService = new AttributeService( rockContext );

            int WorkflowTriggerId = int.Parse( hfWorkflowTriggerId.Value );

            if ( WorkflowTriggerId == 0 )
            {
                workflowTrigger = new WorkflowTrigger();
                WorkflowTriggerService.Add( workflowTrigger );
            }
            else
            {
                workflowTrigger = WorkflowTriggerService.Get( WorkflowTriggerId );
            }

            workflowTrigger.WorkflowTypeId = ddlWorkflowType.SelectedValueAsInt().Value;
            workflowTrigger.WorkflowTriggerType = (WorkflowTriggerType)System.Enum.Parse( typeof( WorkflowTriggerType ), rblTriggerType.SelectedValue );

            workflowTrigger.EntityTypeId = ddlEntityType.SelectedValueAsInt().Value;
            workflowTrigger.EntityTypeQualifierColumn = ddlQualifierColumn.SelectedValue;

            // If the trigger type is PreSave and the tbQualifierValue does not exist,
            // use the previous and alt qualifier value
            if ( workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PreSave )
            {
                if ( !string.IsNullOrEmpty( tbQualifierValue.Text ) )
                {
                    // in this case, use the same value as the previous and current qualifier value
                    workflowTrigger.EntityTypeQualifierValue = tbQualifierValue.Text;
                    workflowTrigger.EntityTypeQualifierValuePrevious = tbQualifierValue.Text;
                }
                else
                {
                    workflowTrigger.EntityTypeQualifierValue = tbQualifierValueAlt.Text;
                    workflowTrigger.EntityTypeQualifierValuePrevious = tbPreviousQualifierValue.Text;
                }
            }
            else
            {
                // use the regular qualifier and clear the previous value qualifier since it does not apply.
                workflowTrigger.EntityTypeQualifierValue = tbQualifierValue.Text;
                workflowTrigger.EntityTypeQualifierValuePrevious = string.Empty;
            }

            workflowTrigger.IsActive = cbIsActive.Checked;
            if ( string.IsNullOrWhiteSpace( tbWorkflowName.Text ) )
            {
                workflowTrigger.WorkflowName = null;
            }
            else
            {
                workflowTrigger.WorkflowName = tbWorkflowName.Text;
            }

            if ( !workflowTrigger.IsValid )
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            Rock.Workflow.TriggerCache.Refresh();

            NavigateToParentPage();
        }
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail(string itemKey, int itemKeyValue)
        {
            if (!itemKey.Equals("WorkflowTriggerId"))
            {
                return;
            }

            pnlDetails.Visible = true;
            WorkflowTrigger WorkflowTrigger = null;

            if (!itemKeyValue.Equals(0))
            {
                WorkflowTrigger   = new WorkflowTriggerService().Get(itemKeyValue);
                lActionTitle.Text = ActionTitle.Edit(WorkflowTrigger.FriendlyTypeName);
            }
            else
            {
                WorkflowTrigger = new WorkflowTrigger {
                    Id = 0, WorkflowTriggerType = WorkflowTriggerType.PostSave
                };
                lActionTitle.Text = ActionTitle.Add(WorkflowTrigger.FriendlyTypeName);
            }

            LoadDropDowns();

            hfWorkflowTriggerId.Value = WorkflowTrigger.Id.ToString();
            ddlEntityType.SetValue(WorkflowTrigger.EntityTypeId);
            LoadColumnNames();
            tbQualifierValue.Text = WorkflowTrigger.EntityTypeQualifierValue;
            ddlWorkflowType.SetValue(WorkflowTrigger.WorkflowTypeId);
            rblTriggerType.SelectedValue = WorkflowTrigger.WorkflowTriggerType.ConvertToInt().ToString();
            tbWorkflowName.Text          = WorkflowTrigger.WorkflowName ?? string.Empty;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized("Edit"))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(WorkflowTrigger.FriendlyTypeName);
            }

            if (WorkflowTrigger.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(WorkflowTrigger.FriendlyTypeName);
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(WorkflowTrigger.FriendlyTypeName);
                btnCancel.Text    = "Close";
            }

            ddlEntityType.Enabled      = !readOnly;
            ddlQualifierColumn.Enabled = !readOnly;
            tbQualifierValue.ReadOnly  = readOnly;
            ddlWorkflowType.Enabled    = !readOnly;
            rblTriggerType.Enabled     = !readOnly;
            tbWorkflowName.ReadOnly    = readOnly;

            btnSave.Visible = !readOnly;
        }
 /// <summary>
 /// To the model.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static WorkflowTrigger ToModel( this WorkflowTriggerDto value )
 {
     WorkflowTrigger result = new WorkflowTrigger();
     value.CopyToModel( result );
     return result;
 }
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="itemKey">The item key.</param>
        /// <param name="itemKeyValue">The item key value.</param>
        public void ShowDetail( string itemKey, int itemKeyValue )
        {
            if ( !itemKey.Equals( "WorkflowTriggerId" ) )
            {
                return;
            }

            pnlDetails.Visible = true;
            WorkflowTrigger WorkflowTrigger = null;

            if ( !itemKeyValue.Equals( 0 ) )
            {
                WorkflowTrigger = new WorkflowTriggerService( new RockContext() ).Get( itemKeyValue );
                lActionTitle.Text = ActionTitle.Edit( WorkflowTrigger.FriendlyTypeName ).FormatAsHtmlTitle();
            }
            else
            {
                WorkflowTrigger = new WorkflowTrigger { Id = 0, WorkflowTriggerType = WorkflowTriggerType.PostSave, IsActive=true };
                lActionTitle.Text = ActionTitle.Add( WorkflowTrigger.FriendlyTypeName ).FormatAsHtmlTitle();
            }

            LoadDropDowns();

            hfWorkflowTriggerId.Value = WorkflowTrigger.Id.ToString(); 
            ddlEntityType.SetValue( WorkflowTrigger.EntityTypeId );
            LoadColumnNames();
            ddlQualifierColumn.SetValue( WorkflowTrigger.EntityTypeQualifierColumn );
            tbQualifierValue.Text = WorkflowTrigger.EntityTypeQualifierValue;
            ddlWorkflowType.SetValue( WorkflowTrigger.WorkflowTypeId );
            rblTriggerType.SelectedValue = WorkflowTrigger.WorkflowTriggerType.ConvertToInt().ToString();
            tbWorkflowName.Text = WorkflowTrigger.WorkflowName ?? string.Empty;
            cbIsActive.Checked = WorkflowTrigger.IsActive ?? false;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if ( !IsUserAuthorized( Authorization.EDIT ) )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( WorkflowTrigger.FriendlyTypeName );
            }

            if ( WorkflowTrigger.IsSystem )
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem( WorkflowTrigger.FriendlyTypeName );
            }

            if ( readOnly )
            {
                lActionTitle.Text = ActionTitle.View( WorkflowTrigger.FriendlyTypeName );
                btnCancel.Text = "Close";
            }

            ddlEntityType.Enabled = !readOnly;
            ddlQualifierColumn.Enabled = !readOnly;
            tbQualifierValue.ReadOnly = readOnly;
            ddlWorkflowType.Enabled = !readOnly;
            rblTriggerType.Enabled = !readOnly;
            tbWorkflowName.ReadOnly = readOnly;
            cbIsActive.Enabled = !readOnly;

            btnSave.Visible = !readOnly;

        }
Exemple #19
0
 // For state changes that do not require parameters.
 public void ChangeTo(WorkflowTrigger trigger)
 {
     stateMachine.Fire <DateTime>(trigger);
 }
Exemple #20
0
 /// <summary>
 /// fires the requested trigger
 /// </summary>
 /// <param name="workflowTrigger">trigger to run</param>
 public void Fire(WorkflowTrigger workflowTrigger)
 {
     _stateMachine.Fire(workflowTrigger);
 }
 /// <summary>
 /// Instantiates a new DTO object from the entity
 /// </summary>
 /// <param name="workflowTrigger"></param>
 public WorkflowTriggerDto( WorkflowTrigger workflowTrigger )
 {
     CopyFromModel( workflowTrigger );
 }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click(object sender, EventArgs e)
        {
            WorkflowTrigger        workflowTrigger;
            var                    rockContext            = new RockContext();
            WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService(rockContext);
            AttributeService       attributeService       = new AttributeService(rockContext);
            bool                   usePreviousValue       = false;

            int WorkflowTriggerId = int.Parse(hfWorkflowTriggerId.Value);

            if (WorkflowTriggerId == 0)
            {
                workflowTrigger = new WorkflowTrigger();
                WorkflowTriggerService.Add(workflowTrigger);
            }
            else
            {
                workflowTrigger = WorkflowTriggerService.Get(WorkflowTriggerId);
            }

            workflowTrigger.WorkflowTypeId      = ddlWorkflowType.SelectedValueAsInt().Value;
            workflowTrigger.WorkflowTriggerType = (WorkflowTriggerType)System.Enum.Parse(typeof(WorkflowTriggerType), rblTriggerType.SelectedValue);

            workflowTrigger.EntityTypeId = ddlEntityType.SelectedValueAsInt().Value;
            workflowTrigger.EntityTypeQualifierColumn = ddlQualifierColumn.SelectedValue;

            //
            // If the trigger type is PreSave, PostSave or ImmediatePostSave then we have
            // a previous value option.
            //
            if (workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PreSave ||
                workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.PostSave ||
                workflowTrigger.WorkflowTriggerType == WorkflowTriggerType.ImmediatePostSave)
            {
                usePreviousValue = true;
            }

            // If the trigger type is PreSave and the tbQualifierValue does not exist,
            // use the previous and alt qualifier value
            if (usePreviousValue)
            {
                if (!string.IsNullOrEmpty(tbQualifierValue.Text))
                {
                    // in this case, use the same value as the previous and current qualifier value
                    workflowTrigger.EntityTypeQualifierValue         = tbQualifierValue.Text;
                    workflowTrigger.EntityTypeQualifierValuePrevious = tbQualifierValue.Text;
                }
                else
                {
                    workflowTrigger.EntityTypeQualifierValue         = tbQualifierValueAlt.Text;
                    workflowTrigger.EntityTypeQualifierValuePrevious = tbPreviousQualifierValue.Text;
                }
            }
            else
            {
                // use the regular qualifier and clear the previous value qualifier since it does not apply.
                workflowTrigger.EntityTypeQualifierValue         = tbQualifierValue.Text;
                workflowTrigger.EntityTypeQualifierValuePrevious = string.Empty;
            }

            workflowTrigger.IsActive = cbIsActive.Checked;
            if (string.IsNullOrWhiteSpace(tbWorkflowName.Text))
            {
                workflowTrigger.WorkflowName = null;
            }
            else
            {
                workflowTrigger.WorkflowName = tbWorkflowName.Text;
            }

            if (!workflowTrigger.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            WorkflowTriggersCache.Remove();

            NavigateToParentPage();
        }
        /// <summary>
        /// Shows the edit.
        /// </summary>
        /// <param name="workflowTriggerId">The workflow trigger identifier.</param>
        public void ShowDetail(int workflowTriggerId)
        {
            pnlDetails.Visible = true;
            WorkflowTrigger workflowTrigger = null;

            if (!workflowTriggerId.Equals(0))
            {
                workflowTrigger   = new WorkflowTriggerService(new RockContext()).Get(workflowTriggerId);
                lActionTitle.Text = ActionTitle.Edit(WorkflowTrigger.FriendlyTypeName).FormatAsHtmlTitle();
            }

            if (workflowTrigger == null)
            {
                workflowTrigger = new WorkflowTrigger {
                    Id = 0, WorkflowTriggerType = WorkflowTriggerType.PostSave, IsActive = true
                };
                lActionTitle.Text = ActionTitle.Add(WorkflowTrigger.FriendlyTypeName).FormatAsHtmlTitle();
            }

            LoadDropDowns();

            hfWorkflowTriggerId.Value = workflowTrigger.Id.ToString();
            ddlEntityType.SetValue(workflowTrigger.EntityTypeId);
            LoadColumnNames();
            ddlQualifierColumn.SetValue(workflowTrigger.EntityTypeQualifierColumn);
            ShowQualifierValues(workflowTrigger);
            ddlWorkflowType.SetValue(workflowTrigger.WorkflowTypeId);
            rblTriggerType.SelectedValue = workflowTrigger.WorkflowTriggerType.ConvertToInt().ToString();
            tbWorkflowName.Text          = workflowTrigger.WorkflowName ?? string.Empty;
            cbIsActive.Checked           = workflowTrigger.IsActive ?? false;

            // render UI based on Authorized and IsSystem
            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!IsUserAuthorized(Authorization.EDIT))
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(WorkflowTrigger.FriendlyTypeName);
            }

            if (workflowTrigger.IsSystem)
            {
                readOnly = true;
                nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(WorkflowTrigger.FriendlyTypeName);
            }

            if (readOnly)
            {
                lActionTitle.Text = ActionTitle.View(WorkflowTrigger.FriendlyTypeName);
                btnCancel.Text    = "Close";
            }

            ddlEntityType.Enabled      = !readOnly;
            ddlQualifierColumn.Enabled = !readOnly;
            tbQualifierValue.ReadOnly  = readOnly;
            ddlWorkflowType.Enabled    = !readOnly;
            rblTriggerType.Enabled     = !readOnly;
            tbWorkflowName.ReadOnly    = readOnly;
            cbIsActive.Enabled         = !readOnly;

            btnSave.Visible = !readOnly;
        }
 public WorkflowState Fire(WorkflowTrigger trigger)
 {
     throw new System.NotImplementedException();
 }
Exemple #25
0
        /// <summary>
        /// Determines whether the entity matches the current and/or previous qualifier values.
        /// If
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="trigger">The trigger.</param>
        /// <returns>true if matches; false otherwise</returns>
        private static bool IsQualifierMatch(ContextItem item, Dictionary <string, PropertyInfo> properties, WorkflowTrigger trigger)
        {
            bool match = false;

            try
            {
                var dbEntity = item.DbEntityEntry;

                // Now attempt to find a match taking into account the EntityTypeQualifierValue and/or EntityTypeQualifierValuePrevious
                if (properties.ContainsKey(trigger.EntityTypeQualifierColumn.ToLower()))
                {
                    var propertyInfo = properties[trigger.EntityTypeQualifierColumn.ToLower()];

                    bool hasPrevious = !string.IsNullOrEmpty(trigger.EntityTypeQualifierValuePrevious);
                    bool hasCurrent  = !string.IsNullOrEmpty(trigger.EntityTypeQualifierValue);

                    var currentProperty = propertyInfo.GetValue(item.Entity, null);
                    var currentValue    = currentProperty != null?currentProperty.ToString() : string.Empty;

                    var previousValue = string.Empty;

                    if (item.OriginalValues != null && item.OriginalValues.ContainsKey(propertyInfo.Name))
                    {
                        previousValue = item.OriginalValues[propertyInfo.Name].ToStringSafe();
                    }
                    else
                    {
                        var dbPropertyEntry = dbEntity.Property(propertyInfo.Name);
                        if (dbPropertyEntry != null)
                        {
                            previousValue = item.PreSaveState == EntityState.Added ? string.Empty : dbPropertyEntry.OriginalValue.ToStringSafe();
                        }
                    }

                    if (trigger.WorkflowTriggerType == WorkflowTriggerType.PreDelete ||
                        trigger.WorkflowTriggerType == WorkflowTriggerType.PostDelete)
                    {
                        match = (previousValue == trigger.EntityTypeQualifierValue);
                    }

                    if (trigger.WorkflowTriggerType == WorkflowTriggerType.PostAdd)
                    {
                        match = (currentValue == trigger.EntityTypeQualifierValue);
                    }

                    if (trigger.WorkflowTriggerType == WorkflowTriggerType.ImmediatePostSave ||
                        trigger.WorkflowTriggerType == WorkflowTriggerType.PostSave ||
                        trigger.WorkflowTriggerType == WorkflowTriggerType.PreSave)
                    {
                        if (trigger.WorkflowTriggerValueChangeType == WorkflowTriggerValueChangeType.ValueEqual)
                        {
                            match = trigger.EntityTypeQualifierValue == currentValue;
                        }
                        else
                        {
                            if (hasCurrent && !hasPrevious)
                            {
                                // ...and previous cannot be the same as the current (must be a change)
                                match = (currentValue == trigger.EntityTypeQualifierValue &&
                                         currentValue != previousValue);
                            }
                            else if (!hasCurrent && hasPrevious)
                            {
                                // ...and previous cannot be the same as the current (must be a change)
                                match = (previousValue == trigger.EntityTypeQualifierValuePrevious &&
                                         previousValue != currentValue);
                            }
                            else if (hasCurrent && hasPrevious)
                            {
                                match = (currentValue == trigger.EntityTypeQualifierValue &&
                                         previousValue == trigger.EntityTypeQualifierValuePrevious);
                            }
                            else if (!hasCurrent && !hasPrevious)
                            {
                                match = previousValue != currentValue;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }

            return(match);
        }
Exemple #26
0
 public void ChangeTo(WorkflowTrigger trigger)
 {
     _stateMachine.Fire(trigger);
 }
Exemple #27
0
        /// <summary>
        /// Determines whether the entity matches the current and/or previous qualifier values.
        /// If
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="trigger">The trigger.</param>
        /// <returns>true if matches; false otherwise</returns>
        private static bool IsQualifierMatch(ContextItem item, Dictionary <string, PropertyInfo> properties, WorkflowTrigger trigger)
        {
            bool match    = false;
            var  dbEntity = item.DbEntityEntry;

            // Now attempt to find a match taking into account the EntityTypeQualifierValue and/or EntityTypeQualifierValuePrevious
            if (properties.ContainsKey(trigger.EntityTypeQualifierColumn.ToLower()))
            {
                var propertyInfo = properties[trigger.EntityTypeQualifierColumn.ToLower()];

                bool hasPrevious = !string.IsNullOrEmpty(trigger.EntityTypeQualifierValuePrevious);
                bool hasCurrent  = !string.IsNullOrEmpty(trigger.EntityTypeQualifierValue);

                // it's apparently not possible to interrogate the dbEntity of virtual properties
                // so it's illegal if they somehow selected one of these; and it's not a match.
                if (propertyInfo.GetGetMethod().IsVirtual)
                {
                    // TODO: log a silent exception?
                    return(false);
                }

                var currentProperty = propertyInfo.GetValue(item.Entity, null);
                var currentValue    = currentProperty != null?currentProperty.ToString() : string.Empty;

                var previousValue = string.Empty;

                var dbPropertyEntry = dbEntity.Property(propertyInfo.Name);
                if (dbPropertyEntry != null)
                {
                    previousValue = dbEntity.State == EntityState.Added ? string.Empty : dbPropertyEntry.OriginalValue.ToStringSafe();
                }

                if (trigger.WorkflowTriggerType == WorkflowTriggerType.PreDelete ||
                    trigger.WorkflowTriggerType == WorkflowTriggerType.PostDelete)
                {
                    match = (previousValue == trigger.EntityTypeQualifierValue);
                }

                if (trigger.WorkflowTriggerType == WorkflowTriggerType.ImmediatePostSave ||
                    trigger.WorkflowTriggerType == WorkflowTriggerType.PostSave)
                {
                    match = (currentValue == trigger.EntityTypeQualifierValue);
                }

                if (trigger.WorkflowTriggerType == WorkflowTriggerType.PreSave)
                {
                    if (hasCurrent && !hasPrevious)
                    {
                        // ...and previous cannot be the same as the current (must be a change)
                        match = (currentValue == trigger.EntityTypeQualifierValue &&
                                 currentValue != previousValue);
                    }
                    else if (!hasCurrent && hasPrevious)
                    {
                        // ...and previous cannot be the same as the current (must be a change)
                        match = (previousValue == trigger.EntityTypeQualifierValuePrevious &&
                                 previousValue != currentValue);
                    }
                    else if (hasCurrent && hasPrevious)
                    {
                        match = (currentValue == trigger.EntityTypeQualifierValue &&
                                 previousValue == trigger.EntityTypeQualifierValuePrevious);
                    }
                    else if (!hasCurrent && !hasPrevious)
                    {
                        // If they used an entity type qualifier column, at least one qualifier value is required.
                        // TODO: log as silent exception?
                    }
                }
            }
            return(match);
        }
Exemple #28
0
 /// <summary>
 /// fires the requested trigger
 /// </summary>
 /// <param name="workflowTrigger">trigger to run</param>
 public void Fire(WorkflowTrigger workflowTrigger)
 {
     _stateMachine.Fire(workflowTrigger);
 }
        /// <summary>
        /// Handles the Click event of the btnSave 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 btnSave_Click( object sender, EventArgs e )
        {
            WorkflowTrigger WorkflowTrigger;
            var rockContext = new RockContext();
            WorkflowTriggerService WorkflowTriggerService = new WorkflowTriggerService( rockContext );
            AttributeService attributeService = new AttributeService( rockContext );

            int WorkflowTriggerId = int.Parse( hfWorkflowTriggerId.Value );

            if ( WorkflowTriggerId == 0 )
            {
                WorkflowTrigger = new WorkflowTrigger();
                WorkflowTriggerService.Add( WorkflowTrigger );
            }
            else
            {
                WorkflowTrigger = WorkflowTriggerService.Get( WorkflowTriggerId );
            }

            WorkflowTrigger.EntityTypeId = ddlEntityType.SelectedValueAsInt().Value;
            WorkflowTrigger.EntityTypeQualifierColumn = ddlQualifierColumn.SelectedValue;
            WorkflowTrigger.EntityTypeQualifierValue = tbQualifierValue.Text;
            WorkflowTrigger.WorkflowTypeId = ddlWorkflowType.SelectedValueAsInt().Value;
            WorkflowTrigger.WorkflowTriggerType = (WorkflowTriggerType)System.Enum.Parse( typeof( WorkflowTriggerType ), rblTriggerType.SelectedValue );
            WorkflowTrigger.IsActive = cbIsActive.Checked;
            if ( string.IsNullOrWhiteSpace( tbWorkflowName.Text ) )
            {
                WorkflowTrigger.WorkflowName = null;
            }
            else
            {
                WorkflowTrigger.WorkflowName = tbWorkflowName.Text;
            }

            if ( !WorkflowTrigger.IsValid )
            {
                // Controls will render the error messages                    
                return;
            }

            rockContext.SaveChanges();

            Rock.Workflow.TriggerCache.Refresh();

            NavigateToParentPage();
        }
 public bool CanFire(WorkflowTrigger trigger)
 {
     return false;
 }