示例#1
0
 public int DoSomething(int one, string two)
 {
     var testMessage = new TestMessage { one = one, two = two };
     byte[] messageBytes = messageSerializer.SerialiseMessage(testMessage);
     var messageTypeDefinition = new MessageTypeDefinition { Arguments = new [] { new MessageArgument { Name = "one", Type = typeof(int).FullName }, new MessageArgument { Name = "two", Type = typeof(int).FullName } } };
     return (int) spawnController.StartRequest("DoSomething", messageTypeDefinition, messageBytes).Result;
 }
示例#2
0
        public object RunMessage(string action, MessageTypeDefinition messageTypeDefinition, object argumentsObj)
        {
            var message = JsonConvert.DeserializeObject(argumentsObj.ToString(), messageTypeBuilder.BuildMessageType(messageTypeDefinition));

            //var message = serializer.DeserialiseMessage(messageBytes, messageTypeBuilder.BuildMessageType(messageTypeDefinition));
            var arguments = messageTypeDefinition.Arguments.Select(x => message.GetType().GetField(x.Name).GetValue(message)).ToArray();
            return instanceType.GetMethod(action).Invoke(instance, arguments);
        }
 public MessageTypeDefinition BuildMessageTypeDefinition(MethodInfo methodInfo)
 {
     var obj = new MessageTypeDefinition()
     {
         Arguments = methodInfo.GetParameters().Select(x => new MessageArgument { Name = x.Name, Type = x.ParameterType.AssemblyQualifiedName }).ToArray()
     };
     return obj;
 }
 public Type BuildMessageType(MessageTypeDefinition messageTypeDefinition)
 {
     AssemblyBuilder assemblyBuilder = TypeBuilderHelper.CreateAssemblyBuilder("JobSpawnMessage");
     TypeBuilder typeBuilder = TypeBuilderHelper.CreateTypeBuilder(assemblyBuilder, "JobSpawnMessage");
     messageTypeDefinition.Arguments.ForEach(argument => typeBuilder.DefineField(argument.Name, Type.GetType(argument.Type), FieldAttributes.Public));
     var type = typeBuilder.CreateType();
     assemblyBuilder.Save("JobSpawnMessageAssembly.dll");
     return type;
 }
示例#5
0
        public async Task<object> StartRequest(string action, MessageTypeDefinition messageTypeDefinition, object arguments)
        {
            var message = new Message.Message { Action = action, MessageTypeDefinition = messageTypeDefinition, Arguments = arguments };

            MessageClient messageClient = new MessageClient();
            var messageResult = await messageClient.SendMessage(message);

            var returnType = concreteType.GetMethod(action).ReturnType;
            //var obj = ByteArrayToObject(messageResult.Result);

            return Convert.ChangeType(messageResult.Result, returnType);

            //var result = host.RunMessage(action, messageTypeDefinition, messageBytes);
            //var result =  messageResult.Result;
        }
示例#6
0
 public Task<object> StartRequest(string action, MessageTypeDefinition messageTypeDefinition, object arguments)
 {
     this.action = action;
     this.messageTypeDefinition = messageTypeDefinition;
     this.arguments = arguments;
     return Task.FromResult((object)3);
 }