Exemple #1
0
        private static bool SetOptionsUsingCommandLineParameters(FileProcessor.clsParseCommandLine objParseCommandLine)
        {
            // Returns True if no problems; otherwise, returns false

            var lstValidParameters = new List <string> {
                "I", "O", "R", "Reverse",
                "IgnoreCase", "Header", "KeepEmpty",
                "Col", "Delim", "IsNumeric",
                "MaxInMemory", "ChunkSize",
                "Work", "L", "Log"
            };

            try
            {
                // Make sure no invalid parameters are present
                if (objParseCommandLine.InvalidParametersPresent(lstValidParameters))
                {
                    var badArguments = new List <string>();
                    foreach (string item in objParseCommandLine.InvalidParameters(lstValidParameters))
                    {
                        badArguments.Add("/" + item);
                    }

                    ShowErrorMessage("Invalid commmand line parameters", badArguments);

                    return(false);
                }

                if (objParseCommandLine.NonSwitchParameterCount > 0)
                {
                    mInputFilePath = objParseCommandLine.RetrieveNonSwitchParameter(0);
                }

                if (!ParseParameter(objParseCommandLine, "I", "an input file name", ref mInputFilePath))
                {
                    return(false);
                }
                if (!ParseParameter(objParseCommandLine, "O", "an output folder name", ref mOutputFolderPath))
                {
                    return(false);
                }

                if (objParseCommandLine.IsParameterPresent("R") ||
                    objParseCommandLine.IsParameterPresent("Reverse"))
                {
                    mReverseSort = true;
                }

                if (objParseCommandLine.IsParameterPresent("IgnoreCase"))
                {
                    mIgnoreCase = true;
                }

                if (objParseCommandLine.IsParameterPresent("Header"))
                {
                    mHasHeaderLine = true;
                }

                if (objParseCommandLine.IsParameterPresent("KeepEmpty"))
                {
                    mKeepEmptyLines = true;
                }


                if (!ParseParameterInt(objParseCommandLine, "Col", "a column number (the first column is column 1)", ref mSortColumn))
                {
                    return(false);
                }

                var strValue = string.Empty;
                if (!ParseParameter(objParseCommandLine, "Delim", "a delimiter", ref strValue))
                {
                    return(false);
                }
                if (!string.IsNullOrWhiteSpace(strValue))
                {
                    mColumnDelimiter = string.Copy(strValue);
                }

                if (objParseCommandLine.IsParameterPresent("IsNumeric"))
                {
                    mSortColumnIsNumeric = true;
                }

                if (!ParseParameterInt(objParseCommandLine, "MaxInMemory", "a file size, in MB", ref mMaxFileSizeMBForInMemorySort))
                {
                    return(false);
                }

                if (!ParseParameterInt(objParseCommandLine, "ChunkSize", "a memory size, in MB", ref mChunkSizeMB))
                {
                    return(false);
                }

                if (!ParseParameter(objParseCommandLine, "Work", "a folder path", ref mWorkingDirectoryPath))
                {
                    return(false);
                }

                if (objParseCommandLine.IsParameterPresent("L") || objParseCommandLine.IsParameterPresent("Log"))
                {
                    mUseLogFile = true;

                    if (objParseCommandLine.RetrieveValueForParameter("L", out strValue))
                    {
                        mLogFilePath = string.Copy(strValue);
                    }
                    else if (objParseCommandLine.RetrieveValueForParameter("Log", out strValue))
                    {
                        mLogFilePath = string.Copy(strValue);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error parsing the command line parameters: " + Environment.NewLine + ex.Message);
            }

            return(false);
        }
        public static void Main()
        {
            var commandLineParser = new clsParseCommandLine();
            commandLineParser.ParseCommandLine();

            if (commandLineParser.NeedToShowHelp) {
                ShowProgramHelp();
                return;
            }

            var extractScanFilters = commandLineParser.IsParameterPresent("GetFilters");
            if (extractScanFilters)
            {
                var workingDirectory = ".";

                if (commandLineParser.NonSwitchParameterCount > 0)
                {
                    workingDirectory = commandLineParser.RetrieveNonSwitchParameter(0);
                }
                ExtractScanFilters(workingDirectory);
                return;
            }

            var sourceFilePath = DEFAULT_FILE_PATH;

            if (commandLineParser.NonSwitchParameterCount > 0) {
                sourceFilePath = commandLineParser.RetrieveNonSwitchParameter(0);
            }

            var fiSourceFile = new FileInfo(sourceFilePath);

            if (!fiSourceFile.Exists) {
                Console.WriteLine("File not found: " + fiSourceFile.FullName);
                return;
            }

            var centroid = commandLineParser.IsParameterPresent("centroid");
            var testSumming = commandLineParser.IsParameterPresent("sum");

            var startScan = 0;
            var endScan = 0;

            string strValue;
            int intValue;

            if (commandLineParser.RetrieveValueForParameter("Start", out strValue)) {
                if (int.TryParse(strValue, out intValue))
                {
                    startScan = intValue;
                }
            }

            if (commandLineParser.RetrieveValueForParameter("End", out strValue))
            {
                if (int.TryParse(strValue, out intValue))
                {
                    endScan = intValue;
                }
            }

            TestScanFilterParsing();

            TestReader(fiSourceFile.FullName, centroid, testSumming, startScan, endScan);

            if (centroid) {
                // Also process the file with centroiding off
                TestReader(fiSourceFile.FullName, false, testSumming, startScan, endScan);
            }

            // Uncomment the following to test the GetCollisionEnergy() function
            //TestReader("..\EDRN_ERG_Spop_ETV1_50fmolHeavy_0p5ugB53A_Frac48_3Oct12_Gandalf_W33A1_16a.raw")

            Console.WriteLine("Done");
        }
        private static bool SetOptionsUsingCommandLineParameters(clsParseCommandLine objParseCommandLine)
        {
            // Returns True if no problems; otherwise, returns false
            var lstValidParameters = new List<string> { "Local", "Preview", "LogDB", "FS" };

            try
            {
                // Make sure no invalid parameters are present
                if (objParseCommandLine.InvalidParametersPresent(lstValidParameters))
                {
                    var badArguments = new List<string>();
                    foreach (var item in objParseCommandLine.InvalidParameters(lstValidParameters))
                    {
                        badArguments.Add("/" + item);
                    }

                    ShowErrorMessage("Invalid commmand line parameters", badArguments);

                    return false;
                }

                // Query objParseCommandLine to see if various parameters are present
                if (objParseCommandLine.NonSwitchParameterCount > 0)
                {
                    mMTSServer = objParseCommandLine.RetrieveNonSwitchParameter(0);
                }

                if (objParseCommandLine.IsParameterPresent("Local"))
                {
                    mLocalServerMode = true;
                }

                if (objParseCommandLine.IsParameterPresent("Preview"))
                {
                    mPreviewMode = true;
                }

                string strValue;
                if (objParseCommandLine.RetrieveValueForParameter("LogDB", out strValue))
                {
                    if (string.IsNullOrWhiteSpace(strValue))
                        ShowErrorMessage("/LogDB does not have a value; not overriding the logging connection string");
                    else
                        mLogDBConnectionString = strValue;
                }

                if (objParseCommandLine.RetrieveValueForParameter("FS", out strValue))
                {
                    if (string.IsNullOrWhiteSpace(strValue))
                        ShowErrorMessage("/FS does not have a value; not overriding the minimum free space");
                    else
                    {
                        if (!int.TryParse(strValue, out mMinimumCacheFreeSpaceGB))
                            ShowErrorMessage("Error converting " + strValue + " to an integer for parameter /FS");
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                ShowErrorMessage("Error parsing the command line parameters: " + Environment.NewLine + ex.Message);
            }

            return false;
        }