Exemplo n.º 1
0
 public void SetUp()
 {
     theFubuRequest  = new InMemoryFubuRequest();
     theData         = new InMemoryRequestData();
     objectConverter = new ObjectConverter();
     theRequest      = new FubuSmartRequest(theData, objectConverter, theFubuRequest);
 }
 public void SetUp()
 {
     theData         = new InMemoryRequestData();
     theLibrary      = new ConverterLibrary();
     objectConverter = new ObjectConverter(new InMemoryServiceLocator(), theLibrary);
     theRequest      = new SmartRequest(theData, objectConverter);
 }
        public async Task CreateCheckoutSessionAsync()
        {
            WriteTimedDebug("CreateCheckoutSessionAsync");

            Uri requestUri = GetFullUri("api/v1/shopping/pos/checkout/create");

            HttpRequestMessage httpreq = new HttpRequestMessage(HttpMethod.Post, requestUri);

            string posDeviceApiLicenseCode = await StateManager.GetStateAsync <string>(PosDeviceApiLicenseCodeKey).ConfigureAwait(false);

            httpreq.Headers.Add("lazlo-apilicensecode", posDeviceApiLicenseCode);

            SmartRequest <object> req = new SmartRequest <object> {
            };

            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);

            SmartResponse <CheckoutSessionCreateResponse> response = JsonConvert.DeserializeObject <SmartResponse <CheckoutSessionCreateResponse> >(responseJson);

            if (message.IsSuccessStatusCode)
            {
                await StateManager.SetStateAsync(CheckoutLicenseCodeKey, response.Data.CheckoutLicenseCode);
            }

            else
            {
                throw new Exception(response.Error.Message);
            }
        }
        public static SmartBase <T> Map <T>(this SmartContext <T> to, SmartRequest <T> smartRequest)
        {
            to.Data      = smartRequest.Data;
            to.CreatedOn = smartRequest.CreatedOn;
            to.Uuid      = smartRequest.Uuid;
            to.Latitude  = smartRequest.Latitude;
            to.Longitude = smartRequest.Longitude;

            return(to);
        }
Exemplo n.º 5
0
        public async Task CallEntityReceivedAsync(EntitySecret entitySecret)
        {
            try
            {
                Uri requestUri = GetFullUri("api/v1/shopping/checkout/entity/received");

                HttpRequestMessage httpreq = new HttpRequestMessage(HttpMethod.Post, requestUri);

                string appApiLicenseCode = await StateManager.GetStateAsync <string>(AppApiLicenseCodeKey).ConfigureAwait(false);

                string consumerLicenseCode = await StateManager.GetStateAsync <string>(ConsumerLicenseCodeKey).ConfigureAwait(false);

                string checkoutSessionLicenseCode = await StateManager.GetStateAsync <string>(CheckoutSessionLicenseCodeKey).ConfigureAwait(false);

                httpreq.Headers.Add("lazlo-consumerlicensecode", consumerLicenseCode);
                httpreq.Headers.Add("lazlo-apilicensecode", appApiLicenseCode);
                httpreq.Headers.Add("lazlo-txlicensecode", checkoutSessionLicenseCode);

                SmartRequest <EntityReceivedRequest> entityReceivedRequest = new SmartRequest <EntityReceivedRequest>
                {
                    Data = new EntityReceivedRequest
                    {
                        EntityLicenseCode = entitySecret.ValidationLicenseCode,
                        MediaHash         = entitySecret.Hash
                    }
                };

                string json = JsonConvert.SerializeObject(entityReceivedRequest);

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

                HttpResponseMessage message = await _HttpClient.SendAsync(httpreq);

                if (message.IsSuccessStatusCode)
                {
                    WriteTimedDebug($"EntityReceived success: {entitySecret.ValidationLicenseCode}");
                }

                else
                {
                    string err = await message.Content.ReadAsStringAsync();

                    throw new Exception($"EntityReceived failed: {err}");
                }
            }

            catch (Exception ex)
            {
                WriteTimedDebug(ex);
                //Ignore for now
            }
        }
        public async Task CallCheckoutCompleteAsync()
        {
            try
            {
                Uri requestUri = GetFullUri("api/v2/shopping/pos/checkout/complete");

                SmartRequest <CheckoutCompletePosRequest> req = new SmartRequest <CheckoutCompletePosRequest>
                {
                    Data = new CheckoutCompletePosRequest
                    {
                        AmountPaid = 5.29M
                    }
                };

                HttpRequestMessage httpreq = new HttpRequestMessage(HttpMethod.Put, requestUri);

                string json = JsonConvert.SerializeObject(req);

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

                string checkoutSessionCode = await StateManager.GetStateAsync <string>(CheckoutLicenseCodeKey).ConfigureAwait(false);

                string posDeviceApiLicenseCode = await StateManager.GetStateAsync <string>(PosDeviceApiLicenseCodeKey).ConfigureAwait(false);

                httpreq.Headers.Add("lazlo-apilicensecode", posDeviceApiLicenseCode);
                httpreq.Headers.Add("lazlo-txlicensecode", checkoutSessionCode);

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

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

                if (message.IsSuccessStatusCode)
                {
                    await _Machine.FireAsync(PosDeviceSimulationTriggerType.WaitForConsumerToLeave);
                }

                else
                {
                    throw new Exception($"CheckoutComplete failed: {responseJson}");
                }
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                await _Machine.FireAsync(PosDeviceSimulationTriggerType.WaitForConsumerToPay);
            }
        }
Exemplo n.º 7
0
 public void SetUp()
 {
     theData = new InMemoryRequestData();
     objectConverter = new ObjectConverter();
     theRequest = new SmartRequest(theData, objectConverter);
 }
        private async Task OnValidateAsync()
        {
            try
            {
                string appApiLicenseCode = await StateManager.GetStateAsync <string>(AppApiLicenseCodeKey).ConfigureAwait(false);

                string consumerLicenseCode = await StateManager.GetStateAsync <string>(ConsumerLicenseCodeKey).ConfigureAwait(false);

                List <EntitySecret> entities = await StateManager.GetStateAsync <List <EntitySecret> >(EntitiesKey).ConfigureAwait(false);

                Uri requestUri = GetFullUri("api/v2/validation/validate");

                HttpRequestMessage httpreq = new HttpRequestMessage(HttpMethod.Post, requestUri);

                SmartRequest <ValidationsRequest> validationRequest = new SmartRequest <ValidationsRequest>
                {
                    Data = new ValidationsRequest
                    {
                        Validations = entities.Select(z => new ValidationRequest
                        {
                            MediaHash             = z.Hash,
                            ValidationLicenseCode = z.ValidationLicenseCode
                        }).ToList()
                    },
                    Latitude  = _Latitude,
                    Longitude = _Longitude,
                    Uuid      = Id.GetGuidId().ToString()
                };

                string json = JsonConvert.SerializeObject(validationRequest);

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

                httpreq.Headers.Add("lazlo-consumerlicensecode", consumerLicenseCode);
                httpreq.Headers.Add("lazlo-apilicensecode", appApiLicenseCode);

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

                WriteTimedDebug($"Ticket Checkout request sent");

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

                var response = JsonConvert.DeserializeObject <SmartResponse <ValidationResponse> >(responseJson);

                if (message.IsSuccessStatusCode)
                {
                    if (response.Data.TicketValidationStatuses.Sum(z => z.CurrentValue) > 0)
                    {
                        if (await StateManager.ContainsStateAsync(WorkflowCompletionDetectedKey))
                        {
                            WriteTimedDebug("Houston, we've got a problem");
                        }

                        decimal claimAmount = response.Data.TicketValidationStatuses.Sum(z => z.CurrentValue);

                        await StateManager.SetStateAsync(ClaimLicenseCodeKey, response.Data.ClaimLicenseCode);

                        await StateManager.SetStateAsync(ClaimAmountKey, claimAmount);

                        await _StateMachine.FireAsync(ConsumerSimulationExchangeAction.WaitToExchange);
                    }

                    else if (response.Data.TicketValidationStatuses.All(z => z.OutstandingPanelCount == 0) && response.Data.TicketValidationStatuses.Sum(z => z.CurrentValue) == 0)
                    {
                        if (await StateManager.TryAddStateAsync(WorkflowCompletionDetectedKey, true))
                        {
                            WriteTimedDebug($"Cycle complete: {Id}");
                        }

                        // Looping for now to make sure logic is correct, but I think I saw a potential situation where a ticket still had value
                        await _StateMachine.FireAsync(ConsumerSimulationExchangeAction.GoIdle);

                        // The following is ultimately the proper workflow
                        //var reminder = GetReminder(WorkflowReminderKey);
                        //await UnregisterReminderAsync(reminder);
                        //TODO Queue actor deletion
                    }

                    else
                    {
                        await _StateMachine.FireAsync(ConsumerSimulationExchangeAction.GoIdle);
                    }
                }

                else
                {
                    throw new Exception($"Validation failed: {response.Error.Message}");
                }
            }

            catch (Exception ex)
            {
                WriteTimedDebug(ex);
                await _StateMachine.FireAsync(ConsumerSimulationExchangeAction.GoIdle);
            }
        }
        private async Task OnExchangeAsync()
        {
            try
            {
                string claimLicenseCode = await StateManager.GetStateAsync <string>(ClaimLicenseCodeKey);

                decimal totalAmount = await StateManager.GetStateAsync <decimal>(ClaimAmountKey);

                var availableMerchandise = await RetrieveMerchandiseAsync();

                // TODO Make this more robust
                MerchantDisplay merchant = (from p in availableMerchandise
                                            where p.Ranges.Any(z => totalAmount >= z.Low && totalAmount <= z.High)
                                            select p).First();

                string appApiLicenseCode = await StateManager.GetStateAsync <string>(AppApiLicenseCodeKey).ConfigureAwait(false);

                string consumerLicenseCode = await StateManager.GetStateAsync <string>(ConsumerLicenseCodeKey).ConfigureAwait(false);

                Uri requestUri = GetFullUri("api/v3/claim/ticket/exchange/low");

                HttpRequestMessage httpreq = new HttpRequestMessage(HttpMethod.Post, requestUri);

                SmartRequest <ClaimExchangeLowRequest> claimRequest = new SmartRequest <ClaimExchangeLowRequest>
                {
                    Data = new ClaimExchangeLowRequest
                    {
                        ClaimLicenseCode = claimLicenseCode,
                        Merchandise      = new List <ClaimExchangeMerchandise>
                        {
                            new ClaimExchangeMerchandise
                            {
                                Amount           = totalAmount,
                                MerchandiseRefId = merchant.MerchandiseRefId
                            }
                        }
                    },
                    Latitude  = _Latitude,
                    Longitude = _Longitude,
                    Uuid      = Id.GetGuidId().ToString()
                };

                string json = JsonConvert.SerializeObject(claimRequest);

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

                httpreq.Headers.Add("lazlo-consumerlicensecode", consumerLicenseCode);
                httpreq.Headers.Add("lazlo-apilicensecode", appApiLicenseCode);

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

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

                var response = JsonConvert.DeserializeObject <SmartResponse <ClaimExchangeResponse2> >(responseJson);

                if (message.IsSuccessStatusCode)
                {
                    Debug.WriteLine("Exchange succeeded");

                    await StateManager.SetStateAsync(CheckoutSessionLicenseCodeKey, response.Data.CheckoutLicenseCode);

                    await _StateMachine.FireAsync(ConsumerSimulationExchangeAction.WaitForGiftCardsToRender);
                }

                else
                {
                    throw new Exception($"Exchange failed: {response.Error.Message}");
                }
            }

            catch (Exception ex)
            {
                WriteTimedDebug(ex);
                await _StateMachine.FireAsync(ConsumerSimulationExchangeAction.WaitToExchange);
            }
        }
Exemplo n.º 10
0
 public void SetUp()
 {
     theData = new InMemoryRequestData();
     theLibrary = new ConverterLibrary();
     objectConverter = new ObjectConverter(new InMemoryServiceLocator(), theLibrary);
     theRequest = new SmartRequest(theData, objectConverter);
 }
Exemplo n.º 11
0
 public void SetUp()
 {
     theFubuRequest = new InMemoryFubuRequest();
     theData = new InMemoryRequestData();
     objectConverter = new ObjectConverter();
     theRequest = new FubuSmartRequest(theData, objectConverter, theFubuRequest);
 }
Exemplo n.º 12
0
 public void SetUp()
 {
     theData         = new InMemoryRequestData();
     objectConverter = new ObjectConverter();
     theRequest      = new SmartRequest(theData, objectConverter);
 }
        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");
            }
        }