private async Task GetAndSendCard(IDialogContext context, string intentionId) { Card newCard; // Get the cache var user = await UserStorageManager.GetUser(this.UserId); cardListReference = !string.IsNullOrEmpty(user?.CardsCache) ? JsonConvert.DeserializeObject <Dictionary <string, Tuple <int, int, List <Card> > > >(user.CardsCache) : new Dictionary <string, Tuple <int, int, List <Card> > >(); // Get another card if (cardListReference.ContainsKey(intentionId)) { var entry = cardListReference[intentionId]; var newIndex = entry.Item2 + 1; if (newIndex < entry.Item3.Count) { newCard = entry.Item3[newIndex]; cardListReference[intentionId] = new Tuple <int, int, List <Card> >(entry.Item1, newIndex, entry.Item3); } else { var(hashcode, cards) = CardHelper.GetIntentionCards(intentionId, entry.Item1); cardListReference[intentionId] = new Tuple <int, int, List <Card> >(hashcode, 0, cards); newCard = cards[0]; } } else { var(hashcode, cards) = CardHelper.GetIntentionCards(intentionId, 0); cardListReference.Add(intentionId, new Tuple <int, int, List <Card> >(hashcode, 0, cards)); newCard = cards[0]; } // Send the card await SendCard(context, newCard); // Save the cache if (user != null) { user.CardsCache = JsonConvert.SerializeObject(cardListReference, new JsonSerializerSettings { ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver() }); UserStorageManager.UpdateUser(user); } // Wait for a response context.Wait(State1); }
private async void UpdateResumeCookie(IMessageActivity message) { try { var resumptionCookie = new ResumptionCookie(message).GZipSerialize(); //var resumptionCookie = JsonConvert.SerializeObject(new ConversationReference(context.Activity.Id)); var currentuser = await UserStorageManager.GetUser(this.UserId); if (currentuser != null) { currentuser.ResumptionCookie = resumptionCookie; UserStorageManager.UpdateUser(currentuser); } } catch (Exception) { throw; } }