コード例 #1
0
        //private void bW1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        //{
        //    TxtStatus.Text += (string) e.UserState;
        //    TxtStatus.Text += Environment.NewLine;
        //}

        private void bW1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            WorkerThreadResult result = e.Result as WorkerThreadResult;

            TxtStatus.Clear();
            TxtStatus.AppendText("Total processed files: " + result.FileDone.Count.ToString());
            TxtStatus.AppendText(Environment.NewLine);
            TxtStatus.AppendText("Total duplicate files: " + result.NumDupFiles.ToString());
            TxtStatus.AppendText(Environment.NewLine);
            if (!string.IsNullOrEmpty(result.ErrLog))
            {
                TxtStatus.AppendText("Error: ");
                TxtStatus.AppendText(Environment.NewLine);
                TxtStatus.AppendText(result.ErrLog);
            }
        }
コード例 #2
0
ファイル: Worker.cs プロジェクト: khangcode/FindArchiveMail
        public WorkerThreadResult RunMT(bW1Arg arg)
        {
            WorkerThreadResult result = new WorkerThreadResult();

            string indexPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "LuceneData");

            Lucene.Net.Store.Directory directory = Lucene.Net.Store.FSDirectory.Open(indexPath);
            Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            Worker workerObject = new Worker();

            workerObject.Writer      = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
            workerObject.ConStackLog = ErrLog;
            workerObject.SetRAMBufferSizeMB();

            List <FileMeta> LstMsgFile = MyIO.GetFileMsgFromTo(MyConfig.GetMailFolder(), arg.DFrom, arg.DTo);

            if (arg.IsReIndex)
            {
                workerObject.DeleteAllDocuments();
            }
            else
            {
                //Xoa bo nhung item trung lap giua list moi tao va du lieu da index
                using (Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(directory))
                {
                    for (int i = LstMsgFile.Count - 1; i >= 0; i--)
                    {
                        if (MyLucene.CheckDocExist(searcher, LstMsgFile[i]))
                        {
                            LstMsgFile.RemoveAt(i);
                            result.IncreaseNumDupFiles();
                        }
                    }
                }
            }

            //Chay song song
            ParallelLoopResult pResult = Parallel.ForEach(LstMsgFile, (currentFileMeta) => workerObject.DoWork(currentFileMeta));

            StringBuilder sb = new StringBuilder();

            if (pResult.IsCompleted)
            {
                workerObject.DisposeWriter();
                analyzer.Dispose();
                directory.Dispose();

                result.FileDone = LstMsgFile;

                int i = 0;
                foreach (var a in ErrLog)
                {
                    string item;
                    ErrLog.TryPop(out item);
                    i++;
                    sb.Append(i.ToString());
                    sb.Append(". ");
                    sb.Append(item);
                    sb.Append(Environment.NewLine);
                }
                result.ErrLog = sb.ToString();
            }
            return(result);
        }
コード例 #3
0
ファイル: Worker2.cs プロジェクト: khangcode/FindArchiveMail
        public WorkerThreadResult RunMT(List <FileMeta> LstMsgFile, bool IsReIndex)
        {
            WorkerThreadResult result = new WorkerThreadResult();

            string indexPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "LuceneData");

            Lucene.Net.Store.Directory directory = Lucene.Net.Store.FSDirectory.Open(indexPath);
            Lucene.Net.Analysis.Standard.StandardAnalyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            Worker2 workerObject = new Worker2();

            workerObject.Writer      = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
            workerObject.ConStackLog = ErrLog;
            workerObject.SetRAMBufferSizeMB();

            if (IsReIndex)
            {
                workerObject.DeleteAllDocuments();
            }
            else
            {
                //Xoa bo nhung item trung lap giua list moi tao va du lieu da index
                using (Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(directory))
                {
                    for (int idx2 = LstMsgFile.Count - 1; idx2 >= 0; idx2--)
                    {
                        if (MyLucene.CheckDocExist(searcher, LstMsgFile[idx2]))
                        {
                            LstMsgFile.RemoveAt(idx2);
                            result.IncreaseNumDupFiles();
                        }
                    }
                }
            }
            //Chia list thanh cac list con
            int chunkSize = 200;
            int maxThread = 25;

            int totalItem = LstMsgFile.Count;
            int numThread = totalItem / chunkSize;

            if (numThread > maxThread)
            {
                numThread = maxThread;
                chunkSize = totalItem / maxThread;
            }
            if (totalItem % chunkSize != 0)
            {
                numThread++;
            }

            List <List <FileMeta> > lst1 = new List <List <FileMeta> >();

            for (int idx = 0; idx < totalItem; idx++)
            {
                int iMin = idx * chunkSize;
                int iMax = iMin + chunkSize;
                if (iMax > totalItem)
                {
                    iMax = totalItem;
                }
                List <FileMeta> lst2 = new List <FileMeta>();
                for (int j = iMin; j < iMax; j++)
                {
                    lst2.Add(LstMsgFile[j]);
                }
                if (lst2.Count != 0)
                {
                    lst1.Add(lst2);
                }
            }

            //Chay song song
            List <Thread> lstTask = new List <Thread>();

            foreach (var item in lst1)
            {
                Thread thread = new Thread(workerObject.DoWork);
                thread.Start(item);
                lstTask.Add(thread);
            }

            //Cho cho den khi cac thread chay xong moi chay tiep
            foreach (var th in lstTask)
            {
                th.Join();
            }

            //Luu du lieu
            workerObject.DisposeWriter();
            analyzer.Dispose();
            directory.Dispose();

            result.FileDone = LstMsgFile;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < ErrLog.Count; i++)
            {
                string item = ErrLog.Pop();
                sb.Append((i + 1).ToString());
                sb.Append(". ");
                sb.Append(item);
                sb.Append(Environment.NewLine);
            }
            result.ErrLog = sb.ToString();
            return(result);
        }