Example #1
0
        // Edition des fichiers une fois que tous les threads sont terminés
        public static void IndexFinalize(ThreadParameters p)
        {
            File.Delete(Util.GetFinalRejectedFilePath());
            File.Delete(Util.GetFinalResultFilePath());
            for (int i = 0; i < p.NumberOfWorkingThreads; i++)
            {
                Util.AppendFiles(Util.GetRejectedFilePath(i), Util.GetFinalRejectedFilePath());
                Util.AppendFiles(Util.GetResultFilePath(i), Util.GetFinalResultFilePath());
            }
            Util.SortUniq(Util.GetFinalRejectedFilePath(), Util.GetSortedUniqRejectedFilePath());
            Util.SortUniq(Util.GetFinalResultFilePath(), Util.GetSortedUniqResultFilePath());

            Util.DisplayFile(Util.GetSortedUniqRejectedFilePath());
            Util.DisplayFile(Util.GetSortedUniqResultFilePath());
        }
Example #2
0
        //_________________________________________________________________________________________________________

        //                     DELEGATES THAT RUN ON BACKGROUND WORKER THREADS

        //

        // Extraction Delegate that run on the background worker thread
        public static void DoExtraction(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker         = sender as BackgroundWorker;
            ThreadParameters p              = (ThreadParameters)e.Argument;
            string           resultFilePath = Util.GetResultFilePath(p.ThreadNum);
            List <string>    wordlistresult = new List <string>();
            int rc = Commands.ExtractPattern(worker, p.Text, p.Pattern, p.IgnoreCase, ref wordlistresult);

            Util.WriteToFile(resultFilePath, wordlistresult, Msg.MSG_NOTHING_FOUND_OR_NO_TEXT);
            e.Result = rc;
            if (rc != 0)
            {
                e.Cancel = true;
            }
            else
            {
                Util.SortUniq(resultFilePath, Util.GetSortedUniqResultFilePath());
                Util.DisplayFile(Util.GetSortedUniqResultFilePath());
            }
            e.Cancel = true;
            worker.CancelAsync();
        }
Example #3
0
        // Extract Delegate for index that run on the background worker thread
        public static void DoExtractionForIndexFiltered(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker           = sender as BackgroundWorker;
            ThreadParameters p                = (ThreadParameters)e.Argument;
            List <string>    wordListAccepted = new List <string>();
            List <string>    wordListRejected = new List <string>();
            int rc = Commands.ExtractWordsForIndexFiltered(worker, p.StringList, p.Pattern, ref wordListAccepted, ref wordListRejected, Util.GetFilters(), p.MinWordLength);

            if (rc != 0)
            {
                e.Result = rc;
            }
            if (rc != 0)
            {
                e.Cancel = true;
            }
            else
            {
                Util.SortedUniqToFile(wordListAccepted, Util.GetResultFilePath(p.ThreadNum), Msg.MSG_NOTHING_FOUND_OR_NO_TEXT);
                Util.SortedUniqToFile(wordListRejected, Util.GetRejectedFilePath(p.ThreadNum), Msg.MSG_NOTHING_REJECTED);
            }
            e.Cancel = true;
            worker.CancelAsync();
        }
Example #4
0
        // Edition des fichiers une fois que tous les threads sont terminés
        public static void DoNothingToDo(ThreadParameters ThreadParam)
        {

        }
Example #5
0
        public void Start(DoWorkEventHandler DoWork, DoFinalizeThreadsWork DoFinalize, ThreadParameters Thread1p, ThreadParameters Thread2p, ThreadParameters Thread3p, ThreadParameters Thread4p)
        {
            nbWorker = 4;
            nbRemainingWorkers = 4;
            AllocateBackgroundWorkerAndSetDelegate(DoWork, 0);
            AllocateBackgroundWorkerAndSetDelegate(DoWork, 1);
            AllocateBackgroundWorkerAndSetDelegate(DoWork, 2);
            AllocateBackgroundWorkerAndSetDelegate(DoWork, 3);
            DoFinalizeCurrent = DoFinalize;

            msgPrefix = nbWorker + COMMON_MSG2;
            label1.Text = msgPrefix;

            Show();

            Thread1p.NumberOfWorkingThreads = nbWorker;
            Thread2p.NumberOfWorkingThreads = nbWorker;
            Thread3p.NumberOfWorkingThreads = nbWorker;
            Thread4p.NumberOfWorkingThreads = nbWorker;
            Thread1p.ThreadNum = 0;
            Thread2p.ThreadNum = 1;
            Thread3p.ThreadNum = 2;
            Thread4p.ThreadNum = 3;
            WorkersArray[0].RunWorkerAsync(Thread1p);
            WorkersArray[1].RunWorkerAsync(Thread2p);
            WorkersArray[2].RunWorkerAsync(Thread3p);
            WorkersArray[3].RunWorkerAsync(Thread4p);
        }
Example #6
0
        public void Start(DoWorkEventHandler DoWork, DoFinalizeThreadsWork DoFinalize, ThreadParameters p)
        {
            nbWorker = 1;
            nbRemainingWorkers = 1;
            AllocateBackgroundWorkerAndSetDelegate(DoWork, 0);
            DoFinalizeCurrent = DoFinalize;

            msgPrefix = nbWorker + COMMON_MSG1;
            label1.Text = msgPrefix;

            p.ThreadNum = 0;
            WorkersArray[0].RunWorkerAsync(p);
        }
Example #7
0
        private void menuCommand3_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            // Open ProgressForm and Background workers manager
            ThreadParamsAndProgress progressForm = new ThreadParamsAndProgress();
            // Get all selected text
            Application appli   = (Application)Ctrl.Application;
            string      strText = "";

            if (appli != null)
            {
                if (appli.Selection != null)
                {
                    strText = appli.Selection.Text;
                    // Parse all words
                    List <string> wordListAll = new List <string>();
                    int           rc1         = Commands.ExtractPattern(strText, WORDS_PATTERN, true, ref wordListAll);

                    // Multi-threading represents a boost only if there are many words to process
                    int count = wordListAll.Count;
                    int sliceSize;
                    int remainder;
                    ThreadParamsAndProgress.DoFinalizeThreadsWork DoFinalize = new ThreadParamsAndProgress.DoFinalizeThreadsWork(Commands.IndexFinalize);
                    if (count > 3)
                    {
                        switch (Environment.ProcessorCount)
                        {
                        case 2:
                            // Prepare parameters
                            sliceSize = count / 2;
                            Math.DivRem(count, 2, out remainder);
                            List <string>    wordlist21 = wordListAll.GetRange(0, sliceSize);
                            List <string>    wordlist22 = wordListAll.GetRange(sliceSize, sliceSize + remainder);
                            ThreadParameters p21        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist21);
                            ThreadParameters p22        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist22);
                            // Start threads
                            progressForm.Start(Commands.DoExtractionForIndexFiltered, DoFinalize, p21, p22);
                            break;

                        case 3:
                            // Prepare parameters
                            sliceSize = count / 3;
                            Math.DivRem(count, 3, out remainder);
                            List <string>    wordlist31 = wordListAll.GetRange(0, sliceSize);
                            List <string>    wordlist32 = wordListAll.GetRange(sliceSize, sliceSize);
                            List <string>    wordlist33 = wordListAll.GetRange(2 * sliceSize, sliceSize + remainder);
                            ThreadParameters p31        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist31);
                            ThreadParameters p32        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist32);
                            ThreadParameters p33        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist33);
                            // Start threads
                            progressForm.Start(Commands.DoExtractionForIndexFiltered, DoFinalize, p31, p32, p33);
                            break;

                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                            // Prepare parameters
                            sliceSize = count / 4;
                            Math.DivRem(count, 4, out remainder);
                            List <string>    wordlist41 = wordListAll.GetRange(0, sliceSize);
                            List <string>    wordlist42 = wordListAll.GetRange(sliceSize, sliceSize);
                            List <string>    wordlist43 = wordListAll.GetRange(2 * sliceSize, sliceSize);
                            List <string>    wordlist44 = wordListAll.GetRange(3 * sliceSize, sliceSize + remainder);
                            ThreadParameters p41        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist41);
                            ThreadParameters p42        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist42);
                            ThreadParameters p43        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist43);
                            ThreadParameters p44        = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordlist44);
                            // Start threads
                            progressForm.Start(Commands.DoExtractionForIndexFiltered, DoFinalize, p41, p42, p43, p44);
                            break;

                        default:
                            ThreadParameters p1 = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordListAll);
                            progressForm.Start(Commands.DoExtractionForIndexFiltered, DoFinalize, p1);
                            break;
                        }
                    }
                    else
                    {
                        ThreadParameters p1 = new ThreadParameters(null, strText, WORDS_PATTERN, GetMinWordLength(), true, false, wordListAll);
                        progressForm.Start(Commands.DoExtractionForIndexFiltered, DoFinalize, p1);
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show(Msg.MSG_NOTHING_FOUND_OR_NO_TEXT, ThisAddIn.ADDIN_TITLE);
                }
            }
        }