public void MultiLevel() { // see bug #4101 IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly(); try { isf.CreateDirectory("dir1"); string [] dirs = isf.GetDirectoryNames("*"); Assert.AreEqual(dirs.Length, 1, "1a"); Assert.AreEqual(dirs [0], "dir1", "1b"); isf.CreateDirectory("dir1/test"); dirs = isf.GetDirectoryNames("dir1/*"); Assert.AreEqual(dirs.Length, 1, "2a"); Assert.AreEqual(dirs [0], "test", "2b"); isf.CreateDirectory("dir1/test/test2a"); isf.CreateDirectory("dir1/test/test2b"); dirs = isf.GetDirectoryNames("dir1/test/*"); Assert.AreEqual(dirs.Length, 2, "3a"); Assert.AreEqual(dirs [0], "test2a", "3b"); Assert.AreEqual(dirs [1], "test2b", "3c"); } finally { isf.DeleteDirectory("dir1/test/test2a"); isf.DeleteDirectory("dir1/test/test2b"); isf.DeleteDirectory("dir1/test"); isf.DeleteDirectory("dir1"); } }
/// <summary> /// Adds the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="expirationDate">The expiration date.</param> /// <param name="value">The value.</param> private void Add(string key, DateTime expirationDate, object value) { lock (_sync) { if (!_myStore.DirectoryExists(key)) { _myStore.CreateDirectory(key); } else { string currentFile = GetFileNames(key).FirstOrDefault(); if (currentFile != null) { _myStore.DeleteFile(string.Format("{0}\\{1}", key, currentFile)); } _myStore.DeleteDirectory(key); _myStore.CreateDirectory(key); } string fileName = string.Format("{0}\\{1}.cache", key, expirationDate.ToFileTimeUtc()); if (_myStore.FileExists(fileName)) { _myStore.DeleteFile(fileName); } NormalWrite(fileName, value); } }
public void MoveDirectory () { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly (); // Mare sure to remove them if they exist already if (isf.DirectoryExists ("subdir")) isf.DeleteDirectory ("subdir"); if (isf.DirectoryExists ("subdir-new")) isf.DeleteDirectory ("subdir-new"); isf.CreateDirectory ("subdir"); Assert.AreEqual (true, isf.DirectoryExists ("subdir"), "#A0"); isf.MoveDirectory ("subdir", "subdir-new"); Assert.AreEqual (false, isf.DirectoryExists ("subdir"), "#A1"); Assert.AreEqual (true, isf.DirectoryExists ("subdir-new"), "#A2"); try { isf.MoveDirectory (String.Empty, "subdir-new-new"); Assert.Fail ("#Exc1"); } catch (ArgumentException) { } try { isf.MoveDirectory (" ", "subdir-new-new"); Assert.Fail ("#Exc2"); } catch (ArgumentException) { } try { isf.MoveDirectory ("doesntexist", "subdir-new-new"); Assert.Fail ("#Exc3"); } catch (DirectoryNotFoundException) { } try { isf.MoveDirectory ("doesnexist/doesntexist", "subdir-new-new"); Assert.Fail ("#Exc4"); } catch (DirectoryNotFoundException) { } try { isf.MoveDirectory ("subdir-new", "doesntexist/doesntexist"); Assert.Fail ("#Exc5"); } catch (DirectoryNotFoundException) { } // Out of storage dir try { isf.MoveDirectory ("subdir-new", "../../subdir-new"); Assert.Fail ("#Exc6"); } catch (IsolatedStorageException) { } isf.Remove (); isf.Close (); isf.Dispose (); }
[Test] // https://bugzilla.novell.com/show_bug.cgi?id=376188 public void CreateSubDirectory () { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly (); isf.CreateDirectory ("subdir"); isf.CreateDirectory ("subdir/subdir2"); Assert.AreEqual (1, isf.GetDirectoryNames ("*").Length, "subdir"); Assert.AreEqual (1, isf.GetDirectoryNames ("subdir/*").Length, "subdir/subdir2"); isf.DeleteDirectory ("subdir/subdir2"); isf.DeleteDirectory ("subdir"); }
public void DirectoryExists() { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly(); isf.CreateDirectory("subdir"); isf.CreateDirectory("subdir/subdir2"); isf.CreateDirectory("subdir3"); Assert.AreEqual(true, isf.DirectoryExists("subdir/"), "#A0"); Assert.AreEqual(true, isf.DirectoryExists("subdir/subdir2/"), "#A1"); Assert.AreEqual(true, isf.DirectoryExists("subdir3"), "#A2"); Assert.AreEqual(true, isf.DirectoryExists(String.Empty), "#A3"); // Weird Assert.AreEqual(false, isf.DirectoryExists("subdir99"), "#A4"); Assert.AreEqual(false, isf.DirectoryExists("../../subdir"), "#A5"); Assert.AreEqual(false, isf.DirectoryExists("*"), "#A5"); Assert.AreEqual(false, isf.DirectoryExists("subdir*"), "#A6"); isf.DeleteDirectory("subdir3"); Assert.AreEqual(false, isf.DirectoryExists("subdir3"), "#B0"); isf.DeleteDirectory("subdir/subdir2"); isf.DeleteDirectory("subdir"); try { isf.DirectoryExists(null); Assert.Fail("#Exc1"); } catch (ArgumentNullException) { } isf.Close(); try { isf.DirectoryExists("subdir"); Assert.Fail("#Exc2"); } catch (InvalidOperationException) { } isf.Dispose(); try { isf.DirectoryExists("subdir"); Assert.Fail("#Exc3"); } catch (ObjectDisposedException) { } // We want to be sure that if not closing but disposing // should fire ObjectDisposedException instead of InvalidOperationException isf = IsolatedStorageFile.GetUserStoreForAssembly(); isf.Dispose(); try { isf.DirectoryExists("subdir"); Assert.Fail("#Exc4"); } catch (ObjectDisposedException) { } }
public static void DeleteDirectory(string folderToRemove) { try { //get all folders inside it Folder/* string[] folders = store.GetDirectoryNames(folderToRemove + "*"); for (int i = 0; i < folders.Length; i++) { DeleteDirectory(folderToRemove + folders[i] + "/"); } //get all files inside it string[] files = store.GetFileNames(folderToRemove + "*"); for (int i = 0; i < files.Length; i++) { store.DeleteFile(folderToRemove + files[i]); } //finally, delete this directory once it's empty store.DeleteDirectory(folderToRemove.TrimEnd('/')); } catch { Debug.WriteLine("Failed to delete directory"); } }
public void DeleteDirectory(string dir) { if (_isoFile.DirectoryExists(dir)) { _isoFile.DeleteDirectory(dir); } }
// helper function from: http://stackoverflow.com/questions/18422331/easy-way-to-recursively-delete-directories-in-isolatedstorage-on-wp7-8 private void DeleteDirectoryRecursively(IsolatedStorageFile storageFile, String dirName) { try { String pattern = dirName + @"\*"; String[] files = storageFile.GetFileNames(pattern); foreach (var fName in files) { storageFile.DeleteFile(Path.Combine(dirName, fName)); } String[] dirs = storageFile.GetDirectoryNames(pattern); foreach (var dName in dirs) { DeleteDirectoryRecursively(storageFile, Path.Combine(dirName, dName)); } if (storageFile.DirectoryExists(dirName)) { storageFile.DeleteDirectory(dirName); } } catch (Exception e) { Debug.WriteLine("Unable to delete directory : " + dirName); } }
public static void ClearDirectory(string dirName) { IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication(); if (!isoFile.DirectoryExists(dirName)) { return; } string[] dirNames = isoFile.GetDirectoryNames(dirName + "\\*"); string[] fileNames = isoFile.GetFileNames(dirName + "\\*"); if (fileNames.Length > 0) { for (int i = 0; i < fileNames.Length; i++) { isoFile.DeleteFile(System.IO.Path.Combine(dirName, fileNames[i])); } } if (dirNames.Length > 0) { for (int i = 0; i < dirNames.Length; i++) { ClearDirectory(System.IO.Path.Combine(dirName, dirNames[i])); isoFile.DeleteDirectory(System.IO.Path.Combine(dirName, dirNames[i])); } } }
//deleting the directory public static void DeleteDirectoryRecursively(this IsolatedStorageFile storageFile, String dirName) { if (!storageFile.DirectoryExists(dirName)) { return; } String pattern = dirName + "/*"; String[] files = storageFile.GetFileNames(pattern); foreach (String fName in files) { String temp = dirName + "/" + fName + "\n"; if (storageFile.FileExists(temp)) { storageFile.DeleteFile(temp); } } String[] dirs = storageFile.GetDirectoryNames(pattern); foreach (String dName in dirs) { String temp = dirName + "/" + dName; if (storageFile.DirectoryExists(temp)) { DeleteDirectoryRecursively(storageFile, temp); } } storageFile.DeleteDirectory(dirName); }
public static bool DeleteDirectory(String DirectoryName) { using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication()) { lock (iso) { if (!iso.DirectoryExists(DirectoryName)) { return(true); } var files = iso.GetFileNames(DirectoryName + "\\*"); foreach (string file in files) { try { iso.DeleteFile(DirectoryName + "\\" + file); } catch (Exception e) { ErrorLogging.Log("ISOHelper", e.Message, "ISOHelperError", "file :" + DirectoryName + "\\" + file); } } files = iso.GetFileNames(DirectoryName + "\\*"); if (files.Length < 1) { iso.DeleteDirectory(DirectoryName); return(true); } return(false); } } }
/// <summary> /// Saves the level to isolated storage. /// </summary> /// <param name="levelNumber">The level number.</param> /// <param name="contentManagerFormat">Whether to format the data for the content manager or the xml serializer.</param> public void Save(int levelNumber, bool contentManagerFormat) { if (levelNumber > 0) { #if WINDOWS_PHONE using (IsolatedStorageFile levelFile = IsolatedStorageFile.GetUserStoreForApplication()) #else using (IsolatedStorageFile levelFile = IsolatedStorageFile.GetUserStoreForDomain()) #endif { string directoryName = contentManagerFormat ? "ContentManager_" + levelNumber.ToString() : levelNumber.ToString(); if (levelFile.DirectoryExists(directoryName)) { foreach (string name in levelFile.GetFileNames(directoryName + "/*")) { levelFile.DeleteFile(directoryName + "/" + name); } levelFile.DeleteDirectory(directoryName); } levelFile.CreateDirectory(directoryName); this.SerializeLevelPoints(directoryName, levelFile, contentManagerFormat); this.SerializePlatforms(directoryName, levelFile, contentManagerFormat); this.SerializeInteractiveEntities(directoryName, levelFile, contentManagerFormat); } } else { throw new Exception("The level value must be greater than 0."); } }
/// <summary> /// Deletes all sub directories and files of the specified directory recursively. /// </summary> /// <param name="path">Path of the directory to delete</param> internal static void DeleteDirectory(string path) { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { if (storage.DirectoryExists(path)) { // Get the directories list string[] dirs = storage.GetDirectoryNames(path + "\\*"); foreach (string dir in dirs) { DeleteDirectory(Path.Combine(path, dir)); } // Get the files list string[] files = storage.GetFileNames(path + "\\*"); foreach (string file in files) { storage.DeleteFile(Path.Combine(path, file)); } // Delete the directory storage.DeleteDirectory(path); } } }
public void DeleteDirectory_NonEmpty () { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly (); isf.CreateDirectory ("subdir"); isf.CreateDirectory ("subdir/subdir2"); isf.DeleteDirectory ("subdir"); }
private async void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e) { List <KeyValue <int, GameData> > Database = new List <KeyValue <int, GameData> >(); using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { await IsolatedStorageHelper.Save <List <KeyValue <int, GameData> > >(Database, "/GameLibrary/Database.xml"); App.ViewModel.MainGameView.GamesList.Clear(); if (isoStore.DirectoryExists("/GameImages/")) { foreach (var file in isoStore.GetFileNames("/GameImages/")) { if (isoStore.FileExists("/GameImages/" + file)) { isoStore.DeleteFile("/GameImages/" + file); } } isoStore.DeleteDirectory("/GameImages/"); } } clearCacheButton.IsEnabled = false; }
public void MoveOldCrashlogsIfNeeded(IsolatedStorageFile store) { try { if (store.DirectoryExists(Constants.OldCrashDirectoryName)) { var files = store.GetFileNames(Path.Combine(Constants.OldCrashDirectoryName, Constants.CrashFilePrefix + "*.log")); if (files.Length > 0) { if (!store.DirectoryExists(Constants.CrashDirectoryName)) { store.CreateDirectory(Constants.CrashDirectoryName); } foreach (var fileName in files) { store.MoveFile(Path.Combine(Constants.OldCrashDirectoryName, Path.GetFileName(fileName)), Path.Combine(Constants.CrashDirectoryName, Path.GetFileName(fileName))); } if (store.GetFileNames(Path.Combine(Constants.OldCrashDirectoryName, Constants.CrashFilePrefix + "*.*")).Length == 0) { store.DeleteDirectory(Constants.OldCrashDirectoryName); } } } } catch (Exception e) { HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e); } }
public void CreateDirectory_DirectoryWithSameNameExists() { string dir = "new-dir"; string file = Path.Combine(dir, "new-file"); IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly(); try { isf.CreateDirectory(dir); using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(file, FileMode.OpenOrCreate, isf)) { isfs.WriteByte(0); } string pattern = Path.Combine(dir, "*"); Assert.AreEqual(1, isf.GetFileNames(file).Length, "file exists"); // create again directory isf.CreateDirectory(dir); Assert.AreEqual(1, isf.GetFileNames(file).Length, "file still exists"); } finally { isf.DeleteFile(file); isf.DeleteDirectory(dir); } }
public void ReadDirectoryAsFile() { string dirname = "this-is-a-dir"; IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForDomain(); try { string[] dirs = isf.GetDirectoryNames(dirname); if (dirs.Length == 0) { isf.CreateDirectory(dirname); } Read(dirname); } catch (UnauthorizedAccessException uae) { // check that we do not leak the full path to the missing file // as we do not have the FileIOPermission's PathDiscovery rights Assert.IsTrue(uae.Message.IndexOf(dirname) >= 0, "dirname"); Assert.IsFalse(uae.Message.IndexOf("\\" + dirname) >= 0, "fullpath"); try { isf.DeleteDirectory(dirname); } catch (IsolatedStorageException) { // this isn't where we want ot fail! // and 1.x isn't always cooperative } throw; } }
private void SendStoredMessages() { if (NetworkInterface.NetworkInterfaceType != NetworkInterfaceType.None) { try { using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (isolatedStorage.DirectoryExists("RaygunIO")) { string[] fileNames = isolatedStorage.GetFileNames("RaygunIO\\*.txt"); foreach (string name in fileNames) { IsolatedStorageFileStream isoFileStream = isolatedStorage.OpenFile("RaygunIO\\" + name, FileMode.Open); using (StreamReader reader = new StreamReader(isoFileStream)) { string text = reader.ReadToEnd(); SendMessage(text, false, false); } isolatedStorage.DeleteFile("RaygunIO\\" + name); } isolatedStorage.DeleteDirectory("RaygunIO"); } } } catch (Exception ex) { Debug.WriteLine(string.Format("Error sending stored messages to Raygun.io {0}", ex.Message)); } } }
public static void deleteDirectory(String path) { using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { isoStore.DeleteDirectory(CFilePath.removeLastSlash(path)); } }
/// <summary> /// Deletes single survey from IsolatedStorage. /// </summary> /// <param name="surveyId">Id of survey you want to delete.</param> public void Delete(string surveyId) { Read(); IEnumerable <SurveyBasicInfo> surveys; surveys = from SurveyBasicInfo in _list where SurveyBasicInfo.SurveyId == surveyId select SurveyBasicInfo; try { OperationsOnListOfResults resultsOperations = new OperationsOnListOfResults(surveyId); resultsOperations.DeleteAllResults(); SurveyBasicInfo survey = surveys.First <SurveyBasicInfo>(); using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { string filePath = System.IO.Path.Combine("surveys", string.Format("{0}.xml", survey.SurveyId)); string directoryPath = System.IO.Path.Combine("surveys", survey.SurveyId); string listOfResultPath = System.IO.Path.Combine(directoryPath, "listOfResults.xml"); try { isoStore.DeleteFile(filePath); isoStore.DeleteFile(listOfResultPath); isoStore.DeleteDirectory(directoryPath); } catch (IsolatedStorageException) { /*that means that this files doesn't exists*/ } } _list.Remove(survey); Write(); } catch (InvalidOperationException) { } }
/// <summary> /// Deletes a folder in the isolated storage /// </summary> /// <param name="FolderName">The folder name</param> public void DeleteFolder(string FolderName) { if (myStorage.DirectoryExists(FolderName)) { myStorage.DeleteDirectory(FolderName); } }
public static bool delDirIsoStorBeforeUnzip(string dirName) { bool result; try { IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication(); string text = dirName + "\\*"; string[] fileNames = userStoreForApplication.GetFileNames(text); string[] array = fileNames; for (int i = 0; i < array.Length; i++) { string text2 = array[i]; userStoreForApplication.DeleteFile(Path.Combine(dirName, text2)); } string[] directoryNames = userStoreForApplication.GetDirectoryNames(text); string[] array2 = directoryNames; for (int j = 0; j < array2.Length; j++) { string text3 = array2[j]; delDirIsoStorBeforeUnzip(Path.Combine(dirName, text3)); } userStoreForApplication.DeleteDirectory(dirName); result = true; } catch (Exception ex) { // WLUtils.LOG("cleaning or IsolatedStorage (directupdate skins) .... " + ex); result = false; } return(result); }
public async Task Clear() { await consistencyLock.WaitAsync(); if (_storage.DirectoryExists("cache")) { foreach (var file in _storage.GetFileNames("cache/*.*")) { try { _storage.DeleteFile(Path(file)); } catch (Exception) { } } try { _storage.DeleteDirectory("cache"); } catch (Exception) { } } consistencyLock.Release(); }
public static void DestroyOffline() { using (IsolatedStorageFile fileStorage = IsolatedStorageFile.GetUserStoreForApplication()) { try { // deleting index string dbFilePath = String.Format(CacheStore.CacheFilePathNoExtFormat, CacheDirectory, CacheDatabase); if (fileStorage.FileExists(dbFilePath)) { fileStorage.DeleteFile(dbFilePath); } // deleting individual records if (fileStorage.DirectoryExists(CacheDirectory)) { string[] fileNames = fileStorage.GetFileNames(String.Format("{0}/*", CacheDirectory)); foreach (string fileName in fileNames) { fileStorage.DeleteFile(String.Format(CacheStore.CacheFilePathNoExtFormat, CacheDirectory, fileName)); } fileStorage.DeleteDirectory(CacheDirectory); } } catch (IOException) { } } }
private void SendStoredMessages() { lock (_sendLock) { if (!ValidateApiKey()) { System.Diagnostics.Debug.WriteLine("ApiKey has not been provided, skipping sending stored Raygun messages"); return; } try { using (IsolatedStorageFile isolatedStorage = GetIsolatedStorageScope()) { string directoryName = "RaygunOfflineStorage"; if (isolatedStorage.DirectoryExists(directoryName)) { string[] fileNames = isolatedStorage.GetFileNames(directoryName + "\\*.txt"); foreach (string name in fileNames) { IsolatedStorageFileStream isoFileStream = isolatedStorage.OpenFile(directoryName + "\\" + name, FileMode.Open); using (StreamReader reader = new StreamReader(isoFileStream)) { string text = reader.ReadToEnd(); try { if (WebProxy != null) { WebClientHelper.WebProxy = WebProxy; } WebClientHelper.Send(text, _apiKey, ProxyCredentials); } catch { // If just one message fails to send, then don't delete the message, and don't attempt sending anymore until later. return; } System.Diagnostics.Debug.WriteLine("Sent " + name); } isolatedStorage.DeleteFile(directoryName + "\\" + name); } if (isolatedStorage.GetFileNames(directoryName + "\\*.txt").Length == 0) { System.Diagnostics.Debug.WriteLine("Successfully sent all pending messages"); isolatedStorage.DeleteDirectory(directoryName); } } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine($"Error sending stored messages to Raygun.io due to: {ex}"); } } }
void DeleteDir(string dirPath) { using (IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication()) { storeFile.DeleteDirectory(dirPath); } }
/// <summary> /// Removes a directory and any files or subdirectories within it /// from the persistence store /// </summary> /// <param name="dirName"></param> /// <returns></returns> public void DeleteDirectory(string dirName) { foreach (var fileName in _isolatedStorage.GetFileNames(dirName + Path.DirectorySeparatorChar + "*")) { DeleteFile(Path.Combine(dirName, fileName)); } _isolatedStorage.DeleteDirectory(dirName); }
public void CanDeleteEmptyDirectoryWithinStore() { using (IsolatedStorageFile store = NewStore()) { store.DeleteDirectory(RootTestDirectory); Assert.That(store.GetDirectoryNames("*"), Has.No.Member(RootTestDirectory)); } }
public ECollegeResponseCacheEntry Get(string cacheKey) { string dirPath = GetDirectoryForCacheKey(cacheKey); ECollegeResponseCacheEntry result = null; lock (dirPath) { if (storage.DirectoryExists(dirPath)) { string existingCacheFileName = storage.GetFileNames(GetFileGlobForCacheKey(cacheKey)).FirstOrDefault(); if (existingCacheFileName != null) { var existingCacheFilePath = string.Format("{0}\\{1}", dirPath, existingCacheFileName); var expirationDate = DateTime.FromFileTimeUtc(long.Parse(Path.GetFileNameWithoutExtension(existingCacheFileName))); if (expirationDate >= DateTime.UtcNow) { using (var f = new IsolatedStorageFileStream(existingCacheFilePath, FileMode.Open, FileAccess.Read, storage)) { using (var sr = new StreamReader(f)) { result = new ECollegeResponseCacheEntry(); result.CachedAt = DateTime.Now; result.Data = sr.ReadToEnd(); } } } else { storage.DeleteFile(existingCacheFilePath); storage.DeleteDirectory(dirPath); } } else { storage.DeleteDirectory(dirPath); } } } return(result); }