Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
 public static List <GroupInfo> GetAllGroups()
 {
     using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring))
     {
         return(DbCompiledQueries.GetAllGroups(context).ToList());
     }
 }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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);
     }
 }
Exemplo n.º 7
0
 public static GroupInfo getGroupInfoForId(string groupId)
 {
     using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring))
     {
         GroupInfo cObj = DbCompiledQueries.GetGroupInfoForID(context, groupId).FirstOrDefault();
         return(cObj);
     }
 }
Exemplo n.º 8
0
 public static void deleteGroupWithId(string groupId)
 {
     using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring))
     {
         context.groupInfo.DeleteAllOnSubmit <GroupInfo>(DbCompiledQueries.GetGroupInfoForID(context, groupId));
         MessagesTableUtils.SubmitWithConflictResolve(context);
     }
 }
Exemplo n.º 9
0
 public static void deleteAllMessagesForMsisdn(string msisdn)
 {
     using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring))
     {
         context.messages.DeleteAllOnSubmit <ConvMessage>(DbCompiledQueries.GetMessagesForMsisdn(context, msisdn));
         SubmitWithConflictResolve(context);
     }
 }
Exemplo n.º 10
0
        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());
            }
        }
Exemplo n.º 11
0
        /* 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());
            }
        }
Exemplo n.º 12
0
 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);
     }
 }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 14
0
 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);
     }
 }
Exemplo n.º 15
0
 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);
     }
 }
Exemplo n.º 16
0
        /* 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);
        }
Exemplo n.º 17
0
 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);
 }
Exemplo n.º 18
0
 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);
     }
 }
Exemplo n.º 19
0
 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);
     }
 }
Exemplo n.º 20
0
 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);
     }
 }
Exemplo n.º 21
0
 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);
     }
 }
Exemplo n.º 22
0
 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());
     }
 }
Exemplo n.º 23
0
 /// <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);
     }
 }
Exemplo n.º 24
0
        //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);
        }