internal SharedFileSecretCredentials(XtiFolder xtiFolder, string key, IDataProtector dataProtector) : base(key, dataProtector) { sharedAppDataFolder = xtiFolder .SharedAppDataFolder() .WithSubFolder("Secrets"); }
public void CreateFileAndReadFileTest() { const string path = "~/b/a.txt"; const string text = "Test"; AppDataFolder.CreateFile(path, text); Assert.AreEqual(text, AppDataFolder.ReadFile(path)); }
public string GetDirectory(AppDataFolder appDataFolder, string localFolderName = null) { return(GetSettingsDirectory(GetSpecialFolder(appDataFolder), _companyName, _productName, localFolderName)); }
private async Task <StorageFile> getFile() { if (_file == null) { _file = await AppDataFolder.CreateFileAsync(_fileName, CreationCollisionOption.OpenIfExists); } return(_file); }
public void GetVirtualPathTest() { const string path = "~/b/a.txt"; var fullPath = AppDataFolder.MapPath(path); Assert.AreEqual("~/App_Data/b/a.txt", AppDataFolder.GetVirtualPath(fullPath)); Assert.AreEqual("~/App_Data/b/b.txt", AppDataFolder.GetVirtualPath(VirtualPathProvider.MapPath("~/b/b.txt"))); Assert.AreEqual("~/App_Data/a/b/c", AppDataFolder.GetVirtualPath("~/a/b/c")); Assert.AreEqual("~/App_Data/a/b/c", AppDataFolder.GetVirtualPath("a/b/c")); Assert.AreEqual("~/App_Data/a/b/c", AppDataFolder.GetVirtualPath("/a/b/c")); }
private void UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { File.AppendAllText(AppDataFolder.GetPath("FatalError.txt"), DateTime.Now.ToString() + " - FATAL ERROR AppDomain - UnhandledException (by " + sender + " : " + e.ExceptionObject + "\n\n\n"); } catch { MessageBox.Show("Une erreur importante est survenue !\n" + e); } }
private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { try { File.AppendAllText(AppDataFolder.GetPath("FatalError.txt"), DateTime.Now.ToString() + " - FATAL ERROR TaskScheduler - UnobservedTaskException (by " + sender + " : " + e.Exception + "\n\n\n"); } catch { MessageBox.Show("Une erreur importante est survenue !\n" + e); } }
public void StoreFileTest() { const string path1 = "~/b/b.txt"; const string path2 = "~/b/c.txt"; const string text = "Test"; AppDataFolder.CreateFile(path1, text); AppDataFolder.StoreFile(AppDataFolder.MapPath(path1), path2); Assert.AreEqual(text, AppDataFolder.ReadFile(path2)); AppDataFolder.DeleteFile(path1); AppDataFolder.DeleteFile(path2); }
public void MapPathTest() { var baseDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data"); Assert.AreEqual(baseDirectory, AppDataFolder.MapPath("~/")); Assert.AreEqual(Path.Combine(baseDirectory, "a", "c.txt"), AppDataFolder.MapPath("~/a/b/../c.txt")); Assert.AreEqual(baseDirectory, AppDataFolder.MapPath(AppDataFolder.MapPath("~/"))); Assert.AreEqual(Path.Combine(baseDirectory, "a"), AppDataFolder.MapPath(AppDataFolder.MapPath("~/a"))); baseDirectory += "\\"; Assert.AreEqual(baseDirectory, AppDataFolder.MapPath(baseDirectory)); }
private static Environment.SpecialFolder GetSpecialFolder( AppDataFolder appDataFolder) { switch (appDataFolder) { case AppDataFolder.Local: return(Environment.SpecialFolder.LocalApplicationData); case AppDataFolder.Roaming: return(Environment.SpecialFolder.ApplicationData); default: throw new ArgumentOutOfRangeException(nameof(appDataFolder), "Unknown app data folder type."); } }
/// <summary> /// Initializes config locations and setup /// </summary> private void Initialize() { var parentMask = pathMask; var searchPath = CurrentPath; var configFiles = new List <string>(); // Find RootPath if (File.Exists($@"{CurrentPath.AddLast(@"\")}{FileNames.AppSettingsJson}")) { RootPath = CurrentPath; } else { for (var count = 0; count < parentLevels; count++) { searchPath = Path.GetFullPath(Path.Combine(CurrentPath, parentMask)); if (File.Exists($@"{searchPath.AddLast(@"\")}{FileNames.AppSettingsJson}")) { RootPath = searchPath; break; } parentMask += pathMask; } } // Add appsettings.json if (File.Exists($@"{RootPath.AddLast(@"\")}{FileNames.AppSettingsJson}")) { configFiles.Add($@"{RootPath.AddLast(@"\")}{FileNames.AppSettingsJson}"); } // Add appsettings.{environment}.json if (File.Exists($@"{RootPath.AddLast(@"\")}{string.Format(FileNames.AppSettingsEnvironmentJson, CurrentEnvironment)}")) { configFiles.Add($@"{RootPath.AddLast(@"\")}{string.Format(FileNames.AppSettingsEnvironmentJson, CurrentEnvironment)}"); } // Add App_Data\AppSettings.json if (File.Exists($@"{AppDataFolder.AddLast(@"\")}{FileNames.AppSettingsJson}")) { configFiles.Add($@"{AppDataFolder.AddLast(@"\")}{FileNames.AppSettingsJson}"); } // Add App_Data\ConnectionStrings.json if (File.Exists($@"{AppDataFolder.AddLast(@"\")}{FileNames.ConnectionStringsJson}")) { configFiles.Add($@"{AppDataFolder.AddLast(@"\")}{FileNames.ConnectionStringsJson}"); } // Load Load(configFiles); }
public static async Task SaveStringAsFile(string content, string fileName) { storage.StorageFile myFile = await AppDataFolder.CreateFileAsync(fileName, storage.CreationCollisionOption.ReplaceExisting); await SaveStringAsFile(content, myFile); }
public static async Task SaveBytesAsFile(byte[] bytes, string fileName) { storage.StorageFile myFile = await AppDataFolder.CreateFileAsync(fileName, storage.CreationCollisionOption.ReplaceExisting); await SaveBytesAsFile(bytes, myFile); }
public static async Task <T> LoadXmlFileAsync <T>(string fileName) where T : VMBase { storage.StorageFile myFile = await AppDataFolder.GetFileAsync(fileName); return(await LoadXmlFileAsync <T>(myFile)); }
public async Task SaveAsXmlAsync <T>(string fileName) where T : VMBase { storage.StorageFile myFile = await AppDataFolder.CreateFileAsync(fileName, storage.CreationCollisionOption.ReplaceExisting); await SaveAsXmlAsync <T>(myFile); }