Ejemplo n.º 1
0
        public WatcherCache(
            [NotNull] IWatcherFactory <TKey, TValue> factory,
            [NotNull] IEqualityComparer <TKey> comparer)
        {
            this.factory = factory ?? throw new ArgumentNullException(nameof(factory));

            cache = new ConcurrentDictionary <TKey, CountingAdapter>(comparer ?? throw new ArgumentNullException(nameof(comparer)));
        }
Ejemplo n.º 2
0
        public IDisposable Attach(TContext context)
        {
            if (_factory == null)
            {
                var remap            = new int[_actions.Count];
                var compactedActions = new List <BindingAction>();
                for (int i = 0; i < _actions.Count; ++i)
                {
                    var action = _actions[i];
                    if (action != null)
                    {
                        remap[i] = compactedActions.Count;
                        compactedActions.Add(action);
                    }
                    else
                    {
                        remap[i] = -1;
                    }
                }

                _compactedActions = compactedActions.ToArray();

                _factory = Binder.AllowReuseOfWatchers
                    ? (IWatcherFactory <TContext>) new ReusableWatcherFactory <TContext>(_compactedActions, _rootNode.CreateBindingNode(remap))
                    : new DefaultWatcherFactory <TContext>(_actions.ToArray(), _rootNode.CreateBindingNode(remap));
            }

            var watcher = _factory.Attach(context);

            foreach (var action in _compactedActions)
            {
                if (action.RunOnAttach)
                {
                    try
                    {
                        action.Action(context);
                    }
                    catch (Exception ex)
                    {
                        var ea = new ExceptionEventArgs(ex);
                        Binder.ExceptionHandler?.Invoke(this, ea);
                        if (!ea.Handled)
                        {
                            throw;
                        }
                    }
                }
            }

            return(watcher);
        }
Ejemplo n.º 3
0
        public Application(IRepository repository, IWatcherFactory watcherFactory)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }
            if (watcherFactory == null)
            {
                throw new ArgumentNullException("watcherFactory");
            }

            _repository         = repository;
            _fileWatcherFactory = watcherFactory;
        }
Ejemplo n.º 4
0
 public RedisManager(IWatcherFactory <TModel> watcherFactory)
Ejemplo n.º 5
0
 public WatcherCache(IWatcherFactory <TKey, TValue> factory)
     : this(factory, EqualityComparer <TKey> .Default)
 {
 }
Ejemplo n.º 6
0
 public void SetUp()
 {
     watcherFactory = Substitute.For <IWatcherFactory <string, string> >();
     watcherCache   = new WatcherCache <string, string>(watcherFactory);
     settings       = "settings";
 }