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 void deleteBlocklist() { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { context.blockedUsersTable.DeleteAllOnSubmit <Blocked>(context.GetTable <Blocked>()); context.SubmitChanges(); } }
public static void addContact(ContactInfo user) { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { context.users.InsertOnSubmit(user); context.SubmitChanges(); } }
public static void deleteAllContacts() { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { context.users.DeleteAllOnSubmit <ContactInfo>(context.GetTable <ContactInfo>()); SubmitWithConflictResolve(context); } }
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 List <ContactInfo> getAllContactsToInvite() { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { var users = from user in context.users where user.OnHike == false orderby user.Name select user; return(users.ToList <ContactInfo>()); } }
public static List <ContactInfo> getAllContactsByGroup() { using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { var users = from user in context.users orderby user.Name select user; return(users.ToList <ContactInfo>()); } }
public static void block(string msisdn) { Blocked userBlocked = new Blocked(msisdn); using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { context.blockedUsersTable.InsertOnSubmit(userBlocked); SubmitWithConflictResolve(context); } }
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 addContacts(List <ContactInfo> contacts) { if (contacts == null) { return; } using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring + "; Max Buffer Size = 2048")) { context.users.InsertAllOnSubmit(contacts); context.SubmitChanges(); } }
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); } }
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 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()); } }
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); } }
private static void SubmitWithConflictResolve(HikeUsersDb context) { try { context.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException e) { Console.WriteLine(e.Message); // Automerge database values for members that client // has not modified. foreach (ObjectChangeConflict occ in context.ChangeConflicts) { occ.Resolve(RefreshMode.KeepChanges); // second client changes will be submitted. } } // Submit succeeds on second try. context.SubmitChanges(ConflictMode.FailOnFirstConflict); }
public static void addBlockList(List <string> msisdns) { if (msisdns == null) { return; } using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { foreach (string m in msisdns) { context.blockedUsersTable.InsertOnSubmit(new Blocked(m)); } try { context.SubmitChanges(); } catch (DuplicateKeyException dke) { dke.ToString(); } } }
public static void createDatabaseAsync() { if (App.appSettings.Contains(App.IS_DB_CREATED)) // shows db are created { return; } BackgroundWorker bw = new BackgroundWorker(); bw.DoWork += (s, e) => { try { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { if (!string.IsNullOrEmpty(MiscDBUtil.THUMBNAILS) && !store.DirectoryExists(MiscDBUtil.THUMBNAILS)) { store.CreateDirectory(MiscDBUtil.THUMBNAILS); } if (!string.IsNullOrEmpty(MiscDBUtil.MISC_DIR) && !store.DirectoryExists(MiscDBUtil.MISC_DIR)) { store.CreateDirectory(MiscDBUtil.MISC_DIR); } if (!store.DirectoryExists(ConversationTableUtils.CONVERSATIONS_DIRECTORY)) { store.CreateDirectory(ConversationTableUtils.CONVERSATIONS_DIRECTORY); } if (!store.DirectoryExists(HikeConstants.SHARED_FILE_LOCATION)) { store.CreateDirectory(HikeConstants.SHARED_FILE_LOCATION); } if (!store.DirectoryExists(HikeConstants.ANALYTICS_OBJECT_DIRECTORY)) { store.CreateDirectory(HikeConstants.ANALYTICS_OBJECT_DIRECTORY); } } // Create the database if it does not exist. Stopwatch st = Stopwatch.StartNew(); using (HikeChatsDb db = new HikeChatsDb(MsgsDBConnectionstring)) { if (db.DatabaseExists() == false) { db.CreateDatabase(); } } using (HikeUsersDb db = new HikeUsersDb(UsersDBConnectionstring)) { if (db.DatabaseExists() == false) { db.CreateDatabase(); } } using (HikeMqttPersistenceDb db = new HikeMqttPersistenceDb(MqttDBConnectionstring)) { if (db.DatabaseExists() == false) { db.CreateDatabase(); } } WriteToIsoStorageSettings(App.IS_DB_CREATED, true); st.Stop(); long msec = st.ElapsedMilliseconds; Debug.WriteLine("APP: Time to create Dbs : {0}", msec); } catch { RemoveKeyFromAppSettings(App.IS_DB_CREATED); } }; bw.RunWorkerAsync(); }
public static void clearDatabase() { #region DELETE CONVS,CHAT MSGS, GROUPS, GROUP MEMBERS,THUMBNAILS ConversationTableUtils.deleteAllConversations(); DeleteAllThumbnails(); DeleteAllAttachmentData(); GroupManager.Instance.DeleteAllGroups(); using (HikeChatsDb context = new HikeChatsDb(App.MsgsDBConnectionstring)) { context.messages.DeleteAllOnSubmit <ConvMessage>(context.GetTable <ConvMessage>()); context.groupInfo.DeleteAllOnSubmit <GroupInfo>(context.GetTable <GroupInfo>()); try { context.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException e) { Debug.WriteLine(e.Message); // 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); } #endregion #region DELETE USERS, BLOCKLIST using (HikeUsersDb context = new HikeUsersDb(App.UsersDBConnectionstring)) { context.blockedUsersTable.DeleteAllOnSubmit <Blocked>(context.GetTable <Blocked>()); context.users.DeleteAllOnSubmit <ContactInfo>(context.GetTable <ContactInfo>()); try { context.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException e) { Debug.WriteLine(e.Message); // 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); } #endregion #region DELETE MQTTPERSISTED MESSAGES using (HikeMqttPersistenceDb context = new HikeMqttPersistenceDb(App.MqttDBConnectionstring)) { context.mqttMessages.DeleteAllOnSubmit <HikePacket>(context.GetTable <HikePacket>()); try { context.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (ChangeConflictException e) { Debug.WriteLine(e.Message); // 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); } #endregion #region DELETE FAVOURITES AND PENDING REQUESTS DeleteFavourites(); DeletePendingRequests(); #endregion }