public static void removeSentMessage(long timestamp) { lock (lockObj) { using (HikeMqttPersistenceDb context = new HikeMqttPersistenceDb(App.MqttDBConnectionstring)) { List <HikePacket> entriesToDelete = DbCompiledQueries.GetMqttMsgForTimestamp(context, timestamp).ToList(); if (entriesToDelete == null || entriesToDelete.Count == 0) { return; } context.mqttMessages.DeleteAllOnSubmit <HikePacket>(entriesToDelete); try { context.SubmitChanges(ConflictMode.ContinueOnConflict); Debug.WriteLine("Removed unsent packet with timestamp :: " + timestamp); } catch (ChangeConflictException e) { Debug.WriteLine(e.Message); Debug.WriteLine("Failed to remove unsent packet with timestamp :: " + timestamp); // Automerge database values for members that client // has not modified. foreach (ObjectChangeConflict occ in context.ChangeConflicts) { occ.Resolve(RefreshMode.KeepChanges); } } // Submit succeeds on second try. context.SubmitChanges(ConflictMode.FailOnFirstConflict); } } }
/// <summary> /// Thread safe function to update msg status /// </summary> /// <param name="ids"></param> /// <param name="status"></param> /// <returns></returns> public static string updateAllMsgStatus(string fromUser, long[] ids, int status) { bool shouldSubmit = false; string msisdn = null; using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring + ";Max Buffer Size = 1024")) { for (int i = 0; i < ids.Length; i++) { ConvMessage message = DbCompiledQueries.GetMessagesForMsgId(context, ids[i]).FirstOrDefault <ConvMessage>(); if (message != null) { if ((int)message.MessageStatus < status) { if (fromUser == null || fromUser == message.Msisdn) { message.MessageStatus = (ConvMessage.State)status; msisdn = message.Msisdn; shouldSubmit = true; } } } } if (shouldSubmit) { SubmitWithConflictResolve(context); } shouldSubmit = false; return(msisdn); } }
public static List <GroupInfo> GetAllGroups() { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { return(DbCompiledQueries.GetAllGroups(context).ToList()); } }
public static void deleteMultipleRows(List <ContactInfo.DelContacts> ids) { if (ids == null || ids.Count == 0) { return; } bool shouldSubmit = false; using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { //using (HikeChatsDb chats = new HikeChatsDb(App.MsgsDBConnectionstring)) { for (int i = 0; i < ids.Count; i++) { context.users.DeleteAllOnSubmit <ContactInfo>(DbCompiledQueries.GetUsersWithGivenId(context, ids[i].Id)); if (App.ViewModel.ConvMap.ContainsKey(ids[i].Msisdn)) { ConversationListObject obj = App.ViewModel.ConvMap[ids[i].Msisdn]; obj.ContactName = null; ConversationTableUtils.saveConvObject(obj, obj.Msisdn); //ConversationTableUtils.saveConvObjectList(); } } } SubmitWithConflictResolve(context); } }
public static string updateMsgStatus(string fromUser, long msgID, int val) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring + ";Max Buffer Size = 1024")) { ConvMessage message = DbCompiledQueries.GetMessagesForMsgId(context, msgID).FirstOrDefault <ConvMessage>(); if (message != null) { if ((int)message.MessageStatus < val) { if (fromUser == null || fromUser == message.Msisdn) { message.MessageStatus = (ConvMessage.State)val; SubmitWithConflictResolve(context); return(message.Msisdn); } else { return(null); } } } else { return(null); } } return(null); }
public static List <Blocked> getBlockList() { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { List <Blocked> res = DbCompiledQueries.GetBlockList(context).ToList <Blocked>(); return((res == null || res.Count == 0) ? null : res); } }
public static GroupInfo getGroupInfoForId(string groupId) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { GroupInfo cObj = DbCompiledQueries.GetGroupInfoForID(context, groupId).FirstOrDefault(); return(cObj); } }
public static void deleteGroupWithId(string groupId) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { context.groupInfo.DeleteAllOnSubmit <GroupInfo>(DbCompiledQueries.GetGroupInfoForID(context, groupId)); MessagesTableUtils.SubmitWithConflictResolve(context); } }
public static void deleteAllMessagesForMsisdn(string msisdn) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { context.messages.DeleteAllOnSubmit <ConvMessage>(DbCompiledQueries.GetMessagesForMsisdn(context, msisdn)); SubmitWithConflictResolve(context); } }
public static List <ConvMessage> getAllMessages() { List <ConvMessage> res; using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { res = DbCompiledQueries.GetAllMessages(context).ToList <ConvMessage>(); return((res == null || res.Count == 0) ? null : res.ToList()); } }
/* This queries messages table and get the last message for given msisdn*/ public static ConvMessage getLastMessageForMsisdn(string msisdn) { List <ConvMessage> res; using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { res = DbCompiledQueries.GetMessagesForMsisdn(context, msisdn).ToList <ConvMessage>(); return((res == null || res.Count == 0) ? null : res.Last()); } }
public static bool IsGroupAlive(string groupId) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { GroupInfo cObj = DbCompiledQueries.GetGroupInfoForID(context, groupId).FirstOrDefault(); if (cObj == null) { return(false); } return(cObj.GroupAlive); } }
public static bool isUserBlocked(string msisdn) { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { List <Blocked> res = DbCompiledQueries.GetBlockedUserForMsisdn(context, msisdn).ToList <Blocked>(); if (res != null && res.Count > 0) { return(true); } } return(false); }
public static void SetGroupAlive(string groupId) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { GroupInfo cObj = DbCompiledQueries.GetGroupInfoForID(context, groupId).FirstOrDefault(); if (cObj == null) { return; } cObj.GroupAlive = true; MessagesTableUtils.SubmitWithConflictResolve(context); } }
public static void unblock(string msisdn) { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { List <Blocked> res = DbCompiledQueries.GetBlockedUserForMsisdn(context, msisdn).ToList <Blocked>(); if (res == null || res.Count == 0) { return; } context.blockedUsersTable.DeleteAllOnSubmit(res); SubmitWithConflictResolve(context); } }
/* Adds a chat message to message Table.*/ public static bool addMessage(ConvMessage convMessage) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring + ";Max Buffer Size = 1024;")) { if (convMessage.MappedMessageId > 0) { IQueryable <ConvMessage> qq = DbCompiledQueries.GetMessageForMappedMsgIdMsisdn(context, convMessage.Msisdn, convMessage.MappedMessageId, convMessage.Message); ConvMessage cm = qq.FirstOrDefault(); if (cm != null) { return(false); } } long currentMessageId = convMessage.MessageId; context.messages.InsertOnSubmit(convMessage); try { context.SubmitChanges(); } catch (Exception ex) { Debug.WriteLine("Exception while inserting msg in CHATS DB : " + ex.StackTrace); return(false); } //if (convMessage.GrpParticipantState == ConvMessage.ParticipantInfoState.NO_INFO) //{ // long msgId = convMessage.MessageId; // Deployment.Current.Dispatcher.BeginInvoke(() => // { // NewChatThread currentPage = App.newChatThreadPage; // if (currentPage != null) // { // if (convMessage.IsSent) // { // SentChatBubble sentChatBubble; // currentPage.OutgoingMsgsMap.TryGetValue(currentMessageId, out sentChatBubble); // if (sentChatBubble != null) // { // currentPage.OutgoingMsgsMap.Remove(currentMessageId); // currentPage.OutgoingMsgsMap.Add(convMessage.MessageId, sentChatBubble); // sentChatBubble.MessageId = convMessage.MessageId; // } // } // } // }); //} } return(true); }
public static bool updateGroupName(string groupId, string groupName) { using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { GroupInfo cObj = DbCompiledQueries.GetGroupInfoForID(context, groupId).FirstOrDefault(); if (cObj == null) { return(false); } cObj.GroupName = groupName; MessagesTableUtils.SubmitWithConflictResolve(context); } return(true); }
public static void deleteMultipleRows(List <ContactInfo> ids) { if (ids == null || ids.Count == 0) { return; } using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { for (int i = 0; i < ids.Count; i++) { context.users.DeleteAllOnSubmit <ContactInfo>(DbCompiledQueries.GetUsersWithGivenId(context, ids[i].Id)); } SubmitWithConflictResolve(context); } }
public static void updateOnHikeStatus(string msisdn, bool joined) { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { List <ContactInfo> res = DbCompiledQueries.GetContactFromMsisdn(context, msisdn).ToList <ContactInfo>(); if (res == null || res.Count == 0) { return; } foreach (ContactInfo cInfo in res) { cInfo.OnHike = (bool)joined; } SubmitWithConflictResolve(context); } }
public static List <ContactInfo> getAllContacts() { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { List <ContactInfo> res; try { res = DbCompiledQueries.GetAllContacts(context).ToList <ContactInfo>(); } catch (ArgumentNullException) { res = null; } return((res == null || res.Count == 0) ? null : res); } }
public static List <ContactInfo> GetAllHikeContactsOrdered() { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { List <ContactInfo> res; try { res = DbCompiledQueries.GetAllHikeContactsOrdered(context).ToList <ContactInfo>(); } catch (Exception) { res = null; } return(res); } }
public static ContactInfo getContactInfoFromMSISDN(string msisdn) { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { List <ContactInfo> res; try { res = DbCompiledQueries.GetContactFromMsisdn(context, msisdn).ToList <ContactInfo>(); } catch (Exception) { res = null; } return((res == null || res.Count == 0) ? null : res.First()); } }
/// <summary> /// Retrives all messages thet were unsent previously, and are required to send when connection re-establishes /// deletes pending messages from db after reading /// </summary> /// <returns></returns> public static List <HikePacket> getAllSentMessages() { try { List <HikePacket> res; using (HikeMqttPersistenceDb context = new HikeMqttPersistenceDb(App.MqttDBConnectionstring)) { res = DbCompiledQueries.GetAllSentMessages(context).ToList <HikePacket>(); //context.mqttMessages.DeleteAllOnSubmit(context.mqttMessages); //context.SubmitChanges(); } return((res == null || res.Count() == 0) ? null : res); } catch (Exception e) { Debug.WriteLine("Exception while fetching MQTT msgs : " + e.StackTrace); return(null); } }
//private static HikeChatsDb chatsDbContext = new HikeChatsDb(App.MsgsDBConnectionstring); // use this chatsDbContext to improve performance /* This is shown on chat thread screen*/ public static List <ConvMessage> getMessagesForMsisdn(string msisdn, long lastMessageId, int count) { List <ConvMessage> res = DbCompiledQueries.GetMessagesForMsisdnForPaging(DbCompiledQueries.chatsDbContext, msisdn, lastMessageId, count).ToList <ConvMessage>(); return((res == null || res.Count == 0) ? null : res); }