Esempio n. 1
0
        public void DoWork(object obj) //chay Parallel.ForEach
        {
            if (obj == null)
            {
                return;
            }
            FileMeta fileMeta = (FileMeta)obj;

            if (string.IsNullOrEmpty(fileMeta.FullName))
            {
                return;
            }

            string sPath = MyConfig.GetMailFolder();

            try
            {
                using (var msg = new MsgReader.Outlook.Storage.Message(fileMeta.FullName))
                {
                    //msg.Type == MsgReader.Outlook.MessageType.Email
                    //msg.Type == MsgReader.Outlook.MessageType.AppointmentRequest
                    //msg.Type == MsgReader.Outlook.MessageType.EmailNonDeliveryReport
                    // etc
                    Document doc = new Document();

                    doc.Add(new Field("SentOn", msg.GetSentOnEx(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                    doc.Add(new Field("ReceivedOn", msg.GetReceivedOnEx(), Field.Store.YES, Field.Index.NOT_ANALYZED));

                    doc.Add(new Field("Subject", msg.Subject.EmptyIfNullEx(), Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("Body", msg.BodyText.EmptyIfNullEx(), Field.Store.YES, Field.Index.ANALYZED));

                    doc.Add(new Field("SenderEmailAddress", msg.Sender.Email.EmptyIfNullEx(), Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("SenderName", msg.Sender.DisplayName.EmptyIfNullEx(), Field.Store.YES, Field.Index.ANALYZED));

                    doc.Add(new Field("To", msg.GetEmailToEx(), Field.Store.YES, Field.Index.ANALYZED));
                    doc.Add(new Field("CC", msg.GetEmailCcEx(), Field.Store.YES, Field.Index.ANALYZED));

                    doc.Add(new Field("Categories", msg.GetCategoryEx(), Field.Store.YES, Field.Index.ANALYZED));

                    doc.Add(new Field("FlagRequest", msg.GetFlagEx(), Field.Store.YES, Field.Index.NOT_ANALYZED));

                    doc.Add(new Field("Importance", msg.GetImportanceEx(), Field.Store.YES, Field.Index.NOT_ANALYZED));

                    doc.Add(new Field("AttachmentNames", msg.GetAttachmentNames().EmptyIfNullEx(), Field.Store.YES, Field.Index.ANALYZED));

                    doc.Add(new Field("FullFileName", fileMeta.FileNameWithoutPath, Field.Store.YES, Field.Index.NOT_ANALYZED));
                    doc.Add(new Field("LastWriteTime", fileMeta.LastWriteTime, Field.Store.YES, Field.Index.NOT_ANALYZED));

                    Writer.AddDocument(doc);
                    //  ConStackLog.Push(msg.Subject);
                }
            }
            catch (Exception ex)
            {
                ConStackLog.Push(ex.Message + "|" + fileMeta.FullName);
            }
        }
Esempio n. 2
0
        public static bool CheckDocExist(IndexSearcher searcher, FileMeta fileMeta)
        {
            TopDocs top = null;

            try
            {
                Query        query1 = new TermQuery(new Term("FullFileName", fileMeta.FileNameWithoutPath));
                Query        query2 = new TermQuery(new Term("LastWriteTime", fileMeta.LastWriteTime));
                BooleanQuery query3 = new BooleanQuery();
                query3.Add(query1, Occur.MUST);
                query3.Add(query2, Occur.MUST);
                top = searcher.Search(query3, 1);
            }
            catch (Exception)
            {
                return(false);
            }
            if (top.TotalHits == 0)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        public static List <FileMeta> GetFileMsg(string sPath)
        {
            List <FileMeta> lst = new List <FileMeta>();

            try
            {
                string[] fileNames = System.IO.Directory.GetFiles(sPath, "*.*", SearchOption.AllDirectories);
                foreach (var fileName in fileNames)
                {
                    if (System.IO.Path.GetExtension(fileName).ToUpper() == ".MSG")
                    {
                        FileMeta item = new FileMeta(sPath);
                        item.FullName       = fileName;
                        item.DLastWriteTime = System.IO.File.GetLastWriteTime(fileName);
                        lst.Add(item);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Thong bao", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            return(lst);
        }