/// <summary> /// 为指定用户生成指定附件的拷贝 /// </summary> /// <param name="attachment">指定附件实体</param> /// <param name="userId">指定用户的id</param> /// <returns>新附件实体</returns> public T CloneForUser(T attachment, long userId) { //复制数据库记录 T newAttachment = (T) new Attachment(); newAttachment.ContentType = attachment.ContentType; newAttachment.FileLength = attachment.FileLength; newAttachment.FriendlyFileName = attachment.FriendlyFileName; newAttachment.Height = attachment.Height; newAttachment.MediaType = attachment.MediaType; newAttachment.OwnerId = userId; newAttachment.TenantTypeId = attachment.TenantTypeId; newAttachment.UserDisplayName = userService.GetUser(userId).DisplayName; newAttachment.UserId = userId; newAttachment.Width = attachment.Width; newAttachment.FileName = newAttachment.GenerateFileName(); EventBus <T> .Instance().OnBefore(newAttachment, new CommonEventArgs(EventOperationType.Instance().Create())); attachmentRepository.Insert(newAttachment); EventBus <T> .Instance().OnAfter(newAttachment, new CommonEventArgs(EventOperationType.Instance().Create())); //复制文件 Stream stream = null; try { IStoreFile file = StoreProvider.GetFile(attachment.GetRelativePath(), attachment.FileName); stream = file.OpenReadStream(); StoreProvider.AddOrUpdateFile(newAttachment.GetRelativePath(), newAttachment.FileName, stream); } catch { } finally { if (stream != null) { stream.Close(); stream.Dispose(); } } //根据不同租户类型的设置生成不同尺寸的图片,用于图片直连访问 if (newAttachment.MediaType == MediaType.Image) { TenantAttachmentSettings tenantAttachmentSettings = TenantAttachmentSettings.GetRegisteredSettings(newAttachment.TenantTypeId); if (tenantAttachmentSettings != null && tenantAttachmentSettings.ImageSizeTypes != null && tenantAttachmentSettings.ImageSizeTypes.Count > 0) { foreach (var imageSizeType in tenantAttachmentSettings.ImageSizeTypes) { IStoreFile file = StoreProvider.GetResizedImage(newAttachment.GetRelativePath(), newAttachment.FileName, imageSizeType.Size, imageSizeType.ResizeMethod); } } } return(newAttachment); }
/// <summary> /// 获取Logo /// </summary> /// <param name="associateId">关联Id</param> /// <returns></returns> public IStoreFile GetLogo(object associateId) { return(StoreProvider.GetFile(GetLogoRelativePath(associateId), GetLogoFileName(associateId))); }