示例#1
0
        public void GenerateResponse <TRequest, TResponse>(CommandRequestId id, Func <CommandRequestId, TRequest, TResponse> creator)
            where TRequest : ICommandRequest
            where TResponse : struct, IReceivedCommandResponse
        {
            if (!outgoingRequests.TryGetValue(id.Raw, out var request))
            {
                throw new ArgumentException($"Could not find a request with request id {id}");
            }

            var commandClass = ComponentDatabase.GetCommandMetaclassFromRequest <TRequest>();

            if (typeof(TResponse) != commandClass.ReceivedResponse)
            {
                throw new ArgumentException($"Invalid response type {typeof(TResponse)}, expected {commandClass.ReceivedResponse}");
            }

            CurrentDiff.AddCommandResponse(creator(id, (TRequest)request), commandClass.ComponentId, commandClass.CommandIndex);
            requestIds[typeof(TRequest)].Remove(id.Raw);
            outgoingRequests.Remove(id.Raw);
        }
示例#2
0
        public void GenerateResponses <TRequest, TResponse>(Func <CommandRequestId, TRequest, TResponse> creator)
            where TRequest : ICommandRequest
            where TResponse : struct, IReceivedCommandResponse
        {
            var ids          = GetOutboundCommandRequests <TRequest>();
            var commandClass = ComponentDatabase.GetCommandMetaclassFromRequest <TRequest>();

            if (typeof(TResponse) != commandClass.ReceivedResponse)
            {
                throw new ArgumentException($"Invalid response type {typeof(TResponse)}, expected {commandClass.ReceivedResponse}");
            }

            foreach (var id in ids)
            {
                var request = outgoingRequests[id.Raw];
                CurrentDiff.AddCommandResponse(creator(id, (TRequest)request), commandClass.ComponentId, commandClass.CommandIndex);
                outgoingRequests.Remove(id.Raw);
            }

            requestIds[typeof(TRequest)].Clear();
        }