public static void Main(string[] args) { var usm = new UserStorageManager(); var master = usm.GetMasterStorage(new UserIdGenerator(), null, null); master.Add(new User { FirstName = "name", LastName = "surename", DateOfBirth = DateTime.Now }); master.Add(new User { FirstName = "name1", LastName = "surename1", DateOfBirth = DateTime.Now }); Console.WriteLine("Master"); foreach (var user in master.Search(u => true)) { Console.WriteLine(user.FirstName + " " + user.LastName); } Console.ReadLine(); master.Delete(0); Console.WriteLine("Master"); foreach (var user in master.Search(u => true)) { Console.WriteLine(user.FirstName + " " + user.LastName); } Console.ReadLine(); usm.UnloadDomains(); //var usm = new UserStorageManager(); //var slaves = usm.GetSlaveServices(); //Console.ReadLine(); //Console.WriteLine("Slave"); //foreach (var user in slaves.First(a => true).Search(u => true)) //{ // Console.WriteLine(user.FirstName + " " + user.LastName); //} //Console.ReadLine(); //Console.WriteLine("Slave"); //foreach (var user in slaves.First().Search(u => true)) //{ // Console.WriteLine(user.FirstName + " " + user.LastName); //} //Console.ReadLine(); //usm.UnloadDomains(); }
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; } }
public async Task WakeUpConversation() { var users = UserStorageManager.GetUsers(); // Send good morning var morningUsers = from u in users where DateTime.UtcNow.Hour + u.Gmtplus >= 8 && DateTime.UtcNow.Hour + u.Gmtplus < 9 select u; var intentionId = CardHelper.GoodMorningIntentionId; await SendGood(morningUsers.ToList(), intentionId); // Send good evening var eveningUsers = from u in users where DateTime.UtcNow.Hour + u.Gmtplus >= 22 && DateTime.UtcNow.Hour + u.Gmtplus < 23 select u; intentionId = CardHelper.GoodEveningIntentionId; await SendGood(eveningUsers.ToList(), intentionId); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { await RespondingMessage(activity); var timezone = findTimeZone(activity.From.Id); UserStorageManager.AddOrUpdateUser(activity.From.Id, activity.From.Name, activity.Recipient.Id, activity.Recipient.Name, activity.ServiceUrl, timezone, activity.ChannelId); await Conversation.SendAsync(activity, () => new RootDialog(activity.From.Id)); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }