Exemple #1
0
        public void CheckDateTypeTest()
        {
            OracleTableDependency <DataTimeModel> tableDependency = null;

            try
            {
                tableDependency            = new OracleTableDependency <DataTimeModel>(ConnectionString, TableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.Start();
                Thread.Sleep(5000);

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

            Assert.AreEqual(Truncate(timeStampColumn.Value, TimeSpan.FromSeconds(2)), Truncate(timeStampColumnReturned.Value, TimeSpan.FromSeconds(2)));
            Assert.AreEqual(dateColum.Date, dateColumReturned.Date);
            Assert.AreEqual(Truncate(timeStampWithTimeZone.DateTime, TimeSpan.FromMilliseconds(1)), Truncate(timeStampWithTimeZoneReturned.DateTime, TimeSpan.FromMilliseconds(1)));
            Assert.AreEqual(Truncate(timeStampWithLocalTimeZone.Value, TimeSpan.FromMilliseconds(1)), Truncate(timeStampWithLocalTimeZoneReturned.Value, TimeSpan.FromMilliseconds(1)));
            Assert.AreEqual(intervalDayToSecondColumn.Value, intervalDayToSecondColumnReturned.Value);
            Assert.AreEqual(intervalYearToMonthColumn.Value, intervalYearToMonthColumnReturned.Value);
        }
        public void CheckTypeTest()
        {
            OracleTableDependency <FloatAndIntegerTypesModel> tableDependency = null;

            try
            {
                tableDependency            = new OracleTableDependency <FloatAndIntegerTypesModel>(ConnectionString, TableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.OnError   += this.TableDependency_OnError;
                tableDependency.Start();
                Thread.Sleep(1000);

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

            Assert.AreEqual(GotModel.FLOATCOLUMN, SetModel.FLOATCOLUMN);
            Assert.AreEqual(GotModel.FLOATCOLUMN, SetModel.FLOATCOLUMN);
            Assert.AreEqual(GotModel.NUMBERCOLUMN, SetModel.NUMBERCOLUMN);
        }
Exemple #3
0
        public static void ClassInitialize(TestContext testContext)
        {
            var random = ReverseString(DateTime.Now.Ticks.ToString());

            NamingToUse += GetColumnName(Convert.ToUInt16(random.Substring(1, 1)));
            NamingToUse += GetColumnName(Convert.ToUInt16(random.Substring(2, 1)));
            NamingToUse += GetColumnName(Convert.ToUInt16(random.Substring(3, 1)));
            NamingToUse += GetColumnName(Convert.ToUInt16(random.Substring(4, 1)));

            OracleHelper.DropTable(ConnectionString, TableName);
            using (var connection = new OracleConnection(ConnectionString))
            {
                connection.Open();
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = $"CREATE TABLE {TableName} (NAME varchar2(50))";
                    command.ExecuteNonQuery();
                }
            }

            using (var tableDependency = new OracleTableDependency <GetMessageAfterRestartTestOracleModel>(
                       ConnectionString,
                       TableName,
                       mapper: null,
                       updateOf: (List <string>)null,
                       automaticDatabaseObjectsTeardown: false,
                       namingConventionForDatabaseObjects: NamingToUse))
            {
                tableDependency.OnChanged += (object sender, RecordChangedEventArgs <GetMessageAfterRestartTestOracleModel> e) => { };
                tableDependency.Start(60, 120);
            }

            Thread.Sleep(1 * 60 * 1000);
        }
        public void CheckTest()
        {
            OracleTableDependency <XmlAModel> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <XmlAModel>();
                mapper.AddMapping(c => c.XmlColumn, "XMLCOLUMN");

                tableDependency            = new OracleTableDependency <XmlAModel>(ConnectionString, TableName, mapper);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.Start();
                Thread.Sleep(1000);

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


            var expectedXml = new XmlDocument();

            expectedXml.LoadXml(XML);
            var gotXml = new XmlDocument();

            gotXml.LoadXml(_xml);

            Assert.AreEqual(gotXml.InnerXml, expectedXml.InnerXml);
        }
        public void EventForSpecificColumnsTest()
        {
            OracleTableDependency <MultiDmlOperationsTesOracleModel> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <MultiDmlOperationsTesOracleModel>();
                mapper.AddMapping(c => c.Name, "Long Description");

                tableDependency            = new OracleTableDependency <MultiDmlOperationsTesOracleModel>(ConnectionString, TableName, mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();

                Thread.Sleep(5000);

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

            Assert.AreEqual(_counter, 9);
            Assert.AreEqual(_deletedValue, "XXXXXX");
        }
        public void CheckTest2()
        {
            OracleTableDependency <Varchar2Model> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <Varchar2Model>();
                mapper.AddMapping(c => c.Name, "COLUMN3");

                tableDependency            = new OracleTableDependency <Varchar2Model>(ConnectionString, TableName, mapper);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.Start();
                Thread.Sleep(1000);

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

            Assert.AreEqual("stringa ccia", _name);
        }
Exemple #7
0
        public void Test2()
        {
            OracleTableDependency <NullMessageContentTestOracleModel> tableDependency = null;
            string naming = null;

            try
            {
                var mapper = new ModelToTableMapper <NullMessageContentTestOracleModel>();
                mapper.AddMapping(c => c.Description, "Long Description");

                tableDependency            = new OracleTableDependency <NullMessageContentTestOracleModel>(ConnectionString, TableName, mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;
                Thread.Sleep(1000);

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

            Assert.IsTrue(_id > 0);
            Assert.IsTrue(string.IsNullOrWhiteSpace(_name));
            Assert.IsTrue(string.IsNullOrWhiteSpace(_description));
            Assert.IsTrue(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming));
        }
Exemple #8
0
        public void Test()
        {
            var namingToUse = "AAAMOSGTRO".ToUpper();

            var mapper = new ModelToTableMapper <TestOracleModel>();

            mapper.AddMapping(c => c.Description, "Long Description").AddMapping(c => c.Name, "NAME");

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

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

                Thread.Sleep(1 * 25 * 1000);

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

            Assert.IsTrue(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, namingToUse));
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.Name, _checkValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.Description, _checkValues[ChangeType.Insert.ToString()].Item1.Description);
        }
        public void TaskCancellationTest()
        {
            string naming = null;
            OracleTableDependency <TaskCancellationTestOracleModel> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <TaskCancellationTestOracleModel>();
                mapper.AddMapping(c => c.Name, "Long Description");

                tableDependency            = new OracleTableDependency <TaskCancellationTestOracleModel>(ConnectionString, TableName, mapper);
                tableDependency.OnChanged += (sender, e) => { };
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(500);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            var areAllDbObjectDisposed = OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming);

            Assert.IsTrue(areAllDbObjectDisposed == true);
        }
        public void EventForAllColumnsTest()
        {
            OracleTableDependency <AAAItem2> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency            = new OracleTableDependency <AAAItem2>(ConnectionString, TableName);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(1000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(2000);
            }
            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(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming));
        }
        public void Test()
        {
            OracleTableDependency <DataAnnotationTestOracleModel> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency            = new OracleTableDependency <DataAnnotationTestOracleModel>(ConnectionString);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                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.Description, CheckValues[ChangeType.Insert.ToString()].Item1.Description);

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

            Assert.IsTrue(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming));
        }
Exemple #12
0
        private void RunFirstTime(string namingToUse)
        {
            var mapper = new ModelToTableMapper <TestOracleModel>();

            mapper.AddMapping(c => c.Description, "Long Description").AddMapping(c => c.Name, "NAME");

            var tableDependency = new OracleTableDependency <TestOracleModel>(ConnectionString, TableName, mapper, false, namingToUse);

            tableDependency.OnChanged += TableDependency_Changed;
            tableDependency.Start(60, 120);
        }
        static void Main()
        {
            DropAndCreateTable(ConnectionString, "PRODUCTS");

            using (var tableDependency = new OracleTableDependency <Product>(ConnectionString, TableName))
            {
                tableDependency.OnChanged += Changed;
                tableDependency.OnError   += tableDependency_OnError;

                tableDependency.Start();
                Console.WriteLine(@"Waiting for receiving notifications: change some records in the table...");
                Console.WriteLine(@"Press a key to exit");
                Console.ReadKey();
            }
        }
        public void Test()
        {
            OracleTableDependency <Item5> tableDependency = null;
            string naming = null;

            var mapper = new ModelToTableMapper <Item5>();

            mapper.AddMapping(c => c.Infos, "More Info");

            var updateOf = new List <string>();

            updateOf.Add("More Info");

            try
            {
                tableDependency            = new OracleTableDependency <Item5>(ConnectionString, TableName, mapper, updateOf);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                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()].Name, "Pizza MERGHERITA");
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Infos, "Pizza MERGHERITA");

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Name, "Pizza MERGHERITA");
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Infos, "FUNGHI PORCINI");

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Name, "Pizza");
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Infos, "FUNGHI PORCINI");

            Assert.IsTrue(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming));
        }
Exemple #15
0
        public void Test()
        {
            OracleTableDependency <EventForAllColumnsTestOracleModel> tableDependency = null;
            string naming = null;

            try
            {
                var mapper = new ModelToTableMapper <EventForAllColumnsTestOracleModel>();
                mapper.AddMapping(c => c.Description, "Long Description");

                tableDependency            = new OracleTableDependency <EventForAllColumnsTestOracleModel>(ConnectionString, TableName, mapper);
                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, 3);

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

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

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

            Assert.IsTrue(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming));
        }
Exemple #16
0
        public void All()
        {
            OracleTableDependency <TriggerTypeTestOracleModel> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency = new OracleTableDependency <TriggerTypeTestOracleModel>(
                    ConnectionString,
                    TableName,
                    null,
                    (IList <string>)null,
                    DmlTriggerType.All,
                    true);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(1000);

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

            Assert.AreEqual(_counter, 3);

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

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

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

            Assert.IsTrue(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming));
        }
        static void Main()
        {
            DropAndCreateTable(ConnectionString, TableName);

            var mapper = new ModelToTableMapper <DatabaseObjectCleanUpTestOracleModel>();

            mapper.AddMapping(c => c.Description, "Long Description");

            using (var tableDependency = new OracleTableDependency <DatabaseObjectCleanUpTestOracleModel>(ConnectionString, TableName, mapper))
            {
                tableDependency.OnChanged    += Changed;
                tableDependency.TraceLevel    = TraceLevel.Verbose;
                tableDependency.TraceListener = new TextWriterTraceListener(File.Create("c:\\temp\\output.txt"));
                tableDependency.OnError      += tableDependency_OnError;

                tableDependency.Start();
                Console.WriteLine(@"Waiting for receiving notifications: change some records in the table...");
                Console.WriteLine(@"Press a key to exit");
                Console.ReadKey();
            }
        }
        public void CheckTypeTest()
        {
            OracleTableDependency <RAWTypeModel> tableDependency = null;

            try
            {
                tableDependency            = new OracleTableDependency <RAWTypeModel>(ConnectionString, TableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.OnError   += TableDependency_OnError;
                tableDependency.Start();
                Thread.Sleep(1000);

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

            Assert.AreEqual(GetString(SetModel.RAWCOLUMN), GetString(GotModel.RAWCOLUMN));
        }
Exemple #19
0
        public void CheckTypeTest2()
        {
            OracleTableDependency <NVarchar2CharModel> tableDependency = null;

            try
            {
                tableDependency            = new OracleTableDependency <NVarchar2CharModel>(ConnectionString, TableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.OnError   += TableDependency_OnError;
                tableDependency.Start();
                Thread.Sleep(1000);

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

            Assert.AreEqual(_gotString, STRING_TEST_2);
        }
        public void Test()
        {
            var namingToUse = "AAA_SAME_OBJ".ToUpper();

            var mapper = new ModelToTableMapper <DisposeAndRestartWithSameObjectsTestOracleModel>();

            mapper.AddMapping(c => c.Description, "Long Description");

            using (var tableDependency = new OracleTableDependency <DisposeAndRestartWithSameObjectsTestOracleModel>(ConnectionString, TableName, mapper, false))
            {
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                namingToUse = tableDependency.DataBaseObjectsNamingConvention;
                Thread.Sleep(1 * 25 * 1000);
            }

            using (var tableDependency = new OracleTableDependency <DisposeAndRestartWithSameObjectsTestOracleModel>(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(2 * 60 * 1000);
            }

            Assert.IsTrue(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, namingToUse));
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.Name, _checkValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.Description, _checkValues[ChangeType.Insert.ToString()].Item1.Description);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.Name, _checkValues[ChangeType.Update.ToString()].Item1.Name);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.Description, _checkValues[ChangeType.Update.ToString()].Item1.Description);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.Name, _checkValues[ChangeType.Delete.ToString()].Item1.Name);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.Description, _checkValues[ChangeType.Delete.ToString()].Item1.Description);
        }
Exemple #21
0
        public void MergeTest()
        {
            OracleTableDependency <MargeTestOracleModel> tableDependency = null;

            try
            {
                tableDependency            = new OracleTableDependency <MargeTestOracleModel>(ConnectionString, TarghetTableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.OnError   += this.TableDependency_OnError;
                tableDependency.Start();
                Thread.Sleep(1000);

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

            Assert.AreEqual(this._insertedValues.Quantity, 100);
            Assert.AreEqual(this._modifiedValues.Quantity, 200);
        }
Exemple #22
0
        public void Test()
        {
            OracleTableDependency <AAA_Item3> tableDependency = null;
            string naming = null;

            try
            {
                UpdateOfModel <AAA_Item3> updateOF = new UpdateOfModel <AAA_Item3>();
                updateOF.Add(model => model.FamilyName);

                tableDependency            = new OracleTableDependency <AAA_Item3>(ConnectionString, updateOF);
                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, 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(OracleHelper.AreAllDbObjectsDisposed(ConnectionString, naming));
        }
Exemple #23
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;
            }
        }
 public void StartTableWatcher()
 {
     _dependency.Start();
 }