private Option <uint> SendGenericCommand <TResponse>(CommandCallback <TResponse> callback, Func <uint, uint> sendRequestWithTimeoutMs, TimeSpan?timeout = null) { var callbackWrapper = new CommandCallbackWrapper <TResponse>(callback); if (component != null && component.Authority != Authority.Authoritative && component.Authority != Authority.AuthorityLossImminent) { // This needs to be deferred, so that all callbacks are registered // before they are actually called. communicator.Defer(() => callbackWrapper.TriggerWithError(StatusCode.AuthorityLost, string.Format( "Tried to send a command from (entity ID: {0}, component: {1}) without " + "authority on that pair.", component.EntityId, component.GetType() ))); return(new Option <uint>()); } var timeoutMs = timeout.HasValue ? (uint)timeout.Value.Milliseconds : DefaultCommandTimeoutMs; var requestId = sendRequestWithTimeoutMs(timeoutMs); requestIdToCallback.Add(requestId, callbackWrapper); return(requestId); }
private void SendGenericCommand <TResponse>(IComponentWriter writer, bool requireAuthority, CommandCallback <TResponse> callback, Action sendAction) { var callbackWrapper = new CommandCallbackWrapper <TResponse>(callback); if (requireAuthority && (writer == null || communicator.GetAuthority(writer.EntityId, writer.ComponentId) == Authority.NotAuthoritative)) { // This needs to be deferred, so that all callbacks are registered // before they are actually called. communicator.Defer(() => callbackWrapper.TriggerWithAuthorityError()); return; } sendAction(); }