Example #1
6
        private void FormMain_Load(object sender, EventArgs e)
        {
            splashScreenManager1.ShowWaitForm();
            var connectionString = ConfigurationManager.ConnectionStrings["MasterDbContext"].ConnectionString;

            var mapper = new ModelToTableMapper<LineStatus>();
            mapper.AddMapping(c => c.NameLine, "NameLine");

            tableDependency = new SqlTableDependency<LineStatus>(connectionString, "LineStatus", mapper);

            tableDependency.OnStatusChanged += TableDependency_OnStatusChanged;
            tableDependency.OnChanged += TableDependency_Changed;
            tableDependency.OnError += TableDependency_OnError;
            tableDependency.Start();
            splashScreenManager1.CloseWaitForm();
        }
        public void MultiInsertTest()
        {
            _checkValues.Clear();
            SqlTableDependency <MultiDmlOperationsTestSqlServerModel> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <MultiDmlOperationsTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name");

                tableDependency            = new SqlTableDependency <MultiDmlOperationsTestSqlServerModel>(_connectionString, TableName, mapper);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.OnError   += this.TableDependency_OnError;
                tableDependency.Start();

                Thread.Sleep(10000);

                var t = new Task(MultiInsertOperation);
                t.Start();
                t.Wait(40000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual("NONNA", _checkValues[1].Name);
            Assert.AreEqual("DIRCE", _checkValues[1].Surname);
            Assert.AreEqual("ZIA", _checkValues[0].Name);
            Assert.AreEqual("ALFREDINA", _checkValues[0].Surname);
        }
        public void Test()
        {
            string naming = null;
            SqlTableDependency <TaskCancellationTestSqlServerModel> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <TaskCancellationTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "First Name").AddMapping(c => c.Surname, "Second Name");

                tableDependency            = new SqlTableDependency <TaskCancellationTestSqlServerModel>(ConnectionStringForTestUser, tableName: TableName, mapper: mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(1000 * 15 * 1);
                tableDependency.Stop();

                Thread.Sleep(5000);
            }
            catch
            {
                tableDependency?.Dispose();
            }

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #4
0
        public void UpdateOneInterestedColumn()
        {
            SqlTableDependency <NotificationOnlyWhenNewValueIsDifferentFromOldValueSqlServerModel> tableDependency = null;
            string naming;

            try
            {
                var mapper = new ModelToTableMapper <NotificationOnlyWhenNewValueIsDifferentFromOldValueSqlServerModel>();
                mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second NAME");

                tableDependency            = new SqlTableDependency <NotificationOnlyWhenNewValueIsDifferentFromOldValueSqlServerModel>(ConnectionStringForTestUser, tableName: TableName, mapper: mapper);
                tableDependency.OnChanged += TableDependency_Changed1;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent1);
                t.Start();
                Thread.Sleep(1000 * 5 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter1, 2);
            Assert.AreEqual(CheckValues1[0].Item2.Name, CheckValues1[0].Item1.Name);
            Assert.AreEqual(CheckValues1[0].Item2.Surname, CheckValues1[0].Item1.Surname);
            Assert.AreEqual(CheckValues1[1].Item2.Name, CheckValues1[1].Item1.Name);
            Assert.AreEqual(CheckValues1[1].Item2.Surname, CheckValues1[1].Item1.Surname);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
        public void Test()
        {
            string naming;
            SqlTableDependency <CustomFilterSqlServerModel> tableDependency = null;
            ITableDependencyFilter filterExpression = new CustomSqlTableDependencyFilter(2);

            try
            {
                tableDependency = new SqlTableDependency <CustomFilterSqlServerModel>(
                    ConnectionStringForTestUser,
                    includeOldValues: true,
                    filter: filterExpression);

                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(1000 * 15 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 3);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, CheckValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Name, CheckValues[ChangeType.Update.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, CheckValues[ChangeType.Delete.ToString()].Item1.Name);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #6
0
        public void EventForAllColumnsTest()
        {
            SqlTableDependency <NoTableAndColumnDefinitionsTestSqlServerTestModel> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency            = new SqlTableDependency <NoTableAndColumnDefinitionsTestSqlServerTestModel>(ConnectionStringForTestUser);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(1000 * 10 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 3);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, CheckValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Surname, CheckValues[ChangeType.Insert.ToString()].Item1.Surname);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Name, CheckValues[ChangeType.Update.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Surname, CheckValues[ChangeType.Update.ToString()].Item1.Surname);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, CheckValues[ChangeType.Delete.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Surname, CheckValues[ChangeType.Delete.ToString()].Item1.Surname);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
        public void Test()
        {
            SqlTableDependency <RealTypesTestSqlServerModel> tableDependency = null;
            string naming;

            try
            {
                tableDependency            = new SqlTableDependency <RealTypesTestSqlServerModel>(ConnectionStringForTestUser);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(1000 * 15 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.RealColumn, CheckValues[ChangeType.Insert.ToString()].Item1.RealColumn);

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.RealColumn, CheckValues[ChangeType.Update.ToString()].Item1.RealColumn);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.RealColumn, CheckValues[ChangeType.Delete.ToString()].Item1.RealColumn);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
        public void Test()
        {
            bool startReceivingMessages = false;

            var tableDependency = new SqlTableDependency <EndpointsStatusModel>(ConnectionStringForTestUser, includeOldValues: true);

            tableDependency.OnChanged += (o, args) => { startReceivingMessages = true; };
            tableDependency.Start();
            var naming = tableDependency.DataBaseObjectsNamingConvention;

            Assert.IsTrue(this.IsSenderEndpointInStatus(naming, ConversationEndpointState.SO));
            Assert.IsTrue(this.IsReceiverEndpointInStatus(naming, null));

            var t = new Task(InsertRecord);

            t.Start();
            while (startReceivingMessages == false)
            {
                Thread.Sleep(1000 * 1 * 1);
            }

            Assert.IsTrue(this.IsSenderEndpointInStatus(naming, ConversationEndpointState.CO));
            Assert.IsTrue(this.IsReceiverEndpointInStatus(naming, ConversationEndpointState.CO));

            tableDependency.Stop();

            Thread.Sleep(1000 * 15 * 1);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #9
0
        public bool Initialize(string userId, CancellationToken token)
        {
            try
            {
                return(Task.Run(() =>
                {
                    var finalConnectionString = _adapter == null ?
                                                connectionString :
                                                _adapter.ConnectionStrings(this.connectionStringName);

                    Expression <Func <TTable, bool> > filterExpression = p => p.ExecutorId == userId;

                    ITableDependencyFilter whereCondition = new SqlTableDependencyFilter <TTable>(filterExpression);

                    Table = new SqlTableDependency <TTable>(
                        finalConnectionString,
                        TableName,
                        filter: whereCondition);

                    Table.OnChanged += OnChangeRaised;
                    Table.OnError += Table_OnError;
                    Table.Start();

                    return true;
                }, token).Result);
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #10
0
        public void EnumTest()
        {
            SqlTableDependency <EnumTestSqlServerModel> tableDependency = null;

            try
            {
                tableDependency            = new SqlTableDependency <EnumTestSqlServerModel>(ConnectionString, TableName);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(30000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 3);

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, CheckValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Surname, CheckValues[ChangeType.Insert.ToString()].Item1.Surname);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Tipo, CheckValues[ChangeType.Insert.ToString()].Item1.Tipo);

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Name, CheckValues[ChangeType.Update.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Surname, CheckValues[ChangeType.Update.ToString()].Item1.Surname);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Tipo, CheckValues[ChangeType.Update.ToString()].Item1.Tipo);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, CheckValues[ChangeType.Delete.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Surname, CheckValues[ChangeType.Delete.ToString()].Item1.Surname);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Tipo, CheckValues[ChangeType.Delete.ToString()].Item1.Tipo);
        }
Example #11
0
        public void MergeTest()
        {
            SqlTableDependency <MargeTestSqlServerModel> tableDependency = null;

            try
            {
                tableDependency            = new SqlTableDependency <MargeTestSqlServerModel>(ConnectionString, TargetTableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.OnError   += this.TableDependency_OnError;
                tableDependency.Start();

                Thread.Sleep(10000);

                var t = new Task(MergeOperation);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(this._insertedValues.Quantity, 100);
            Assert.AreEqual(this._modifiedValues.Quantity, 200);
            Assert.AreEqual(this._deletedValues.Quantity, 0);
        }
Example #12
0
        public async Task <IEnumerable <dummyModel> > GetSqlTblDep()
        {
            using (SqlConnection connection = new SqlConnection(_config.GetConnectionString(commonName.defaultConn)))
            {
                connection.Open();
                using (SqlCommand command =
                           new SqlCommand("SELECT ID, Name FROM [dbo].dummyTable", connection))
                {
                    try
                    {
                        var cs = _config.GetConnectionString(commonName.defaultConn);
                        _tableDependency            = new SqlTableDependency <dummyModel>(cs, "dummyTable", null, null, null, null, DmlTriggerType.All);
                        _tableDependency.OnChanged += Changed;
                        //_tableDependency.OnError += TableDependency_OnError;
                        _tableDependency.Start();
                        var result = await connection.QueryAsync <dummyModel>(command.CommandText);

                        return(result);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
            }
        }
        public void Test()
        {
            var mapper = new ModelToTableMapper <EventForAllColumnsTestSqlServerModel>();

            mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name");

            var tableDependency = new SqlTableDependency <EventForAllColumnsTestSqlServerModel>(ConnectionStringForTestUser, tableName: TableName, mapper: mapper);

            tableDependency.OnChanged += TableDependency_OnChanged;
            tableDependency.Start();
            DbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention;

            var t = new Task(BigModifyTableContent);

            t.Start();
            Thread.Sleep(1000 * 10 * 1);

            Thread.Sleep(1000 * 30 * 1);
            tableDependency.Stop();

            SmalModifyTableContent();

            Thread.Sleep(4 * 60 * 1000);
            Assert.IsTrue(base.AreAllDbObjectDisposed(DbObjectsNaming));
            Assert.IsTrue(base.CountConversationEndpoints(DbObjectsNaming) == 0);
        }
        public void StatusTest()
        {
            try
            {
                var mapper = new ModelToTableMapper <StatusTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "FIRST name");
                mapper.AddMapping(c => c.Surname, "Second Name");
                this._tableDependency                  = new SqlTableDependency <StatusTestSqlServerModel>(ConnectionString, TableName, mapper);
                this._tableDependency.OnChanged       += this.TableDependency_Changed;
                this._tableDependency.OnStatusChanged += this.TableDependency_OnStatusChanged;

                this._tableDependency.Start();

                Thread.Sleep(1 * 60 * 1000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);

                this._tableDependency.Stop();

                foreach (var status in statuses)
                {
                    Assert.IsTrue(statuses[status.Key] == true);
                }
            }
            finally
            {
                this._tableDependency?.Dispose();
            }
        }
Example #15
0
        private static void Setup()
        {
            var mapper = new ModelToTableMapper <Customer>();

            mapper.AddMapping(c => c.Surname, "LastName");
            mapper.AddMapping(c => c.Name, "FirstName");

            using (var dep = new SqlTableDependency <Customer>(_con, "Customer", mapper: mapper))
            {
                dep.OnChanged += (s, e) =>
                {
                    Customer customer = e.Entity;
                    Console.WriteLine("DML Op: {0}", e.ChangeType);
                    Console.WriteLine("ID: {0}", customer.Id);
                    Console.WriteLine("First Name: {0}", customer.Name);
                    Console.WriteLine("Last Name: {0}", customer.Surname);
                    customerQue.Enqueue(customer);
                };
                dep.Start();


                Timer timer = new Timer((arg) => {
                    ProcessData();
                }, null, 0, 5000);


                Console.WriteLine("Press a key to exit");
                Console.ReadKey();



                dep.Stop();
            }
        }
Example #16
0
        public void Test()
        {
            var    tableDependency = new SqlTableDependency <Issue18Model>(ConnectionStringForTestUser);
            string objectNaming;

            try
            {
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                objectNaming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(1000 * 15 * 1);
            }
            finally
            {
                tableDependency.Dispose();
            }


            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Id, 1);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Price, 123.0001002000000100M);

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Id, 1);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Price, 1234.0002003000000000M);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Id, 1);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Price, 1234.0002003000000000M);

            Assert.IsTrue(base.AreAllDbObjectDisposed(objectNaming));
            Assert.IsTrue(base.CountConversationEndpoints(objectNaming) == 0);
        }
Example #17
0
 public ListenerSlq(string connectionString, string tableName, ModelToTableMapper <LoadAndCountTestSqlServerModel> mapper)
 {
     this._tableDependency            = new SqlTableDependency <LoadAndCountTestSqlServerModel>(connectionString, tableName, mapper);
     this._tableDependency.OnChanged += this.TableDependency_OnChanged;
     this._tableDependency.Start(60, 120);
     this._listenerResult.ObjectNaming = this._tableDependency.DataBaseObjectsNamingConvention;
 }
Example #18
0
        private static int counter = 1;  // For debug to check whether the interval is running

        // The constructor initializes the database connections and adds column mappings if any
        public SQLServerStream()
        {
            /**
             * No need to do mappings since model class properties exactly match the db column names. If otherwise then need to
             *  var mapper = new ModelToTableMapper<Customer>();
             *  mapper.AddMapping(c => c.Surname, "Second Name");
             *  mapper.AddMapping(c => c.Name, "First Name");
             **/

            using (var dep = new SqlTableDependency <ModelProcessedHistory>(Globals.DBConnectionString, Globals.DBTableName))
            {
                dep.OnChanged += Changed;
                dep.Start();

                Console.WriteLine("Press a key to exit");
#if DEBUG
                // Need to use this in debug mode to read user input keys to either quit, pause or resume service
                // In other location, the program is kept alive by infite loop if key is not either if Q, P or R
                // In Progaram.Main(), ConsoleHarness.Run() is called for every input key which in turn determines whether
                // the service should (P)ause, (R)esume or (Stop) OR keep running infinitely for any other key that isn't
                // in this set. Makes the service easy to debug
                Console.ReadKey();
#else
                // We don't really need  Console.ReadKey(); here since the console input isn't important
                // Just need to put the service in infinite loop waiting for user input thus keeping it alive
                Thread.Sleep(Timeout.Infinite);
#endif


                dep.Stop();
            }
        }
Example #19
0
        public async Task <int> subscribeBookingAdd(int locId1, int locId2, string groupName)
        {
            _groupName = groupName;
            ITableDependencyFilter filterExpression = new BookingSqlTableDependencyFilter(locId1, locId2);

            using (SqlConnection connection = new SqlConnection(_config.GetConnectionString(commonName.defaultConn)))
            {
                try
                {
                    var cs = _config.GetConnectionString(commonName.defaultConn);
                    _tableDependency = new SqlTableDependency <Booking>(connectionString: cs,
                                                                        tableName: Booking.tableName,
                                                                        filter: filterExpression,
                                                                        notifyOn: DmlTriggerType.Insert);
                    _tableDependency.OnChanged += Changed;
                    //_tableDependency.OnError += TableDependency_OnError;
                    _tableDependency.Start();
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    connection.Close();
                }
            }

            return(0);
        }
Example #20
0
        public void Test()
        {
            SqlTableDependency <MassiveChangesInSingleCommandModel> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency            = new SqlTableDependency <MassiveChangesInSingleCommandModel>(ConnectionStringForTestUser);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t1 = new Task(ModifyTableContent1);
                var t2 = new Task(ModifyTableContent2);

                t1.Start();
                t2.Start();

                Thread.Sleep(1000 * 30 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.IsTrue(CheckValues[ChangeType.Insert.ToString()].All(m => (m.Id == 1 || m.Id == 3) && (m.Name == "Luciano Bruschi" || m.Name == "Dina Bruschi")));
            Assert.IsTrue(CheckValues[ChangeType.Insert.ToString()].Count == 20);
            Assert.IsTrue(CheckValues[ChangeType.Update.ToString()].All(m => (m.Id == 2 || m.Id == 4) && (m.Name == "Ceccarelli Velia" || m.Name == "Ismano Del Bianco")));
            Assert.IsTrue(CheckValues[ChangeType.Update.ToString()].Count == 20);
            Assert.IsTrue(CheckValues[ChangeType.Delete.ToString()].All(m => (m.Id == 2 || m.Id == 4) && (m.Name == "Ceccarelli Velia" || m.Name == "Ismano Del Bianco")));
            Assert.IsTrue(CheckValues[ChangeType.Delete.ToString()].Count == 20);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #21
0
        public void Test()
        {
            SqlTableDependency <TableNameFromModelClassNameAndUpdateOfTestSqlServerModel> tableDependency = null;
            string naming;

            try
            {
                UpdateOfModel <TableNameFromModelClassNameAndUpdateOfTestSqlServerModel> updateOf = new UpdateOfModel <TableNameFromModelClassNameAndUpdateOfTestSqlServerModel>();
                updateOf.Add(model => model.FamilyName);

                tableDependency            = new SqlTableDependency <TableNameFromModelClassNameAndUpdateOfTestSqlServerModel>(ConnectionStringForTestUser, updateOf: updateOf);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(1000 * 10 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 2);

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, CheckValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.FamilyName, CheckValues[ChangeType.Insert.ToString()].Item1.FamilyName);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, CheckValues[ChangeType.Delete.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.FamilyName, CheckValues[ChangeType.Delete.ToString()].Item1.FamilyName);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
        public void Test()
        {
            var mapper = new ModelToTableMapper <DatabaseObjectAutoCleanUpAfter2InsertsTestSqlServerModel>();

            mapper.AddMapping(c => c.Name, "First Name").AddMapping(c => c.Surname, "Second Name");

            var tableDependency = new SqlTableDependency <DatabaseObjectAutoCleanUpAfter2InsertsTestSqlServerModel>(ConnectionStringForTestUser, includeOldValues: true, tableName: TableName, mapper: mapper);

            tableDependency.OnChanged += TableDependency_OnChanged;
            tableDependency.Start();
            var dbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention;

            Thread.Sleep(500);

            tableDependency.StopWithoutDisposing();

            Thread.Sleep(500);

            var t = new Task(ModifyTableContent);

            t.Start();

            Thread.Sleep(1000 * 60 * 4);

            Assert.IsTrue(base.AreAllDbObjectDisposed(dbObjectsNaming));
            Assert.IsTrue(base.CountConversationEndpoints(dbObjectsNaming) == 0);
        }
        public void Test1()
        {
            string objectNaming = string.Empty;

            using (var tableDependency = new SqlTableDependency <Issue177Model>(ConnectionStringForTestUser, tableName: TableName))
            {
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.OnError   += TableDependency_OnError;
                objectNaming = tableDependency.DataBaseObjectsNamingConvention;
                tableDependency.Start();

                Thread.Sleep(5000);
                var t = new Task(ModifyTableContent1);
                t.Start();

                Thread.Sleep(1000 * 15 * 1);
            }

            Thread.Sleep(240000);

            Assert.IsNotNull(TheError);
            Assert.IsTrue(TheError is NoMatchBetweenModelAndTableColumns);

            Assert.IsTrue(base.AreAllDbObjectDisposed(objectNaming));
            Assert.IsTrue(base.CountConversationEndpoints(objectNaming) == 0);
        }
Example #24
0
        public void OnlyUdate()
        {
            SqlTableDependency <TriggerTypeTestSqlServerModel> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency = new SqlTableDependency <TriggerTypeTestSqlServerModel>(
                    ConnectionStringForTestUser,
                    tableName: TableName,
                    notifyOn: DmlTriggerType.Update);

                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(1000 * 15 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 1);

            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.Name, "Pizza Funghi");
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.Surname, "Pizza Mergherita");

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #25
0
        public void RaiseException1()
        {
            SqlTableDependency <TriggerTypeTestSqlServerModel> tableDependency = null;
            string naming = null;

            var updateOf = new UpdateOfModel <TriggerTypeTestSqlServerModel>();

            updateOf.Add(i => i.Surname);

            try
            {
                tableDependency = new SqlTableDependency <TriggerTypeTestSqlServerModel>(
                    ConnectionStringForTestUser,
                    tableName: TableName,
                    updateOf: updateOf,
                    notifyOn: DmlTriggerType.Insert);

                naming = tableDependency.DataBaseObjectsNamingConvention;
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #26
0
        public void MultiInsertTest()
        {
            ModifiedValues.Clear();
            SqlTableDependency <MultiDmlOperationsTestSqlServerModel> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <MultiDmlOperationsTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name");

                tableDependency            = new SqlTableDependency <MultiDmlOperationsTestSqlServerModel>(ConnectionStringForTestUser, tableName: TableName, mapper: mapper);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.OnError   += this.TableDependency_OnError;
                tableDependency.Start();

                var t = new Task(MultiInsertOperation);
                t.Start();
                Thread.Sleep(1000 * 15 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(3, ModifiedValues.Count);
            Assert.IsTrue(InitialValues.Any(i => i.Equals(ModifiedValues[0])));
            Assert.IsTrue(InitialValues.Any(i => i.Equals(ModifiedValues[1])));
            Assert.IsTrue(InitialValues.Any(i => i.Equals(ModifiedValues[2])));
        }
Example #27
0
        public void Test4()
        {
            string objectNaming;
            var    tableDependency = new SqlTableDependency <Issue53Model4>(ConnectionStringForTestUser, tableName: TableName4);

            try
            {
                tableDependency.OnChanged += TableDependency_Changed4;
                tableDependency.Start();
                objectNaming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent4);
                t.Start();
                Thread.Sleep(1000 * 5 * 1);
            }
            finally
            {
                tableDependency.Dispose();
            }

            Assert.AreEqual(_checkValues4[ChangeType.Insert.ToString()].Item2.Id, _checkValues4[ChangeType.Insert.ToString()].Item1.Id);
            Assert.AreEqual(_checkValues4[ChangeType.Insert.ToString()].Item2.Gender, _checkValues4[ChangeType.Insert.ToString()].Item1.Gender);
            Assert.AreEqual(_checkValues4[ChangeType.Update.ToString()].Item2.Id, _checkValues4[ChangeType.Update.ToString()].Item1.Id);
            Assert.AreEqual(_checkValues4[ChangeType.Update.ToString()].Item2.Gender, _checkValues4[ChangeType.Update.ToString()].Item1.Gender);
            Assert.AreEqual(_checkValues4[ChangeType.Delete.ToString()].Item2.Id, _checkValues4[ChangeType.Delete.ToString()].Item1.Id);
            Assert.AreEqual(_checkValues4[ChangeType.Delete.ToString()].Item2.Gender, _checkValues4[ChangeType.Delete.ToString()].Item1.Gender);

            Assert.IsTrue(base.AreAllDbObjectDisposed(objectNaming));
            Assert.IsTrue(base.CountConversationEndpoints(objectNaming) == 0);
        }
Example #28
0
        public void TableWithTest()
        {
            SqlTableDependency <UseSchemaOtherThanDboTestSqlServer2Model> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency            = new SqlTableDependency <UseSchemaOtherThanDboTestSqlServer2Model>(ConnectionStringForSa);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(1000 * 10 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 3);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Description, CheckValues[ChangeType.Insert.ToString()].Item1.Description);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Description, CheckValues[ChangeType.Update.ToString()].Item1.Description);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Description, CheckValues[ChangeType.Delete.ToString()].Item1.Description);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #29
0
        public void Test()
        {
            SqlTableDependency <TransactionTestSqlServer4Model> tableDependency = null;
            string naming;

            try
            {
                var mapper = new ModelToTableMapper <TransactionTestSqlServer4Model>();
                mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name");

                tableDependency            = new SqlTableDependency <TransactionTestSqlServer4Model>(ConnectionStringForTestUser, tableName: TableName, mapper: mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent);
                t.Start();

                Thread.Sleep(1000 * 5 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 0);
            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
        public void Test()
        {
            SqlTableDependency <MassiveChangesModel> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency            = new SqlTableDependency <MassiveChangesModel>(ConnectionStringForTestUser);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                var t = new Task(ModifyTableContent);
                t.Start();

                while (Done == false)
                {
                    Thread.Sleep(1000 * 30 * 1);
                }
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.IsTrue(CheckValues[ChangeType.Insert.ToString()].All(m => m.Id == 1 && m.Name == "Luciano Bruschi"));
            Assert.IsTrue(CheckValues[ChangeType.Insert.ToString()].Count == ChangesNumber);
            Assert.IsTrue(CheckValues[ChangeType.Update.ToString()].All(m => m.Id == 2 && m.Name == "Ceccarelli Velia"));
            Assert.IsTrue(CheckValues[ChangeType.Update.ToString()].Count == ChangesNumber);
            Assert.IsTrue(CheckValues[ChangeType.Delete.ToString()].All(m => m.Id == 2 && m.Name == "Ceccarelli Velia"));
            Assert.IsTrue(CheckValues[ChangeType.Delete.ToString()].Count == ChangesNumber);

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
        public void OnlyInsert()
        {
            SqlTableDependency <TriggerTypeTestSqlServerModel> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency = new SqlTableDependency <TriggerTypeTestSqlServerModel>(
                    ConnectionString,
                    tableName: TableName,
                    notifyOn: DmlTriggerType.Insert);

                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 1);

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, "Pizza Mergherita");
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Surname, "Pizza Mergherita");

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
        }
Example #32
-1
        private StockMonitor(IHubConnectionContext<dynamic> clients)
        {
            Clients = clients;
            _stockService = new StockService();

            _stockDependency = new SqlTableDependency<Stock>(ExchangeConfiguration.ConnectionString, "Stock");
            _stockDependency.OnChanged += _stockDependency_OnChanged;
            _stockDependency.OnError += _tableDependency_OnError;
            _stockDependency.Start();
        }