public override void ServerSide(List <Common.Connections.Connection> ServerConnections, Common.Connections.Connection ThisConnection) { Send(ThisConnection); System.Threading.Thread.Sleep(50); using (ConversationDataContext tmpDB = new ConversationDataContext()) { List <MessageItem> Messages = ((ConversationItem)(from a in tmpDB.ConversationItems where a.ConversationGUID == this.ConversationID select a).Single()).MessageItems.OrderBy(a => a.MessageID).ToList(); //LOOP THROUGH EACH MESSAGE IN THE DATABASE AND SEND IT BACK TO THE PERSON REQUESTING THE CONVERSATION foreach (MessageItem tmpMessage in Messages) { //UNWRAP THE MESSAGE AND SEND IT BACK TO THE SAME CONNECTION WHICH ASKED FOR IT Message_Private tmpPrivateMessage = (Message_Private)MessageWrapper.UnPackageFromTCP(tmpMessage.MessageData.ToArray(), true); //USED TO STOP THE SOUND FROM PLAYING SINCE THIS MESSAGE IS AN ARCHIVED MESSAGE WE DO NOT NEED TO NOTIFY THE USER IT HAS ARIVED tmpPrivateMessage.IsArchive = true; //SEND THE TMP MESSAGE BACK tmpPrivateMessage.Send(ThisConnection); //SLEEP BRIEFLY TO SLOW MESSAGE ARIVAL ON THE CLIENT System.Threading.Thread.Sleep(50); } //CHECK TO SEE IF WE NEED TO DELETE THE ITEM FROM A MISSED CONVERSATION LIST OR NOT tmpDB.MissedConversationItems.DeleteAllOnSubmit(from a in tmpDB.MissedConversationItems where a.ConversationItem.ConversationGUID == this.ConversationID select a); tmpDB.SubmitChanges(); } }
public override void ServerSide(List <Connection> ServerConnections, Connection ThisConnection) { //SEND THIS MESSAGE TO EVERYONE ATTACHED TO THE CONVERSATION WINDOW THE USER IS ENTERING TEXT using (ConversationDataContext tmpDB = new ConversationDataContext()) { foreach (Connection ServerConnection in (from a in ServerConnections where a != ThisConnection && (from b in tmpDB.ConversationMembers where b.ConversationItem.ConversationGUID == this.ConversationID select b.UserID).Contains(a.UserID) select a)) { Send(ServerConnection); } } }
public override void ServerSide(List <Connection> ServerConnections, Connection ThisConnection) { IContactsProvider ContactProvider = StaticFunctions.GetContactsProvider(); //RETURN THE LIST OF USERS WHO ARE ATTACHED TO THIS CONVERSATION SO THE TITLE OF A WINDOW MAY BE UPDATED using (ConversationDataContext tmpDB = new ConversationDataContext()) { this.Recipients = (from a in tmpDB.ConversationMembers where a.ConversationItem.ConversationGUID == this.ConversationID select ContactProvider.UserNameFromID(a.UserID)).ToArray(); } //SEND THE MESSAGE TO THE CLIENT Send(ThisConnection); }
public override void ServerSide(List <Connection> ServerConnections, Connection ThisConnection) { IContactsProvider ContactProvider = StaticFunctions.GetContactsProvider(); using (ConversationDataContext tmpDB = new ConversationDataContext()) { long[] ConvIDS = (from a in tmpDB.MissedConversationItems where a.UserID == ThisConnection.UserID select a.MissedMessageID).ToArray(); //CREATE THE LIST OF CONVERSATIONS WHICH WE ARE SENDING BACK TO THE USER this.MissedConversations = (from a in tmpDB.MissedConversationItems where ConvIDS.Contains(a.MissedMessageID) && a.ConversationItem.MessageItems.Count() > 0 select new Conversation() { ConversationID = a.ConversationItem.ConversationGUID, Date = a.ConversationItem.DateCreated, MessageCount = a.ConversationItem.MessageItems.Count(), Recipients = string.Join("; ", a.ConversationItem.ConversationMembers.Select(b => ContactProvider.UserNameFromID(b.UserID)).ToArray()) }).ToArray(); //IF THERE ARE MISSED CONVERSATIONS THEN REPLY TO THE USER Send(ThisConnection); } }
public override void ServerSide(List <Connection> ServerConnections, Connection ThisConnection) { IContactsProvider ContactProvider = StaticFunctions.GetContactsProvider(); using (ConversationDataContext tmpDB = new ConversationDataContext()) { long[] ConvIDS = (from a in tmpDB.ConversationMembers where a.UserID == ThisConnection.UserID select a.ConversationID).ToArray(); ConversationItem[] ConvList = (from a in tmpDB.ConversationItems where ConvIDS.Contains(a.ConversationID) select a).ToArray(); //GET THE RECENT MESSAGES FROM THE DATABASE this.RecentList = (from a in ConvList where a.MessageItems.Count() > 0 && a.DateCreated > DateTime.Now.AddDays(this.DaysToSearch * -1) select new Conversation() { Date = a.DateCreated, Preview = ((Message_Private)MessageWrapper.UnPackageFromTCP(a.MessageItems.First().MessageData.ToArray(), true)).Message, Recipients = string.Join("; ", a.ConversationMembers.Select(b => ContactProvider.UserNameFromID(b.UserID)).OrderBy(c => c).ToArray()), MessageCount = a.MessageItems.Count(), ConversationID = a.ConversationGUID }).OrderBy(a => a.Date).Reverse().ToArray(); //SEND THE INFORMATION BACK TO THE USER Send(ThisConnection); } }
async Task <BotData> IBotDataStore <BotData> .LoadAsync(IAddress key, BotStoreType botStoreType, CancellationToken cancellationToken) { using (var context = new ConversationDataContext(_connectionStringName)) { try { SqlBotDataEntity entity = SqlBotDataEntity.GetSqlBotDataEntity(key, botStoreType, context); if (entity == null) { return(new BotData(eTag: String.Empty, data: null)); } return(new BotData(entity.ETag, entity.GetData())); } catch (Exception ex) { throw new HttpException((int)HttpStatusCode.InternalServerError, ex.Message); } } }
internal static SqlBotDataEntity GetSqlBotDataEntity(IAddress key, BotStoreType botStoreType, ConversationDataContext context) { SqlBotDataEntity entity = null; var query = context.BotData.OrderByDescending(d => d.Timestamp); switch (botStoreType) { case BotStoreType.BotConversationData: entity = query.FirstOrDefault(d => d.BotStoreType == botStoreType && d.ChannelId == key.ChannelId && d.ConversationId == key.ConversationId); break; case BotStoreType.BotUserData: entity = query.FirstOrDefault(d => d.BotStoreType == botStoreType && d.ChannelId == key.ChannelId && d.UserId == key.UserId); break; case BotStoreType.BotPrivateConversationData: entity = query.FirstOrDefault(d => d.BotStoreType == botStoreType && d.ChannelId == key.ChannelId && d.ConversationId == key.ConversationId && d.UserId == key.UserId); break; default: throw new ArgumentException("Unsupported bot store type!"); } return(entity); }
public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item) { var activity = await item as Activity; var userId = context.Activity.From.Id; using (ConversationDataContext dataContext = new ConversationDataContext()) { if (!dataContext.UserConversations.Any( c => c.UserId == userId && c.ConversationId == context.Activity.Conversation.Id)) { dataContext.UserConversations.Add(new UserConversation { ID = Guid.NewGuid().ToString(), ConversationId = context.Activity.Conversation.Id, UserId = userId }); try { dataContext.SaveChanges(); } catch (Exception e) { //TODO: Add error logging Console.WriteLine(e); throw; } } } var reply = activity.CreateReply(); if (activity.Text == null) { var value = activity.Value as Newtonsoft.Json.Linq.JObject; if (value != null) { var cardValue = value.ToObject <CardValue>(); var activityValue = activity.Value as Newtonsoft.Json.Linq.JObject; if (activityValue != null) { var categorySelection = activityValue.ToObject <CategorySelection>(); var category = categorySelection.Category; //query the database for products of this category type, create another adaptive card displaying the products and send to user reply.Text = "Category=" + category; await context.PostAsync(reply); } return; } } else if (activity.Text.ToLowerInvariant().Contains("hero")) { ReplyHeroCard(activity, reply); } else if (activity.Text.ToLowerInvariant().Contains("adaptive")) { ReplyAdaptiveCard(context, activity, reply); } else { int length = (activity.Text ?? string.Empty).Length; reply.Text = $"You sent {activity.Text} which was {length} characters"; } await context.PostAsync(reply); context.Wait(MessageReceivedAsync); }
async Task IBotDataStore <BotData> .SaveAsync(IAddress key, BotStoreType botStoreType, BotData botData, CancellationToken cancellationToken) { SqlBotDataEntity entity = new SqlBotDataEntity(botStoreType, key.BotId, key.ChannelId, key.ConversationId, key.UserId, botData.Data) { ETag = botData.ETag, ServiceUrl = key.ServiceUrl }; using (var context = new ConversationDataContext(_connectionStringName)) { try { if (String.IsNullOrEmpty(entity.ETag)) { context.BotData.Add(entity); } else if (entity.ETag == "*") { var foundData = SqlBotDataEntity.GetSqlBotDataEntity(key, botStoreType, context); if (botData.Data != null) { if (foundData == null) { context.BotData.Add(entity); } else { foundData.Data = entity.Data; foundData.ServiceUrl = entity.ServiceUrl; } } else { if (foundData != null) { context.BotData.Remove(foundData); } } } else { var foundData = SqlBotDataEntity.GetSqlBotDataEntity(key, botStoreType, context); if (botData.Data != null) { if (foundData == null) { context.BotData.Add(entity); } else { foundData.Data = entity.Data; foundData.ServiceUrl = entity.ServiceUrl; foundData.ETag = entity.ETag; } } else { if (foundData != null) { context.BotData.Remove(foundData); } } } context.SaveChanges(); } catch (System.Data.SqlClient.SqlException err) { throw new HttpException((int)HttpStatusCode.InternalServerError, err.Message); } } }