/// <summary>
        /// 读取XPS缩略图
        /// </summary>
        /// <param name="res_key"></param>
        /// <param name="rft"></param>
        /// <returns></returns>
        public static string XpsImage(string resFile, ResFileType rft)
        {
            string url = "";

            try
            {
                if (!string.IsNullOrEmpty(resFile))
                {
                    string filePath = RWUtility.GetResPath(resFile);
                    if (System.IO.File.Exists(filePath))
                    {
                        string path = resFile.Split('/')[0] + "/thumbnail.jpg";
                        if (IsFileExists(path))
                        {
                            url = GetResUrl(path);
                        }
                    }
                }
                if (url.Length == 0)
                {
                    if (ResConfig.Current.Icons.ContainsKey(rft))
                    {
                        return(ResConfig.Current.ResUrlDefault + ResConfig.Current.Icons[rft].Default);
                    }
                }
            }
            catch (Exception ex)
            {
                OSeage.Common.Log.Logger.Error(string.Format("[{0}]XpsImage Error:{1}", resFile, ex.ToString()));
            }
            return(url);
        }
 /// <summary>
 /// 根据类型获取缺省时显示的网址
 /// </summary>
 /// <param name="rft"></param>
 /// <returns></returns>
 public static string GetDefaultUrlByResFileType(ResFileType rft)
 {
     if (ResConfig.Current.Icons.ContainsKey(rft))
     {
         return(ResConfig.Current.ResUrlDefault + ResConfig.Current.Icons[rft].Default);
     }
     else
     {
         return(string.Empty);
     }
 }
        /// <summary>
        /// 图片缩放
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="rft"></param>
        /// <returns></returns>
        public static string PicZoomAuto(string filePath, ResFileType rft)
        {
            filePath = RWUtility.GetResPath(filePath);
            string savePath = string.Empty;

            if (ResConfig.Current.Icons.ContainsKey(rft))
            {
                IconInfo size    = ResConfig.Current.Icons[rft];
                string   dirPath = Path.GetDirectoryName(filePath) + string.Format("\\{0}x{1}\\", size.Width, size.Height);
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                ImgUtil.ZoomAuto(filePath, dirPath + Path.GetFileName(filePath), size.Width, size.Height, null, null, 100);
                savePath = dirPath + Path.GetFileName(filePath);
            }
            return(savePath);
        }
        /// <summary>
        /// 获取html字符串中的第一个图片
        /// </summary>
        /// <param name="htmlText"></param>
        /// <returns></returns>
        public static string GetFirstImages(string htmlText, ResFileType rft)
        {
            string img = string.Empty;
            // 定义正则表达式用来匹配 img 标签
            Regex regImg = new Regex(@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>", RegexOptions.IgnoreCase);

            // 搜索匹配的字符串
            MatchCollection matches = regImg.Matches(htmlText);

            if (matches.Count > 0)
            {
                img = matches[0].Groups["imgUrl"].Value;
            }
            if (string.IsNullOrEmpty(img))
            {
                return(ResConfig.Current.ResUrlDefault + ResConfig.Current.Icons[rft].Default);
            }
            return(img);
        }
        /// <summary>
        /// 根据资源相对路径,获取资源的URL数据,带文件是否存在判断以及不存在时返回缺省值
        /// </summary>
        /// <returns></returns>
        public static string FormatResUrl(string resFile, ResFileType rft)
        {
            string url = "";

            try
            {
                if (!string.IsNullOrEmpty(resFile))
                {
                    if (ResConfig.Current.Icons.ContainsKey(rft))
                    {
                        string path = resFile.Split('/')[0] + string.Format("\\{0}x{1}\\",
                                                                            ResConfig.Current.Icons[rft].Width, ResConfig.Current.Icons[rft].Height) +
                                      resFile.Split('/')[1];
                        if (IsFileExists(path))
                        {
                            url = GetResUrl(path);
                        }
                    }
                    else
                    {
                        if (IsFileExists(resFile))
                        {
                            url = GetResUrl(resFile);
                        }
                    }
                }
                if (url.Length == 0)
                {
                    if (ResConfig.Current.Icons.ContainsKey(rft))
                    {
                        return(ResConfig.Current.ResUrlDefault + ResConfig.Current.Icons[rft].Default);
                    }
                }
            }
            catch (Exception ex)
            {
                OSeage.Common.Log.Logger.Error(string.Format("[{0}]FormatResUrl Error:{1}", resFile, ex.ToString()));
            }
            return(url);
        }
 private IList<ResFileInfo> GetFileList(string path, ResFileType type, CheckFileValidate checkMethod)
 {
     List<ResFileInfo> list = new List<ResFileInfo>();
     DirectoryInfo dir = new DirectoryInfo(path);
     if (dir.Exists)
     {
         foreach (FileInfo file in dir.GetFiles())
         {
             if (checkMethod(file))
             {
                 ResFileInfo resFile = new ResFileInfo();
                 resFile.FileName = file.Name;
                 resFile.Extension = file.Extension;
                 resFile.Type = type;
                 resFile.CreateTime = file.CreationTime;
                 resFile.UpdateTime = file.LastWriteTime;
                 resFile.Size = CountSize(file.Length);
                 list.Add(resFile);
             }
         }
     }
     return list;
 }
        private IList <ResFileInfo> GetFileList(string path, ResFileType type, CheckFileValidate checkMethod)
        {
            List <ResFileInfo> list = new List <ResFileInfo>();
            DirectoryInfo      dir  = new DirectoryInfo(path);

            if (dir.Exists)
            {
                foreach (FileInfo file in dir.GetFiles())
                {
                    if (checkMethod(file))
                    {
                        ResFileInfo resFile = new ResFileInfo();
                        resFile.FileName   = file.Name;
                        resFile.Extension  = file.Extension;
                        resFile.Type       = type;
                        resFile.CreateTime = file.CreationTime;
                        resFile.UpdateTime = file.LastWriteTime;
                        resFile.Size       = CountSize(file.Length);
                        list.Add(resFile);
                    }
                }
            }
            return(list);
        }
        /// <summary>
        /// 创建缩略图
        /// </summary>
        public static string CutAvatar(string imgSrc, int x, int y, int width, int height, long Quality, ResFileType rft, int t)
        {
            try
            {
                imgSrc = RWUtility.GetResPath(imgSrc);
                string dirPath = string.Empty;
                if (ResConfig.Current.Icons.ContainsKey(rft))
                {
                    IconInfo size = ResConfig.Current.Icons[rft];
                    dirPath = Path.GetDirectoryName(imgSrc) + string.Format("\\{0}x{1}\\", size.Width, size.Height);
                    if (!Directory.Exists(dirPath))
                    {
                        Directory.CreateDirectory(dirPath);
                    }

                    Image  original = Image.FromFile(imgSrc);
                    Bitmap img      = new Bitmap(t, t, PixelFormat.Format24bppRgb);
                    img.MakeTransparent(img.GetPixel(0, 0));
                    img.SetResolution(72, 72);
                    using (Graphics gr = Graphics.FromImage(img))
                    {
                        if (original.RawFormat.Equals(ImageFormat.Jpeg) || original.RawFormat.Equals(ImageFormat.Png) || original.RawFormat.Equals(ImageFormat.Bmp))
                        {
                            gr.Clear(Color.Transparent);
                        }
                        if (original.RawFormat.Equals(ImageFormat.Gif))
                        {
                            gr.Clear(Color.White);
                        }

                        gr.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                        gr.SmoothingMode      = SmoothingMode.AntiAlias;
                        gr.CompositingQuality = CompositingQuality.HighQuality;
                        gr.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                        gr.TextRenderingHint  = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                        using (var attribute = new System.Drawing.Imaging.ImageAttributes())
                        {
                            attribute.SetWrapMode(WrapMode.TileFlipXY);
                            gr.DrawImage(original, new Rectangle(0, 0, t, t), x, y, width, height, GraphicsUnit.Pixel, attribute);
                        }
                    }
                    ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/jpeg");
                    if (original.RawFormat.Equals(ImageFormat.Jpeg))
                    {
                        myImageCodecInfo = GetEncoderInfo("image/jpeg");
                    }
                    else
                    if (original.RawFormat.Equals(ImageFormat.Png))
                    {
                        myImageCodecInfo = GetEncoderInfo("image/png");
                    }
                    else
                    if (original.RawFormat.Equals(ImageFormat.Gif))
                    {
                        myImageCodecInfo = GetEncoderInfo("image/gif");
                    }
                    else
                    if (original.RawFormat.Equals(ImageFormat.Bmp))
                    {
                        myImageCodecInfo = GetEncoderInfo("image/bmp");
                    }

                    System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                    EncoderParameters myEncoderParameters    = new EncoderParameters(1);
                    EncoderParameter  myEncoderParameter     = new EncoderParameter(myEncoder, Quality);
                    myEncoderParameters.Param[0] = myEncoderParameter;
                    img.Save(dirPath + Path.GetFileName(imgSrc), myImageCodecInfo, myEncoderParameters);
                }
                return(dirPath + Path.GetFileName(imgSrc));
            }
            catch
            {
                return("");
            }
        }