예제 #1
0
        /// <summary>
        /// 生成缩略水印图
        /// </summary>
        /// <param name="waterType"></param>
        /// <param name="waterPossition"></param>
        /// <param name="text"></param>
        /// <param name="textFont"></param>
        /// <param name="textSize"></param>
        /// <param name="textColor"></param>
        /// <param name="waterPhoto"></param>
        /// <returns></returns>
        public FileInfo SaveAs(int waterType, int waterPossition, string text, string textFont, int textSize, string textColor, string waterPhoto, string filePath, string fileExtension, string fileName)
        {
            HttpFileCollection files = HttpContext.Current.Request.Files;
            FileInfo           info  = null;

            try
            { this.saveFileFolderPath = ServerHelper.MapPath(filePath);
              this.fileExtension      = fileExtension;

              //this.saveFileName = FileHelper.CreateFileName(this.fileNameType, this.localFileName, this.fileExtension);
              this.saveFileName = fileName + fileExtension;

              this.saveFileFullPath = this.saveFileFolderPath + this.saveFileName;
              //this.postedFile.SaveAs(this.saveFileFullPath);
              //如果原始图片存在
              if (System.IO.File.Exists(saveFileFullPath))
              {
                  var imgTypes = ".jpg|.gif|.bmp|.png|.jpeg";
                  if (imgTypes.IndexOf(this.fileExtension.ToLower()) != -1) //必须是图片类型才能加压缩
                  {
                      if (allImageIsNail == 1)                              //如果网站设置开启压缩图片
                      {
                          Image image = Image.FromFile(this.saveFileFullPath);
                          if (image.Width > maxWidth)      //如果图片超出设置的编辑器图片宽度,将图片压缩
                          {
                              //string filePath = this.saveFileFullPath;
                              string nailPath = this.saveFileFolderPath + "temp_nail" + this.fileExtension;
                              ImageHelper.MakeThumbnailImage(this.saveFileFullPath, nailPath, maxWidth, maxWidth, ThumbnailType.WidthFix);
                              image.Dispose();
                              System.IO.File.Delete(this.saveFileFullPath);         //删除原图
                              System.IO.File.Move(nailPath, this.saveFileFullPath); //重命名压缩后的文件
                          }
                          image.Dispose();
                      }

                      //添加水印
                      string sFileName = System.IO.Path.GetFileNameWithoutExtension(saveFileName) + "_wm" + this.fileExtension;
                      string newPath   = System.IO.Path.Combine(this.saveFileFolderPath, sFileName);
                      if (waterType == 2)
                      {
                          ImageHelper.AddTextWater(saveFileFullPath, newPath, waterPossition, text, textFont, textColor, textSize);
                      }
                      else
                      {
                          ImageHelper.AddImageWater(saveFileFullPath, newPath, waterPossition, waterPhoto);
                      }
                      //删除没上水印的老图
                      //if (System.IO.File.Exists(saveFileFullPath))
                      //{
                      //    System.IO.File.Delete(saveFileFullPath);
                      //}

                      info = new FileInfo(newPath);
                  }
              }
            }
            catch
            {
                throw;
            }
            return(info);
        }
예제 #2
0
        public FileInfo SaveFromTaobao(int waterType, int waterPossition, string text, string textFont, int textSize, string textColor, string waterPhoto, string fileName)
        {
            this.saveFileFolderPath = ServerHelper.MapPath("~/Upload/TaoBaoPhoto/Original/");
            FileInfo info = new FileInfo(ServerHelper.MapPath(fileName));

            try
            {
                if (fileName == "")
                {
                    throw new Exception("不能上传空文件");
                }
                this.localFileLength = info.Length;
                if (this.localFileLength >= (this.sizes * 0x400))
                {
                    throw new Exception("上传的图片不能大于:" + this.sizes + "KB");
                }
                this.fileExtension = FileHelper.GetFileExtension(fileName);
                if (this.fileType.ToLower().IndexOf(this.fileExtension) == -1)
                {
                    throw new Exception("目前本系统支持的格式为:" + this.fileType);
                }

                this.saveFileFullPath = ServerHelper.MapPath(fileName);

                var imgTypes = ".jpg|.gif|.bmp|.png|.jpeg";
                if (imgTypes.IndexOf(this.fileExtension.ToLower()) != -1) //必须是图片类型才能加压缩
                {
                    if (allImageIsNail == 1)                              //如果网站设置开启压缩图片
                    {
                        Image image = Image.FromFile(this.saveFileFullPath);
                        if (image.Width > maxWidth)//如果图片超出设置的编辑器图片宽度,将图片压缩
                        {
                            string filePath = this.saveFileFullPath;
                            string nailPath = this.saveFileFolderPath + "temp_nail" + this.fileExtension;
                            ImageHelper.MakeThumbnailImage(this.saveFileFullPath, nailPath, maxWidth, maxWidth, ThumbnailType.WidthFix);
                            image.Dispose();
                            System.IO.File.Delete(filePath);         //删除原图
                            System.IO.File.Move(nailPath, filePath); //重命名压缩后的文件
                        }
                        image.Dispose();
                    }

                    //添加水印
                    string sFileName = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_wm" + this.fileExtension;
                    string newPath   = System.IO.Path.Combine(this.saveFileFolderPath, sFileName);
                    if (waterType == 2)
                    {
                        ImageHelper.AddTextWater(saveFileFullPath, newPath, waterPossition, text, textFont, textColor, textSize);
                    }
                    else
                    {
                        ImageHelper.AddImageWater(saveFileFullPath, newPath, waterPossition, waterPhoto);
                    }
                    //删除没上水印的老图
                    //if (System.IO.File.Exists(saveFileFullPath))
                    //{
                    //    System.IO.File.Delete(saveFileFullPath);
                    //}

                    info = new FileInfo(newPath);
                }
            }
            catch
            {
                throw;
            }
            return(info);
        }
예제 #3
0
 public static void ProcessExceptionForWebService(Exception ex)
 {
     new TxtLog(ServerHelper.MapPath(@"\LogWebService\")).Write(ex.ToString());
 }
예제 #4
0
 private static void RecordLog(Exception ex)
 {
     new TxtLog(ServerHelper.MapPath(@"\Log\")).Write(ex.ToString());
 }
예제 #5
0
        private void URLRewriter_BeginRequest(object sender, EventArgs e)
        {
            HttpContext context     = ((HttpApplication)sender).Context;
            string      originalUrl = context.Request.RawUrl;
            string      rawUrl      = context.Request.RawUrl;

            if (this.IsRewriter(rawUrl))
            {
                this.ReadURLList();
                bool flag = false;
                foreach (URLInfo info in this.urlList)
                {
                    string vitualPath = info.VitualPath;
                    string realPath   = info.RealPath;
                    if (info.IsEffect)
                    {
                        if (vitualPath.StartsWith("~"))
                        {
                            vitualPath = HttpContext.Current.Request.ApplicationPath + vitualPath.Substring(2);
                        }
                        if (realPath.StartsWith("~"))
                        {
                            realPath = HttpContext.Current.Request.ApplicationPath + realPath.Substring(2);
                        }

                        //有QueryString的URL,去掉后再匹配
                        if (rawUrl.IndexOf('?') > -1)
                        {
                            rawUrl = rawUrl.Split(new char[] { '?' })[0];
                        }
                        Match match = new Regex("^" + vitualPath + "$", RegexOptions.IgnoreCase).Match(rawUrl);

                        if (match.Success)
                        {
                            for (int i = match.Groups.Count; i >= 1; i--)
                            {
                                realPath = realPath.Replace("$" + i.ToString(), match.Groups[i].Value);
                            }
                            rawUrl = path + realPath;
                            flag   = true;
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    rawUrl = path + rawUrl;
                }
                if (replaceFileTypeDic != null)
                {
                    foreach (KeyValuePair <string, string> pair in replaceFileTypeDic)
                    {
                        if (rawUrl.IndexOf("?") > -1)
                        {
                            rawUrl = StringHelper.ReplaceEx(rawUrl.Substring(0, rawUrl.IndexOf("?")), pair.Key, pair.Value) + rawUrl.Substring(rawUrl.IndexOf("?"));
                        }
                        else
                        {
                            rawUrl = StringHelper.ReplaceEx(rawUrl, pair.Key, pair.Value);
                        }
                    }
                }
                try
                {
                    if (!flag)
                    {
                        Dictionary <string, string> fileNameDic = new Dictionary <string, string>();
                        List <FileInfo>             fileList    = FileHelper.ListDirectory(ServerHelper.MapPath("/Plugins/Template/" + path.Replace("/Ashx/", "") + "/"), "|.htm|");
                        foreach (FileInfo file in fileList)
                        {
                            string tempFileName = file.FullName.Replace(ServerHelper.MapPath("\\Plugins\\Template\\" + path.Replace("/Ashx/", "") + "\\"), string.Empty).Replace("\\", "/");
                            fileNameDic.Add(tempFileName.ToLower(), tempFileName);
                        }
                        //如果没有对应文件,跳转到原始路径,不进行地址重写
                        if (rawUrl.IndexOf("?") > -1)
                        {
                            rawUrl = rawUrl.Substring(0, rawUrl.IndexOf("?"));
                        }
                        string afterUrl = rawUrl.Replace(path, "").Replace(".ashx", ".htm").ToLower();
                        afterUrl = afterUrl.Substring(1, afterUrl.Length - 1);//去除"/"
                        if (fileNameDic.ContainsKey(afterUrl))
                        {
                            context.RewritePath(rawUrl);
                        }
                        else
                        {
                            context.RewritePath(originalUrl);
                        }
                    }
                    else
                    {
                        context.RewritePath(rawUrl);
                    }
                }
                catch
                {
                    context.Response.Write("未找到该页面");
                }
            }
        }