SetVariables() public method

public SetVariables ( object>.IEnumerable values ) : void
values object>.IEnumerable
return void
コード例 #1
0
        public async Task Should_publish_the_completed_event()
        {
            Task<ConsumeContext<RoutingSlipCompleted>> completed = SubscribeHandler<RoutingSlipCompleted>();
            Task<ConsumeContext<RoutingSlipActivityCompleted>> activity = SubscribeHandler<RoutingSlipActivityCompleted>();

            var builder = new RoutingSlipBuilder(NewId.NextGuid());
            builder.AddSubscription(Bus.Address, RoutingSlipEvents.All);

            ActivityTestContext testActivity = GetActivityContext<AddressActivity>();
            builder.AddActivity(testActivity.Name, testActivity.ExecuteUri);

            builder.SetVariables(new
            {
                Address = new Uri("http://google.com/"),
            });

            await Bus.Execute(builder.Build());

            await completed;

            var consumeContext = await activity;

            Assert.AreEqual(new Uri("http://google.com/"), consumeContext.Message.GetResult<string>("UsedAddress"));
        }
コード例 #2
0
        public async Task BookMeeting(ConsumeContext<BookMeeting> context)
        {
            var builder = new RoutingSlipBuilder(NewId.NextGuid());

            builder.AddActivity(_settings.ReserveRoomActivityName,
                _settings.ReserveRoomExecuteAddress, new
                {
                    ReservationApiKey = "secret"
                });

            builder.AddActivity(_settings.FetchAvatarActivityName, _settings.FetchAvatarExecuteAddress);

            builder.SetVariables(new
            {
                context.Message.EmailAddress,
                context.Message.StartTime,
                context.Message.Duration,
                context.Message.RoomCapacity
            });

            var routingSlip = builder.Build();

            await context.Execute(routingSlip);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: jandauz/Sample-Courier
        static void Main()
        {
            ConfigureLogger();

            // MassTransit to use Log4Net
            Log4NetLogger.Use();

            IBusControl busControl = CreateBus();

            BusHandle busHandle = busControl.Start();

            string validateQueueName = ConfigurationManager.AppSettings["ValidateActivityQueue"];

            Uri validateAddress = _host.Settings.GetQueueAddress(validateQueueName);

            string retrieveQueueName = ConfigurationManager.AppSettings["RetrieveActivityQueue"];

            Uri retrieveAddress = _host.Settings.GetQueueAddress(retrieveQueueName);

            try
            {
                for (;;)
                {
                    Console.Write("Enter an address (quit exits): ");
                    string requestAddress = Console.ReadLine();
                    if (requestAddress == "quit")
                        break;

                    if (string.IsNullOrEmpty(requestAddress))
                        requestAddress = "http://www.microsoft.com/index.html";

                    int limit = 1;

                    if (requestAddress.All(x => char.IsDigit(x) || char.IsPunctuation(x)))
                    {
                        string[] values = requestAddress.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
                        requestAddress = values[0];
                        if (values.Length > 1)
                        {
                            limit = int.Parse(values[1]);
                            Console.WriteLine("Sending {0}", limit);
                        }
                    }

                    switch (requestAddress)
                    {
                        case "0":
                            requestAddress = "http://www.microsoft.com/index.html";
                            break;
                        case "1":
                            requestAddress = "http://i.imgur.com/Iroma7d.png";
                            break;
                        case "2":
                            requestAddress = "http://i.imgur.com/NK8eZUe.jpg";
                            break;
                    }

                    Uri requestUri;
                    try
                    {
                        requestUri = new Uri(requestAddress);
                    }
                    catch (UriFormatException)
                    {
                        Console.WriteLine("The URL entered is invalid: " + requestAddress);
                        continue;
                    }

                    IEnumerable<Task> tasks = Enumerable.Range(0, limit).Select(x => Task.Run(async () =>
                    {
                        var builder = new RoutingSlipBuilder(NewId.NextGuid());

                        builder.AddActivity("Validate", validateAddress);
                        builder.AddActivity("Retrieve", retrieveAddress);

                        builder.SetVariables(new
                        {
                            RequestId = NewId.NextGuid(),
                            Address = requestUri,
                        });

                        RoutingSlip routingSlip = builder.Build();

                        await busControl.Publish<RoutingSlipCreated>(new
                        {
                            TrackingNumber = routingSlip.TrackingNumber,
                            Timestamp = routingSlip.CreateTimestamp,
                        });

                        await busControl.Execute(routingSlip);
                    }));

                    Task.WaitAll(tasks.ToArray());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception!!! OMG!!! {0}", ex);
                Console.ReadLine();
            }
            finally
            {
                busHandle.Stop(TimeSpan.FromSeconds(30));
            }
        }