/// <summary>
        /// Execute bundle rules
        /// </summary>
        public Object ExecuteBundleRules(String trigger, Object bundle)
        {
            try
            {
                IDictionary <String, Object> bdl = bundle as IDictionary <String, Object>;

                object rawItems = null;
                if (!bdl.TryGetValue("resource", out rawItems))
                {
                    this.m_tracer.TraceVerbose("Bundle contains no items: {0}", JavascriptUtils.ProduceLiteral(bdl));
                    return(bundle);
                }

                Object[] itms = rawItems as object[];

                for (int i = 0; i < itms.Length; i++)
                {
                    try
                    {
                        itms[i] = this.m_owner.InvokeRaw(trigger, itms[i]);
                    }
                    catch (Exception)
                    {
                        //if (System.Diagnostics.Debugger.IsAttached)
                        throw;
                        //else
                        //    Tracer.GetTracer(typeof(BusinessRulesBridge)).TraceError("Error applying rule for {0}: {1}", itms[i], e);
                    }
                }

                //bdl.Add("resource", itms);
                return(bdl);
            }
            catch (Exception e)
            {
                this.m_tracer.TraceError("Error executing bundle rules: {0}", e);
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invoke raw
        /// </summary>
        public object InvokeRaw(String triggerName, Object data)
        {
            lock (this.m_lock) // Only one object can use this thread at a time
            {
                var sdata = data as IDictionary <String, Object>;
                if (sdata == null || !sdata.ContainsKey("$type"))
                {
                    return(data);
                }
                var callList = this.GetCallList(this.m_binder.BindToType("SanteDB.Core.Model, Version=1.1.0.0", sdata["$type"].ToString()), triggerName);
                var retVal   = data;

                if (callList.Any())
                {
                    foreach (var c in callList)
                    {
                        try
                        {
                            if (c.Guard == null || this.GuardEval(c.Guard, sdata))
                            {
                                data = c.Callback.DynamicInvoke(data);
                            }
                        }
                        catch (JavaScriptException e)
                        {
                            this.m_tracer.TraceError("JAVASCRIPT ERROR RUNNING {0} OBJECT :::::> {3}@{2}\r\n{1}", triggerName, JavascriptUtils.ProduceLiteral(data), e.LineNumber, e);
                            throw new DetectedIssueException(new List <DetectedIssue>()
                            {
                                new DetectedIssue()
                                {
                                    Priority = DetectedIssuePriorityType.Error,
                                    Text     = $"Error executing {triggerName} (rule id: {c.Id}) {e.Error.ToString()} @ {e.Location.Start.Line} - {e.Location.End.Line}"
                                }
                            });
                        }
                        catch (Exception e)
                        {
                            this.m_tracer.TraceError("Error running {0} for {1} : {2}", triggerName, JavascriptUtils.ProduceLiteral(data), e);
                            throw new JsBusinessRuleException($"Error running business rule {triggerName} for {JavascriptUtils.ProduceLiteral(data)} - {e.Message}", e);
                        }
                    }
                }

                return(data);
            }
        }