private async Task GetNextInLine() { try { WriteTimedDebug("GetNextInLine"); Random random = new Random(); PosDeviceModes posDeviceMode = random.Next(0, 2) == 0 ? PosDeviceModes.ConsumerScans : PosDeviceModes.PosDeviceScans; posDeviceMode = PosDeviceModes.PosDeviceScans; if (posDeviceMode == PosDeviceModes.ConsumerScans) { await CreateCheckoutSessionAsync(); } int partitionIndex = random.Next(0, 4); ServicePartitionKey servicePartitionKey = new ServicePartitionKey(partitionIndex); ILineService proxy = ServiceProxy.Create <ILineService>(LineServiceUri, servicePartitionKey); List <ApiLicenseDisplay> codes = await StateManager.GetStateAsync <List <ApiLicenseDisplay> >(AppApiLicensesKey); string appApiLicenseCode = codes.First().Code; Guid consumerId = await proxy.GetNextConsumerInLineAsync(appApiLicenseCode); await StateManager.SetStateAsync(CurrentConsumerIdKey, consumerId); ActorId consumerActorId = new ActorId(consumerId); IConsumerSimulationActor consumerActor = ActorProxy.Create <IConsumerSimulationActor>(consumerActorId, ConsumerServiceUri); await consumerActor.BeginTransaction(this.Id.GetGuidId(), posDeviceMode); if (posDeviceMode == PosDeviceModes.ConsumerScans) { await _Machine.FireAsync(PosDeviceSimulationTriggerType.WaitForConsumerToCheckout); } else { await _Machine.FireAsync(PosDeviceSimulationTriggerType.WaitForConsumerToPresentQr); } } catch (Exception ex) { WriteTimedDebug(ex); await _Machine.FireAsync(PosDeviceSimulationTriggerType.GoIdle); } }
private async Task CreateToInitialized(string posDeviceApiLicenseCode, List <ApiLicenseDisplay> applicationLicenses, PosDeviceModes posDeviceModes) { await StateManager.TryAddStateAsync(PosDeviceApiLicenseCodeKey, posDeviceApiLicenseCode); await StateManager.TryAddStateAsync(AppApiLicensesKey, applicationLicenses); await StateManager.TryAddStateAsync(PosDeviceModeKey, posDeviceModes); await RegisterWorkflowReminder(); await SetStateAsync(); await _Machine.FireAsync(PosDeviceSimulationTriggerType.GoIdle); }
/// <summary> /// The Actor is Created by calling it, this initializes base values required to be an minimaly viable CheckoutSession /// </summary> /// <param name="authorityRefId"></param> /// <param name="brandRefId"></param> /// <param name="simulationType"></param> /// <returns></returns> public async Task InitializeAsync(string posDeviceApiLicenseCode, List <ApiLicenseDisplay> applicationLicenses, PosDeviceModes posDeviceModes) { try { if (_Machine.State == PosDeviceSimulationStateType.ActorCreated) { await _Machine.FireAsync(_InitializeTrigger, posDeviceApiLicenseCode, applicationLicenses, posDeviceModes); } else { ActorEventSource.Current.ActorMessage(this, $"{nameof(PosDeviceSimulationActor)} already initialized."); } } catch (Exception ex) { WriteTimedDebug(ex); throw; } }