public async Task Handle(SendMessage message, IMessageHandlerContext context)
        {
            var withAttachment = await context.Attachments().GetBytes("withMetadata");

            Assert.Equal("value", withAttachment.Metadata["key"]);
            var replyOptions       = new ReplyOptions();
            var outgoingAttachment = replyOptions.Attachments();

            outgoingAttachment.Add(() =>
            {
                var incomingAttachment = context.Attachments();
                return(incomingAttachment.GetStream());
            });
            await context.Reply(new ReplyMessage(), replyOptions);
        }
Ejemplo n.º 2
0
        public async Task Handle(AMessage message, IMessageHandlerContext context)
        {
            var attachment = context.Attachments();
            var bytes      = await attachment.GetBytes();

            Trace.WriteLine(bytes);
        }
    public async Task Handle(ReplyMessage message, IMessageHandlerContext context)
    {
        var incomingAttachments = context.Attachments();
        var attachment          = await incomingAttachments.GetBytes("bar");

        Console.WriteLine($"Hello from MyHandler. ReplyMessage. bytes: {attachment.Bytes.Length}");
    }
Ejemplo n.º 4
0
    public Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        log.Info("MyMessage received. Attachment will be streamed to the console.");
        var attachments = context.Attachments();

        return(attachments.ProcessStream(
                   name: "attachmentName",
                   action: async stream =>
        {
            using (var reader = new StreamReader(stream))
            {
                while (true)
                {
                    var line = await reader.ReadLineAsync()
                               .ConfigureAwait(false);
                    if (line == null)
                    {
                        break;
                    }

                    Console.WriteLine(line);
                }
            }
        }));
    }
Ejemplo n.º 5
0
        public async Task Handle(MyMessage message, IMessageHandlerContext context)
        {
            var incomingAttachments = context.Attachments();
            var bytes = await incomingAttachments.GetBytes("attachment1")
                        .ConfigureAwait(false);

            // use the byte array
        }
Ejemplo n.º 6
0
        public async Task Handle(MyMessage message, IMessageHandlerContext context)
        {
            var incomingAttachment = context.Attachments();

            Assert.NotNull(await incomingAttachment.GetBytes("fooFile"));
            Assert.NotNull(await incomingAttachment.GetBytes());
            Assert.Equal("Value", message.Property);
            resetEvent.Set();
        }
    public Task Handle(SendMessage message, IMessageHandlerContext context)
    {
        var replyOptions       = new ReplyOptions();
        var outgoingAttachment = replyOptions.Attachments();
        var incomingAttachment = context.Attachments();

        outgoingAttachment.Add(incomingAttachment.GetStream);
        return(context.Reply(new ReplyMessage(), replyOptions));
    }
 public Task Handle(SampleMessage message, IMessageHandlerContext context)
 {
     Console.WriteLine("MyHandler");
     foreach (var header in context.MessageHeaders)
     {
         Console.WriteLine($"{header.Key.Replace("NServiceBus.","")}={header.Value}");
     }
     return(context.Attachments().ProcessStreams(WriteAttachment));
 }
Ejemplo n.º 9
0
    public async Task Handle(SendMessage message, IMessageHandlerContext context)
    {
        var incomingAttachment = context.Attachments();

        using (var stream = await incomingAttachment.GetStream())
        {
            Debug.WriteLine(stream);
        }
        IntegrationTests.SagaEvent.Set();
    }
Ejemplo n.º 10
0
        public async Task Handle(MyMessage message, IMessageHandlerContext context)
        {
            var incomingAttachments = context.Attachments();

            using (var fileToCopyTo = File.Create("FilePath.txt"))
            {
                await incomingAttachments.CopyTo("attachment1", fileToCopyTo)
                .ConfigureAwait(false);
            }
        }
Ejemplo n.º 11
0
    public Task Handle(SampleMessage message, IMessageHandlerContext context)
    {
        log.Info("SampleMessage received");
        log.Info($"Property={message.Property}");
        foreach (var header in context.MessageHeaders)
        {
            var headerSuffix = header.Key.Replace("NServiceBus.", "");
            log.Info($"{headerSuffix}={header.Value}");
        }

        return(context.Attachments().ProcessStreams(WriteAttachment));
    }
Ejemplo n.º 12
0
 public async Task Handle(MyMessage message, IMessageHandlerContext context)
 {
     var incomingAttachments = context.Attachments();
     await incomingAttachments.ProcessStreams(
         action : async(name, stream) =>
     {
         using (var fileToCopyTo = File.Create($"{name}.txt"))
         {
             await stream.CopyToAsync(fileToCopyTo)
             .ConfigureAwait(false);
         }
     });
 }
Ejemplo n.º 13
0
    public async Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        Console.WriteLine("Hello from MyHandler.");
        using (var memoryStream = new MemoryStream())
        {
            var incomingAttachments = context.Attachments();
            await incomingAttachments.CopyTo("foo", memoryStream);

            memoryStream.Position = 0;
            var buffer = memoryStream.GetBuffer();
            Debug.WriteLine(buffer);
        }
    }
Ejemplo n.º 14
0
 public async Task Handle(MyMessage message, IMessageHandlerContext context)
 {
     var incomingAttachments = context.Attachments();
     await incomingAttachments.ProcessStream(
         name : "attachment1",
         action : async stream =>
     {
         // Use the attachment stream. in this example copy to a file
         using (var fileToCopyTo = File.Create("FilePath.txt"))
         {
             await stream.CopyToAsync(fileToCopyTo).ConfigureAwait(false);
         }
     });
 }
    public async Task Handle(ReplyMessage message, IMessageHandlerContext context)
    {
        var randomFileName     = Path.GetRandomFileName();
        var incomingAttachment = context.Attachments();

        using (var target = File.Create(randomFileName))
        {
            await incomingAttachment.CopyTo(target).ConfigureAwait(false);
        }
        File.Delete(randomFileName);

        AttachmentsRunner.countdownEvent.Signal();
        Console.WriteLine(AttachmentsRunner.countdownEvent.CurrentCount);
    }
    public async Task Handle(SendMessage message, IMessageHandlerContext context)
    {
        Console.WriteLine("Hello from MyHandler. SendMessage");
        var incomingAttachments = context.Attachments();
        var attachment          = await incomingAttachments.GetStream("foo");

        var sendOptions = new SendOptions();

        sendOptions.RouteToThisEndpoint();
        var outgoingAttachments = sendOptions.Attachments();

        outgoingAttachments.Add("bar", attachment);
        await context.Send(new ReplyMessage(), sendOptions);
    }
        public async Task Handle(ReplyMessage message, IMessageHandlerContext context)
        {
            using (var memoryStream = new MemoryStream())
            {
                var incomingAttachment = context.Attachments();
                await incomingAttachment.CopyTo(memoryStream);

                memoryStream.Position = 0;
                var buffer = memoryStream.GetBuffer();
                Debug.WriteLine(buffer);
            }

            resetEvent.Set();
        }
Ejemplo n.º 18
0
        public async Task Handle(MyMessage message, IMessageHandlerContext context)
        {
            var incomingAttachments = context.Attachments();

            using (var attachmentStream = incomingAttachments.GetStream("attachment1"))
            {
                // Use the attachment stream. in this example copy to a file
                using (var fileToCopyTo = File.Create("FilePath.txt"))
                {
                    await attachmentStream.CopyToAsync(fileToCopyTo)
                    .ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 19
0
 public async Task Handle(MyMessage message, IMessageHandlerContext context)
 {
     var incomingAttachments = context.Attachments();
     await incomingAttachments.ProcessStreamsForMessage(
         messageId : "theMessageId",
         action : async(name, stream) =>
     {
         // Use the attachment stream. in this example copy to a file
         using (var fileToCopyTo = File.Create($"{name}.txt"))
         {
             await stream.CopyToAsync(fileToCopyTo)
             .ConfigureAwait(false);
         }
     })
     .ConfigureAwait(false);
 }
Ejemplo n.º 20
0
    public async Task Handle(ReplyMessage message, IMessageHandlerContext context)
    {
        var incomingAttachment = context.Attachments();

        IntegrationTests.PerformNestedConnection();

        var buffer = await incomingAttachment.GetBytes();

        Debug.WriteLine(buffer);
        using (var stream = await incomingAttachment.GetStream())
        {
            Debug.WriteLine(stream);
        }

        IntegrationTests.HandlerEvent.Set();
    }
Ejemplo n.º 21
0
        public Task Handle(SendMessage message, IMessageHandlerContext context)
        {
            try
            {
                context.Attachments();
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
                resetEvent.Set();
            }

            return(Task.CompletedTask);
        }
    public async Task Handle(SendMessage message, IMessageHandlerContext context)
    {
        var replyOptions = new SendOptions();

        replyOptions.RouteToThisEndpoint();
        var attachment = await context.Attachments().GetBytes("withMetadata");

        Assert.Equal("value", attachment.Metadata["key"]);
        Assert.NotNull(attachment);
        var outgoingAttachment = replyOptions.Attachments();

        outgoingAttachment.AddBytes(attachment);

        IntegrationTests.PerformNestedConnection();

        await context.Send(new ReplyMessage(), replyOptions);
    }
Ejemplo n.º 23
0
 public async Task Handle(MyMessage message, IMessageHandlerContext context)
 {
     var attachment = context.Attachments();
     var bytes      = await attachment.GetBytes();
 }