コード例 #1
0
        public string[] CheckPairKeyValue(string line, string key, string value)
        {
            string[]  lineData    = line.Split(Symbols.EQUALITY);
            const int N_LINE_DATA = 2;

            // Check valid pair
            RegexValidation.RegexPair(line, this);

            if (lineData.Length == N_LINE_DATA)
            {
                return(lineData);
            }

            string message       = $"No value for {key} can be found";
            string actualValue   = "null";
            string expectedValue = $"{key}={value}";
            Error  error         = new Error(
                message,
                actualValue,
                expectedValue,
                Filename,
                LineNumber,
                ErrorCode.MISSING_VALUE);

            ErrorValidationManager.Errors.Add(error);

            return(null);
        }
コード例 #2
0
        public int ValidateIntegerPair(string line, string keyword)
        {
            string integer         = null;
            int    returnedInteger = -1;

            // Check whether the pair of key-value exists
            string[] lineCountData = CheckPairKeyValue(line, keyword, "(an integer)");

            // Check the line follows valid format
            RegexValidation.RegexIntegerPair(line, this);

            if (lineCountData != null)
            {
                integer = CheckTextValueExist(
                    lineCountData[1],
                    "null",
                    "An integer");
            }

            // Check whether the value is an integer
            if (integer != null)
            {
                returnedInteger = CheckInteger(integer, keyword);
            }

            return(returnedInteger);
        }
コード例 #3
0
        public double ValidateDoublePair(string line, string keyword)
        {
            string doubleNumber   = null;
            double returnedDouble = -1;

            // Check whether the pair of key-value exists
            string[] lineCountData = CheckPairKeyValue(line, keyword, "(a floating number)");

            // Check the line follows valid format
            RegexValidation.RegexDoublePair(line, this);

            if (lineCountData != null)
            {
                doubleNumber = CheckTextValueExist(
                    lineCountData[1],
                    "null",
                    "A floating number");
            }

            // Check whether the value is an integer
            if (doubleNumber != null)
            {
                returnedDouble = CheckDouble(doubleNumber, keyword);
            }

            return(returnedDouble);
        }
コード例 #4
0
        public bool CheckExtension(string filePath, string expectedExtension)
        {
            string extractedExtension   = Path.GetExtension(filePath);
            string filename             = Path.GetFileName(filePath);
            bool   validExtensionFormat = RegexValidation.RegexExtension(filename, this);
            Error  error = new Error();

            if (!validExtensionFormat && extractedExtension == "")
            {
                error.Message       = "File extension cannot be found";
                error.ActualValue   = "null";
                error.ExpectedValue = $".{expectedExtension}";
                error.Filename      = Filename;
                error.LineNumber    = LineNumber;
                error.ErrorCode     = ErrorCode.INVALID_EXTENSION;

                ErrorValidationManager.Errors.Add(error);

                return(false);
            }

            if (extractedExtension == $".{expectedExtension}")
            {
                return(true);
            }

            error.Message       = "The file extension is invalid";
            error.ActualValue   = extractedExtension;
            error.ExpectedValue = $".{expectedExtension}";
            error.Filename      = Filename;
            error.LineNumber    = LineNumber;
            error.ErrorCode     = ErrorCode.INVALID_EXTENSION;

            ErrorValidationManager.Errors.Add(error);

            return(false);
        }