private async Task ScanConsumerQr()
        {
            try
            {
                Guid consumerId = await StateManager.GetStateAsync <Guid>(CurrentConsumerIdKey);

                ActorId consumerActorId = new ActorId(consumerId);

                IConsumerSimulationActor consumerActor = ActorProxy.Create <IConsumerSimulationActor>(consumerActorId, ConsumerServiceUri);

                string checkoutSessionLicenseCode = await consumerActor.PosScansConsumer().ConfigureAwait(false);

                if (checkoutSessionLicenseCode == null)
                {
                    await _Machine.FireAsync(PosDeviceSimulationTriggerType.WaitForConsumerToPresentQr);
                }

                else
                {
                    await StateManager.SetStateAsync(CheckoutLicenseCodeKey, checkoutSessionLicenseCode);

                    await _Machine.FireAsync(PosDeviceSimulationTriggerType.WaitForConsumerToCheckout);
                }
            }

            catch (Exception ex)
            {
                WriteTimedDebug(ex);
                await _Machine.FireAsync(PosDeviceSimulationTriggerType.WaitForConsumerToPresentQr);
            }
        }
        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);
            }
        }
Ejemplo n.º 3
0
        public async Task ReceiveReminderAsync(string reminderName, byte[] state, TimeSpan dueTime, TimeSpan period)
        {
            try
            {
                EntitySecret entitySecret = await RetrieveEntityMediaAsync().ConfigureAwait(false);

                WriteTimedDebug($"Ticket download complete: {entitySecret.ValidationLicenseCode}");

                await CallEntityReceivedAsync(entitySecret);

                Guid sourceActorId = await StateManager.GetStateAsync <Guid>(ConsumerRefIdKey);

                Uri sourceServiceUri = await StateManager.GetStateAsync <Uri>(SourceServiceUriKey);

                if (sourceServiceUri == ConsumerServiceUri)
                {
                    IConsumerSimulationActor consumerActor = ActorProxy.Create <IConsumerSimulationActor>(new ActorId(sourceActorId), sourceServiceUri);

                    await consumerActor.UpdateDownloadStatusAsync(entitySecret);
                }

                else
                {
                    IConsumerExchangeActor exchangeActor = ActorProxy.Create <IConsumerExchangeActor>(new ActorId(sourceActorId), sourceServiceUri);

                    await exchangeActor.UpdateDownloadStatusAsync(entitySecret);
                }

                var reminder = GetReminder(ReminderKey);

                await UnregisterReminderAsync(reminder).ConfigureAwait(false);
            }

            catch (Exception ex)
            {
                WriteTimedDebug(ex);
            }
        }
        private async Task <Guid> CreateConsumerAsync(string appApiLicenseCode)
        {
            byte[] selfieBytes = GetImageBytes("christina.png");

            string selfieBase64 = Convert.ToBase64String(selfieBytes);

            CryptoRandom random = new CryptoRandom();

            int age = random.Next(22, 115);

            SmartRequest <PlayerRegisterRequest> req = new SmartRequest <PlayerRegisterRequest>
            {
                CreatedOn = DateTimeOffset.UtcNow,
                Latitude  = 34.072846D,
                Longitude = -84.190285D,
                Data      = new PlayerRegisterRequest
                {
                    CountryCode  = "US",
                    LanguageCode = "en-US",
                    SelfieBase64 = selfieBase64,
                    Data         = new List <KeyValuePair <string, string> >
                    {
                        new KeyValuePair <string, string>("age", age.ToString())
                    }
                }
                ,
                Uuid = $"{Guid.NewGuid()}"
            };

            Guid correlationRefId = Guid.NewGuid();

            Uri requestUri             = GetFullUri("api/v3/player/registration");
            HttpRequestMessage httpreq = new HttpRequestMessage(HttpMethod.Post, requestUri);

            httpreq.Headers.Add("lazlo-apilicensecode", appApiLicenseCode);
            httpreq.Headers.Add("lazlo-correlationrefId", correlationRefId.ToString());

            string json = JsonConvert.SerializeObject(req);

            httpreq.Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");

            HttpResponseMessage message = await _HttpClient.SendAsync(httpreq).ConfigureAwait(false);

            string responseJson = await message.Content.ReadAsStringAsync().ConfigureAwait(false);

            if (message.IsSuccessStatusCode)
            {
                if (age < 18)
                {
                    throw new CorrelationException("Allowed to register a player under 18")
                          {
                              CorrelationRefId = correlationRefId
                          };
                }

                var statusResponse = JsonConvert.DeserializeObject <SmartResponse <ConsumerRegisterResponse> >(responseJson);

                ActorId consumerActorId = new ActorId(Guid.NewGuid());

                IConsumerSimulationActor consumerActor = ActorProxy.Create <IConsumerSimulationActor>(consumerActorId, ConsumerServiceUri);

                await consumerActor.InitializeAsync(
                    appApiLicenseCode,
                    statusResponse.Data.ConsumerLicenseCode).ConfigureAwait(false);

                return(consumerActorId.GetGuidId());
            }

            else
            {
                throw new Exception("Create player failed");
            }
        }