Esempio n. 1
0
        public void EventSimplyComesBackTest()
        {
            var exception = (Exception)null;
            var triggered = false;

            using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered = e.Name == "test" && e.Counts == 1;
                };
                @event.Open();
                @event.QueueEvents("test");
                using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'test'; end";
                    cmd.ExecuteNonQuery();
                    Thread.Sleep(2000);
                }
                Assert.IsNull(exception);
                Assert.IsTrue(triggered);
            }
        }
Esempio n. 2
0
        public void CancelTest()
        {
            var exception = (Exception)null;
            var triggered = 0;

            using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered++;
                };
                @event.Open();
                @event.QueueEvents("test");
                using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'test'; end";
                    cmd.ExecuteNonQuery();
                    Thread.Sleep(2000);
                }
                @event.CancelEvents();
                using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'test'; end";
                    cmd.ExecuteNonQuery();
                    Thread.Sleep(2000);
                }
                Assert.IsNull(exception);
                Assert.AreEqual(1, triggered);
            }
        }
Esempio n. 3
0
        public async Task NoEventsAfterDispose()
        {
            var triggered = 0;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered++;
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "test" });

                Thread.Sleep(2000);
            }
            Thread.Sleep(2000);
            await using (var cmd = Connection.CreateCommand())
            {
                cmd.CommandText = "execute block as begin post_event 'test'; end";
                await cmd.ExecuteNonQueryAsync();

                Thread.Sleep(2000);
            }
            Assert.AreEqual(0, triggered);
        }
Esempio n. 4
0
        public async Task ProperCountsSingleTest()
        {
            var exception = (Exception)null;
            var triggered = false;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered = e.Name == "test" && e.Counts == 5;
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "test" });

                await using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'test'; post_event 'test'; post_event 'test'; post_event 'test'; post_event 'test'; end";
                    await cmd.ExecuteNonQueryAsync();

                    Thread.Sleep(2000);
                }
                Assert.IsNull(exception);
                Assert.IsTrue(triggered);
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            try
            {
                FbConnectionStringBuilder cs = new FbConnectionStringBuilder();
                cs.DataSource = "localhost";
                cs.Database   = @"E:\Samples\Tempo2012MVVM\Tempo2012\Tempo2012.UI.WPF\bin\Debug\data\TEMPO2012.fdb";
                cs.UserID     = "SYSDBA";
                cs.Password   = "******";
                cs.Charset    = "UTF8";

                connection = new FbConnection(cs.ToString());
                connection.Open();

                FbRemoteEvent revent = new FbRemoteEvent(connection);
                revent.AddEvents(new string[] { "acc_insert", "acc_update", });

                // Add callback to the Firebird events
                revent.RemoteEventCounts += new FbRemoteEventEventHandler(EventCounts);

                // Queue events
                revent.QueueEvents();

                Console.ReadLine();
                connection.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
 public void DoubleQueueingTest()
 {
     using (var @event = new FbRemoteEvent(Connection.ConnectionString))
     {
         Assert.DoesNotThrow(() => @event.QueueEvents("test"));
         Assert.Throws <InvalidOperationException>(() => @event.QueueEvents("test"));
     }
 }
Esempio n. 7
0
        public async Task DoubleQueueingTest()
        {
            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                await @event.OpenAsync();

                Assert.DoesNotThrowAsync(() => @event.QueueEventsAsync(new[] { "test" }));
                Assert.ThrowsAsync <InvalidOperationException>(() => @event.QueueEventsAsync(new[] { "test" }));
            }
        }
Esempio n. 8
0
 static void FirebirdEventListener(string connectionString)
 {
     using (var events = new FbRemoteEvent(connectionString))
     {
         events.RemoteEventCounts += (sender, e) => Console.WriteLine($"Event: {e.Name} | Counts: {e.Counts}");
         events.RemoteEventError  += (sender, e) => Console.WriteLine($"ERROR: {e.Error}");
         events.QueueEvents("NEWFOOBARD_POSTEVENT", "OtherEvent");
         Console.WriteLine("Listening...");
         Console.ReadLine();
     }
 }
Esempio n. 9
0
        public void InitConnection(string serverAddr)
        {
            _serverAddr = serverAddr;
            strConn     = "User=sysdba;Password=masterkey;Database=d:/anprdb/gbuanpr_geoje.fdb;Server=" + serverAddr + ";Port=3050";
            conn        = new FbConnection(strConn);
            conn.Open();
            fbEvent = new FbRemoteEvent(conn);
            fbEvent.AddEvents(new string[] { "item_inserted" });
            fbEvent.RemoteEventCounts += new EventHandler <FbRemoteEventEventArgs>(fbEvent_RemoteEventCounts);
            fbEvent.QueueEvents();

            dbReadThread = new Thread(DbReadThreadFunction);
        }
Esempio n. 10
0
        public EventsForm(Form parent, DBRegistrationClass dbReg)
        {
            InitializeComponent();
            this.MdiParent = parent;
            _dbReg         = dbReg;

            _localNotify.Notify.OnRaiseErrorHandler += Notify_OnRaiseErrorHandler;
            _localNotify.Notify.OnRaiseInfoHandler  += Notify_OnRaiseInfoHandler;

            string cn = ConnectionStrings.Instance().MakeConnectionString(dbReg);

            revent = new FbRemoteEvent(cn);
            revent.RemoteEventCounts += Revent_RemoteEventCounts;   // new FbRemoteEventEventHandler(EventCounts);
        }
Esempio n. 11
0
 public override void StartListenEvents()
 {
     if (ConfigDb.ListenEvents)
     {
         base.StartListenEvents();
         if (conn.State != System.Data.ConnectionState.Open)
         {
             conn.Open();
         }
         remoteEvent = new FbRemoteEvent(conn, new string[] { "LOG_ALERT" });
         remoteEvent.RemoteEventCounts += new FbRemoteEventEventHandler(remoteEvent_RemoteEventCounts);
         remoteEvent.QueueEvents();
     }
 }
        public void NoExceptionWithDispose()
        {
            var exception = (Exception)null;

            using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.QueueEvents("test");
                Thread.Sleep(200);
            }
            Thread.Sleep(200);
            Assert.IsNull(exception);
        }
Esempio n. 13
0
        public void StartListening()
        {
            using (Logger.BeginScope(LoggerHelper.GetCaller()))
            {
                _remoteEvent?.Dispose();

                _remoteEvent = new FbRemoteEvent(ConnectionString);

                var events = _triggers.Select(item => item.EventName).ToList();
                _remoteEvent.QueueEvents(events.ToArray());
                _remoteEvent.RemoteEventCounts += OnDbEvent;

                var eventsStr = events.Aggregate("", (current, item) => current + $"{item} ");
                Logger.LogDebug($"Listening events: {eventsStr}");
            }
        }
Esempio n. 14
0
        public async Task EventNameSeparateSelectionTest()
        {
            var exception  = (Exception)null;
            var triggeredA = false;
            var triggeredB = false;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    switch (e.Name)
                    {
                    case "a":
                        triggeredA = e.Counts == 1;
                        break;

                    case "b":
                        triggeredB = e.Counts == 1;
                        break;
                    }
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "a", "b" });

                await using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'b'; end";
                    await cmd.ExecuteNonQueryAsync();

                    cmd.CommandText = "execute block as begin post_event 'a'; end";
                    await cmd.ExecuteNonQueryAsync();

                    Thread.Sleep(2000);
                }
                Assert.IsNull(exception);
                Assert.IsTrue(triggeredA);
                Assert.IsTrue(triggeredB);
            }
        }
Esempio n. 15
0
        public async Task NoExceptionWithDispose()
        {
            var exception = (Exception)null;

            await using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                await @event.OpenAsync();

                await @event.QueueEventsAsync(new[] { "test" });

                Thread.Sleep(2000);
            }
            Thread.Sleep(2000);
            Assert.IsNull(exception);
        }
Esempio n. 16
0
 public override void StopListenEvents()
 {
     if (ConfigDb.ListenEvents)
     {
         if (remoteEvent != null)
         {
             try
             {
                 remoteEvent.CancelEvents();
             }
             catch
             {
             }
             remoteEvent = null;
         }
         conn.Close();
         base.StopListenEvents();
     }
 }
Esempio n. 17
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Inizini();
            FbConnectionStringBuilder cs = new FbConnectionStringBuilder();

            cs.DataSource = "localhost";
            cs.Database   = "C:/trilogis/trilogis.fb20";
            cs.UserID     = userdb;
            cs.Password   = passdb;
            cs.Charset    = "NONE";
            FbConnection connection = new FbConnection(cs.ToString());

            connection.Open();
            FbRemoteEvent revent = new FbRemoteEvent(connection);

            revent.AddEvents(new string[] { "pronto" });
            revent.RemoteEventCounts += new FbRemoteEventEventHandler(EventCounts);
            revent.QueueEvents();
        }
        public void NoEventsAfterDispose()
        {
            var triggered = 0;

            using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventCounts += (sender, e) =>
                {
                    triggered++;
                };
                @event.QueueEvents("test");
                Thread.Sleep(200);
            }
            Thread.Sleep(200);
            using (var cmd = Connection.CreateCommand())
            {
                cmd.CommandText = "execute block as begin post_event 'test'; end";
                cmd.ExecuteNonQuery();
                Thread.Sleep(200);
            }
            Assert.AreEqual(0, triggered);
        }
Esempio n. 19
0
    static void Main(string[] args)
    {
        FbConnectionStringBuilder cs = new FbConnectionStringBuilder();

        cs.DataSource = "localhost";
        cs.Database   = @"TESTDATABASE.FDB";
        cs.UserID     = "SYSDBA";
        cs.Password   = "******";
        cs.Charset    = "NONE";
        cs.Pooling    = false;

        FbConnection connection = new FbConnection(cs.ToString());

        connection.Open();

        FbRemoteEvent revent = new FbRemoteEvent(connection);

        revent.AddEvents(new string[] { "new_order" });

        // Add callback to the Firebird events
        revent.RemoteEventCounts += new FbRemoteEventEventHandler(EventCounts);

        // Queue events
        revent.QueueEvents();

        string sql = "EXECUTE BLOCK AS BEGIN POST_EVENT 'new_order'; END";

        FbCommand command = new FbCommand(sql, connection);

        for (int i = 0; i < 5; i++)
        {
            command.ExecuteNonQuery();
        }

        System.Threading.Thread.Sleep(2000);
        connection.Close();
        Console.ReadLine();
    }
        public void EventNameTogetherSelectionTest()
        {
            var exception  = (Exception)null;
            var triggeredA = false;
            var triggeredB = false;

            using (var @event = new FbRemoteEvent(Connection.ConnectionString))
            {
                @event.RemoteEventError += (sender, e) =>
                {
                    exception = e.Error;
                };
                @event.RemoteEventCounts += (sender, e) =>
                {
                    switch (e.Name)
                    {
                    case "a":
                        triggeredA = e.Counts == 1;
                        break;

                    case "b":
                        triggeredB = e.Counts == 1;
                        break;
                    }
                };
                @event.QueueEvents("a", "b");
                using (var cmd = Connection.CreateCommand())
                {
                    cmd.CommandText = "execute block as begin post_event 'b'; post_event 'a'; end";
                    cmd.ExecuteNonQuery();
                    Thread.Sleep(200);
                }
                Assert.IsNull(exception);
                Assert.IsTrue(triggeredA);
                Assert.IsTrue(triggeredB);
            }
        }
Esempio n. 21
0
 public EventsListener(IConnectionOptions builder, params string[] events)
 {
     _remoteEvent = new FbRemoteEvent(builder.ToInsecureConnectionString());
     _remoteEvent.RemoteEventCounts += OnRemoteEvent;
     _remoteEvent.QueueEvents(events);
 }
Esempio n. 22
0
 public static void IniciarEscuta()
 {
     events = new FbRemoteEvent("database = localhost:C:\\Aplicacoes\\BD\\BASE.FDB; user = sysdba; password = masterkey");
     events.QueueEvents("ATUALIZAPROGRESSO", "PROCESSOCONCLUIDO");
 }