public virtual async Task <T> FetchAsync( string projectId, string key, CancellationToken cancellationToken = default(CancellationToken) ) { if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentException("projectId must be provided"); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException("key must be provided"); } cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); var pathToFile = await pathResolver.ResolvePath( projectId, key, serializer.ExpectedFileExtension ).ConfigureAwait(false); if (!File.Exists(pathToFile)) { return(null); } return(LoadObject(pathToFile, key)); }
public async Task DeleteAll( string logLevel = "", CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); var pathToFile = await pathResolver.ResolvePath( options.ProjectId, string.Empty, serializer.ExpectedFileExtension ).ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(logLevel)) { pathToFile = Path.Combine(pathToFile, logLevel); if (!Directory.Exists(pathToFile)) { return; } var levelDir = new DirectoryInfo(pathToFile); // in spite of the bool true which should recursively delete // this throws IOException The directory is not empty but does delete the files try { levelDir.Delete(true); } catch (IOException) { } return; } if (!Directory.Exists(pathToFile)) { return; } var typeDir = new DirectoryInfo(pathToFile); foreach (FileInfo file in typeDir.GetFiles( "*" + serializer.ExpectedFileExtension, SearchOption.AllDirectories).OrderBy(f => f.CreationTimeUtc) ) { file.Delete(); } foreach (var dir in typeDir.GetDirectories()) { try { dir.Delete(true); } catch (IOException) { } } }
public async Task DeleteLoginsByUser( Guid siteId, Guid userId, CancellationToken cancellationToken = default(CancellationToken)) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); if (siteId == Guid.Empty) { throw new ArgumentException("siteId must be provided"); } if (userId == Guid.Empty) { throw new ArgumentException("userId must be provided"); } //await EnsureProjectId().ConfigureAwait(false); var projectId = siteId.ToString(); var folderPath = await loginPathResolver.ResolvePath(projectId).ConfigureAwait(false); // understand structure of key which is the filename //var key = login.UserGuid.ToString() // + "~" + login.SiteGuid.ToString() // + "~" + login.LoginProvider // + "~" + login.ProviderKey; var matchPattern = userId.ToString() + "~" + siteId.ToString() + "~*"; var dir = new DirectoryInfo(folderPath); var matches = dir.GetFiles(matchPattern); foreach (var match in matches) { var foundFileKey = Path.GetFileNameWithoutExtension(match.Name); await loginCommands.DeleteAsync( projectId, foundFileKey, cancellationToken).ConfigureAwait(false); } }
public virtual async Task CreateAsync( string projectId, string key, T obj, CancellationToken cancellationToken = default(CancellationToken) ) { if (obj == null) { throw new ArgumentException("TObject obj must be provided"); } if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentException("projectId must be provided"); } if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentException("key must be provided"); } cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); var pathToFile = await pathResolver.ResolvePath( projectId, key, obj, serializer.ExpectedFileExtension, true ).ConfigureAwait(false); if (File.Exists(pathToFile)) { throw new InvalidOperationException("can't create file that already exists: " + pathToFile); } var serialized = serializer.Serialize(obj); using (StreamWriter s = File.CreateText(pathToFile)) { await s.WriteAsync(serialized); } }