private static ReportCondition ReportConditionFromRule(ReportConditionalFormatRule rule, ReportColumn column) { ReportCondition reportCondition = new ReportCondition(); if (rule.Operator.HasValue && rule.Operator != ConditionType.Unspecified) { string alias = "oper" + rule.Operator.ToString(); reportCondition.Operator = Entity.Get <OperatorEnum>(new EntityRef(alias)); } Parameter parameter = reportCondition.ConditionParameter != null?reportCondition.ConditionParameter.AsWritable <Parameter>() : new Parameter(); // Clear the old parameter if (parameter.ParamTypeAndDefault != null) { parameter.ParamTypeAndDefault.AsWritable().Delete(); } // Force entity resource list for argument if we have entities ActivityArgument activityArgument = null; if (rule.Values != null && rule.Values.Count > 0) { ResourceListArgument resourceList = new ResourceListArgument(); foreach (KeyValuePair <long, string> valuePair in rule.Values) { Resource resource = Entity.Get <Resource>(valuePair.Key); if (resource != null) { resourceList.ResourceListParameterValues.Add(resource); } } TypedArgument argumentType = column.ColumnExpression.ReportExpressionResultType.As <TypedArgument>(); resourceList.ConformsToType = argumentType.ConformsToType; activityArgument = resourceList.As <ActivityArgument>(); activityArgument.Save(); } else if (rule.Operator.HasValue) { int operatorCount = ConditionTypeHelper.GetArgumentCount(rule.Operator.Value); if (operatorCount > 0) { activityArgument = ReportConditionHelper.ArgumentForConditionType(column.ColumnExpression.ReportExpressionResultType, rule.Operator.Value, rule.Value); activityArgument.Save(); } } parameter.ParamTypeAndDefault = activityArgument; parameter.Save(); reportCondition.ConditionParameter = parameter; return(reportCondition); }
public void TestLoopOverNoResultsUsingUnsetListVar() { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var wf = new Workflow(); wf.AddDefaultExitPoint(); var loopList = new ResourceListArgument() { Name = "loopList" }; ActivityTestHelper.AddVariableToWorkflow(wf, loopList.As <ActivityArgument>()); //ActivityHelper.AddExpressionToWorkflowVariable(wf, "list", "0"); var forEach1 = new ForEachResource { Name = "foreach1" + DateTime.Now }; var forEach1As = forEach1.As <WfActivity>(); ActivityTestHelper.AddExpressionToActivityArgument(wf, forEach1As, "List", "loopList"); // there shouldn't be any wf.FirstActivity = forEach1As; wf.ContainedActivities.Add(forEach1As); var loopExitPoint = Entity.Get <ExitPoint>(ForeachImplementation.LoopExitPointAlias); ActivityTestHelper.AddTransition(wf, forEach1As, forEach1As, loopExitPoint); ActivityTestHelper.AddTermination(wf, forEach1As); wf.Save(); ToDelete.Add(wf.Id); var run = (RunWorkflow(wf)); IDictionary <string, object> outputs = run.GetOutput(); } }
public void SimpleCountingLoop( ) { using (new WorkflowRunContext { RunTriggersInCurrentThread = true }) { var wf = new Workflow() { Name = "Simple Counting " + DateTime.Now }; wf.AddDefaultExitPoint(); var input = new ResourceListArgument { Name = "in" }; wf.InputArguments.Add(input.As <ActivityArgument>()); var output = new IntegerArgument { Name = "out" }; wf.OutputArguments.Add(output.As <ActivityArgument>()); var employeeType = Entity.Get <EntityType>(new EntityRef("test", "employee")); wf.AddVariable <IntegerArgument>("Count") .AddAssignToVar("Assign To Count", "0", "Count") .AddForEach("foreach1", "in", "test:employee") .AddAssignToVar("Assign To Count 2", "[Count] + 1", "Count", "foreach1", "Loop") .AddTransition("Assign To Count 2", "foreach1"); ActivityTestHelper.AddAssignToVar(wf, "AssignOutput", "Count", "out"); ActivityTestHelper.AddMissingExpressionParametersToWorkflow(wf); wf.Save(); var createdCount = 15; var resources = Enumerable.Range(0, createdCount).Select(v => new Person() { Name = v.ToString() }).ToList(); Entity.Save(resources); var wfInput = new Dictionary <string, object> { { "in", resources } }; var run = (RunWorkflow(wf, wfInput)); IDictionary <string, object> outputs = run.GetOutput(); Assert.AreEqual(1, outputs.Count, "There is one output argument"); var result = (int)outputs["out"]; Assert.AreEqual(createdCount, result, "The loop ran the correct number of times"); } }
/// <summary>Given an arg inst and a value create and activityArgument ready for storage.</summary> /// <param name="activity">The <see cref="WfActivity"/> being run. This cannot be null.</param> /// <param name="arg">The argument for the activity. This cannot be null.</param> /// <param name="value">The value of the argument. Its type is determined by <paramref name="arg"/>. This may be null for certain argument types.</param> /// <returns>The converted value.</returns> /// <exception cref="ArgumentNullException">Neither <paramref name="activity"/> nor <paramref name="arg"/> can be null.</exception> /// <exception cref="ArgumentException"><paramref name="arg"/> must be of a supported type.</exception> public static ActivityArgument ConvertArgInstValue(WfActivity activity, ActivityArgument arg, object value) { if (activity == null) { throw new ArgumentNullException(nameof(activity)); } if (arg == null) { throw new ArgumentNullException(nameof(arg)); } ActivityArgument result; string name = $"{activity.Name ?? "[Unnamed]"}.{arg.Name ?? "[Unnamed]"}"; if (arg.Is <ResourceListArgument>()) { var list = (IEnumerable <IEntity>)value; var created = new ResourceListArgument { Name = name }; if (list != null) { var cleanList = list.Where(e => e != null).Select(e => e.As <Resource>()); created.ResourceListParameterValues.AddRange(cleanList); } result = created.As <ActivityArgument>(); } else if (arg.Is <ResourceArgument>()) { var res = (IEntity)value; var created = new ResourceArgument { Name = name, ResourceParameterValue = res?.As <Resource>() }; result = created.As <ActivityArgument>(); } else if (arg.Is <StringArgument>()) { var created = new StringArgument { Name = name, StringParameterValue = (string)value }; result = created.As <ActivityArgument>(); } else if (arg.Is <BoolArgument>()) { var created = new BoolArgument { Name = name, BoolParameterValue = (bool?)value ?? false }; result = created.As <ActivityArgument>(); } else if (arg.Is <IntegerArgument>()) { var created = new IntegerArgument { Name = name, IntParameterValue = (int?)value ?? 0 }; result = created.As <ActivityArgument>(); } else if (arg.Is <DecimalArgument>()) { var created = new DecimalArgument { Name = name, DecimalParameterValue = (decimal?)value ?? 0 }; result = created.As <ActivityArgument>(); } else if (arg.Is <CurrencyArgument>()) { var created = new CurrencyArgument { Name = name, DecimalParameterValue = (decimal?)value ?? 0 }; result = created.As <ActivityArgument>(); } else if (arg.Is <DateTimeArgument>()) { var created = new DateTimeArgument { Name = name, DateTimeParameterValue = (DateTime?)value }; result = created.As <ActivityArgument>(); } else if (arg.Is <DateArgument>()) { var created = new DateArgument { Name = name, DateParameterValue = (DateTime?)value }; result = created.As <ActivityArgument>(); } else if (arg.Is <TimeArgument>()) { // ensure that timeparametervalue only ever holds a datetime var dt = value is TimeSpan?TimeType.NewTime((TimeSpan)value) : (DateTime?)value; var created = new TimeArgument { Name = name, TimeParameterValue = dt }; result = created.As <ActivityArgument>(); } else if (arg.Is <GuidArgument>()) { var created = new GuidArgument { Name = name, GuidParameterValue = (Guid?)value ?? Guid.Empty }; result = created.As <ActivityArgument>(); } else { throw new ArgumentException($"Unsupported ActivityArgument '{arg.IsOfType.First().Name}' in '{name}'", "arg"); } return(result); }