public static EnsureDirectoryExists ( string pathName ) : void | ||
pathName | string | The path to the file that will be created |
Résultat | void |
static IAzureSession CreateInstance(IDataStore dataStore = null) { var session = new AdalSession { ClientFactory = new ClientFactory(), AuthenticationFactory = new AuthenticationFactory(), DataStore = dataStore ?? new DiskDataStore(), OldProfileFile = "WindowsAzureProfile.xml", OldProfileFileBackup = "WindowsAzureProfile.xml.bak", ProfileDirectory = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Resources.AzureDirectoryName), ProfileFile = "AzureProfile.json", TokenCacheFile = "TokenCache.dat" }; try { FileUtilities.DataStore = session.DataStore; FileUtilities.EnsureDirectoryExists(session.ProfileDirectory); var cacheFile = Path.Combine(session.ProfileDirectory, session.TokenCacheFile); session.TokenCache = new ProtectedFileTokenCache(cacheFile, session.DataStore); } catch { session.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache()); } return(session); }
static IAzureTokenCache InitializeTokenCache(IDataStore store, string cacheDirectory, string cacheFile, string autoSaveMode) { IAzureTokenCache result = new AuthenticationStoreTokenCache(new AzureTokenCache()); if (autoSaveMode == ContextSaveMode.CurrentUser) { try { FileUtilities.DataStore = store; FileUtilities.EnsureDirectoryExists(cacheDirectory); var cachePath = Path.Combine(cacheDirectory, cacheFile); result = new ProtectedFileTokenCache(cachePath, store); } catch { } } return(result); }
static IAzureSession CreateInstance() { var session = new AdalSession { ClientFactory = new ClientFactory(), AuthenticationFactory = new AuthenticationFactory(), DataStore = new DiskDataStore(), OldProfileFile = "WindowsAzureProfile.xml", OldProfileFileBackup = "WindowsAzureProfile.xml.bak", ProfileDirectory = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Resources.AzureDirectoryName), ProfileFile = "AzureProfile.json", TokenCacheFile = "TokenCache.dat" }; try { FileUtilities.DataStore = session.DataStore; FileUtilities.EnsureDirectoryExists(session.ProfileDirectory); var cacheFile = Path.Combine(session.ProfileDirectory, session.TokenCacheFile); var contents = new byte[0]; if (session.DataStore.FileExists(cacheFile)) { contents = session.DataStore.ReadFileAsBytes(cacheFile); } if (contents != null && contents.Length > 0) { contents = ProtectedData.Unprotect(contents, null, DataProtectionScope.CurrentUser); } session.TokenCache = new ProtectedFileTokenCache(contents); } catch { session.TokenCache = new AuthenticationStoreTokenCache(new AzureTokenCache()); } return(session); }
static IAzureTokenCache InitializeTokenCache(IDataStore store, string cacheDirectory, string cacheFile, string autoSaveMode) { IAzureTokenCache result = new AuthenticationStoreTokenCache(new AzureTokenCache()); if (autoSaveMode == ContextSaveMode.CurrentUser) { try { FileUtilities.DataStore = store; FileUtilities.EnsureDirectoryExists(cacheDirectory); var cachePath = Path.Combine(cacheDirectory, cacheFile); result = new ProtectedFileTokenCache(cachePath, store); } catch (Exception ex) { TracingAdapter.Information("[AzureSessionInitializer]: Cannot initialize token cache in 'CurrentUser' mode. Falling back to 'Process' mode."); TracingAdapter.Information($"[AzureSessionInitializer]: Message: {ex.Message}; Stacktrace: {ex.StackTrace}"); } } return(result); }