Exemple #1
0
 public IDictionary <string, string> ToDictionary()
 {
     return(new Dictionary <string, string>()
     {
         { nameof(EventID), EventID.ToString() },
         { nameof(EventType), EventType },
         { nameof(UserID), UserID },
         { nameof(SourceIPAddress), SourceIPAddress },
         { nameof(DataTimeStamp), DataTimeStamp.ToString() }
     });
 }
Exemple #2
0
        private void process(IQueable msg)
        {
            try
            {
                if (msg is ErlException)
                {
                    this.Mailbox.DeliverError(this, (ErlException)msg);
                    return;
                }
                var erlMsg = msg as ErlMsg;

                if (erlMsg == null)
                {
                    throw new ErlException("Invalid message type: " + msg.GetType());
                }

                var map     = ((ErlDataStore)Store).Map;
                var binding = new ErlVarBind();

                //{Schema, TS, ChangeType :: $d | $w, [{schema, Flds...}]} %% delete, write(upsert)
                //{Schema, TS, ChangeType :: $D | $C | $c, []}             %% Drop, Create, Clear
                if (erlMsg.Msg == null ||
                    !erlMsg.Msg.Match(SUBSCRIPTION_MSG_PATTERN, binding))
                {
                    return;
                }

                var schemaName = ((ErlAtom)binding[SCHEMA]).Value;
                var ts         = binding[TIMESTAMP].ValueAsLong;
                var op         = (char)((ErlByte)binding[TYPE]).Value;
                var rows       = ((ErlList)binding[ROWS]).Value;

                var schema = map.GetCRUDSchemaForName(schemaName);


                m_LastTimeStamp = new DataTimeStamp(ts);

                CRUDSubscriptionEvent.EventType etp;

                switch (op)
                {
                case 'd': etp = CRUDSubscriptionEvent.EventType.RowDelete; break;

                case 'c': etp = CRUDSubscriptionEvent.EventType.TableClear; break;

                case 'D': etp = CRUDSubscriptionEvent.EventType.TableDrop; break;

                case 'C': etp = CRUDSubscriptionEvent.EventType.TableCreate; break;

                default:  etp = CRUDSubscriptionEvent.EventType.RowUpsert; break;
                }

                if (rows.Count > 0)
                {
                    int errors = 0;
                    foreach (var rowTuple in rows.Cast <ErlTuple>())
                    {
                        try
                        {
                            var row  = map.ErlTupleToRow(schemaName, rowTuple, schema);
                            var data = new CRUDSubscriptionEvent(etp, schema, row, m_LastTimeStamp);
                            this.Mailbox.Deliver(this, data);
                        }
                        catch (Exception ie)
                        {
                            errors++;
                            log(ie);
                        }
                    }

                    // TODO: Add error reporting to user
                }
                else
                { //used to clear data, no rows are fetched
                    var data = new CRUDSubscriptionEvent(etp, schema, null, m_LastTimeStamp);
                    this.Mailbox.Deliver(this, data);
                }
            }
            catch (Exception err)
            {
                log(err);
            }
        }
Exemple #3
0
        private void process(IQueable msg)
        {
            try
            {
                if (msg is ErlException)
                {
                    this.Mailbox.DeliverError(this, (ErlException)msg);
                    return;
                }
                var erlMsg = msg as ErlMsg;

                if (erlMsg == null)
                {
                    throw new ErlException("Invalid message type: " + msg.GetType());
                }

                var map     = ((ErlDataStore)Store).Map;
                var binding = new ErlVarBind();

                //{Schema, TS, ChangeType :: $d | $w, [{schema, Flds...}]} %% delete, write(upsert)
                //{Schema, TS, ChangeType :: $D | $C | $c, []}             %% Drop, Create, Clear
                if (erlMsg.Msg == null ||
                    !erlMsg.Msg.Match(SUBSCRIPTION_MSG_PATTERN, binding))
                {
                    return;
                }

                var schemaName = ((ErlAtom)binding[SCHEMA]).Value;
                var ts         = binding[TIMESTAMP].ValueAsLong;
                var op         = (char)((ErlByte)binding[TYPE]).Value;
                var rows       = ((ErlList)binding[ROWS]).Value;

                var schema = map.GetCRUDSchemaForName(schemaName);


                m_LastTimeStamp = new DataTimeStamp(ts);

                CRUDSubscriptionEvent.EventType etp;

                switch (op)
                {
                case 'd': etp = CRUDSubscriptionEvent.EventType.RowDelete; break;

                case 'c': etp = CRUDSubscriptionEvent.EventType.TableClear; break;

                case 'D': etp = CRUDSubscriptionEvent.EventType.TableDrop; break;

                case 'C': etp = CRUDSubscriptionEvent.EventType.TableCreate; break;

                default:  etp = CRUDSubscriptionEvent.EventType.RowUpsert; break;
                }

                if (rows.Count > 0)
                {
                    foreach (var rowTuple in rows.Cast <ErlTuple>())
                    {
                        var row  = map.ErlTupleToRow(schemaName, rowTuple, schema);
                        var data = new CRUDSubscriptionEvent(etp, schema, row, new DataTimeStamp(ts));
                        this.Mailbox.Deliver(this, data);
                    }
                }
                else
                { //used to clear data, no rows are fetched
                    var data = new CRUDSubscriptionEvent(etp, schema, null, new DataTimeStamp(ts));
                    this.Mailbox.Deliver(this, data);
                }
            }
            catch (Exception err)
            {
                App.Log.Write(
                    new Log.Message
                {
                    Type      = Log.MessageType.Error,
                    Topic     = CoreConsts.ERLANG_TOPIC,
                    From      = "{0}.process()".Args(GetType().Name),
                    Text      = err.ToMessageWithType(),
                    Exception = err
                }
                    );
            }
        }