protected override NodeTimeInfo GetTimeInfo(NodeBase node) { try { using (var scope = _factory.CreateScope()) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); if (node.NodeType == NodeType.Directory) { var folderEntity = CompositeFileSystemHelper.FolderPathToEntity(uow, _userEntity, node.Path.StringPath); return(new NodeTimeInfo(folderEntity.Created, folderEntity.LastAccessed, folderEntity.LastUpdated)); } else if (node.NodeType == NodeType.File) { var fileEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, node.Path.StringPath); return(new NodeTimeInfo(fileEntity.Created, fileEntity.LastAccessed, fileEntity.LastUpdated)); } else { throw new NotImplementedException(); } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
protected override long GetLength(NodeBase node) { try { if (!node.Exists() || node.NodeType == NodeType.Directory) { return(0L); } using (var scope = _factory.CreateScope()) { if (node.NodeType == NodeType.File) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); var fileEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, node.Path.StringPath); return(fileEntity.RealFileSize); } else { throw new NotImplementedException(); } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
protected override NodeBase SaveContent(NodeBase node, NodeContent content) { if (!node.Exists()) { return(node); } FileInfo file = null; try { using (var scope = _factory.CreateScope()) { var callPath = $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}"; if (node.NodeType == NodeType.File) { var conf = scope.ServiceProvider.GetRequiredService <IConfiguration>(); var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); var fileEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, node.Path.StringPath); file = new FileInfo(conf["Storage:UnstructuredDataPath"] + Path.DirectorySeparatorChar + fileEntity.RealPath + Path.DirectorySeparatorChar + fileEntity.RealFileName); fileEntity = CompositeFileSystemHelper.SaveFileStream(conf, content.GetStream(), fileEntity); uow.UserFiles.Update(fileEntity); uow.Commit(); Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' file '{node.Path}' to '{file.FullName}'"); return(node); } else { throw new NotImplementedException(); } } } catch (Exception ex) when(ex is DbUpdateException || ex is DbUpdateConcurrencyException) { if (file.Exists) { file.Delete(); } Log.Error(ex.ToString()); throw; } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
protected override NodeBase Move(NodeBase toBeMovedNode, DirectoryNode targetDirectory) { try { using (var scope = _factory.CreateScope()) { var callPath = $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}"; var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); if (toBeMovedNode.NodeType == NodeType.Directory) { var toBeMovedEntity = CompositeFileSystemHelper.FolderPathToEntity(uow, _userEntity, toBeMovedNode.Path.StringPath); var toBeMovedPath = CompositeFileSystemHelper.FolderEntityToPath(uow, _userEntity, toBeMovedEntity); var targetEntity = CompositeFileSystemHelper.FolderPathToEntity(uow, _userEntity, targetDirectory.Path.StringPath); var targetPath = CompositeFileSystemHelper.FolderEntityToPath(uow, _userEntity, targetEntity); toBeMovedEntity.ParentId = targetEntity.Id; uow.UserFolders.Update(toBeMovedEntity); uow.Commit(); Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' from '{toBeMovedPath}' to '{targetPath}'"); return(new DirectoryNode(toBeMovedNode.Name, targetDirectory)); } else if (toBeMovedNode.NodeType == NodeType.File) { var toBeMovedEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, toBeMovedNode.Path.StringPath); var toBeMovedPath = CompositeFileSystemHelper.FileEntityToPath(uow, _userEntity, toBeMovedEntity); var targetEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, targetDirectory.Path.StringPath); var targetPath = CompositeFileSystemHelper.FileEntityToPath(uow, _userEntity, targetEntity); toBeMovedEntity.FolderId = targetEntity.Id; uow.UserFiles.Update(toBeMovedEntity); uow.Commit(); Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' from '{toBeMovedPath}' to '{targetPath}'"); return(new FileNode(toBeMovedNode.Name, targetDirectory)); } else { throw new NotImplementedException(); } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
protected override NodeAttributes GetAttributes(NodeBase node) { try { if (!node.Exists()) { return(node.Attributes); } using (var scope = _factory.CreateScope()) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); if (node.NodeType == NodeType.Directory) { var folderEntity = CompositeFileSystemHelper.FolderPathToEntity(uow, _userEntity, node.Path.StringPath); if (folderEntity.ReadOnly) { return(new NodeAttributes(FileAttributes.Directory | FileAttributes.ReadOnly)); } else { return(new NodeAttributes(FileAttributes.Directory)); } } else if (node.NodeType == NodeType.File) { var fileEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, node.Path.StringPath); if (fileEntity.ReadOnly) { return(new NodeAttributes(FileAttributes.ReadOnly)); } else { return(new NodeAttributes(FileAttributes.Normal)); } } else { throw new NotImplementedException(); } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
protected override NodeBase Rename(NodeBase node, string newName) { try { using (var scope = _factory.CreateScope()) { var callPath = $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}"; var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); if (node.NodeType == NodeType.Directory) { var folderEntity = CompositeFileSystemHelper.FolderPathToEntity(uow, _userEntity, node.Path.StringPath); folderEntity.VirtualName = newName; uow.UserFolders.Update(folderEntity); uow.Commit(); var folderPath = CompositeFileSystemHelper.FolderEntityToPath(uow, _userEntity, folderEntity); Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' from '{node.Path}' to '{folderPath}'"); return(new DirectoryNode(newName, node.Parent)); } else if (node.NodeType == NodeType.File) { var fileEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, node.Path.StringPath); fileEntity.VirtualName = newName; uow.UserFiles.Update(fileEntity); uow.Commit(); var filePath = CompositeFileSystemHelper.FileEntityToPath(uow, _userEntity, fileEntity); Log.Information($"'{callPath}' '{_userEntity.IdentityAlias}' from '{node.Path}' to '{filePath}'"); return(new FileNode(newName, node.Parent)); } else { throw new NotImplementedException(); } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
protected override bool Exists(NodePath path, NodeType nodeType) { try { using (var scope = _factory.CreateScope()) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); if (nodeType == NodeType.Directory) { var folderEntity = CompositeFileSystemHelper.FolderPathToEntity(uow, _userEntity, path.StringPath); if (folderEntity != null) { return(true); } return(false); } else if (nodeType == NodeType.File) { var fileEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, path.StringPath); if (fileEntity != null) { return(true); } return(false); } else { throw new NotImplementedException(); } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }
protected override NodeBase SetAttributes(NodeBase node, NodeAttributes attributes) { try { using (var scope = _factory.CreateScope()) { var uow = scope.ServiceProvider.GetRequiredService <IUnitOfWork>(); if (node.NodeType == NodeType.Directory) { var folderEntity = CompositeFileSystemHelper.FolderPathToEntity(uow, _userEntity, node.Path.StringPath); folderEntity.ReadOnly = attributes.IsReadOnly; uow.UserFolders.Update(folderEntity); uow.Commit(); return(node); } else if (node.NodeType == NodeType.File) { var fileEntity = CompositeFileSystemHelper.FilePathToEntity(uow, _userEntity, node.Path.StringPath); fileEntity.ReadOnly = attributes.IsReadOnly; uow.UserFiles.Update(fileEntity); uow.Commit(); return(node); } else { throw new NotImplementedException(); } } } catch (Exception ex) { Log.Error(ex.ToString()); throw; } }