/// <summary>
        /// Start processing the user selected Omicron Test Files.
        /// </summary>
        private void StartProcessingFiles()
        {
            int regulatorGeneration = !MyCommons.GenerateRegulators ? 1 : MaximumRegulatorNumber;

            int profileGeneration = !MyCommons.GenerateRegulators ? 2 : 5;

            // Reset File counter.
            MyCommons.CurrentFileNumber = 0;

            // Update FileProcessBar;
            ViewModel.FileProgressBarMax = MyCommons.TotalFileNumber = FileNames.Count * regulatorGeneration * (profileGeneration - 1);

            // Refresh Process bars.
            ViewModel.UpdateCommand.Execute(null);

            // get Change Active Profile value.
            ViewModel.ChangeActiveProfile = MyCommons.ChangeActiveProfileValue;

            try
            {
                // make regulator files.
                for (regulator = 1; regulator <= regulatorGeneration; regulator++)
                {
                    // since original files are always profile 1 need to update this only when regulator changes.
                    ViewModel.FindWhatTextBoxText    = new Regulator().GetValues(regulator, 0, Column.OriginalSettingValue) ?? string.Empty; // would have every profiles
                    ViewModel.ReplaceWithTextBoxText = new Regulator().GetValues(regulator, 0, Column.ReplacementValue) ?? string.Empty;     // would have every profiles

                    // since original files are always profile 1. Change 1 -> whatever is the file profile is.
                    MyCommons.FindProfile = new Regulator().GetValues(regulator, 1, Column.OriginalTestValue) ?? string.Empty;
                    // MyCommons.FindProfile = new Regulator().GetValues(MyCommons.Regulators, regulator, 1, Column.OriginalTestValue);

                    Parallel.ForEach(FileNames, MyCommons.ParallelingOptions, (currentFile) =>
                    {
                        // for (int profile = 1; profile <= 4; profile++)
                        Parallel.For(1, profileGeneration, MyCommons.ParallelingOptions, (profile) =>
                        {
                            // would have Profile x only
                            MyCommons.ReplaceProfile = new Regulator().GetValues(regulator, profile, Column.ReplacementValue) ?? string.Empty;
                            //MyCommons.ReplaceProfile = new Regulator().GetValues(MyCommons.Regulators, regulator, profile, Column.ReplacementValue);

                            activeProfile = profile;

                            SetSearchItems();

                            // Increment current file number;
                            MyCommons.CurrentFileNumber++;
                            MyCommons.CurrentModuleNumber = 0;
                            ViewModel.UpdateCommand.Execute(null);

                            CurrentFileName    = currentFile;
                            MyCommons.FileName = Path.GetFileName(CurrentFileName);

                            try
                            {
                                // opens the document
                                Task.Factory.StartNew(() =>
                                {
                                    try
                                    {
                                        // Polling CancellationToken's status.
                                        // If cancellation requested throw error and exit loop.
                                        if (MyCommons.CancellationToken.IsCancellationRequested == true)
                                        {
                                            MyCommons.CancellationToken.ThrowIfCancellationRequested();
                                        }

                                        // Update DetailsTextBoxText.
                                        ViewModel.DetailsTextBoxText =
                                            MyCommons.LogProcess.Append(
                                                string.Format(
                                                    CultureInfo.InvariantCulture,
                                                    MyResources.Strings_CurrentFileName,
                                                    Environment.NewLine,
                                                    Repeat.StringDuplicate(Settings.Default.RepeatChar, Settings.Default.RepeatNumber),
                                                    Path.GetFileName(CurrentFileName),
                                                    string.Format(CultureInfo.InvariantCulture,
                                                                  MyResources.Strings_TestStart,
                                                                  DateTime.Now)))
                                            .ToString();

                                        // Open Omicron Document.
                                        // this.OmicronDocument = OpenDocument ( this.CurrentFileName, "" );
                                        OmicronDocument = OpenDocument(CurrentFileName);
                                    }
                                    catch (ArgumentException ae)
                                    {
                                        // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                        ErrorHandler.Log(ae, CurrentFileName);
                                        return;
                                    }
                                    catch (AggregateException ae)
                                    {
                                        foreach (Exception ex in ae.InnerExceptions)
                                        {
                                            // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                            ErrorHandler.Log(ex, CurrentFileName);
                                        }
                                        return;
                                    }
                                }
                                                      , MyCommons.CancellationToken)
                                .ContinueWith(scanThread =>
                                {
                                    // scans the document
                                    try
                                    {
                                        // Polling CancellationToken's status.
                                        // If cancellation requested throw error and exit loop.
                                        if (MyCommons.CancellationToken.IsCancellationRequested == true)
                                        {
                                            MyCommons.CancellationToken.ThrowIfCancellationRequested();
                                        }

                                        // Scan the Test Document for the Test Modules.
                                        Scan();
                                    }
                                    catch (AggregateException ae)
                                    {
                                        foreach (Exception ex in ae.InnerExceptions)
                                        {
                                            // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                            ErrorHandler.Log(ex, CurrentFileName);
                                        }
                                        return;
                                    }
                                }
                                              , MyCommons.CancellationToken)
                                .Wait();

                                // Save the new file with a different name.
                                Task.Factory.StartNew(() =>
                                {
                                    try
                                    {
                                        // Polling CancellationToken's status.
                                        // If cancellation requested throw error and exit loop.
                                        if (MyCommons.CancellationToken.IsCancellationRequested == true)
                                        {
                                            MyCommons.CancellationToken.ThrowIfCancellationRequested();
                                        }

                                        // Save the new file.
                                        SaveOmicronFiles(OmicronDocument.FullName, true);
                                    }
                                    catch (AggregateException ae)
                                    {
                                        foreach (Exception ex in ae.InnerExceptions)
                                        {
                                            // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                            ErrorHandler.Log(ex, CurrentFileName);
                                        }
                                        return;
                                    }
                                }
                                                      , MyCommons.CancellationToken)
                                .ContinueWith(closeThread =>
                                {
                                    // close the document
                                    try
                                    {
                                        // Polling CancellationToken's status.
                                        // If cancellation requested throw error and exit loop.
                                        if (MyCommons.CancellationToken.IsCancellationRequested == true)
                                        {
                                            MyCommons.CancellationToken.ThrowIfCancellationRequested();
                                        }

                                        // Close Omicron Control Center without saving any changes to the original file.
                                        OmicronDocument.Close(false);
                                    }
                                    catch (COMException ae)
                                    {
                                        ErrorHandler.Log(ae, CurrentFileName);
                                        return;
                                    }
                                    catch (AggregateException ae)
                                    {
                                        foreach (Exception ex in ae.InnerExceptions)
                                        {
                                            // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                            ErrorHandler.Log(ex, CurrentFileName);
                                        }
                                        return;
                                    }
                                }
                                              , MyCommons.CancellationToken)
                                .ContinueWith(threadCloseApp =>
                                {
                                    // quit the application
                                    try
                                    {
                                        // Polling CancellationToken's status.
                                        // If cancellation requested throw error and exit loop.
                                        if (MyCommons.CancellationToken.IsCancellationRequested == true)
                                        {
                                            MyCommons.CancellationToken.ThrowIfCancellationRequested();
                                        }

                                        // Close Omicron Control Center Application
                                        OmicronApplication.Quit();
                                    }
                                    catch (COMException ae)
                                    {
                                        ErrorHandler.Log(ae, CurrentFileName);
                                    }
                                    catch (ObjectDisposedException ae)
                                    {
                                        ErrorHandler.Log(ae, CurrentFileName);
                                    }
                                    catch (AggregateException ae)
                                    {
                                        foreach (Exception ex in ae.InnerExceptions)
                                        {
                                            // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                            ErrorHandler.Log(ex, CurrentFileName);
                                        }
                                        return;
                                    }
                                }
                                              , MyCommons.CancellationToken)
                                .Wait();

                                // terminate omicron processes.
                                Task.Factory.StartNew(() =>
                                {
                                    try
                                    {
                                        // Garbage Collection.
                                        OmicronApplication = null;
                                        OmicronDocument    = null;

                                        // Polling CancellationToken's status.
                                        // If cancellation requested throw error and exit loop.
                                        if (MyCommons.CancellationToken.IsCancellationRequested == true)
                                        {
                                            MyCommons.CancellationToken.ThrowIfCancellationRequested();
                                        }

                                        // Terminate Omicron Processes.
                                        KillOmicronProcesses();
                                    }
                                    catch (COMException ae)
                                    {
                                        ErrorHandler.Log(ae, CurrentFileName);
                                    }
                                    catch (ObjectDisposedException ae)
                                    {
                                        ErrorHandler.Log(ae, CurrentFileName);
                                    }
                                    catch (AggregateException ae)
                                    {
                                        foreach (Exception ex in ae.InnerExceptions)
                                        {
                                            // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                            ErrorHandler.Log(ex, CurrentFileName);
                                        }
                                        return;
                                    }
                                }
                                                      , MyCommons.CancellationToken)
                                .Wait();

                                ViewModel.FileSideCoverText = MyResources.Strings_FormEndTest;

                                // Refresh Process bars.
                                ViewModel.UpdateCommand.Execute(null);
                            }
                            catch (COMException ae)
                            {
                                ErrorHandler.Log(ae, CurrentFileName);
                            }
                            catch (ObjectDisposedException ae)
                            {
                                ErrorHandler.Log(ae, CurrentFileName);
                            }
                            catch (AggregateException ae)
                            {
                                foreach (Exception ex in ae.InnerExceptions)
                                {
                                    // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                                    ErrorHandler.Log(ex, CurrentFileName);
                                }
                                return;
                            }
                        });
                    });
                }
            }
            catch (OperationCanceledException oe)
            {
                // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                ErrorHandler.Log(oe, CurrentFileName);
                return;
            }
            catch (COMException ce)
            {
                // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                ErrorHandler.Log(ce, CurrentFileName);
                return;
            }
        }
        private void SaveOmicronFile()
        {
            try
            {
                // Polling CancellationToken's status.
                // If cancellation requested throw error and exit loop.
                if (MyCommons.CancellationToken.IsCancellationRequested == true)
                {
                    MyCommons.CancellationToken.ThrowIfCancellationRequested();
                }

                // Setting new password to original password so the user can still have same level protection in the modified files.
                // For more info: http://briannoyesblog.azurewebsites.net/2015/03/04/wpf-using-passwordbox-in-mvvm/
                ISecurePasswordToString secureToString = new SecurePasswordToString();
                string insecurePassword = secureToString.ConvertToInsecureString(ViewModel.Password);

                bool protectionChanged = OmicronDocument.ChangeProtection(ProtectionLevel, string.Empty, insecurePassword);

                // Clear insecurePassword.
                insecurePassword = string.Empty;

                if (!protectionChanged)
                {
                    // Bad password or unknown problem the user interaction necessary.
                    // try to fail gracefully.
                    throw new ArgumentException("protectionChanged");
                }
                else
                {
                    // Depending file exists and saveAs value,
                    // Save the files.
                    if (File.Exists(OldFileName))
                    {
                        if (SaveAs)
                        {
                            OmicronDocument.SaveAs(OldFileName);
                        }
                        else
                        {
                            OmicronDocument.Save();
                        }
                    }
                    else
                    {
                        OmicronDocument.SaveAs(OldFileName);
                    }

                    // Update DetailsTextBoxText.
                    MyCommons.MyViewModel.DetailsTextBoxText =
                        MyCommons.LogProcess.Append(
                            (string.Format(
                                 CultureInfo.InvariantCulture,
                                 MyResources.Strings_TestEnd,
                                 DateTime.Now,
                                 Environment.NewLine,
                                 Repeat.StringDuplicate(Settings.Default.RepeatChar, Settings.Default.RepeatNumber),
                                 MyCommons.FileName,
                                 OldFileName)
                            ))
                        .ToString();
                }
            }
            catch (System.Runtime.InteropServices.COMException ae)
            {
                ErrorHandler.Log(ae, OldFileName);
                return;
            }
            catch (ArgumentException ae)
            {
                // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                ErrorHandler.Log(ae, OldFileName);
                return;
            }
            catch (NullReferenceException ne)
            {
                // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                ErrorHandler.Log(ne, OldFileName);
                return;
            }
            catch (AggregateException ae)
            {
                foreach (Exception ex in ae.InnerExceptions)
                {
                    // Save to the fileOutputFolder and print to Debug window if the project build is in Debug.
                    ErrorHandler.Log(ex, OldFileName);
                }
                return;
            }
        }