コード例 #1
0
        /// <summary>
        /// Parses old file name  to generate a new file name.
        /// </summary>
        /// <returns>Returns new file name with a different order of words per team meeting requests.</returns>
        private string ParseFileName()
        {
            // Remove every matching pattern to exposed root test name like "Bandwidth"
            string testName = new AnalyzeValues().Extract(input: Path.GetFileNameWithoutExtension(FileNameWithPath), pattern: new AnalyzeValues().TestFileNamePatterns, keywords: new AnalyzeValues().FileNameKeywords);

            string fileNameWithoutRevision = Path.GetFileNameWithoutExtension(FileNameWithPath);

            // if the user desires to keep "Rev#" otherwise just delete it.
            if (!Settings.Default.AppendFileName)
            {
                // Ritchie has version control file names do not require Rev# suffix. However,
                // since "Rev#" contains a number providing a dictionary solution would be difficult so this service
                // provided by the following code.
                Regex rx = new Regex(@"\b[Rr]ev\d\b\w*");
                // replace "Rev#" with empty string.
                fileNameWithoutRevision = rx.Replace(fileNameWithoutRevision, string.Empty);
            }

            // temp storage to keep replacement words.
            string keywords = new AnalyzeValues().Replace(input: fileNameWithoutRevision, pattern: new AnalyzeValues().TestFileNamePatterns, keywords: new AnalyzeValues().FileNameKeywords);
            // words[0]: ProductName, words[1]: P1, words[2]: PowerScheme, words[3]: Frequency
            List <string> words = new List <string>(keywords.Split('_').ToList());


            // regulator
            string regulatorFolderName = words.Count < 4 ? string.Empty : $"regulator {regulator}";

            // split replacement words to insert test file name and new short name for "Regulator #" in the file name, also append file extension.
            string modifiedFolderName = Path.Combine(path1: MyResources.Strings_ModifedFolderName.ToLower(),
                                                     path2: regulatorFolderName);

            // generate new values
            string profileFolderName = words.Count > 1 ? (activeProfile > 0 ? $"profile {activeProfile}" : string.Empty) : string.Empty;

            if (words.Count > 1)
            {
                words[1] = $"P{activeProfile}";
            }

            // temp storage to keep replacement words.
            string testSubFolderName = string.Empty;

            if (!string.IsNullOrWhiteSpace(keywords))
            {
                testSubFolderName = new AnalyzeValues().Replace(input: testName, pattern: new AnalyzeValues().TestFolderNamePatterns, keywords: new AnalyzeValues().FolderNameKeywords);
            }

            // test folder
            string testFolderName = Path.Combine(path1: modifiedFolderName,
                                                 path2: testSubFolderName,
                                                 path3: profileFolderName);

            // new file name
            string fileNameWithExtension = string.IsNullOrWhiteSpace(keywords) ? $"{testName}{Path.GetExtension(FileNameWithPath)}": words.Count < 4 ? $"{words[0]}{Path.GetExtension(FileNameWithPath)}" : $"{words[0]}_{testName}_Reg {regulator}_{words[1]}_{words[2]}_{words[3]}{Path.GetExtension(FileNameWithPath)}";


            // new filename with path
            string fileNamePathWithExtension = Path.Combine(path1: Path.GetDirectoryName(FileNameWithPath),
                                                            path2: testFolderName,
                                                            path3: fileNameWithExtension);

            // let's limit file name length > MaxFileNameLength omicron test universe fails to save modified files.
            // just add a sub folder named "modified files" with original file name
            // do not modify anything else
            if (fileNamePathWithExtension.Length > Settings.Default.MaxFileNameLength)
            {
                // mode full filename
                fileNamePathWithExtension = Path.Combine(path1: Path.GetDirectoryName(FileNameWithPath),
                                                         path2: MyResources.Strings_ModifedFolderName.ToLower(),
                                                         path3: Path.GetFileName(FileNameWithPath));

                // if this new file name is still > MaxFileNameLength
                // let put this file under user document
                if (fileNamePathWithExtension.Length > Settings.Default.MaxFileNameLength)
                {
                    fileNamePathWithExtension = Path.Combine(path1: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                                             path2: typeof(MainWindow).Assembly.GetName().Name,
                                                             path3: MyResources.Strings_ModifedFolderName.ToLower(),
                                                             path4: Path.GetFileName(FileNameWithPath));
                }
            }

            return(fileNamePathWithExtension);
        }
コード例 #2
0
        private void ScanDocument()
        {
            try
            {
                // Omicron Test Module index is between 1 and TestModules.Count
                int startPosition = 1;

                // Local thread variable to hold total module number after deletion.
                int moduleCounter = 0;

                // Update total module number.
                // MyCommons.TotalModuleNumber = this.OmicronDocument.TestModules.Count;
                MyCommons.TotalModuleNumber = OmicronDocument.OLEObjects.Count;
                MyCommons.MyViewModel.ModuleProgressBarMax = MyCommons.TotalModuleNumber;
                MyCommons.MyViewModel.UpdateCommand.Execute(null);

                Debug.WriteLine("SCANNING thread: {0}", Thread.CurrentThread.GetHashCode());
                Debug.WriteLine("Total TestModule: {0} ", MyCommons.TotalModuleNumber);

                // All Test Modules in the Omicron test file.
                // TestModules testModules = this.OmicronDocument.TestModules;

                // Parallel.For (fromInclusive Int32, toExclusive Int32, parallelOptions, body)
                // TotalModelNumber IS EXCLUSIVE SO MUST ADD 1 TO IT.
                // Otherwise the last Test Module will never be processed.
                Parallel.For(startPosition, MyCommons.TotalModuleNumber + 1, MyCommons.ParallelingOptions, testModule =>
                {
                    // increment counter to open next test module.
                    Interlocked.Add(ref moduleCounter, 1);

                    OmicronProgramId   = OmicronDocument.OLEObjects.get_Item(moduleCounter).ProgID;
                    OmicronProgramName = OmicronDocument.OLEObjects.get_Item(moduleCounter).Name;
                    // update current module number.
                    // MyCommons.CurrentModuleNumber = testModule;
                    MyCommons.CurrentModuleNumber = moduleCounter;
                    MyCommons.MyViewModel.UpdateCommand.Execute(null);


                    Debug.WriteLine(string.Format("{0}", new String(Settings.Default.RepeatChar, Settings.Default.RepeatNumber)));
                    Debug.WriteLine(string.Format("SCAN PARALLEL thread: {0}", Thread.CurrentThread.GetHashCode()));
                    Debug.WriteLine(string.Format("Test module name...: {0}", OmicronProgramName));
                    Debug.WriteLine(string.Format("Test module type...: {0}", OmicronProgramId));
                    Debug.WriteLine(string.Format("{0}", new String(Settings.Default.RepeatChar, Settings.Default.RepeatNumber)));
                    Debug.WriteLine("Making a decision if the user wants to delete this test module.....");

                    // REMOVE named Module(s)
                    if (ItemsToRemove.TryGetValue(OmicronProgramName, out string tempValue))
                    {
                        if (tempValue == OmicronProgramId)
                        {
                            Debug.WriteLine(string.Format("Deleting ProgID {0}\tand Name: {1}", OmicronProgramId, OmicronProgramName));
                            Debug.WriteLine(" ... TEST MODULE MARK FOR DELETION ....");
                            OmicronDocument.OLEObjects.get_Item(moduleCounter).Delete();
                            // just deleted a test module. Omicron updates total test module counter.
                            // this is the reason for the decrement.
                            Interlocked.Decrement(ref moduleCounter);

                            // Show detailed output if the user wants it.
                            if (Settings.Default.ShowDetailedOutput)
                            {
                                // Update DetailsTextBoxText.
                                MyCommons.MyViewModel.DetailsTextBoxText =
                                    MyCommons.LogProcess.Append(
                                        string.Format(
                                            CultureInfo.InvariantCulture,
                                            MyResources.Strings_RemoveTM,
                                            OmicronProgramName,
                                            OmicronProgramId,
                                            Environment.NewLine))
                                    .ToString();
                            }
                        }
                    }

                    // store old title
                    string title = OmicronDocument.OLEObjects.get_Item(moduleCounter).Name;
                    Debug.WriteLine($"--------------------------> old title: {title}");
                    // update title.
                    OmicronDocument.OLEObjects.get_Item(moduleCounter).Name = new AnalyzeValues().Change(input: title, pattern: new AnalyzeValues().TitlePatterns, keywords: new AnalyzeValues().TitleKeywords);


                    // temp storage to keep replacement words.
                    if (new AnalyzeValues().IsMatch(title, new AnalyzeValues().ProfilePatterns))
                    {
                        string keywords         = new AnalyzeValues().Match(input: title, pattern: new AnalyzeValues().ProfilePatterns);
                        string replacementTitle = System.Text.RegularExpressions.Regex.Split(input: keywords,
                                                                                             pattern: "(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)",
                                                                                             options: System.Text.RegularExpressions.RegexOptions.None,
                                                                                             matchTimeout: TimeSpan.FromMilliseconds(100))[0];

                        Dictionary <string, string> what = new Dictionary <string, string>()
                        {
                            { keywords, $"{replacementTitle}{activeProfile}" }
                        };

                        string newTitle = new AnalyzeValues().Change(input: title, pattern: new AnalyzeValues().ProfilePatterns, keywords: what); // System.Text.RegularExpressions.Regex.Replace(input: title, pattern: "(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)", replacement: replacementTitle);
                        Debug.WriteLine($"--------------------------> keywords: {keywords}, replacementTitle: {replacementTitle}, newTitle: {newTitle}");

                        OmicronDocument.OLEObjects.get_Item(moduleCounter).Name = newTitle;
                    }

                    Debug.WriteLine($"--------------------------> new title: {OmicronDocument.OLEObjects.get_Item(moduleCounter).Name} ");
                    Debug.WriteLine($"--------------------------> group mod: {(Convert.ToBoolean(UseDefaultSettingBehavior) ? "Using Settings" : "Using Tests")}");

                    // Categorize Omicron Modules
                    if (OmicronDocument.OLEObjects.get_Item(moduleCounter).IsTestModule)
                    {
                        TestModule currentModule = OmicronDocument.OLEObjects.get_Item(moduleCounter).TestModule; //testModules.Item[moduleCounter];

                        //// update current test module title if needed.
                        // currentModule.Name = new AnalyzeValues().Change(input: currentModule.Name, pattern: new AnalyzeValues().TitlePatterns, keywords: new AnalyzeValues().TitleKeywords);

                        Debug.WriteLine(" .... NO DELETION REQUIRED ....");

                        switch (OmicronProgramId)
                        {
                        case ProgId.Execute:

                            try
                            {
                                // Polling CancellationToken's status.
                                // If cancellation requested throw error and exit loop.
                                if (MyCommons.CancellationToken.IsCancellationRequested == true)
                                {
                                    MyCommons.CancellationToken.ThrowIfCancellationRequested();
                                }
                                Debug.WriteLine("--- Add option to modify 'Title' --- DONE");
                                Debug.WriteLine("--- Add option to modify 'Path' --- DONE");
                                Debug.WriteLine("--- Add option to modify 'Execution Options' ---");
                                Debug.WriteLine("--- as of 10/30/2018 ---");
                                Debug.WriteLine($"--------------------------> group mod: {(Convert.ToBoolean(UseDefaultSettingBehavior) ? "Using Settings" : "Using Tests")}");

                                // Retrieve parameters and save.
                                Retrieve(currentModule);
                            }
                            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;
                            }

                            break;

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

                                Debug.WriteLine("--- Future use object 'Ramping Test Module' ---");
                                Debug.WriteLine("--- Add options to link each item to 'XRio Block' ---");
                                Debug.WriteLine("--- Add option to modify 'Title' ---");
                                Debug.WriteLine("--- as of 10/30/2018 ---");

                                //// update current test module title if needed.
                                //currentModule.Name = new AnalyzeValues().Change(input: currentModule.Name, pattern: new AnalyzeValues().TitlePatterns, keywords: new AnalyzeValues().TitleKeywords);

                                // Retrieve parameters and save.
                                // Retrieve(currentTestModule);
                                currentModule.Clear();
                            }
                            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;
                            }
                            break;

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

                                Debug.WriteLine("--- Future use object 'State Sequencer Test Module' ---");
                                Debug.WriteLine("--- Add options to link each item to 'XRio Block' ---");
                                Debug.WriteLine("--- Add option to modify 'Title' ---");
                                Debug.WriteLine("--- as of 10/30/2018 ---");

                                // Retrieve parameters and save.
                                // Retrieve(currentTestModule);
                                currentModule.Clear();
                            }
                            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;
                            }
                            break;

                        default:
                            // Not supported test module. move on to the next module.
                            break;
                        }
                    }
                    else
                    {
                        Debug.WriteLine("--- NonTest object ---");
                        Debug.WriteLine(string.Format("Test module name...: {0}", OmicronProgramName));
                        Debug.WriteLine(string.Format("Test module type...: {0}", OmicronProgramId));

                        // it is not a Test Module.
                        switch (OmicronProgramId)
                        {
                        case ProgId.XRio:

                            // Polling CancellationToken's status.
                            // If cancellation requested throw error and exit loop.
                            if (MyCommons.CancellationToken.IsCancellationRequested == true)
                            {
                                MyCommons.CancellationToken.ThrowIfCancellationRequested();
                            }
                            Debug.WriteLine("--- Future use object 'XRio Block' ---");
                            Debug.WriteLine("--- Add option to modify 'Title' ---");
                            Debug.WriteLine("--- as of 10/30/2018 ---");

                            // future use.
                            var xrio = OmicronDocument.OLEObjects.get_Item(moduleCounter);

                            break;

                        case ProgId.Hardware:
                            // Polling CancellationToken's status.
                            // If cancellation requested throw error and exit loop.
                            if (MyCommons.CancellationToken.IsCancellationRequested == true)
                            {
                                MyCommons.CancellationToken.ThrowIfCancellationRequested();
                            }
                            Debug.WriteLine("--- Future use object 'Hardware Configuration' ---");
                            Debug.WriteLine("--- Add option to modify 'Title' ---");
                            Debug.WriteLine("--- as of 10/30/2018 ---");
                            break;

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

                            Debug.WriteLine("--- Future use object 'Groups' ---");
                            Debug.WriteLine("--- Add option to modify 'Title' ---");
                            Debug.WriteLine("--- as of 10/30/2018 ---");

                            Group group = OmicronDocument.OLEObjects.get_Item(moduleCounter).Group;

                            UseDefaultSettingBehavior = new AnalyzeValues().IsMatch(group.Name, new AnalyzeValues().GroupFolderPatterns);

                            // decide which behavior to use based on the folder name.
                            if (Convert.ToBoolean(UseDefaultSettingBehavior))
                            {
                                // true: Old method where point read and replaced per Execute parameters.
                                ItemsToFind    = new List <string>(ViewModel.FindWhatTextBoxText.Split('|'));
                                ItemsToReplace = new List <string>(ViewModel.ReplaceWithTextBoxText.Split('|'));
                            }
                            else
                            {
                                // false: New method where point read is always Profile 1 and replaced per active Profile generating process
                                ItemsToFind    = new List <string>(MyCommons.FindProfile.Split('|'));
                                ItemsToReplace = new List <string>(MyCommons.ReplaceProfile.Split('|'));
                            }

                            if (ItemsToFind.Count > 1)
                            {
                                Debug.WriteLine($"ItemsToFind: {ItemsToFind[5]}-{ItemsToFind[10]}-{ItemsToFind[15]}, ItemsToReplace: {ItemsToReplace[5]}-{ItemsToReplace[10]}-{ItemsToReplace[15]}");
                            }

                            break;

                        default:
                            break;
                        }
                    }
                });
            }
            catch (NullReferenceException ae)
            {
                ErrorHandler.Log(ae, CurrentFileName);
                return;
            }
            catch (OperationCanceledException 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;
            }
        }