当前位置: 首页>>代码示例>>C#>>正文


C# CommandContext.TryGet方法代码示例

本文整理汇总了C#中CommandContext.TryGet方法的典型用法代码示例。如果您正苦于以下问题:C# CommandContext.TryGet方法的具体用法?C# CommandContext.TryGet怎么用?C# CommandContext.TryGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommandContext的用法示例。


在下文中一共展示了CommandContext.TryGet方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override void Execute(CommandContext context)
        {
            ShoppingCart cart;

            if (!context.TryGet(out cart))
            {
                Console.Out.WriteLine("No order is currently active, please use `StartOrder` to start a new one");
                return;
            }

            double orderValue = new Random().Next(100, 1000);
            var parts = context.GetParameters().Split(' ');
            if (parts.Length == 2)
            {
                orderValue = double.Parse(parts[1]);
            }
            context.Bus.Send(new PlaceOrder
            {
                OrderId = cart.OrderId,
                CustomerId = "12345abc",
                OrderDate = DateTime.UtcNow,
                OrderValue = orderValue
            });

            Console.Out.WriteLine($"Thank you for your order, your order confirmation should arrive shortly - {cart.OrderId}");
            context.Remove<ShoppingCart>();
        }
开发者ID:calebjenkins,项目名称:SagaMasterClass.Skeleton,代码行数:27,代码来源:PlaceOrderCommand.cs

示例2: GeneratePrompt

        static void GeneratePrompt(CommandContext context)
        {
            ShoppingCart cart;

            string promptContext = null;
            if (context.TryGet(out cart))
            {
                promptContext = cart.OrderId.Substring(0, 6);
            }

            if (!string.IsNullOrEmpty(promptContext))
            {
                promptContext = $" [{promptContext}]";
            }

            Console.Out.Write($"Shop{promptContext}>");
        }
开发者ID:calebjenkins,项目名称:SagaMasterClass.Skeleton,代码行数:17,代码来源:Program.cs

示例3: Execute

        public override void Execute(CommandContext context)
        {
            ShoppingCart cart;

            if (!context.TryGet(out cart))
            {
                Console.Out.WriteLine("No order is currently active, please use `StartOrder` to start a new one");
                return;
            }

            context.Bus.Send(new CancelOrder
            {
                OrderId = cart.OrderId
            });

            Console.Out.WriteLine($"Order {cart.OrderId} has been canceled");
            context.Remove<ShoppingCart>();
        }
开发者ID:noelklein,项目名称:SagaMasterClass,代码行数:18,代码来源:CancelOrderCommand.cs

示例4: Execute

        public override void Execute(CommandContext context)
        {
            ShoppingCart currentCart;

            if (context.TryGet(out currentCart))
            {
                Console.Out.WriteLine($"Order {currentCart.OrderId} is currently active, please use PlaceOrder|CancelOrder to complete it first");

                return;
            }
            var orderId = Guid.NewGuid().ToString();

            context.Set(new ShoppingCart(orderId));
            context.Bus.Send(new StartOrder
            {
                OrderId = orderId
            });
            Console.Out.WriteLine($"Order {orderId} created, use PlaceOrder|CancelOrder to proceed");
        }
开发者ID:noelklein,项目名称:SagaMasterClass,代码行数:19,代码来源:StartOrderCommand.cs


注:本文中的CommandContext.TryGet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。