Пример #1
0
 public void SavePhotoFromUrlTest()
 {
     string savePath="/ScenicImg";
     string savePathPhy = @"e:\testDetailimgLocalizer\";
     string savedFileName = "http://www.tourol.cn/Img/slide/2.png".GetHashCode().ToString();
     ImageLocalizer localizer = new ImageLocalizer(
         "http://www.tourol.cn/Img/slide/2.png"
         ,savePathPhy
         , savePath
         ,savedFileName);
     string actual= localizer.SavePhotoFromUrl();
     Assert.AreEqual(savePath+"/"+ savedFileName+".png", actual);
     FileInfo file = new FileInfo(savePathPhy + savedFileName + ".png");
     Assert.IsTrue(file.Exists);
     Assert.IsTrue(file.LastAccessTime.AddSeconds(2) > DateTime.Now);
 }
Пример #2
0
        /// <summary>
        /// 最终结果
        /// </summary>
        /// <summary>
        /// 按照order,使用rule过滤.
        /// </summary>
        /// <param name="rawContent"></param>
        /// <returns></returns>
        public string FilterUsingRuleSet(ref string rawContent, bool returnJsonFormat)
        {
            string completeResult = string.Empty;
            Rules.Sort(SortCompare);
            foreach (BaseRule rule in Rules)
            {
                //通过规则过滤文本
                string filtered = rule.FilterUsingRule(ref rawContent);

                //合并
                completeResult += filtered;
            }
            //判断是否有替换文本
            if (OldRegex.Count > 0)
            {
                for (int i = 0; i < OldRegex.Count; i++)
                {
                    MatchCollection mc = Regex.Matches(completeResult, OldRegex[i],RegexOptions.Singleline);
                    if (mc.Count > 0)
                    {
                        foreach (Match item in mc)
                        {
                            completeResult = completeResult.Replace(item.Value, NewRegex[i]);
                        }
                    }
                }
            }
            //是否返回json格式
            if (returnJsonFormat)
            {
                completeResult = Code + ":\"" + completeResult + "\"";
            }
            if (NeedImageLocalizer)
            {
                string[] imageUrls = TextHelper.GetImageUrl(completeResult, ImageLocalizerType);
                foreach (string imageUrl in imageUrls)
                {
                    ImageLocalizer localizer = new ImageLocalizer(imageUrl
                        , ImagePath
                        , VirtualPath
                        , Math.Abs(imageUrl.GetHashCode()).ToString());
                    string newImagePath = localizer.SavePhotoFromUrl();
                    completeResult = completeResult.Replace(imageUrl, newImagePath);
                }
                //string[] temp=ImagePath.Split(new char[]{'\\'},StringSplitOptions.RemoveEmptyEntries);
                //ImagePath = string.Empty;
                //for (int i = 0; i < temp.Length-1; i++)
                //{
                //    ImagePath += temp[i] + "\\";
                //}
            }
            return completeResult;
        }