Esempio n. 1
0
        public ActivityResult ProcessWorkFlow(FuzeActivity container, FuzeActivity currentActivity, ActivityInput input)
        {
            Contracts.ActivityResult activityResult = null;
            container.CurrentActivityID = currentActivity.ActivityID;

            // map all input to the activity for activity execution.
            SetInputMappingsFromWorkFlow(container, currentActivity);

            // execute the workflow
            currentActivity.Execute();

            // map if the item has any output mappings.
            SetOutputMappingsToWorkFlow(container, currentActivity);

            // check the activity type
            if (currentActivity.ActivityType == "FORM")
            {
                // map all output to the activity result.
                activityResult = new ActivityResult();
                activityResult.Results = new Dictionary<string, object>();
              //  activityResult.Results.Add("FormResult", currentActivity.GetType().GetProperty("ActivityResult").GetValue(currentActivity, null));
                MapOutPutMappingToActivityResult(container, currentActivity, activityResult);
                activityResult.ValidationResults = currentActivity.ValidationErros.ToDictionary(c => c.ValidationKey, x => x.ValidationResult);

                // check for persistance
                PersistActivity(container, input);
                activityResult.WorkflowInstanceID = input.WorkflowInstanceID;
                if (currentActivity.OutComes == null || currentActivity.OutComes.Count() == 0)
                {
                    RemoveActivityInstance(input.WorkflowInstanceID);
                }

                return activityResult;
            }
            else if (currentActivity.ActivityType == "CUSTOM")
            {
                if (currentActivity.OutComes == null || currentActivity.OutComes.Count() == 0)
                {
                    RemoveActivityInstance(input.WorkflowInstanceID);
                    return activityResult;
                }

                container.NextActivityID = currentActivity.OutComes.First().Activity.ActivityID;
                return ProcessWorkFlow(container, currentActivity.OutComes.First().Activity, input);
            }
            return activityResult;
        }
Esempio n. 2
0
 private void SetOutputMappingsToWorkFlow(FuzeActivity container, FuzeActivity currentActivity)
 {
     if (currentActivity.OutputMappings != null)
     {
         foreach (Mapping mapping in currentActivity.OutputMappings)
         {
             PropertyInfo propertyInfo = container.GetType().GetProperty(mapping.MappingArgument);
             propertyInfo.SetValue(container, Convert.ChangeType(currentActivity.GetType().GetProperty(mapping.InputArgument).GetValue(currentActivity, null), propertyInfo.PropertyType), null);
         }
     }
 }
Esempio n. 3
0
        private void MapOutPutMappingToActivityResult(FuzeActivity container, FuzeActivity currentActivity, Contracts.ActivityResult activityResult)
        {
            if (currentActivity.OutputMappings != null)
            {
                foreach (Mapping mapping in currentActivity.OutputMappings)
                {

                    PropertyInfo propertyInfo = container.GetType().GetProperty(mapping.MappingArgument);
                    activityResult.Results.Add(mapping.MappingArgument, propertyInfo.GetValue(container));

                }
            }
        }
Esempio n. 4
0
        private void PersistActivity(FuzeActivity container, ActivityInput input)
        {
            bool isUpdate = false;
            if (input.WorkflowInstanceID == Guid.Empty)
            {
                input.WorkflowInstanceID = Guid.NewGuid();
            }
            else
            {
                isUpdate = true;
            }
            StringBuilder instanceXaml = new StringBuilder();
            using (StringWriter writer = new StringWriter(instanceXaml))
            {
                XamlServices.Save(writer, container);
            }

            var workflowInstance = new FuzeWorkflowInstance()
            {
                WorkflowInstanceID = input.WorkflowInstanceID,
                WorkFlow = instanceXaml.ToString()
            };

            if (isUpdate)
            {
                RemoveActivityInstance(workflowInstance.WorkflowInstanceID);
            }

            dbContext.FuzeWorkflowInstances.Add(workflowInstance);
            dbContext.SaveChanges();
        }
Esempio n. 5
0
        private void MapInputParameters(Contracts.ActivityInput input, FuzeActivity activity)
        {
            if (input.Inputs != null)
            {
                // get all input properties of the workflow.
                var properties = activity.GetType().GetProperties()
                                 .Where(prop => prop.IsDefined(typeof(InputAttribute), false));

                foreach (var property in properties)
                {
                    if (input.Inputs[property.Name] != null)
                    {
                        property.SetValue(activity, Convert.ChangeType(input.Inputs[property.Name], property.PropertyType), null);
                    }
                }

            }
        }