Esempio n. 1
0
        private void ValidateTransitions(WorkflowMetadata metadata)
        {
            using (Profiler.Measure("WorkflowImplementation.ValidateTransitions"))
            {
                foreach (var tran in metadata.AllTransitions)
                {
                    if (tran.FromActivity == null || tran.FromExitPoint == null || tran.ToActivity == null)
                    {
                        metadata.AddValidationError(
                            string.Format("Workflow '{0}' does not have one of its transitions ({1}) fully described. It must have a from activity and exit point and a destination. "
                                          + "From {2} {3} to {4}",
                                          ActivityInstance.Name, tran.Id,
                                          tran.FromActivity != null ? tran.FromActivity.Name ?? tran.FromActivity.Id.ToString() : "null",
                                          tran.FromExitPoint != null ? tran.FromExitPoint.Name ?? tran.FromExitPoint.Id.ToString() : "null",
                                          tran.ToActivity != null ? tran.ToActivity.Name ?? tran.FromActivity.Id.ToString() : "null"
                                          ));
                    }

                    // validate that all transitions point to children of the workflow
                    if (tran.ToActivity != null && (tran.ToActivity.ContainingWorkflow == null || tran.ToActivity.ContainingWorkflow.Id != _activityInstanceAsWf.Id))
                    {
                        metadata.AddValidationError(string.Format("Activity '{0}' is not a child of the workflow but is part of a transition", tran.FromActivity.Name));
                    }
                }
            }
        }
        /// <summary>
        /// Validate the activity, adding any validation errors to the metadata
        /// </summary>
        /// <param name="metadata"></param>
        public virtual void Validate(WorkflowMetadata metadata)
        {
            using (Profiler.Measure("ActivityImplementationBase.Validate"))
            {
                var manditoryArgs = ActivityInstance.GetInputArguments().Where(arg => arg.ArgumentIsMandatory ?? false);

                // we can't validate inputs unless we are part of a workflow
                if (ActivityInstance.ContainingWorkflow == null)
                {
                    return;
                }

                foreach (var manditoryArg in manditoryArgs)
                {
                    var expression = metadata.GetPopulatedBy(ActivityInstance, manditoryArg);

                    if (expression == null)
                    {
                        metadata.AddValidationError(
                            string.Format(
                                "Mandatory arguments must be given a value. Activity: '{0}'  Argument: '{1}'",
                                ActivityInstance.Name, manditoryArg.Name));
                    }
                }
            }
        }
Esempio n. 3
0
        public override void Validate(WorkflowMetadata metadata)
        {
            base.Validate(metadata);

            var activityAs = ActivityInstance.Cast <AssignToVariable>();

            if (activityAs.TargetVariable == null)
            {
                metadata.AddValidationError(string.Format("Variable has not been assigned. Activity: '{0}'", activityAs.Name));
            }
        }
        /// <summary>
        /// Validate that the reply workflow is marked as RunAsOwner.
        /// </summary>
        /// <param name="metadata"></param>
        public override void Validate(WorkflowMetadata metadata)
        {
            base.Validate(metadata);

            var activityAs = ActivityInstance.Cast <NotifyActivity>();

            foreach (var entry in activityAs.NReplyMap)
            {
                if (String.IsNullOrWhiteSpace(entry.Name))
                {
                    metadata.AddValidationError($"An all entries in the reply mapping must contain a value: '{activityAs.Name}'");
                }
                else if (entry.RmeWorkflow == null)
                {
                    metadata.AddValidationError($"Mapping entry '{entry.Name}' does not point to a workflow: '{activityAs.Name}'");
                }
                else if (entry.RmeWorkflow.WorkflowRunAsOwner != true)
                {
                    metadata.AddValidationError($"Mapping entry '{entry.Name}' points to a workflow that is not set to 'Run as owner': '{activityAs.Name}'");
                }
            }
        }
Esempio n. 5
0
        private void ValidateTransitions2(WorkflowMetadata metadata)
        {
            using (Profiler.Measure("WorkflowImplementation.ValidateTransitions2"))
            {
                //
                // Validate that all the transitions from the activities are in the Transitions list
                var comparer = new EntityIdComparer();

                var wfTransAndTerms = ((IEnumerable <IEntity>)_activityInstanceAsWf.Transitions).Union((IEnumerable <IEntity>)_activityInstanceAsWf.Terminations).ToList();

                using (Profiler.Measure("WorkflowImplementation.ValidateTransitions2.1"))
                {
                    foreach (var activity in _activityInstanceAsWf.ContainedActivities)
                    {
                        // validate that all the transitions are on the workflow

                        var missing = activity.ForwardTransitions.Except(wfTransAndTerms, comparer);

                        if (missing.Any())
                        {
                            metadata.AddValidationError(string.Format("Activity \"{0}\" has a transition that is not listed against the workflow.", activity.Name ?? "(Unnamed)"));
                        }


                        // validate that the transitions have a from exit point on the activity or its type
                        var exitPoints = metadata.GetExitpointsForActivity(activity.Id);
                        foreach (var tran in activity.ForwardTransitions)
                        {
                            if (!exitPoints.Contains(tran.FromExitPoint, comparer))
                            {
                                metadata.AddValidationError(
                                    string.Format("Activity \"{0}\" has a transition whose exit point is not from the origin activity.", activity.Name ?? "(Unnamed)"));
                            }
                        }
                    }
                }
            }
        }
        public override void Validate(WorkflowMetadata metadata)
        {
            base.Validate(metadata);

            var workflowToProxy = ActivityInstance.As <WorkflowProxy>().WorkflowToProxy;

            if (workflowToProxy == null)
            {
                metadata.AddValidationError("Workflow to run has not been set.");
            }

            //
            // The proxy workflow will be validated separately
            //
        }
Esempio n. 7
0
        private void ValidateWorkflowVariables(WorkflowMetadata metadata)
        {
            using (Profiler.Measure("WorkflowImplementation.ValidateWorkflowVariables"))
            {
                // Validate workflow variables
                var inputArgumentsNames = _activityInstanceAsWf.InputArguments.Select(arg => arg.Name);

                foreach (var wfVar in _activityInstanceAsWf.Variables)
                {
                    if (inputArgumentsNames.Contains(wfVar.Name))
                    {
                        metadata.AddValidationError(string.Format("Name of variable '{0}' clashed with the input argument of the same name.", wfVar.Name));
                    }
                }
            }
        }
Esempio n. 8
0
        public override void Validate(WorkflowMetadata metadata)
        {
            base.Validate(metadata);

            var activityInstanceAs = ActivityInstance.Cast <ForEachResource>();

            var terminationsCount =
                activityInstanceAs.ContainingWorkflow.Terminations.Count(t => t.FromActivity.Id == activityInstanceAs.Id);

            var transitionsCount = activityInstanceAs.ContainingWorkflow.Transitions.Count(t => t.FromActivity.Id == activityInstanceAs.Id);

            if (transitionsCount + terminationsCount != 2)
            {
                metadata.AddValidationError(string.Format("Every 'For Each' activity must have a Loop and a Finish transition. Activity: '{0}'", activityInstanceAs.Name));
            }
        }
Esempio n. 9
0
 private void ValidateTerminations(WorkflowMetadata metadata)
 {
     using (Profiler.Measure("WorkflowImplementation.ValidateTerminations"))
     {
         foreach (var term in _activityInstanceAsWf.Terminations)
         {
             if (term.FromActivity == null || term.FromExitPoint == null || term.WorkflowExitPoint == null)
             {
                 metadata.AddValidationError(
                     string.Format(
                         "Workflow '{0}' does not have one of its terminations fully described. It must have a from activity and exit point and a workflow exit point. From '{1}':'{2}'  To:'{3}'",
                         ActivityInstance.Name,
                         term.FromActivity != null ? term.FromActivity.Name ?? "Unnamed activity" : "Activity not specified",
                         term.FromExitPoint != null ? term.FromExitPoint.Name ?? "Unnamed exit" : "Exit not specified",
                         term.WorkflowExitPoint != null ? term.WorkflowExitPoint.Name ?? "Unnamed workflow exit" : "Exit not specified"));
             }
         }
     }
 }
Esempio n. 10
0
        public override void Validate(WorkflowMetadata metadata)
        {
            using (Profiler.Measure("WorkflowImplementation.Validate"))
            {
                using (new SecurityBypassContext())
                {
                    base.Validate(metadata);

                    // validate first activity
                    if (_activityInstanceAsWf.FirstActivity == null)
                    {
                        metadata.AddValidationError("First Activity is missing.");
                    }

                    // ensure that all workflow variables are also in the expression parameters
                    foreach (var v in _activityInstanceAsWf.Variables)
                    {
                        if (_activityInstanceAsWf.ExpressionParameters.All(p => p.ArgumentInstanceArgument.Id != v.Id))
                        {
                            metadata.AddValidationError(string.Format("Variable '{0}' is missing from the expression parameter list.", v.Name));
                        }
                    }

                    // ensure the name, activity and argument are defined for the expression parameters
                    foreach (var param in _activityInstanceAsWf.ExpressionParameters)
                    {
                        if (param.Name == null)
                        {
                            metadata.AddValidationError(string.Format("Parameter '{0}' is missing a name.", param.Id));
                        }

                        if (param.ArgumentInstanceActivity == null || param.ArgumentInstanceArgument == null)
                        {
                            metadata.AddValidationError(string.Format("Parameter '{0}' is missing source information, must have both activity and argument defined.", param.Name));
                        }
                    }

                    ValidateExpressions(metadata);

                    ValidateWorkflowVariables(metadata);
                    ValidateTransitions(metadata);
                    ValidateTerminations(metadata);

                    ValidateTransitions2(metadata);


                    //
                    // validate first activity
                    //
                    if (_activityInstanceAsWf.FirstActivity == null)
                    {
                        metadata.AddValidationError("The workflow has no first activity.");
                    }

                    //
                    // Validate all the contained activities
                    foreach (var activityInstance in metadata.CachedInstances.Values)
                    {
                        if (activityInstance != this)
                        {
                            activityInstance.Validate(metadata);
                        }
                    }

                    //
                    // Ensure that all activities have unique names. (This ensures that activity outputs cannot have name clashes.)
                    var allNames   = _activityInstanceAsWf.ContainedActivities.Select(a => a.Name);
                    var duplicates = allNames.GroupBy(s => s).SelectMany(grp => grp.Skip(1));

                    if (duplicates.Count() > 0)
                    {
                        metadata.AddValidationError(string.Format("All activities in a workflow must have a unique name: {0}", string.Join(", ", duplicates)));
                    }
                }
            }
        }