本文整理汇总了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>();
}
示例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}>");
}
示例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>();
}
示例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");
}