private static void ProcessOpList(OpList opList) { foreach (var disconnectOp in opList.OfOpType <DisconnectOp>()) { Log.Information(disconnectOp.Reason); } }
private void CompleteCommands(OpList opList) { foreach (var op in opList.Ops) { switch (op.OpType) { case OpType.ReserveEntityIdsResponse: CompleteCommand(op.ReserveEntityIdsResponseOp); break; case OpType.CreateEntityResponse: CompleteCommand(op.CreateEntityResponseOp); break; case OpType.DeleteEntityResponse: CompleteCommand(op.DeleteEntityResponseOp); break; case OpType.EntityQueryResponse: CompleteCommand(op.EntityQueryResponseOp); break; case OpType.CommandResponse: CompleteCommand(op.CommandResponseOp); break; } } }
public static bool TryGetWorkerFlagChange(this OpList opList, string flagName, out string newValue) { newValue = string.Empty; var found = false; foreach (var op in opList.OfOpType <FlagUpdateOp>().Where(op => op.Name == flagName)) { newValue = op.Value; // Don't break early, ensure that the last received flag update is the one that's applied. found = true; } return(found); }
public void ProcessOpList(OpList opList) { foreach (var op in opList.OfOpType <ComponentUpdateOp>().OfComponent(componentId)) { if (!op.Update.SchemaData.HasValue || !getEvents(op.Update.SchemaData.Value, out var newEvents)) { continue; } foreach (var evt in newEvents) { eventBuffer.Enqueue(evt); } } }
public void ProcessOpList(OpList list) { Activated = ImmutableHashSet <EntityId> .Empty; Deactivated = ImmutableHashSet <EntityId> .Empty; foreach (var op in list.OfOpType <AddComponentOp>()) { Added(op); } foreach (var op in list.OfOpType <RemoveComponentOp>()) { Removed(op); } }
private Task StartBackgroundOpsGathering() { return(Task.Factory.StartNew(() => { // We have to resort to polling here since connection.GetOpList doesn't provide a means of cancellation try { while (!processOpsCts.Token.IsCancellationRequested) { if (GetConnectionStatusCode() != ConnectionStatusCode.Success) { break; } OpList opList; lock (connectionLock) { var rawOps = connection.GetOpList(1); if (rawOps.GetOpCount() == 0) { continue; } opList = new OpList(rawOps); } // NB: finish processing the OpList before adding it to the queue, since it will be Disposed on whatever thread is enumerating the ops collection. CompleteCommands(opList); ops.Add(opList); } } finally { ops.CompleteAdding(); } }, TaskCreationOptions.LongRunning)); }
public static IEnumerable <T> OfOpType <T>(this OpList ops) where T : struct { if (!TypeMaps.TryGetValue(typeof(T), out var opType)) { throw new ArgumentException($"{typeof(T).Name} is not a SpatialOS op type."); } foreach (var op in ops) { if (op.OpType != opType) { continue; } switch (opType) { case OpType.Disconnect: yield return(ReinterpretCast <DisconnectOp, T>(op.DisconnectOp)); break; case OpType.FlagUpdate: yield return(ReinterpretCast <FlagUpdateOp, T>(op.FlagUpdateOp)); break; case OpType.LogMessage: yield return(ReinterpretCast <LogMessageOp, T>(op.LogMessageOp)); break; case OpType.Metrics: yield return(ReinterpretCast <MetricsOp, T>(op.MetricsOp)); break; case OpType.CriticalSection: yield return(ReinterpretCast <CriticalSectionOp, T>(op.CriticalSectionOp)); break; case OpType.AddEntity: yield return(ReinterpretCast <AddEntityOp, T>(op.AddEntityOp)); break; case OpType.RemoveEntity: yield return(ReinterpretCast <RemoveEntityOp, T>(op.RemoveEntityOp)); break; case OpType.ReserveEntityIdsResponse: yield return(ReinterpretCast <ReserveEntityIdsResponseOp, T>(op.ReserveEntityIdsResponseOp)); break; case OpType.CreateEntityResponse: yield return(ReinterpretCast <CreateEntityResponseOp, T>(op.CreateEntityResponseOp)); break; case OpType.DeleteEntityResponse: yield return(ReinterpretCast <DeleteEntityResponseOp, T>(op.DeleteEntityResponseOp)); break; case OpType.EntityQueryResponse: yield return(ReinterpretCast <EntityQueryResponseOp, T>(op.EntityQueryResponseOp)); break; case OpType.AddComponent: yield return(ReinterpretCast <AddComponentOp, T>(op.AddComponentOp)); break; case OpType.RemoveComponent: yield return(ReinterpretCast <RemoveComponentOp, T>(op.RemoveComponentOp)); break; case OpType.AuthorityChange: yield return(ReinterpretCast <AuthorityChangeOp, T>(op.AuthorityChangeOp)); break; case OpType.ComponentUpdate: yield return(ReinterpretCast <ComponentUpdateOp, T>(op.ComponentUpdateOp)); break; case OpType.CommandRequest: yield return(ReinterpretCast <CommandRequestOp, T>(op.CommandRequestOp)); break; case OpType.CommandResponse: yield return(ReinterpretCast <CommandResponseOp, T>(op.CommandResponseOp)); break; default: throw new ArgumentOutOfRangeException(); } } }