public RowId AddRow(Row row)
        {
            AssertNotDisposed();

            if (Transaction.ReadOnly())
            {
                throw new Exception("Transaction is Read only.");
            }

            if (TableSource.IsReadOnly)
            {
                throw new InvalidOperationException("Can not add row - table is read-only.");
            }

            int rowNum;

            try {
                rowNum = TableSource.AddRow(row);
            } catch (Exception ex) {
                throw new InvalidOperationException(
                          String.Format("Unknown error when adding a row to the table '{0}'.", TableInfo.TableName), ex);
            }

            row.SetRowNumber(rowNum);

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.

            EventRegistry.Register(new TableRowEvent(TableId, rowNum, TableRowEventType.Add));

            return(new RowId(TableId, rowNum));
        }
        public void UpdateRow(Row row)
        {
            AssertNotDisposed();

            if (Transaction.ReadOnly())
            {
                throw new Exception("Transaction is Read only.");
            }

            // Check this isn't a Read only source
            if (TableSource.IsReadOnly)
            {
                throw new InvalidOperationException("Can not update row - table is read-only.");
            }

            if (row.RowId.IsNull)
            {
                throw new ArgumentException("The ROWID cannot be null in an update.");
            }

            if (row.RowId.TableId != TableId)
            {
                throw new ArgumentException("The row was not created from this table.");
            }

            var rowNum = row.RowId.RowNumber;

            if (rowNum < 0)
            {
                throw new ArgumentException("The number part of the ROWID is invalid.");
            }

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.
            EventRegistry.Register(new TableRowEvent(TableId, rowNum, TableRowEventType.UpdateRemove));

            int newRowIndex;

            try {
                newRowIndex = TableSource.AddRow(row);
            } catch (IOException e) {
                throw new InvalidOperationException("IO Error: " + e.Message, e);
            }

            row.SetRowNumber(newRowIndex);

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.
            EventRegistry.Register(new TableRowEvent(TableId, newRowIndex, TableRowEventType.UpdateAdd));
        }
        public bool RemoveRow(RowId rowId)
        {
            AssertNotDisposed();

            if (rowId.IsNull)
            {
                throw new ArgumentNullException("rowId");
            }

            if (rowId.TableId != TableId)
            {
                throw new ArgumentException("The table part of the ROWID is not this table.");
            }
            if (rowId.RowNumber < 0)
            {
                throw new ArgumentException("The number part of the ROWID is not valid for remove.");
            }

            if (Transaction.ReadOnly())
            {
                throw new Exception("Transaction is Read only.");
            }

            // Check this isn't a Read only source
            if (TableSource.IsReadOnly)
            {
                throw new InvalidOperationException("Can not remove row - table is Read only.");
            }

            // NOTE: This must <b>NOT</b> call 'RemoveRow' in TableSource.
            //   We do not want to delete a row permanently from the underlying
            //   file because the transaction using this data source may yet decide
            //   to roll back the change and not delete the row.

            // Note this doesn't need to be synchronized because we are exclusive on
            // this table.
            EventRegistry.Register(new TableRowEvent(rowId.TableId, rowId.RowNumber, TableRowEventType.Remove));

            return(true);
        }
Exemple #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            const string topic = "build.workshop.something";

            services.AddControllersWithViews();

            services.AddTransient <EventHandlerFactory>();
            services.AddTransient <IEventHandler <WorkshopCreated>, WorkshopCreatedHandler>();

            var eventRegistry = new EventRegistry();

            services.AddSingleton <EventRegistry>(eventRegistry);

            eventRegistry
            .Register <WorkshopCreated>("workshop_created", topic);

            services.AddTransient <KafkaConfiguration>();
            services.AddTransient <KafkaConsumerFactory>();
            services.AddTransient <KafkaProducerFactory>();
            services.AddHostedService <KafkaConsumer>();
            services.AddHostedService <KafkaProducer>();
        }
Exemple #5
0
    private void RegisterHooks()
    {
        eventRegistry?.UnregisterAll();
        eventRegistry = new EventRegistry();
        //interrupt if welder turns off
        if (welder)
        {
            eventRegistry.Register(welder.OnWelderOffServer, OnWelderOff);
        }

        if (startProgressInfo.Target.IsObject)
        {
            //if targeting an object, interrupt if object moves away
            eventRegistry.Register(startProgressInfo.Target.Target.OnLocalPositionChangedServer, OnLocalPositionChanged);

            //interrupt if target is despawned
            eventRegistry.Register(startProgressInfo.Target.Target.OnDespawnedServer, OnDespawned);
        }
        //interrupt if active hand slot changes
        var activeSlot = playerScript.DynamicItemStorage?.GetActiveHandSlot();

        eventRegistry.Register(activeSlot?.OnSlotContentsChangeServer, OnSlotContentsChanged);
        usedSlot = activeSlot;
        //interrupt if cuffed
        eventRegistry.Register(playerScript.playerMove.OnCuffChangeServer, OnCuffChange);
        //interrupt if slipped
        eventRegistry.Register(playerScript.registerTile.OnSlipChangeServer, OnSlipChange);
        //interrupt if conscious state changes
        eventRegistry.Register(playerScript.playerHealth.OnConsciousStateChangeServer, OnConsciousStateChange);
        initialConsciousState = playerScript.playerHealth.ConsciousState;
        //interrupt if player moves at all
        eventRegistry.Register(playerScript.registerTile.OnLocalPositionChangedServer, OnLocalPositionChanged);
        //interrupt if player turns away and turning is not allowed
        eventRegistry.Register(playerScript.playerDirectional.OnDirectionChange, OnDirectionChanged);
        initialDirection = playerScript.playerDirectional.CurrentDirection;
        //interrupt if tile is on different matrix and either matrix moves / rotates
        if (crossMatrix)
        {
            if (startProgressInfo.Target.TargetMatrixInfo.MatrixMove != null)
            {
                eventRegistry.Register(startProgressInfo.Target.TargetMatrixInfo.MatrixMove.MatrixMoveEvents.OnStartMovementServer, OnMatrixStartMove);
                eventRegistry.Register(startProgressInfo.Target.TargetMatrixInfo.MatrixMove.MatrixMoveEvents.OnRotate, OnMatrixRotate);
            }

            var performerMatrix = playerScript.registerTile.Matrix;
            if (performerMatrix.MatrixMove != null)
            {
                eventRegistry.Register(performerMatrix.MatrixMove.MatrixMoveEvents.OnStartMovementServer, OnMatrixStartMove);
                eventRegistry.Register(performerMatrix.MatrixMove.MatrixMoveEvents.OnRotate, OnMatrixRotate);
            }
        }
    }
Exemple #6
0
 private void RegisterEvent(TableRowEvent rowEvent)
 {
     EventRegistry.Register(rowEvent);
     Transaction.Context.OnEvent(rowEvent);
 }