public IDictionary <string, object> Execute(Job job, WorkerData data) { IDictionary <string, object> outArgs = null; Dictionary <string, object> inArgs = new Dictionary <string, object>(); try { if ((this.RuleSetType == RuleSetTypes.PreValidate) || (this.RuleSetType == RuleSetTypes.PostValidate)) { job.ThrowErrorIfNull(this.Activity.DisplayName); inArgs.Add("Job", job); } else { data.ThrowErrorIfNull(this.Activity.DisplayName); inArgs.Add("Data", data); } if (this.Activity != null) { Trace.TraceInformation("Executing business a '{0}' type rule '{1}'", this.RuleSetType.ToString(), this.Activity.Name); WorkflowInvoker invoker = new WorkflowInvoker(this.Activity); outArgs = invoker.Invoke(inArgs); //outArgs = WorkflowInvoker.Invoke(this.Activity, inArgs); } } catch (BusinessException ex) { Trace.TraceInformation(ex.Message); //It is actually not an exception or error new PostMan(job, false).Send(PostMan.__warningStartTag + ex.Message + PostMan.__warningEndTag); } catch (Exception ex) { Trace.TraceError("There was an error occurred while executing business rule! Job = '{0}', Rule Name = '{1}' Rule Type = '{2}'. {3}{4}", job.JobIdentifier, this.Activity.Name, this.RuleSetType, Environment.NewLine, ex.ToString()); Trace.Flush(); throw ex; } return(outArgs); }
protected override void Execute(CodeActivityContext context) { //Even though concurrent dictionary is threadsafe, our threads are not executing in synchronized //hence in this case a lock is needed //this is not 100% thread safe, do not use for aggregate, use post-validate rules instead lock (_lock) { Job job = context.GetValue(this.Job); if (job == null) { WorkerData data = context.GetValue(this.Data); data.ThrowErrorIfNull(this.DisplayName); job = data.Job; } string key = context.GetValue(this.Key); object value = context.GetValue(this.Value); job.ContainerData.AddOrUpdate(key, value, (keyx, oldValue) => value); Trace.TraceInformation("Container data modified : Key='{0}', Value='{1}'", key, value.ToString()); } }