Example #1
0
        /// <summary>
        /// 同步获取多张比列缩放图片
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public object Post(FSScalePicFileListRequest request)
        {
            int errCode = ImageFilesValid(request);

            if (errCode != (int)FS_ErrorCode.Request_Success)
            {
                return new ScalePicFileListModel {
                    ret = errCode,
                    message = ErrorCodeDic.GetInstance().CodeMessage(errCode),
                    picUrls = null
                };
            }

            var response = new ScalePicFileListModel();
            try
            {
                IPictureFileService picSvr = new PictureFileService();
                response = picSvr.ScalePictureFile(request.file_guid, JsonUtil<List<string>>.FromJosn(request.sizes));
            }
            catch (Exception e)
            {
                string err = string.Format("PictureServiceHost.FSScalePicFileListRequest error = {0}, request = {1}", e.ToString(), JsonUtil<FSScalePicFileListRequest>.ToJson(request));
                LogUtil.Error(err);
            }

            return response;
        }
Example #2
0
        public ScalePicFileListModel ScalePictureFile(string file_guid, List<string> sizes)
        {
            ScalePicFileListModel response = new ScalePicFileListModel();
            response.picUrls = new Dictionary<string, string>();

            #region
            Hashtable nginxService = System.Configuration.ConfigurationManager.GetSection("NginxService") as Hashtable;
            string address = nginxService["Address"].ToString();

            foreach (string size in sizes)
            {
                int width = int.Parse(size.Split('_')[0]);
                int height = int.Parse(size.Split('_')[1]);

                try
                {
                    string picGuid = string.Format("{0}_{1}_{2}", file_guid, width, height);
                    string filePath = ScalePictureOperation.GetFileURLFromCache(file_guid, width, height);

                    if (filePath == null)
                    {
                        if(bytes == null)
                            bytes = ScalePictureOperation.GetOriginlPicBytes(file_guid);

                        if (bytes == null)
                        {
                            errorCode = (int)FS_ErrorCode.DB_FilePath_Null;
                            response.ret = errorCode;
                            response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode);
                            break;
                        }
                        FSImageEntity imageEntity = null;

                        using (MemoryStream ms = new MemoryStream())
                        {
                            ms.Write(bytes, 0, bytes.Length);
                            imageEntity = new FSImageEntity(Image.FromStream(ms), width, height);
                            imageEntity.ConvertSourcePic();
                        }

                        FileEntity newEntity = ScalePictureOperation.PostNewPicture(picGuid + ".jpg", imageEntity.JpegBytes);

                        IFilePicDA fileDA = FSDbFactory.CreatePicWriteFSDB();
                        fileDA.InsertNewPicFileRelation(newEntity.file_guid, picGuid, StringUtil.GetDateTimeSeconds(DateTime.Now));

                        filePath = newEntity.file_path;
                    }

                    if (string.IsNullOrEmpty(filePath))
                    {
                        errorCode = (int)FS_ErrorCode.DB_FilePath_Null;
                        LogUtil.Info(string.Format("ScalePictureFile GetPicFileList size: {0} is not in FDFS", size));
                    }

                    response.picUrls.Add(size, address + filePath);
                }
                catch (Exception ex)
                {
                    LogUtil.Error(string.Format("Exception FSService.Post(ScalePictureFile GetPicFileList): {0}", ex.ToString()));
                    errorCode = (int)FS_ErrorCode.RequestParam_Err;
                    response.ret = errorCode;
                    response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode);
                }
            }
            #endregion

            response.message = ErrorCodeDic.GetInstance().CodeMessage(errorCode);
            return response;
        }