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 UpdateDownloadStatusAsync(EntitySecret entitySecret) { List <EntityDownload> pending = await StateManager.GetStateAsync <List <EntityDownload> >(PendingGiftCardsKey); pending.RemoveAll(z => z.ValidationLicenseCode == entitySecret.ValidationLicenseCode); if (pending.Count == 0) { await StateManager.RemoveStateAsync(PendingGiftCardsKey); await _StateMachine.FireAsync(ConsumerSimulationExchangeAction.GoIdle); } else { await StateManager.SetStateAsync(PendingGiftCardsKey, pending); } }
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); } }