コード例 #1
0
        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);
        }
コード例 #2
0
        public async Task Handle(AMessage message, IMessageHandlerContext context)
        {
            var attachment = context.Attachments();
            var bytes      = await attachment.GetBytes();

            Trace.WriteLine(bytes);
        }
コード例 #3
0
    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}");
    }
コード例 #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);
                }
            }
        }));
    }
コード例 #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
        }
コード例 #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();
        }
コード例 #7
0
    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));
    }
コード例 #8
0
 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));
 }
コード例 #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();
    }
コード例 #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);
            }
        }
コード例 #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));
    }
コード例 #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);
         }
     });
 }
コード例 #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);
        }
    }
コード例 #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);
         }
     });
 }
コード例 #15
0
    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);
    }
コード例 #16
0
    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);
    }
コード例 #17
0
        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();
        }
コード例 #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);
                }
            }
        }
コード例 #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);
 }
コード例 #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();
    }
コード例 #21
0
        public Task Handle(SendMessage message, IMessageHandlerContext context)
        {
            try
            {
                context.Attachments();
            }
            catch (Exception e)
            {
                exception = e;
            }
            finally
            {
                resetEvent.Set();
            }

            return(Task.CompletedTask);
        }
コード例 #22
0
    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);
    }
コード例 #23
0
 public async Task Handle(MyMessage message, IMessageHandlerContext context)
 {
     var attachment = context.Attachments();
     var bytes      = await attachment.GetBytes();
 }