Esempio n. 1
0
        // runs, updates and commits itself, all in one.
        public void Run(IEnumerable <IShielded> trigger)
        {
            Shield.InTransaction(() =>
            {
                var oldItems = _items.Value;
                if (oldItems == null || !oldItems.Overlaps(trigger))
                {
                    return; // not subscribed anymore..
                }
                bool test     = false;
                var testItems = Shield.IsolatedRun(() => test = Test());

                if (test)
                {
                    Trans();
                }

                // _locals will have value if Trans() called Dispose on "itself".
                if (!_locals.HasValue && !testItems.SetEquals(oldItems))
                {
                    if (!testItems.Any())
                    {
                        // get rid of all entries first.
                        Remover(oldItems);
                        throw new InvalidOperationException(
                            "A conditional test function must access at least one shielded field.");
                    }
                    _items.Value = testItems;
                    UpdateEntries();
                }
            });
        }
Esempio n. 2
0
 public CommitSubscription(CommitSubscriptionContext context, Func <bool> test, Action trans)
 {
     Context = context;
     Test    = test;
     Trans   = trans;
     Shield.InTransaction(() => {
         var items = Shield.IsolatedRun(() => Test());
         if (!items.Any())
         {
             throw new InvalidOperationException(
                 "Test function must access at least one shielded field.");
         }
         _items.Value = items;
         UpdateEntries();
     });
 }