public async Task <ActionResult <FolderItemInfo> > Create(string encodedVirtualPath) { string virtualPath = Utils.DecodePath(encodedVirtualPath); if (virtualPath == null) { return(BadRequest("Path encoding error")); } InternalFolder folder; try { string userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); folder = await ShareFolderHelper.GetFolderItem(virtualPath, dbContext, userId, this); } catch (HttpResultException exc) { return(exc.Result); } if (!folder.Permission.Write) { return(Forbid()); } DirectoryInfo info = Directory.CreateDirectory(folder.PhysicalPath); return(FileHelper.GetInfo(folder, info)); }
/// <summary> /// 批量导入 /// </summary> /// <param name="_mySqlConnection"></param> /// <param name="dt"></param> /// <returns></returns> public int BulkLoad(DataTable table) { ImportExcelHelper h = new ImportExcelHelper(); h.ToCsv(table); var columns = table.Columns.Cast <DataColumn>().Select(colum => colum.ColumnName).ToList(); MySqlBulkLoader bulk = new MySqlBulkLoader(con) { FieldTerminator = ",", FieldQuotationCharacter = '"', EscapeCharacter = '"', LineTerminator = "\r\n", FileName = @"../uploads/" + table.TableName + ".csv", NumberOfLinesToSkip = 0, TableName = table.TableName, }; bulk.Columns.AddRange(columns); int ret = bulk.Load(); using (ShareFolderHelper helper = new ShareFolderHelper("test", "yfzx.2019", FilePath.CSVPATH + table.TableName + ".csv")) { //删除临时的csv文件 File.Delete(FilePath.CSVPATH + table.TableName + ".csv"); } return(ret); }
private async Task <InternalFolder> ValidateAddFolderShare(AddFolderShareBody body) { if (string.IsNullOrWhiteSpace(body.Name)) { throw (HttpResultException)BadRequest("Name missing"); } string userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); InternalFolder folder = await ShareFolderHelper.GetFolderItem(body.Path, dbContext, userId, this); if (folder == null) { throw (HttpResultException)NotFound("Base not found"); } if (!HasPermission(folder.Permission, body.Permission)) { throw (HttpResultException)Forbid(); } if (!string.IsNullOrWhiteSpace(folder.PhysicalPath) && !System.IO.Directory.Exists(folder.PhysicalPath)) { throw (HttpResultException)NotFound("Folder not found"); } if (body.UserId != null && !await dbContext.Users.AnyAsync(u => u.Id == body.UserId)) { throw (HttpResultException)BadRequest("User not found"); } return(folder); }
public void Prepare() { try { ShareFolderHelper.ConnectShareFolder(updateFolder, this.user, this.psd); } catch (Exception e) { ThrowHelper.TryThrow(false, StepEnum.OnCheck, Language.I.Text("checking_error", "Can not connect the share folder")); } }
public async Task <ActionResult <FolderItemInfo> > GetInfo(string encodedVirtualPath) { string virtualPath = Utils.DecodePath(encodedVirtualPath); if (virtualPath == null) { return(BadRequest("Path encoding error")); } InternalFolder folder; try { string userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); folder = await ShareFolderHelper.GetFolderItem(virtualPath, dbContext, userId, this); } catch (HttpResultException exc) { return(exc.Result); } if (!folder.Permission.Info) { return(Forbid()); } try { DirectoryInfo info = null; if (!string.IsNullOrWhiteSpace(folder.PhysicalPath)) { info = new DirectoryInfo(folder.PhysicalPath); if (!info.Exists) { return(NotFound()); } } return(FileHelper.GetInfo(folder, info)); } catch (DirectoryNotFoundException) { return(NotFound("Directory not found")); } }
public async Task <ActionResult> Delete(string encodedVirtualPath, [FromQuery] bool recursive) { string virtualPath = Utils.DecodePath(encodedVirtualPath); if (virtualPath == null) { return(BadRequest("Path encoding error")); } InternalFolder folder; try { string userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); folder = await ShareFolderHelper.GetFolderItem(virtualPath, dbContext, userId, this); } catch (HttpResultException exc) { return(exc.Result); } if (!folder.Permission.Write) { return(Forbid()); } try { await Task.Run(() => Directory.Delete(folder.PhysicalPath, recursive)); } catch (DirectoryNotFoundException) { return(NotFound()); } return(Ok()); }
public async Task <ActionResult <bool> > Exists(string encodedVirtualPath) { string virtualPath = Utils.DecodePath(encodedVirtualPath); if (virtualPath == null) { return(BadRequest("Path encoding error")); } InternalFolder folder; try { string userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); folder = await ShareFolderHelper.GetFolderItem(virtualPath, dbContext, userId, this); } catch (HttpResultException) { return(false); } return(folder.Permission.Read && (string.IsNullOrWhiteSpace(folder.PhysicalPath) || Directory.Exists(folder.PhysicalPath))); }
public void CleanUpdateServices() { ShareFolderHelper.Disconnect(this.updateFolder); }
public async Task <ActionResult <FolderContent> > ListFolders(string encodedVirtualPath) { string virtualPath = Utils.DecodePath(encodedVirtualPath ?? string.Empty); if (virtualPath == null) { return(BadRequest("Path encoding error")); } string userId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier); if (string.IsNullOrWhiteSpace(virtualPath)) { return(new FolderContent() { Path = new PathPart[0], Permission = new FileSystemCommon.Models.FileSystem.Folders.FolderItemPermission() { Read = false, List = true, Info = false, Hash = false, Write = false, }, Folders = (await dbContext.ShareFolders .Where(f => f.IsListed && (f.UserId == null || f.UserId == userId)) .Include(f => f.Permission) .ToArrayAsync()) .Where(f => string.IsNullOrWhiteSpace(f.Path) || Directory.Exists(f.Path)) .Select(f => f.ToFolderItem()) .OrderBy(f => f.Name).ToArray(), Files = (await dbContext.ShareFiles .Where(f => f.IsListed && (f.UserId == null || f.UserId == userId)) .Include(f => f.Permission) .ToArrayAsync()) .Where(f => System.IO.File.Exists(f.Path)) .Select(f => f.ToFileItem()) .OrderBy(f => f.Name).ToArray(), }); } InternalFolder folder; try { folder = await ShareFolderHelper.GetFolderItem(virtualPath, dbContext, userId, this); } catch (HttpResultException exc) { return(exc.Result); } if (!folder.Permission.List) { return(Forbid()); } try { return(new FolderContent() { Path = FileHelper.GetPathParts(folder), Permission = folder.Permission, Folders = GetFolders(folder).OrderBy(f => f.Name).ToArray(), Files = GetFiles(folder).OrderBy(f => f.Name).ToArray(), }); } catch (DirectoryNotFoundException) { return(NotFound("Directory not found")); } }
public void Disconnect() { ShareFolderHelper.Disconnect(testPath); }
public void Connect() { ShareFolderHelper.ConnectShareFolder(testPath, "xiangbohua", "xiangbohua1"); FileHelper.CreateDir(tempPath); }