Exemplo n.º 1
0
 /// <summary>
 /// 删除文件系统中的文件
 /// </summary>
 /// <param name="attachment">附件</param>
 protected void DeleteStoredFile(T attachment)
 {
     //如果属于图片附件,则还需删除生成的图片缩略图及附件原图
     if (attachment.MediaType == MediaType.Image)
     {
         //删除所有图(包括原始图、缩略图)
         StoreProvider.DeleteFiles(attachment.GetRelativePath(), attachment.FileName);
     }
     else
     {
         StoreProvider.DeleteFile(attachment.GetRelativePath(), attachment.FileName);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 上传Logo
        /// </summary>
        /// <param name="associateId"></param>
        /// <param name="stream"></param>
        /// <returns>上传文件的相对路径(包含文件名)</returns>
        public string UploadLogo(object associateId, Stream stream)
        {
            string relativeFileName = string.Empty;

            if (stream != null)
            {
                ILogoSettingsManager logoSettingsManager = DIContainer.Resolve <ILogoSettingsManager>();
                LogoSettings         logoSettings        = logoSettingsManager.Get();

                //检查是否需要缩放原图
                Image image = Image.FromStream(stream);
                if (image.Height > this.TenantLogoSettings.MaxHeight || image.Width > this.TenantLogoSettings.MaxWidth)
                {
                    stream = ImageProcessor.Resize(stream, this.TenantLogoSettings.MaxWidth, this.TenantLogoSettings.MaxHeight, logoSettings.ResizeMethod);
                }

                string relativePath = GetLogoRelativePath(associateId);
                string fileName     = GetLogoFileName(associateId);
                relativeFileName = relativePath + "\\" + fileName;

                StoreProvider.AddOrUpdateFile(relativePath, fileName, stream);
                stream.Dispose();

                //根据不同租户类型的设置生成不同尺寸的图片,用于图片直连访问
                if (this.TenantLogoSettings.ImageSizeTypes != null && this.TenantLogoSettings.ImageSizeTypes.Count > 0)
                {
                    foreach (var imageSizeType in this.TenantLogoSettings.ImageSizeTypes.Values)
                    {
                        string sizedFileName = StoreProvider.GetSizeImageName(fileName, imageSizeType.Key, imageSizeType.Value);
                        StoreProvider.DeleteFile(relativePath, sizedFileName);
                        IStoreFile file = StoreProvider.GetResizedImage(relativePath, fileName, imageSizeType.Key, imageSizeType.Value);
                    }
                }
            }

            return(relativeFileName);
        }