Exemplo n.º 1
0
        private void TrySubscribeToTableChanges()
        {
            if (lifetimeScope != LifetimeScope.ConnectionScope && sqlTableDependency != null)
            {
                StartSqlTableDependency();

                return;
            }

            TryStopLastConnection();

            var modelToTableMapper = InitializeMapper();

            try
            {
                sqlTableDependency = CreateSqlTableDependency(modelToTableMapper);

                sqlTableDependency.OnChanged       += SqlTableDependencyOnChanged;
                sqlTableDependency.OnError         += SqlTableDependencyOnError;
                sqlTableDependency.OnStatusChanged += OnSqlTableDependencyStatusChanged;

                StartSqlTableDependency();
            }
            catch (Exception error)
            {
                TryHandlerErrors(error);

                TryReconnect();
            }
        }
Exemplo n.º 2
0
        public NorthwindCacheManager(ICache <T> cache, ITableDependency <T> tableDependency)
        {
            _cache                      = cache ?? throw new ArgumentNullException("Cannot manage null value cache");;
            _tableDependency            = tableDependency ?? throw new ArgumentNullException("Cannot check changes on database with null value argument");
            _tableDependency.OnChanged += _tableDependency_OnChanged;
            _tableDependency.Start();

            void _tableDependency_OnChanged(object sender, RecordChangedEventArgs <T> e)
            {
                _cache.Delete(user);
                Console.WriteLine("Table changed");//for test
            }
        }
Exemplo n.º 3
0
        protected void TryStopLastConnection()
        {
            if (sqlTableDependency == null)
            {
                return;
            }

            sqlTableDependency.OnError         -= SqlTableDependencyOnError;
            sqlTableDependency.OnStatusChanged -= SqlTableDependencyOnStatusChanged;
            sqlTableDependency.OnChanged       -= SqlTableDependencyOnChanged;

            try
            {
                sqlTableDependency.Dispose();
                sqlTableDependency = null;
            }
            catch (Exception e)
            {
                TryHandlerErrors(e);
            }
        }
Exemplo n.º 4
0
 public TestSqlTableDependencyProvider(string connectionString, IScheduler scheduler, ITableDependency <TestModel> tableDependency, LifetimeScope lifetimeScope)
     : base(connectionString, scheduler, tableDependency, lifetimeScope)
 {
 }