/// <summary>
 /// Initializes a new instance of the <see cref="CalculatedFieldContext"/> class.
 /// </summary>
 public CalculatedFieldContext()
 {
     _originalContext = _currentContext;
     _thread = Thread.CurrentThread;
     _currentContext = this;
 }
        public void Dispose()
        {
            if (_disposed)
                return;

            _disposed = true;

            if (_thread != Thread.CurrentThread)
                throw new InvalidOperationException("Scope should be disposed in the original thread.");

            if (_currentContext != this)
                throw new InvalidOperationException("Scope is disposed in incorrect order.");

            _currentContext = _originalContext;

            if (_originalContext != null && _isBusy)
                _originalContext.MarkBusy();
        }
示例#3
0
        public override bool CanExecute(IDynamicObject item, IDynamicObject oldItem)
        {
            if (item == null)
                throw new ArgumentNullException("item");
            //ELMTSUP-2704 Fields Security Rules should be ignored when Action Rule is evaluated
            using (new BypassPropertyCheckContext())
            using (var context = new CalculatedFieldContext())
            {
                bool ruleResult;

                try
                {
                    ruleResult = Expression != null && Expression(item, oldItem);
                }
                catch (Exception ex)
                {
#if !SILVERLIGHT
                    Logger.Log(LogSeverity.Error, "Rule Expression", ex);
#endif

                    ruleResult = false;
                }

                var editableItem = item as IEditableRoot;

                if (editableItem != null)
                {
                    if (!context.IsBusy)
                    {
                        editableItem.SetRuleResult(Guid, ruleResult);
                    }

                    return editableItem.GetRuleResult(Guid) ?? false;
                }

                return !context.IsBusy && ruleResult;
            }
        }