public async Task <ActionResult <PurchaseOrderResponse> > PlaceOrder(List <OrderDto> orders, CancellationToken cancellationToken) { var orderId = Guid.NewGuid(); var builder = new SharedUriBuilder(OrderActorServiceKey); // Calls Actor creation using unique order Id identifier var orderProxy = ActorProxy.Create <IOrderActor>(new ActorId(orderId), builder.ToUri()); try { await orderProxy.SubmitOrderAsync(orders, cancellationToken); ServiceEventSource.Current.Message("Order has been submitted successfully. Actor with OrderId: {0} has been created", orderId); } catch (InvalidOperationException ex) { ServiceEventSource.Current.Message("Actor service: Actor rejected {0}: {1}", orders, ex); throw; } catch (Exception ex) { ServiceEventSource.Current.Message("Actor service: Exception {0}: {1}", orders, ex); throw; } return(new PurchaseOrderResponse { OrderId = orderId }); }
public async Task <ActionResult <AddInventoryResponse> > AddNew( AddInventoryRequest request, CancellationToken cancellationToken) { if (null == request?.Inventory) { throw new ArgumentNullException(nameof(request.Inventory)); } AddInventoryResponse response; var builder = new SharedUriBuilder(InventoryServiceNameKey); var inventoryServiceClient = ServiceProxy.Create <IInventoryService>(builder.ToUri()); try { var status = await inventoryServiceClient.CreateInventoryItemAsync(request.Inventory); response = new AddInventoryResponse { Status = status }; } catch (Exception ex) { ServiceEventSource.Current.Message("There are one or more errors while creating inventory {0}: {1}", request.Inventory.Id, ex); throw; } return(response); }
/// <summary> /// This method is called whenever an actor is activated. /// An actor is activated the first time any of its methods are invoked. /// </summary> protected override async Task OnActivateAsync() { ActorEventSource.Current.ActorMessage(this, "Actor activated."); _tokenSource = new CancellationTokenSource(); _builder = new SharedUriBuilder(ActorService.Context.CodePackageActivationContext, InventoryServiceNameKey); _serviceProxyFactory = new ServiceProxyFactory(); var orderStatusResult = await GetOrderStatusAsync(); // Init order if it's new if (orderStatusResult == OrderStatusTypeDto.Unknown) { await StateManager.SetStateAsync(OrdersKey, new List <OrderDto>()); await StateManager.SetStateAsync <long>(RequestIdPropertyKey, 0); await SetOrderStatusAsync(OrderStatusTypeDto.New); } }