private static object CreateMethodReturnContracts(IPayloadDescriptorProvider payloadProvider, IMethodDescriptorProvider methodProvider, IHubDescriptorProvider hubProvider) { return hubProvider.GetHubs() .Select(hub => methodProvider.GetMethods(hub) .Where(methodDescriptor => payloadProvider.HasPayload(methodDescriptor.ReturnType))) .Where(methodList => methodList.Count() > 0) .ToDictionary(methodList => methodList.First().Hub.HubType.GetHubName(), methodList => methodList .Select(methodDescriptor => { PayloadDescriptor payloadDescriptor = payloadProvider.GetPayload(methodDescriptor.ReturnType); bool enumerable = false; // If payloadDescriptor is null then the return type has a payload within it if (payloadDescriptor == null) { payloadDescriptor = payloadProvider.GetPayload(methodDescriptor.ReturnType.GetEnumerableType()); enumerable = true; } return new object[]{ methodDescriptor.Name, new object[]{ payloadDescriptor.ID, enumerable ? CompressionTypeHelper.EnumerableTypeId : CompressionTypeHelper.DefaultTypeId } }; }).ToDictionary(methodNameToID => methodNameToID[0], methodNameToID => methodNameToID[1])); }
private static object CreateMethodInvokerContracts(IPayloadDescriptorProvider payloadProvider, IMethodDescriptorProvider methodProvider, IHubDescriptorProvider hubProvider) { return hubProvider.GetHubs() .Select(hub => methodProvider.GetMethods(hub) .Where(methodDescriptor => HasPayloadArgument(methodDescriptor.Parameters, payloadProvider))) .Where(methodList => methodList.Count() > 0) .ToDictionary(methodList => methodList.First().Hub.HubType.GetHubName(), methodList => methodList .Select(methodDescriptor => new object[]{ methodDescriptor.Name, methodDescriptor.Parameters .Select(parameterDescriptor => { PayloadDescriptor payloadDescriptor = payloadProvider.GetPayload(parameterDescriptor.ParameterType); bool enumerable = false; long payloadId = -1; // If payloadDescriptor is null then the parameter type may have a payload within it if (payloadDescriptor == null) { // See if parameter is enumerable if(parameterDescriptor.ParameterType.IsEnumerable()) { enumerable = true; payloadDescriptor = payloadProvider.GetPayload(parameterDescriptor.ParameterType.GetEnumerableType()); if(payloadDescriptor != null) { payloadId = payloadDescriptor.ID; } } } else { payloadId = payloadDescriptor.ID; } return new object[]{ payloadId, enumerable ? CompressionTypeHelper.EnumerableTypeId : CompressionTypeHelper.DefaultTypeId }; }) }).ToDictionary(methodNameToID => methodNameToID[0], methodNameToID => methodNameToID[1])); }