internal FileUploadResult Save(SaveArgs args)
        {
            FileUploadResult result = new FileUploadResult();

            //流长度在关闭释放流之后就取不到了
            int length = (int)(args.Stream.Length / 1024);

            FileStream fsWrite = null;
            Stream     stream  = null;
            string     storeFileName;

            #region 存储文件

            try
            {
                string targetDir = Path.Combine(_serverRootDir, "FileStore", args.Domain.ToString());
                if (Directory.Exists(targetDir) == false)
                {
                    Directory.CreateDirectory(targetDir);
                }

                storeFileName = Guid.NewGuid().ToString() + args.FileExtension;

                string outputFileName = Path.Combine(targetDir, storeFileName);

                ////Path.Combine 是 \, HTTP 地址用的是 /
                ////但是序列化时,会对 / 转义成 \/
                //result.RelativeUri = "FileStore" + "/" + _site.SiteInfo.Code + "/" + storeFileName;

                byte[] buffer = new byte[4096];

                fsWrite         = new FileStream(outputFileName, FileMode.Create);
                stream          = args.Stream;
                stream.Position = 0;

                int read = 0;
                do
                {
                    read = stream.Read(buffer, 0, buffer.Length);
                    fsWrite.Write(buffer, 0, read);
                } while (read > 0);
            }
            catch (Exception ex)
            {
                _exceptionHandling.HandleException(ex);
                result.Message = ex.Message;
                result.Success = false;
                return(result);
            }
            finally
            {
                if (fsWrite != null)
                {
                    fsWrite.Flush();
                    fsWrite.Close();
                    fsWrite.Dispose();
                }
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }

            #endregion

            //存储数据库记录
            FileRecord record = new FileRecord();
            record.Id              = args.Id;
            record.Domain          = args.Domain;
            record.FileName        = args.FileName;
            record.StoredFileName  = storeFileName;
            record.Length          = length;
            record.MD5             = args.MD5;
            record.UploadDate      = args.UploadDate;
            record.UploadIPAddress = args.UploadIPAddress;

            _dataBase.Insert(record);

            result.Success       = true;
            result.Id            = args.Id;
            result.StoreFilePath = String.Format("FileStore/{0}/{1}", args.Domain, storeFileName);

            return(result);
        }
        internal GetMemberQRCodeImageResult GetMemberQRCodeImage(string serverRootDir, GetCampaign_MemberQRCodeImageArgs args)
        {
            GetMemberQRCodeImageResult result = new GetMemberQRCodeImageResult();

            if (args == null || String.IsNullOrEmpty(args.LandingUrl))
            {
                result.Message = "参数不正确";
                return(result);
            }

            MemberEntity member = _memberManager.GetMember(args.MemberId);

            if (member == null)
            {
                result.Message = "会员信息不存在";
                return(result);
            }

            FileRecord fileRecord = _fileManager.Get(args.BackgroundImageId);

            if (fileRecord == null)
            {
                result.Message = "背景图信息不存在";
                return(result);
            }

            string backgroundImageFile =
                Path.Combine(serverRootDir, String.Format("FileStore/{0}/{1}", args.Domain, fileRecord.StoredFileName));

            if (File.Exists(backgroundImageFile) == false)
            {
                result.Message = "背景图文件不存在";
                return(result);
            }

            FileDownloadAgentArgs downloadArgs = new FileDownloadAgentArgs();

            downloadArgs.Domain        = args.Domain;
            downloadArgs.Url           = member.Headimgurl_96;
            downloadArgs.ServerRootDir = serverRootDir;

            FileDownloadAgentResult downloadResult = _fileManager.Download(downloadArgs);

            if (downloadResult.Success == false)
            {
                result.Message = downloadResult.Message;
                return(result);
            }

            string headImageFile = Path.Combine(serverRootDir, downloadResult.OutputFile);

            Image qrImage         = null;
            Image backgroundImage = null;
            Image headImage       = null;

            try
            {
                qrImage = QRCodeHelper.GetQRCode(args.LandingUrl);

                if (qrImage == null)
                {
                    result.Message = "二维码生成失败。";
                    return(result);
                }

                backgroundImage = Image.FromFile(backgroundImageFile);
                Graphics g = Graphics.FromImage(backgroundImage);

                //qrImage
                float x = backgroundImage.Width - qrImage.Width - 20;
                float y = backgroundImage.Height - qrImage.Height - 20;
                g.DrawImage(qrImage, x, y);

                //headImage
                x         = 20;
                y         = backgroundImage.Height - 20 - 96;
                headImage = Image.FromFile(headImageFile);
                g.DrawImage(headImage, x, y, 96, 96);

                ////nickName
                //Font font = new Font("黑体", 35f);
                //x = 96 + 40;
                //y = backgroundImage.Height - font.Size - 50;
                //g.DrawString(member.NickName, font, Brushes.Black, new PointF(x, y));

                g.Save();

                string targetDir      = Path.Combine(serverRootDir, "FileStore", args.Domain.ToString());
                string storeFileName  = Guid.NewGuid().ToString() + ".jpg";
                string outputFileName = Path.Combine(targetDir, storeFileName);
                backgroundImage.Save(outputFileName, ImageFormat.Jpeg);

                result.Success  = true;
                result.FileName = String.Format("FileStore/{0}/{1}", args.Domain, storeFileName);
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (qrImage != null)
                {
                    qrImage.Dispose();
                }

                if (backgroundImage != null)
                {
                    backgroundImage.Dispose();
                }

                if (headImage != null)
                {
                    headImage.Dispose();
                }
            }

            return(result);
        }