Example #1
0
        public FileInfo SetVariableFileInfo(string Path, string Keyword, int ParameterIndex, FileInfo fileInfoValue)
        {
            PFSFile    pfsFile    = null;
            PFSKeyword pfsKeyword = null;

            if (!CheckAll(Path, Keyword, out pfsFile, out pfsKeyword))
            {
                return(null);
            }

            try
            {
                pfsKeyword.DeleteParameter(ParameterIndex);
                pfsKeyword.InsertNewParameterFileName(fileInfoValue.FullName, ParameterIndex);
                FileInfo fileInfo = new FileInfo(pfsKeyword.GetParameter(ParameterIndex).ToFileNamePath());

                pfsFile.Write(fi.FullName);
                pfsFile.Close();

                return(fileInfo);
            }
            catch (Exception ex)
            {
                ErrorMessage = string.Format(CSSPDHIRes.ParameterIndex_DoesNotExistForSectionPath_AndKeyword_Error_, ParameterIndex, Path, Keyword, ex.Message + (ex.InnerException != null ? " Inner: " + ex.InnerException.Message : ""));
                OnCSSPDHIChanged(new CSSPDHIEventArgs(new CSSPDHIMessage("Error", -1, false, ErrorMessage)));
                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Example of different modifications to a PFS file, storing the result
        /// in a new file name
        /// </summary>
        /// <param name="filePath">File and path to the pfsExample.pfs file in the TestData folder</param>
        /// <param name="newFilePath">File and path to the new modified file</param>
        public static void ModifyPFSFile(string filePath, string newFilePath)
        {
            // Loading/Reading the file
            PFSFile pfsFile = new PFSFile(filePath, false);

            // Outmost section
            PFSSection target = pfsFile.GetTarget("Run11", 1);

            // Sub-section
            PFSSection section1 = target.GetSection("Results", 1);

            // Rename section
            section1.Name = "HDResults";

            // Add another section after the HDResults section. The new section
            // is returned.
            PFSSection sectionRR = section1.InsertNewSection("RRResults", 2);
            // Add a keyword to the new section. The new keyword is returned.
            PFSKeyword kwOutid = sectionRR.InsertNewKeyword("outid", 1);

            // Add a parameter
            kwOutid.InsertNewParameterString("rr out", 1);
            // Add yet another keyword to the new section. The new keyword is returned.
            PFSKeyword kwFile = sectionRR.InsertNewKeyword("file", 2);

            // Add a parameter
            kwFile.InsertNewParameterFileName(@".\outputRR.res11", 1);

            PFSSection section2 = section1.GetSection("Result", 1);

            // Modify first parameter (string) of keyword
            section2.GetKeyword("outid", 1).GetParameter(1).ModifyStringParameter("hd out");

            // Delete the first keyword in the outer-most section
            target.DeleteKeyword("key1", 1);

            // Write back file
            pfsFile.Write(newFilePath);
        }