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))); }
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); }
public Application(IRepository repository, IWatcherFactory watcherFactory) { if (repository == null) { throw new ArgumentNullException("repository"); } if (watcherFactory == null) { throw new ArgumentNullException("watcherFactory"); } _repository = repository; _fileWatcherFactory = watcherFactory; }
public RedisManager(IWatcherFactory <TModel> watcherFactory)
public WatcherCache(IWatcherFactory <TKey, TValue> factory) : this(factory, EqualityComparer <TKey> .Default) { }
public void SetUp() { watcherFactory = Substitute.For <IWatcherFactory <string, string> >(); watcherCache = new WatcherCache <string, string>(watcherFactory); settings = "settings"; }