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();
        }
        private ModelToTableMapper <T> CreateModelToTableMapperHelper()
        {
            var modelPropertyInfosWithColumnAttribute = typeof(T)
                                                        .GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public)
                                                        .Where(x => CustomAttributeExtensions.IsDefined(x, typeof(ColumnAttribute), false))
                                                        .ToArray();

            if (!modelPropertyInfosWithColumnAttribute.Any())
            {
                return(null);
            }

            var mapper = new ModelToTableMapper <T>();

            foreach (var propertyInfo in modelPropertyInfosWithColumnAttribute)
            {
                var attribute    = propertyInfo.GetCustomAttribute(typeof(ColumnAttribute));
                var dbColumnName = ((ColumnAttribute)attribute)?.Name;
                if (string.IsNullOrWhiteSpace(dbColumnName))
                {
                    dbColumnName = propertyInfo.Name;
                    mapper.AddMapping(propertyInfo, dbColumnName);
                }

                mapper.AddMapping(propertyInfo, dbColumnName);
            }

            return(mapper);
        }
Example #3
0
        public static void Main()
        {
            // The mapper object is used to map model properties
            // that do not have a corresponding table column name.
            // In case all properties of your model have same name
            // of table columns, you can avoid to use the mapper.
            var mapper = new ModelToTableMapper <Customer>();

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

            // Here - as second parameter - we pass table name:
            // this is necessary only if the model name is different from table name
            // (in our case we have Customer vs Customers).
            // If needed, you can also specifiy schema name.
            using (var dep = new SqlTableDependency <Customer>(
                       connectionString: _con,

                       tableName: "Customers", mapper: mapper, executeUserPermissionCheck: false))
            {
                dep.OnChanged += Changed;
                dep.Start();
                string x = Console.ReadLine();

                Console.WriteLine("Press a key to exit");
                Console.ReadKey();
                if (x == "c")
                {
                    dep.Stop();
                }
            }
        }
Example #4
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 #5
0
        public CounterTicker(
            IHubContext <CounterHub> counterHubContext,
            IConfiguration configuration
            )
        {
            Hub            = counterHubContext;
            _configuration = configuration;

            var mapper = new ModelToTableMapper <CounterModel>();

            mapper.AddMapping(s => s.TagName, "tagName");
            mapper.AddMapping(s => s.Counter, "counter");
            mapper.AddMapping(s => s.Quality, "quality");
            mapper.AddMapping(s => s.LastUpdate, "lastUpdate");
            mapper.AddMapping(s => s.IsInitialSave, "isInitialSave");

            _tableDependency = new SqlTableDependency <CounterModel>(
                configuration.GetConnectionString("iconicsConn"),
                schemaName: "dbo",
                tableName: "KEPServer_CurrentStatus_PermCounts"
                );

            _tableDependency.OnChanged += SqlTableDependency_Changed;
            _tableDependency.OnError   += SqlTableDependency_OnError;
            _tableDependency.Start();
        }
Example #6
0
        public KnotService()
        {
            Logger.Info("onInit Service");
            InitializeComponent();
            isStartCompleted = false;
            try
            {
                var mapper = new ModelToTableMapper <DataStep>();
                mapper.AddMapping(model => model.DataStepUID, "DataStepUID");
                mapper.AddMapping(model => model.StepName, "StepName");
                _dependency = new SqlTableDependency <DataStep>(_fusionConnectionString,
                                                                "DataStep",
                                                                mapper: mapper);
                _dependency.OnChanged += _dependency_OnChanged;
                _dependency.OnError   += _dependency_OnError;
                _dependency.Start();

                Logger.Info("onInit Completed");
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Init KnotService");
                Logger.Error(ex.Message);
                Logger.Error(ex.StackTrace);
                throw;
            }
        }
Example #7
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            var mapper = new ModelToTableMapper <Customer>();

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

            dep = new SqlTableDependency <Customer>(_con, "Customers", mapper: mapper);

            dep.OnChanged += Changed;
            dep.Start();

            using (SqlConnection connection = new SqlConnection(_con))
                using (SqlCommand command = new SqlCommand("Select * from Customers", connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var cust = new Customer();
                            cust.Id      = Convert.ToInt32(reader["Id"]);
                            cust.Name    = reader["First Name"].ToString();
                            cust.Surname = reader["Last Name"].ToString();
                            GridSource.Add(cust);
                        }
                    }
                }

            this.Closed += MainWindow_Closed;
        }
        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();
            }
        }
        protected override ModelToTableMapper <Product> OnInitializeMapper(ModelToTableMapper <Product> modelToTableMapper)
        {
            modelToTableMapper.AddMapping(c => c.Id, "Id");
            modelToTableMapper.AddMapping(c => c.Name, "Name");

            return(modelToTableMapper);
        }
        public static IModelToTableMapper <T> GetModelMapperFromColumnDataAnnotation(IEnumerable <TableColumnInfo> tableColumns)
        {
            var modelPropertyInfosWithColumnAttribute = typeof(T)
                                                        .GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public)
                                                        .Where(x => CustomAttributeExtensions.IsDefined((MemberInfo)x, typeof(ColumnAttribute), false))
                                                        .ToArray();

            if (!modelPropertyInfosWithColumnAttribute.Any())
            {
                return(null);
            }

            var mapper = new ModelToTableMapper <T>();

            foreach (var propertyInfo in modelPropertyInfosWithColumnAttribute)
            {
                var attribute    = propertyInfo.GetCustomAttribute(typeof(ColumnAttribute));
                var dbColumnName = ((ColumnAttribute)attribute)?.Name;
                if (string.IsNullOrWhiteSpace(dbColumnName) && tableColumns.Any(tc => tc.Name == propertyInfo.Name))
                {
                    dbColumnName = propertyInfo.Name;
                    mapper.AddMapping(propertyInfo, dbColumnName);
                    continue;
                }

                if (!string.IsNullOrWhiteSpace(dbColumnName))
                {
                    mapper.AddMapping(propertyInfo, dbColumnName);
                }
            }

            return(mapper);
        }
Example #11
0
        public TransactionDependency(TransactionSyncService trtSyncSvc, IStoreDataProvider storeProvider)
        {
            _trtSyncSvc = trtSyncSvc;
            var connectionString = ConfigurationManager.AppSettings["DATA.CONNECTIONSTRING"];
            var providerName     = ConfigurationManager.AppSettings["DATA.PROVIDER"];

            _storeProvider = storeProvider;

            var mapper = new ModelToTableMapper <OrderDetailDto>();

            mapper.AddMapping(c => c.OrderDetailUId, "OrderDetailUId");
            mapper.AddMapping(c => c.Order_UId, "Order_UId");
            //mapper.AddMapping(c => c.Product_Id, "Product_Id");
            //mapper.AddMapping(c => c.CostPrice, "CostPrice");
            //mapper.AddMapping(c => c.Discount, "Discount");
            //mapper.AddMapping(c => c.Price, "Price");
            //mapper.AddMapping(c => c.Quantiy, "Quantiy");
            //mapper.AddMapping(c => c.EntryDate, "EntryDate");

            tableDependency = new SqlTableDependency <OrderDetailDto>(connectionString, "[dbo].[OrderDetails]", mapper);
            tableDependency.TraceListener = new TextWriterTraceListener(Console.Out);
            tableDependency.OnChanged    += tableDependency_OnChanged;
            tableDependency.OnError      += tableDependency_OnError;
            tableDependency.TraceListener = new TextWriterTraceListener(File.Create("c:\\Iposlogs\\transactionlogoutput.txt"));
        }
Example #12
0
        public static ModelToTableMapper <User> GetMapper()
        {
            var mapper = new ModelToTableMapper <User>();

            mapper.AddMapping(u => u.Id, "Id");
            mapper.AddMapping(u => u.Username, "Username");
            return(mapper);
        }
Example #13
0
        public void TestWithOldValues()
        {
            SqlTableDependency <WithMapperTestModel> tableDependency = null;
            string naming;

            var mapper = new ModelToTableMapper <WithMapperTestModel>();

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

            Expression <Func <WithMapperTestModel, bool> > expression = p => p.Identificator == _id;
            ITableDependencyFilter filterExpression = new SqlTableDependencyFilter <WithMapperTestModel>(expression, mapper);

            try
            {
                tableDependency = new SqlTableDependency <WithMapperTestModel>(
                    ConnectionStringForTestUser,
                    includeOldValues: true,
                    tableName: TableName,
                    mapper: mapper,
                    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.Identificator, CheckValues[ChangeType.Insert.ToString()].Item1.Identificator);
            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.IsNull(CheckValuesOld[ChangeType.Insert.ToString()]);

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Identificator, CheckValues[ChangeType.Update.ToString()].Item1.Identificator);
            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(CheckValuesOld[ChangeType.Update.ToString()].Item2.Identificator, CheckValues[ChangeType.Insert.ToString()].Item2.Identificator);
            Assert.AreEqual(CheckValuesOld[ChangeType.Update.ToString()].Item2.Name, CheckValues[ChangeType.Insert.ToString()].Item2.Name);
            Assert.AreEqual(CheckValuesOld[ChangeType.Update.ToString()].Item2.Surname, CheckValues[ChangeType.Insert.ToString()].Item2.Surname);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Identificator, CheckValues[ChangeType.Delete.ToString()].Item1.Identificator);
            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.IsNull(CheckValuesOld[ChangeType.Delete.ToString()]);

            Assert.IsTrue(AreAllDbObjectDisposed(naming));
            Assert.IsTrue(CountConversationEndpoints(naming) == 0);
        }
Example #14
0
        private static ModelToTableMapper <LibraryEntity.Genre> MapGenre()
        {
            var mapperGenre = new ModelToTableMapper <LibraryEntity.Genre>();

            mapperGenre.AddMapping(c => c.MaTL, "MaTL");
            mapperGenre.AddMapping(c => c.TenTL, "TenTL");

            return(mapperGenre);
        }
        public static IModelToTableMapper <test> getTestMapper()
        {
            var mapper = new ModelToTableMapper <test>();

            mapper.AddMapping(model => model.id, "id");
            mapper.AddMapping(model => model.name, "name");
            mapper.AddMapping(model => model.roll, "roll");
            return(mapper);
        }
Example #16
0
        private static ModelToTableMapper <LibraryEntity.Account> MapAccount()
        {
            var mapperAccount = new ModelToTableMapper <LibraryEntity.Account>();

            mapperAccount.AddMapping(c => c.TenTaiKhoan, "TenTaiKhoan");
            mapperAccount.AddMapping(c => c.MatKhau, "MatKhau");
            mapperAccount.AddMapping(c => c.PhanQuyen, "PhanQuyen");

            return(mapperAccount);
        }
Example #17
0
        public Form1()
        {
            InitializeComponent();
            var mapper = new ModelToTableMapper <Zaposleni>();

            mapper.AddMapping(c => c.Prezime, "Prezime");
            mapper.AddMapping(c => c.Ime, "Ime");
            _dependency            = new SqlTableDependency <Zaposleni>(connString, "Zaposleni", mapper: mapper);
            _dependency.OnChanged += Changed;
            _dependency.Start();
        }
        public void TestWithOldValues()
        {
            var mapper = new ModelToTableMapper <Issue55Model>();

            mapper.AddMapping(c => c.PaymentDiscount, "Payment Discount %");
            mapper.AddMapping(c => c.AllowQuantity, "Allow Quantity Disc_");
            mapper.AddMapping(c => c.DocNo, "Applies-to Doc_ No_");

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

            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(_counter, 3);

            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.DocNo, _checkValues[ChangeType.Insert.ToString()].Item1.DocNo);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.AllowQuantity, _checkValues[ChangeType.Insert.ToString()].Item1.AllowQuantity);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.PaymentDiscount, _checkValues[ChangeType.Insert.ToString()].Item1.PaymentDiscount);
            Assert.IsNull(_checkValuesOld[ChangeType.Insert.ToString()]);

            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.DocNo, _checkValues[ChangeType.Update.ToString()].Item1.DocNo);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.AllowQuantity, _checkValues[ChangeType.Update.ToString()].Item1.AllowQuantity);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.PaymentDiscount, _checkValues[ChangeType.Update.ToString()].Item1.PaymentDiscount);
            Assert.AreEqual(_checkValuesOld[ChangeType.Update.ToString()].Item2.DocNo, _checkValues[ChangeType.Insert.ToString()].Item2.DocNo);
            Assert.AreEqual(_checkValuesOld[ChangeType.Update.ToString()].Item2.AllowQuantity, _checkValues[ChangeType.Insert.ToString()].Item2.AllowQuantity);
            Assert.AreEqual(_checkValuesOld[ChangeType.Update.ToString()].Item2.PaymentDiscount, _checkValues[ChangeType.Insert.ToString()].Item2.PaymentDiscount);

            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.DocNo, _checkValues[ChangeType.Delete.ToString()].Item1.DocNo);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.AllowQuantity, _checkValues[ChangeType.Delete.ToString()].Item1.AllowQuantity);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.PaymentDiscount, _checkValues[ChangeType.Delete.ToString()].Item1.PaymentDiscount);
            Assert.IsNull(_checkValuesOld[ChangeType.Delete.ToString()]);

            Assert.IsTrue(base.AreAllDbObjectDisposed(objectNaming));
            Assert.IsTrue(base.CountConversationEndpoints(objectNaming) == 0);
        }
Example #19
0
        public void Servicesqlnotifier()
        {
            var mapper = new ModelToTableMapper <ServiceReport>();

            mapper.AddMapping(c => c.Title, "Title");
            mapper.AddMapping(c => c.ProjectNo, "ProjectNo");

            _serviceDependency            = new SqlTableDependency <ServiceReport>("Data Source=spm-sql;Initial Catalog=SPM_Database;User ID=SPM_Agent;password=spm5445", tableName: "spservicereports", mapper: mapper);
            _serviceDependency.OnChanged += _serviceDependency_OnChanged;
            _serviceDependency.OnError   += _serviceDependency_OnError;
            _serviceDependency.Start();
        }
Example #20
0
        public void Configure(string connectionString)
        {
            var mapper = new ModelToTableMapper <Employee>();

            mapper.AddMapping(c => c.EmployeeId, "EmployeeId");
            mapper.AddMapping(c => c.FirstName, "FirstName");

            _tableDependency            = new SqlTableDependency <Employee>(connectionString, "EmployeeDB", notifyOn: DmlTriggerType.All, mapper: mapper);
            _tableDependency.OnChanged += Changed;
            _tableDependency.OnError   += TableDependency_OnError;
            _tableDependency.Start();
            _logger.LogInformation("Waiting for receiving notifications...");
            Console.WriteLine("Waiting for receiving notifications...");
        }
Example #21
0
        public ScrapTicker(IHubContext <ScrapHub> counterHubContext, IConfiguration configuration)
        {
            Hub            = counterHubContext;
            _configuration = configuration;

            var mapper = new ModelToTableMapper <ScrapModel>();

            mapper.AddMapping(s => s.WorkCenter, "workCenter");
            mapper.AddMapping(s => s.Qty, "qty");
            mapper.AddMapping(s => s.ScrapCode, "scrapCode");
            mapper.AddMapping(s => s.ScrapDesc, "scrapDesc");
            mapper.AddMapping(s => s.ShiftDate, "ShiftDate");
            mapper.AddMapping(s => s.Shift, "Shift");
            mapper.AddMapping(s => s.Hour, "hour_hxh");
            mapper.AddMapping(s => s.OperationNumberLocation, "operationNumberLoc");

            _tableDependency = new SqlTableDependency <ScrapModel>(
                configuration.GetConnectionString("sapConn"),
                schemaName: "dbo",
                tableName: "Scrap"
                );

            _tableDependency.OnChanged += SqlTableDependency_Changed;
            _tableDependency.OnError   += SqlTableDependency_OnError;
            _tableDependency.Start();
        }
Example #22
0
        public void TaskCancellationTest()
        {
            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, mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                tableDependency.Stop();

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

            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #23
0
        public void Test()
        {
            var namingToUse = "CustomNaming";

            var mapper = new ModelToTableMapper <NoDisposeAndRestartWithSameObjectsTestSqlServerModel>();

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

            RunFirstTime(namingToUse);
            Thread.Sleep(3 * 60 * 1000);

            using (var tableDependency = new SqlTableDependency <NoDisposeAndRestartWithSameObjectsTestSqlServerModel>(ConnectionString, TableName, mapper, true, namingToUse))
            {
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                Assert.AreEqual(tableDependency.DataBaseObjectsNamingConvention, namingToUse);

                Thread.Sleep(1 * 25 * 1000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(1 * 60 * 1000);
            }

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(ConnectionString, namingToUse));
            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);
        }
Example #24
0
        public void UpdateOneInterestedColumn()
        {
            SqlTableDependency <ABCTableModel> tableDependency = null;
            string naming = null;

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

                tableDependency            = new SqlTableDependency <ABCTableModel>(_connectionString, TableName, mapper);
                tableDependency.OnChanged += TableDependency_Changed1;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent1);
                t.Start();
                t.Wait(20000);
            }
            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(SqlServerHelper.AreAllDbObjectDisposed(_connectionString, naming));
        }
Example #25
0
        public void EventForAllColumnsTest()
        {
            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, mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(500);

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

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

            Assert.AreEqual(_counter, 0);
            Assert.IsTrue(base.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(base.CountConversationEndpoints(naming) == 0);
        }
Example #26
0
        public static IModelToTableMapper <T> GetModelMapperFromColumnDataAnnotation()
        {
            var modelPropertyInfosWithColumnAttribute = typeof(T)
                                                        .GetProperties(BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public)
                                                        .Where(x => CustomAttributeExtensions.IsDefined((MemberInfo)x, typeof(ColumnAttribute), false))
                                                        .ToArray();

            if (!modelPropertyInfosWithColumnAttribute.Any())
            {
                return(null);
            }

            var mapper = new ModelToTableMapper <T>();

            foreach (var propertyInfo in modelPropertyInfosWithColumnAttribute)
            {
                var attribute    = propertyInfo.GetCustomAttribute(typeof(ColumnAttribute));
                var dbColumnName = ((ColumnAttribute)attribute)?.Name;
                if (dbColumnName != null && mapper.GetMapping(dbColumnName) != null)
                {
                    throw new ModelToTableMapperException("Duplicate mapping for column " + dbColumnName);
                }

                mapper.AddMapping(propertyInfo, dbColumnName);
            }

            return(mapper);
        }
        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);
        }
Example #28
0
        private static void Main()
        {
            // Get Connection string
            var connectionString = ConfigurationManager.ConnectionStrings["SqlServer2008 Test_User"].ConnectionString;

            // Because our model has a property that does not match table column name, we need a mapper C# Model PROPERTY <--> Database Table Column Name
            var mapper = new ModelToTableMapper <Product>();

            mapper.AddMapping(c => c.ItemsInStock, "Quantity");

            // Define WHERE filter specifing the WHERE condition
            // We also pass the mapper defined above as last contructor's parameter
            Expression <Func <Product, bool> > expression     = p => (p.CategoryId == (int)CategorysEnum.Food || p.CategoryId == (int)CategorysEnum.Drink) && p.ItemsInStock <= 10;
            ITableDependencyFilter             whereCondition = new SqlTableDependencyFilter <Product>(expression, mapper);

            // Create SqlTableDependency and pass filter condition, as weel as mapper
            using (var dep = new SqlTableDependency <Product>(connectionString, "Products", mapper: mapper, filter: whereCondition))
            {
                dep.OnChanged += Changed;
                dep.OnError   += OnError;
                dep.Start();

                Console.WriteLine("TableDependency, SqlTableDependency, SqlTableDependencyFilter");
                Console.WriteLine("Copyright (c) 2015-2018 Christian Del Bianco.");
                Console.WriteLine("All rights reserved." + Environment.NewLine);
                Console.WriteLine();
                Console.WriteLine("Waiting for receiving notifications...");
                Console.WriteLine("Press a key to stop");
                Console.ReadKey();
            }
        }
Example #29
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 * 5 * 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 #30
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            SanResturantEntities db = new SanResturantEntities();
            var li = db.SaleFoodOnline.ToList();

            DataTable      dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter("select * from SaleFoodOnline", new SqlConnection(_con));

            da.Fill(dt);

            var co = dt.Rows.Count;

            //var dep = new SqlTableDependency<SaleFoodOnline>(_con, "SaleFoodOnline");
            //dep.OnChanged += Changed;
            //dep.OnError += _dependency_OnError;
            //dep.Start();
            //btnStop.Enabled = true;

            var mapper = new ModelToTableMapper <SaleFoodOnline>();

            mapper.AddMapping(model => model.ID, "ID");
            _dependency            = new SqlTableDependency <SaleFoodOnline>(_con, "SaleFoodOnline", "dbo", mapper);
            _dependency.OnChanged += Changed;
            _dependency.OnError   += _dependency_OnError;
            _dependency.Start();
        }
        public void Test()
        {
            SqlTableDependency <EventForAllColumnsTestSqlServerModel> tableDependency = null;

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

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

                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.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(tableDependency.DataBaseObjectsNamingConvention));
            Assert.IsTrue(base.CountConversationEndpoints(tableDependency.DataBaseObjectsNamingConvention) == 0);
        }
Example #32
0
        public void BenginsendData()
        {
            // string constr = "Data Source=thunder;User Id=thunder;Password=thunder;";
            string constr = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=119.2.29.18)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=thunder)));User Id=thunder;Password=thunder;";
            string table = "STATIONSTATE";
            //try
            //{
            //    OracleDependency.Port = 49500;

            //    OracleConnection s = new OracleConnection(constr);
            //    s.Open();
            //    OracleDependency dep;
            //    //public static string sql = sqlSelect + "where employee_id < 200";
            //    OracleCommand cmd = new OracleCommand("select * from stationlastdata", s);
            //    //绑定OracleDependency实例与OracleCommand实例
            //    dep = new OracleDependency(cmd);
            //    //指定Notification是object-based还是query-based,前者表示表(本例中为tab_cn)中任意数据变化时都会发出Notification;后者提供更细粒度的Notification,例如可以在前面的sql语句中加上where子句,从而指定Notification只针对查询结果里的数据,而不是全表。
            //    dep.QueryBasedNotification = false;
            //    //是否在Notification中包含变化数据对应的RowId
            //    dep.RowidInfo = OracleRowidInfo.Include;
            //    //指定收到Notification后的事件处理方法
            //    dep.OnChange += new OnChangeEventHandler(OnNotificaton);
            //    //是否在一次Notification后立即移除此次注册
            //    cmd.Notification.IsNotifiedOnce = true;
            //    //此次注册的超时时间(秒),超过此时间,注册将被自动移除。0表示不超时。
            //    cmd.Notification.Timeout = 0;
            //    //False表示Notification将被存于内存中,True表示存于数据库中,选择True可以保证即便数据库重启之后,消息仍然不会丢失
            //    cmd.Notification.IsPersistent = true;
            //    //
            //    OracleDataReader odr = cmd.ExecuteReader();
            //}
            //catch (Exception ex)
            //{

            //    throw ex;
            //}

            try
            {
                OracleTableDependency<Item> tableDependency = null;
                OracleConnection s = new OracleConnection(constr); s.Open();
                var mapper = new ModelToTableMapper<Item>();
                mapper.AddMapping(c => c.NAME, "NAME");
                mapper.AddMapping(c => c.SID, "SID");
                mapper.AddMapping(c => c.DATETIME, "TIMEMARK");

                tableDependency = new OracleTableDependency<Item>(constr, table, mapper);
                tableDependency.OnChanged += Changed;
                tableDependency.Start();
                //naming = tableDependency.DataBaseObjectsNamingConvention;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }