private static ServiceAssembly CreateAssemblyRegistration(Assembly assembly) { var messagesById = new ServiceMessageByIdCollection(); var messagesByType = new ServiceMessageByTypeCollection(); var typeModel = RuntimeTypeModel.Create(); foreach (var type in assembly.GetTypes()) { var messageAttributes = type.GetCustomAttributes(typeof(ProtoMessageAttribute), true); if (messageAttributes.Length == 0) continue; Debug.Assert(messageAttributes.Length == 1); var contractAttributes = type.GetCustomAttributes(typeof(ProtoContractAttribute), true); if (contractAttributes.Length == 0) throw new ProtoChannelException(String.Format("Type '{0}' specifies the ProtoMessage attribute but not the ProtoContract attribute", type)); var messageAttribute = (ProtoMessageAttribute)messageAttributes[0]; var message = new ServiceMessage(messageAttribute, type); messagesById.Add(message); messagesByType.Add(message); typeModel.Add(type, true); } if (messagesById.Count == 0) throw new ProtoChannelException(String.Format("Assembly '{0}' does not contain any messages", assembly)); return new ServiceAssembly(assembly, typeModel, messagesById, messagesByType); }
public ServiceAssembly(Assembly assembly, RuntimeTypeModel typeModel, ServiceMessageByIdCollection messagesById, ServiceMessageByTypeCollection messagesByType) { Require.NotNull(assembly, "assembly"); Require.NotNull(typeModel, "typeModel"); Require.NotNull(messagesById, "messagesById"); Require.NotNull(messagesByType, "messagesByType"); Assembly = assembly; TypeModel = typeModel; MessagesById = messagesById; MessagesByType = messagesByType; }
public Service(Type serviceType, ServiceMethodCollection methods, ServiceMessageByIdCollection messagesById, ServiceAssembly serviceAssembly) { Require.NotNull(serviceType, "serviceType"); Require.NotNull(methods, "methods"); Require.NotNull(messagesById, "messagesById"); Require.NotNull(serviceAssembly, "serviceAssembly"); Type = serviceType; ServiceAssembly = serviceAssembly; Methods = methods; Messages = messagesById; var callbackAttributes = serviceType.GetCustomAttributes(typeof(ProtoCallbackContractAttribute), true); if (callbackAttributes.Length > 0) { Debug.Assert(callbackAttributes.Length == 1); CallbackContractType = ((ProtoCallbackContractAttribute)callbackAttributes[0]).Type; } }
private Service CreateServiceRegistration(Type serviceType) { var methods = new ServiceMethodCollection(); var messages = new ServiceMessageByIdCollection(); foreach (var method in serviceType.GetMethods()) { var methodAttributes = method.GetCustomAttributes(typeof(ProtoMethodAttribute), true); if (methodAttributes.Length == 0) continue; Debug.Assert(methodAttributes.Length == 1); var methodAttribute = (ProtoMethodAttribute)methodAttributes[0]; var serviceMethod = new ServiceMethod(method, methodAttribute, this); if (methods.ContainsKey(serviceMethod.Request)) throw new ProtoChannelException(String.Format("Invalid service contract '{0}'; multiple ProtoMethod's found for message type '{1}'", serviceType, serviceMethod.Request.Type)); if (!messages.ContainsKey(serviceMethod.Request.Id)) messages.Add(serviceMethod.Request); if (serviceMethod.Response != null && !messages.ContainsKey(serviceMethod.Response.Id)) messages.Add(serviceMethod.Response); methods.Add(serviceMethod); } if (methods.Count == 0) throw new ProtoChannelException(String.Format("Invalid service contract '{0}'; contract does not specify any handlers", serviceType)); return new Service(serviceType, methods, messages, this); }