/// <summary>Delete a role</summary> /// <param name="role">角色实体</param> /// <returns>返回删除结果</returns> public Task <IdentityResult> DeleteAsync(TRole role, CancellationToken cancellationToken) { if (role == null) { throw new ArgumentNullException("role"); } return(RunTask(() => { var roleId = role.Id; _objectStorage.Delete <TRole>(roleId.ToString()); _objectStorage.Delete <UserRole>(p => p.RoleId == roleId); }, "删除角色")); }
public async Task Scrub(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var orphanedAssetUuids = await getOrphanedAssetUuids(); foreach (var orphanedAssetUuid in orphanedAssetUuids) { cancellationToken.ThrowIfCancellationRequested(); var orphanedAsset = await getOrphanedAssetForDeletion(orphanedAssetUuid); if (orphanedAsset == null) { continue; } _logger.LogInformation("Deleting orphaned asset with UUID {0}...", orphanedAsset.Uuid); try { await _objectStorage.Delete(orphanedAsset.StoragePath, cancellationToken); } catch (Exception ex) { await resetOrphanedAssetDeletion(orphanedAssetUuid); throw ex; } await deleteOrphanedAssetBeingDeleted(orphanedAssetUuid); } }
/// <summary> /// 删除指定实体 /// </summary> /// <param name="entity">实体</param> /// <returns>返回删除成功的实体</returns> /// <exception cref="AccessException">不允许删除时抛出此异常</exception> public virtual TEntity Delete(TEntity entity) { if (CheckAccess(OnCanDelete)) { OnDeleting(new ActionEventArgs <TEntity>(entity)); Invoke(() => { _context.Delete <TEntity>(p => p.Id == entity.Id); //UnitOfWork.Commit(); }); OnDeleted(new ActionEventArgs <TEntity>(entity)); return(entity); } throw new AccessException("CanDelete"); }
/// <summary>Delete a user</summary> /// <param name="user">用户实体</param> /// <returns>删除成功返回</returns> public Task <IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken) { return(RunTask(() => _objectStorage.Delete <MongodbIdentityUser>(user.Id.ToString()), "删除用户失败")); }
bool IObjectStorage.DeleteList(DataBuffer keySpace, StorageKey key) { return(Iface.Delete(keySpace, key)); }
public async Task Sync(string commitId, bool checkForStaleRevision = true) { VersionsBlob versionsBlob = null; try { versionsBlob = await _client.GetJSON <VersionsBlob>("versions"); } catch (ObjectNotFoundException) { } if (!String.IsNullOrWhiteSpace(versionsBlob?.Latest)) { if (versionsBlob.Latest == commitId && await _client.Exists(commitId)) { return; } if (checkForStaleRevision) { try{ await _shellExecutor.ExecTask("git", $"merge-base --is-ancestor {versionsBlob.Latest} {commitId}"); } catch (Exception ex) { // https://git-scm.com/docs/git-merge-base#git-merge-base---is-ancestor if ((int)ex.Data["ExitCode"] == 1) { _metrics.Measure.Counter.Increment(_staleRevision); throw new RevisionException(commitId, versionsBlob.Latest, "Stale Revision"); } _metrics.Measure.Counter.Increment(_badRevision); throw new RevisionException(commitId, versionsBlob.Latest, "Bad Revision"); } } } ; var newVersionBlob = new VersionsBlob { Latest = commitId, Previous = versionsBlob?.Latest, }; var(p, exited) = _shellExecutor("git", $"archive --format=zip {commitId}"); using (var ms = new MemoryStream()) { await p.StandardOutput.BaseStream.CopyToAsync(ms); ms.Position = 0; await exited; if (p.ExitCode != 0) { await HandleArchiveError(p); } using (var zip = new ZipArchive(ms, ZipArchiveMode.Read, false)) { var files = zip.Entries.Select(x => x.FullName).ToList(); var readFn = GetZipReader(zip); foreach (var Converter in Converters) { var(fileName, fileContent, fileMimeType) = Converter.Convert(commitId, files, readFn); await _client.PutString(fileName, fileContent, fileMimeType); _metrics.Measure.Counter.Increment(_fileUpload, new MetricTags("FileName", fileName)); } } } await _client.PutJSON("versions", newVersionBlob); _metrics.Measure.Counter.Increment(_fileUpload, new MetricTags("FileName", "versions")); if (versionsBlob?.Previous != null) { await _client.Delete(versionsBlob.Previous); _metrics.Measure.Counter.Increment(_deletePrevious); } }
public async Task Sync(string commitId, bool checkForStaleRevision = true) { VersionsBlob versionsBlob = null; try { versionsBlob = await _client.GetJSON <VersionsBlob>("versions"); } catch (ObjectNotFoundException) { } if (!String.IsNullOrWhiteSpace(versionsBlob?.Latest)) { if (versionsBlob.Latest == commitId && await _client.Exists(commitId)) { return; } if (checkForStaleRevision) { try{ await _shellExecutor.ExecTask("git", $"merge-base --is-ancestor {versionsBlob.Latest} {commitId}"); } catch (Exception ex) { throw new StaleRevisionException(commitId, versionsBlob.Latest); } } } ; var(p, exited) = _shellExecutor("git", $"archive --format=zip {commitId}"); using (var ms = new MemoryStream()) { await p.StandardOutput.BaseStream.CopyToAsync(ms); ms.Position = 0; await exited; if (p.ExitCode != 0) { throw new Exception("Git archive failed") { Data = { ["stderr"] = await p.StandardError.ReadToEndAsync(), ["code"] = p.ExitCode, }, }; } using (var zip = new ZipArchive(ms, ZipArchiveMode.Read, false)) { var files = zip.Entries.Select(x => x.FullName).ToList(); var bundle = _packer.Pack(files, GetZipReader(zip)); await _client.PutJSON(commitId, bundle); } } if (commitId != versionsBlob?.Latest) { var newVersionBlob = new VersionsBlob { Latest = commitId, Previous = versionsBlob?.Latest, }; await _client.PutJSON("versions", newVersionBlob); if (versionsBlob?.Previous != null) { await _client.Delete(versionsBlob.Previous); } } }