示例#1
0
文件: Mailbox.cs 项目: itadapter/nfx
 public CRUDSubscriptionEvent(EventType type, Schema schema, Row row, DataTimeStamp version)
 {
     Type = type;
       Schema = schema;
       Row = row;
       Version = version;
 }
示例#2
0
 public CRUDSubscriptionEvent(EventType type, Schema schema, Row row, DataTimeStamp version)
 {
     Type    = type;
     Schema  = schema;
     Row     = row;
     Version = version;
 }
 public ErlCRUDQueryExecutionContext(ErlDataStore store, ErlMbox erlMBox = null, DataTimeStamp? ts = null)
 {
     this.DataStore = store;
       ErlMailBox = erlMBox;
       SubscriptionTimestamp = ts;
 }
示例#4
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, new DataTimeStamp(ts));
              this.Mailbox.Deliver(this, data);
            }
            catch(Exception ie)
            {
              errors++;
              log(MessageType.Error, "prcs().forea(rTpl)", ie.ToMessageWithType(), ie);
            }
          }

          // TODO: Add error reporting to user
        }
        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)
      {
        log(MessageType.Error, "prcs().outcatch{}", err.ToMessageWithType(), err);
      }
    }