public static void UploadFile(Packet packet)
        {
            Packet sendPacket;

            try
            {
                string[] splited = packet.Argument.Split(char.Parse("|"));
                Project  project = new Project(splited[0]);
                string   path    = splited[1];
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Upload file to project {1} [{2}]", packet.ClientIP, project.ProjectName, packet.Username));

                FileStoreHelper.UploadFile(project.FullPath + path, packet.Stream);

                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Success, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                ConsoleUtils.Print(string.Format("[{0}]'s Request: Upload file success: {1} [{2}]", packet.ClientIP, path.Substring(path.LastIndexOf(char.Parse("/"))), packet.Username));
            }
            catch (Exception e)
            {
                ConsoleUtils.Print(string.Format("Upload File Error: [{0}] {1}", e.GetType().ToString(), e.Message));
                sendPacket = PacketParser.CreatePacketWithToken(ResponseEnum.Failure, packet.Token);
                packet.Stream.Write(sendPacket.GetBytes(), 0, sendPacket.Length);
                return;
            }
        }
Beispiel #2
0
        public string ExportPDF(string fileName, string formID, string tmpCode)
        {
            SQLHelper sqlHeper   = SQLHelper.CreateSqlHelper(ConnEnum.Base);
            var       dtWordTmpl = sqlHeper.ExecuteDataTable(string.Format("select * from S_UI_Word where Code='{0}'", tmpCode));

            if (dtWordTmpl.Rows.Count == 0)
            {
                return("");
            }
            UIFO    uiFO = FormulaHelper.CreateFO <UIFO>();
            DataSet ds   = uiFO.GetWordDataSource(tmpCode, formID);

            #region 获取word导出的版本
            DataRow  wordTmplRow = dtWordTmpl.Rows[0];
            DateTime date;
            if (ds.Tables[0].Columns.Contains("CreateTime"))
            {
                date = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
            }
            else
            {
                date = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
            }
            foreach (DataRow row in dtWordTmpl.Rows)
            {
                var _startDate = DateTime.Parse(row["VersionStartDate"].ToString());
                var _endDate   = DateTime.MaxValue;
                if (row["VersionEndDate"].ToString() != "")
                {
                    _endDate = DateTime.Parse(row["VersionEndDate"].ToString());
                }

                if (date > _startDate && date < _endDate)
                {
                    wordTmplRow = row;
                    break;
                }
            }
            int?versionNum = 1;
            if (wordTmplRow["VersionNum"].ToString() != "")
            {
                versionNum = int.Parse(wordTmplRow["VersionNum"].ToString());
            }
            string tmplName = dtWordTmpl.Rows[0]["Code"].ToString() + "_" + versionNum + ".docx";
            string tempPath = Server.MapPath("/") + "WordTemplate/" + tmplName;

            if (System.IO.File.Exists(tempPath) == false)
            {
                tmplName = dtWordTmpl.Rows[0]["Code"].ToString() + ".docx";
                tempPath = Server.MapPath("/") + "WordTemplate/" + tmplName;
            }
            #endregion

            var    export = new Formula.ImportExport.AsposeWordExporter();
            byte[] result = export.ExportPDF(ds, tempPath);
            var    name   = fileName.IndexOf(".pdf") >= 0 ? fileName : fileName + ".pdf";
            return(FileStoreHelper.UploadFile(name, result));
        }
Beispiel #3
0
        public JsonResult UploadPicture()
        {
            if (Request.Files["FileData"] != null)
            {
                var         t = Request.Files["FileData"].InputStream;
                string      fileName = Request.Files["FileData"].FileName;
                string      extName = Path.GetExtension(fileName);
                Image       img = Image.FromStream(t);
                ImageFormat imgFormat = ImageHelper.GetImageFormat(extName);
                byte[]      bt = ImageHelper.ImageToBytes(img, imgFormat);
                int         height = img.Height;
                int         width = img.Width;
                int         limitedHeight = !string.IsNullOrEmpty(Request["ThumbHeight"]) ? Convert.ToInt32(Request["ThumbHeight"]) : 60;
                int         thumbHeight, thumbWidth;
                byte[]      btThumb = null;
                if (height > limitedHeight)
                {
                    thumbHeight = limitedHeight;
                    thumbWidth  = thumbHeight * width / height;
                    Image imgThumb = img.GetThumbnailImage(thumbWidth, thumbHeight, null, IntPtr.Zero);
                    btThumb = ImageHelper.ImageToBytes(imgThumb, imgFormat);
                }
                else
                {
                    btThumb = bt;
                }
                var fileID      = FileStoreHelper.UploadFile(fileName, bt, "", "", "", "DocAtlas");
                var thumbFileID = FileStoreHelper.UploadFile(fileName, btThumb, "", "", "", "DocAtlas");

                return(Json(new { PictureName = fileID, ThumbName = thumbFileID }));
            }
            else
            {
                return(Json(""));
            }
        }
Beispiel #4
0
        public void ExecuteQueue()
        {
            var queueData = this.SQLHelperInterface.ExecuteObject <I_FileSynQueue>("select top 1 * from I_FileSynQueue where SynState='" + SynState.New.ToString() + "' order by CreateTime");

            while (queueData != null)
            {
                try
                {
                    StringBuilder interfaceSb = new StringBuilder();
                    if (queueData.SynType == SynType.Download.ToString())
                    {
                        queueData.RequestUrl = this.BaseStorageUrl + "Download?md5=" + queueData.MD5Code + "&filename=" + queueData.FileName;
                        #region 调用api下载文件
                        var response = HttpHelper.GetResponse(queueData.RequestUrl);
                        if (response.ResponseStatus != RestSharp.ResponseStatus.Completed)
                        {
                            throw new Exception(response.ErrorMessage);
                        }

                        var bs = response.RawBytes;
                        if (bs.Length == 0)
                        {
                            var content = response.Content;
                            if (!string.IsNullOrEmpty(content) && content.StartsWith("{"))
                            {
                                throw new Exception(content);
                            }
                            throw new Exception("没有获得正确得文件流数据");
                        }

                        #endregion
                        #region   filestore
                        queueData.FsFileID = FileStoreHelper.UploadFile(queueData.FileName, bs);
                        if (string.IsNullOrEmpty(queueData.FsFileID))
                        {
                            throw new Exception("上传FileStore失败:" + queueData.FsFileID);
                        }
                        #endregion
                        ExecuteDownload(queueData, interfaceSb);
                    }
                    else
                    {
                        queueData.RequestUrl = this.BaseStorageUrl + "UploadFileMobile";
                        #region  载filestore文件
                        var bs = FileStoreHelper.GetFile(queueData.FsFileID);
                        if (bs.Length == 0)
                        {
                            throw new Exception("从FileStore下载失败:" + queueData.FsFileID);
                        }
                        #endregion
                        #region 调用api上传文件
                        if (string.IsNullOrEmpty(queueData.FileName))
                        {
                            queueData.FileName = GetFileName(queueData.FsFileID);
                        }
                        queueData.Response = HttpHelper.PostFile(queueData.RequestUrl, bs, queueData.FileName);
                        #endregion
                        ExecuteUpload(queueData, interfaceSb, bs.Length);
                    }
                    ComplateSync(queueData, interfaceSb);
                }
                catch (Exception e)
                {
                    ErrorSync(queueData, e.Message);
                }
                queueData = this.SQLHelperInterface.ExecuteObject <I_FileSynQueue>("select top 1 * from I_FileSynQueue where SynState='" + SynState.New.ToString() + "' order by CreateTime");
            }
        }