Exemple #1
0
        /// <summary>
        /// 读取js文件内容并压缩
        /// </summary>
        /// <param name="filePathlist"></param>
        /// <returns></returns>
        public static string ReadJSFile(string[] filePathlist)
        {
            StringBuilder jsStr = new StringBuilder();

            try
            {
                string rootPath = Assembly.GetExecutingAssembly().CodeBase.Replace("/bin/Workman.Util.DLL", "").Replace("file:///", "");
                foreach (var filePath in filePathlist)
                {
                    string path = rootPath + filePath;
                    if (DirFileHelper.IsExistFile(path))
                    {
                        string content = File.ReadAllText(path, Encoding.UTF8);
                        if (Config.GetValue("JsCompressor") == "true")
                        {
                            content = javaScriptCompressor.Compress(content);
                        }
                        jsStr.Append(content);
                    }
                }
                return(jsStr.ToString());
            }
            catch (Exception)
            {
                return("");
            }
        }
Exemple #2
0
        /// <summary>
        /// 读取对应文件
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string Read(string filePath)
        {
            StringBuilder str = new StringBuilder();

            try
            {
                string rootPath = Assembly.GetExecutingAssembly().CodeBase.Replace("/bin/Workman.Util.DLL", "").Replace("file:///", "");
                string path     = rootPath + filePath;
                if (DirFileHelper.IsExistFile(path))
                {
                    string content = File.ReadAllText(path, Encoding.UTF8);
                    str.Append(content);
                }
                return(str.ToString());
            }
            catch (Exception)
            {
                return("");
            }
        }
Exemple #3
0
        /// <summary>
        /// 解析附件并且下载到本地目录
        /// </summary>
        /// <param name="filePath">路径</param>
        /// <param name="messageFile">附件对象</param>
        /// <param name="UID"></param>
        /// <returns></returns>
        private static List <MailFile> GetFile(string filePath, MIME_Entity[] messageFile, string UID)
        {
            var resultList = new List <MailFile>();

            foreach (MIME_Entity entity in messageFile)
            {
                var fileName = entity.ContentType.Param_Name;
                var fileByte = (MIME_b_SinglepartBase)entity.Body;
                var fileId   = UID + "_" + fileName;
                DirFileHelper.CreateFile(filePath + fileId, fileByte.Data);
                var fileSize = DirFileHelper.GetFileSize(filePath + fileId);
                resultList.Add(new MailFile
                {
                    FileId   = fileId,
                    FileName = fileName,
                    FileSize = DirFileHelper.ToFileSize(fileSize)
                });
            }
            return(resultList);
        }
Exemple #4
0
 /// <summary>
 /// 获取
 /// </summary>
 /// <param name="account">配置</param>
 /// <param name="receiveCount">已收邮件数、注意:如果已收邮件数和邮件数量一致则不获取</param>
 /// <returns></returns>
 public static List <MailModel> Get(MailAccount account, int receiveCount)
 {
     try
     {
         var filePath   = DirFileHelper.GetAbsolutePath("~/Resource/EmailFile/");
         var resultList = new List <MailModel>();
         using (POP3_Client pop3Client = new POP3_Client())
         {
             pop3Client.Connect(account.POP3Host, account.POP3Port, account.Ssl);
             pop3Client.Login(account.Account, account.Password);
             var messages = pop3Client.Messages;
             if (receiveCount == messages.Count)
             {
                 return(resultList);
             }
             for (int i = messages.Count - 1; receiveCount <= i; i--)
             {
                 var messageItem   = messages[i];
                 var messageHeader = Mail_Message.ParseFromByte(messageItem.MessageToByte());
                 resultList.Add(new MailModel()
                 {
                     UID        = messageItem.UID,
                     To         = messageHeader.From == null ? "" : messageHeader.From[0].Address,
                     ToName     = messageHeader.From == null ? "" : messageHeader.From[0].DisplayName,
                     Subject    = messageHeader.Subject,
                     BodyText   = messageHeader.BodyHtmlText,
                     Attachment = GetFile(filePath, messageHeader.GetAttachments(true, true), messageItem.UID),
                     Date       = messageHeader.Date,
                 });
             }
         }
         return(resultList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }