private void AddNewRow( string application, string area, FileOwner owner) { RowCount++; //Add the controls that constitute a row var cboApp = new ComboBox { Anchor = AnchorStyles.Right | AnchorStyles.Left, DropDownStyle = ComboBoxStyle.DropDownList }; cboApp.Items.AddRange(AppOptions); cboApp.SelectedIndexChanged += new EventHandler(cboApp_SelectedIndexChanged); tableDirs.Controls.Add(cboApp); var txtArea = new TextBox { Anchor = AnchorStyles.Right | AnchorStyles.Left }; tableDirs.Controls.Add(txtArea); var cboOwner = new ComboBox { Anchor = AnchorStyles.Right | AnchorStyles.Left, DropDownStyle = ComboBoxStyle.DropDownList }; cboOwner.Items.AddRange(OwnerOptions); tableDirs.Controls.Add(cboOwner); var cboTrackParam = new ComboBox { Anchor = AnchorStyles.Right | AnchorStyles.Left, DropDownStyle = ComboBoxStyle.DropDownList }; tableDirs.Controls.Add(cboTrackParam); tableDirs.RowCount = RowCount; // Populate the controls with the input arguments if (!cboApp.Items.Contains(application)) { return; } cboApp.SelectedItem = application; // We've already hit the bug by now, these lines are superfluous txtArea.Text = area; cboOwner.SelectedItem = OwnerOptions[(int)owner]; this.Height = (tableDirs.RowCount * 33) + 180; tableDirs.Visible = true; }
public Task AddFileOwnerAsync(FileOwner fileOwner, uint pseudoId) { var tabInex = pseudoId % _option.FileTableCount; var sql = $"insert into fileowner_{tabInex}(FileId,Name,OwnerType,OwnerId,CreateTime) values " + "(@FileId,@Name,@OwnerType,@OwnerId,@CreateTime)"; return(InsertAsync(_masterDb.Connection, _option.DbType, sql, fileOwner, id => fileOwner.Id = id)); }
/// <summary> /// 为指定用户创建文件 /// </summary> public async Task <FileStorageInfo> CreateFileAsync(FileOwnerTypeId ownerTypeId, string hash, Stream file, string fileName, int periodMinute = 0) { if (!_clusterSvce.CurrentServer.AllowUpload) { throw new FriendlyException("请从上传服务器上传"); } string tmpFilePath = null; try { var extName = Path.GetExtension(fileName); if (string.IsNullOrEmpty(extName)) { throw new FriendlyException("文件名缺少扩展名"); } extName = extName.Substring(1).ToLower(); var mime = _mimeProvider.GetMimeByExtensionName(extName); //获取hash if (file != null) { tmpFilePath = await ReceiveToTempFileAsync(file); //优先使用文件的hash //hash = FileUtil.GetSha1(tmpFilePath); } if (string.IsNullOrWhiteSpace(hash)) { throw new FriendlyException("hash 必需指定"); } //throw new FriendlyException("file 与 hash 必需至少指定一个"); Task tSync = null; var pseudoId = GeneratePseudoId(hash); var fileInfo = await FileRepo.GetFileByHashAsync(pseudoId, hash); //文件不存在,并且没有传file流 if (fileInfo == null && tmpFilePath == null) { throw new FileNotFoundException("File does not exist"); } //检查所有者剩余配额 var fileSize = fileInfo?.Length ?? new System.IO.FileInfo(tmpFilePath).Length; var remainQuota = await OwnerRepo.GetOwnerRemainQuotaAsync(ownerTypeId.OwnerType, ownerTypeId.OwnerId); if (remainQuota < fileSize) { throw new FriendlyException("您已经没有足够的空间上传该文件"); } Service.Options.Server recServer = null; //检查存在否 if (fileInfo == null) { //插入新文件记录 recServer = _clusterSvce.ElectServer(); fileInfo = new File { ServerId = recServer.Id, Length = new System.IO.FileInfo(tmpFilePath).Length, MimeId = (int)mime.Id, SHA1 = hash, ExtInfo = string.Empty, CreateTime = DateTime.Now }; await FileRepo.AddFileAsync(fileInfo, pseudoId); tSync = _clusterSvce.SyncFileToServerAsync(this, tmpFilePath, fileInfo, pseudoId, recServer); } else { recServer = _clusterSvce.GetServerById(fileInfo.ServerId); var fileExists = await _clusterSvce.RawFileExistsAsync(this, recServer, pseudoId, fileInfo.CreateTime, fileInfo.Id); if (!fileExists) { //通过hash进来的,并且文件不存在 if (string.IsNullOrEmpty(tmpFilePath)) { await FileRepo.DeleteFileAsync(ownerTypeId.OwnerId, fileInfo.Id, pseudoId); throw new FriendlyException("File does not exist(CFA-FE)"); } //文件被删或意外丢失重传 tSync = _clusterSvce.SyncFileToServerAsync(this, tmpFilePath, fileInfo, pseudoId, recServer); } } var fileOwner = await FileRepo.GetFileOwnerByOwnerAsync(pseudoId, fileInfo.Id, ownerTypeId.OwnerType, ownerTypeId.OwnerId); if (fileOwner == null) { fileOwner = new FileOwner { FileId = fileInfo.Id, Name = fileName, OwnerType = ownerTypeId.OwnerType, OwnerId = ownerTypeId.OwnerId, CreateTime = DateTime.Now }; await FileRepo.AddFileOwnerAsync(fileOwner, pseudoId); } if (tSync != null) { await tSync; } //添加配额使用量 await OwnerRepo.AddOwnerUsedQuotaAsync(ownerTypeId.OwnerType, ownerTypeId.OwnerId, fileSize); return(new FileStorageInfo { File = fileInfo, Owner = fileOwner, Server = recServer, PseudoId = pseudoId }); } finally { if (tmpFilePath != null) { FileUtil.TryDelete(tmpFilePath); } } }
public async Task <List <Attachment> > GetAttachmentsAsync(FileOwner owner, int ownerId) { var result = await _dbContext.Attachments.Where(x => x.Owner == owner && x.OwnerTableId == ownerId).ToListAsync(); return(result); }