Example #1
0
        public JsResultObject LocalHotelImage(string basePath, HotelImageModel image, bool isTop)
        {
            JsResultObject re     = new JsResultObject();
            WebClient      client = new WebClient();
            string         folder = string.Format("{0}/{1}", basePath.TrimEnd('/'), image.hotelFk);

            FileUtil.CreateFolder(folder);
            string filePattern = "";
            string filePath    = "";

            if (isTop)
            {
                if (image.isThum())
                {
                    filePattern = "{0}/top.thum{1}";
                }
                else if (image.isNormal())
                {
                    filePattern = "{0}/top.normal{1}";
                }
                filePath = string.Format(filePattern, folder, FileUtil.GetPostfixStr(image.imgUrl));
            }
            else
            {
                if (image.isThum())
                {
                    filePattern = "{0}/{1}.thum{2}";
                }
                else if (image.isNormal())
                {
                    filePattern = "{0}/{1}.normal{2}";
                }
                else if (image.isAround())
                {
                    filePattern = "{0}/{1}.around{2}";
                }
                else
                {
                    re.code = JsResultObject.CODE_ERROR;
                    return(re);
                }
                filePath = string.Format(filePattern, folder, image.title, FileUtil.GetPostfixStr(image.imgUrl));
            }
            try
            {
                client.DownloadFile(image.imgUrl, filePath);
                re.rowNum = 1;
                re.msg    = "保存图片:" + filePath;
            }
            catch (Exception ex)
            {
                re.rowNum = 0;
                re.msg    = ex.Message;
            }
            return(re);
        }