Exemplo n.º 1
0
        public TriggerNotification <T> To <T>()
        {
            var notify = new TriggerNotification <T>();

            notify.Pid       = Pid;
            notify.Condition = Condition;
            notify.Table     = Table;
            notify.Action    = Action;
            notify.Schema    = Schema;

            notify.EventData = EventData.CloneTo <T>();
            return(notify);
        }
Exemplo n.º 2
0
        protected override void _OnEvent(object sender, NpgsqlNotificationEventArgs npgsqlNotificationEventArgs)
        {
            var notifyObject = JSON.ToObject <NotificationObject>(npgsqlNotificationEventArgs.AdditionalInformation);

            var fqdn = $"{notifyObject.Schema}.{notifyObject.Table}";

            var notify = false;

            foreach (var s in _listenOnTables)
            {
                if (Wildcard.IsMatch(fqdn, s))
                {
                    notify = true;
                    break;
                }
            }

            if (!notify)
            {
                return;
            }


            Dictionary <string, object> returnObject = null;

            ObjectTable table;

            switch (_listenMode)
            {
            case ListenMode.TableEntryPrimaryKeys:
                returnObject = notifyObject.Data;
                break;

            case ListenMode.TableEntry:
                if (notifyObject.Action == TriggerAction.Delete)
                {
                    returnObject = notifyObject.Data;
                }
                else
                {
                    table = GetTable(notifyObject.Table);

                    returnObject = table.QueryByPrimaryKey(notifyObject.Data).CloneTo <Dictionary <string, object> >();
                }
                break;
            }


            var notifyObj = new TriggerNotification()
            {
                Pid       = npgsqlNotificationEventArgs.PID,
                Condition = npgsqlNotificationEventArgs.Condition,
                Schema    = notifyObject.Schema,
                Table     = notifyObject.Table,
                Action    = notifyObject.Action,
                EventData = returnObject
            };

            //Console.WriteLine(Json.ToJson(notifyObj, true));
            _tableNotificationSubject.OnNext(notifyObj);
        }
Exemplo n.º 3
0
        private void _OnEvent(object sender, NpgsqlNotificationEventArgs npgsqlNotificationEventArgs)
        {
            var notifyObject = JSON.ToObject <NotificationObject>(npgsqlNotificationEventArgs.AdditionalInformation);

            var fqdn = $"{notifyObject.Schema}.{notifyObject.Table}";

            var notify = false;

            foreach (var s in _listenOnTables)
            {
                var tablefqdn = $"{s.GetConnectionString().SchemaName}.{s.GetConnectionString().TableName}";
                if (Wildcard.IsMatch(fqdn, tablefqdn))
                {
                    notify = true;
                    break;
                }
            }

            if (!notify)
            {
                return;
            }

            var notifyObj = new TriggerNotification()
            {
                Pid       = npgsqlNotificationEventArgs.PID,
                Condition = npgsqlNotificationEventArgs.Condition,
                Schema    = notifyObject.Schema,
                Table     = notifyObject.Table,
                Action    = notifyObject.Action,
                EventData = notifyObject.Data
            };

            //Dictionary<string, object> returnObject = null;

            //var table = GetTable(notifyObject.Table);
            //switch (notifyObject.Mode)
            //{
            //    case ListenMode.TableEntryPrimaryKeys:
            //        returnObject = notifyObject.Data;
            //        break;
            //    case ListenMode.TableEntry:
            //        if (notifyObject.Action == TriggerAction.Delete) {
            //            returnObject = notifyObject.Data;
            //        } else {
            //            returnObject = table.QueryByPrimaryKey(notifyObject.Data).CloneTo<Dictionary<string, object>>();
            //        }
            //        break;
            //}


            //var notifyObj = new TriggerNotification()
            //{
            //    Pid = npgsqlNotificationEventArgs.PID,
            //    Condition = npgsqlNotificationEventArgs.Condition,
            //    Schema = notifyObject.Schema,
            //    Table = notifyObject.Table,
            //    Action = notifyObject.Action,
            //    EventData = returnObject
            //};

            _tableNotificationSubject.OnNext(notifyObj);
        }