public void LoadGroupCache() { lock (readWriteLock) { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { string[] files = store.GetFileNames(GROUP_DIR + "\\*"); if (files == null || files.Length == 0) { return; } for (int i = 0; i < files.Length; i++) { string grpId = files[i].Replace("_", ":"); if (groupCache.ContainsKey(grpId)) // if this group is already loaded ignore { continue; } string fileName = GROUP_DIR + "\\" + files[i]; List <GroupParticipant> gpList = null; using (var file = store.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var reader = new BinaryReader(file)) { int count = 0; try { count = reader.ReadInt32(); } catch { } if (count > 0) { gpList = new List <GroupParticipant>(count); for (int j = 0; j < count; j++) { GroupParticipant item = new GroupParticipant(); try { item.Read(reader); gpList.Add(item); } catch { item = null; } } } reader.Close(); } try { file.Close(); file.Dispose(); } catch { } } if (gpList != null) { groupCache[grpId] = gpList; } } } } }
public void LoadGroupParticipants(string grpId) { if (groupCache.ContainsKey(grpId)) { return; } lock (readWriteLock) { using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { List <GroupParticipant> gpList = null; string grp = grpId.Replace(":", "_"); string fileName = GROUP_DIR + "\\" + grp; if (!store.FileExists(fileName)) { return; } else { using (var file = store.OpenFile(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var reader = new BinaryReader(file)) { int count = 0; try { count = reader.ReadInt32(); } catch { } if (count > 0) { gpList = new List <GroupParticipant>(count); for (int i = 0; i < count; i++) { GroupParticipant item = new GroupParticipant(); try { item.Read(reader); gpList.Add(item); } catch { item = null; } } } reader.Close(); } try { file.Close(); file.Dispose(); } catch { } } if (gpList != null) { groupCache[grpId] = gpList; } } } } }