public override bool ValidateParams(string line)
        {
            try
            {
                if (!ParsingUtilities.HasOneParam(name, line))
                {
                    return(false);
                }
            }
            catch (RegexMatchTimeoutException)
            {
                return(false);
            }

            string path;

            try
            {
                path = ParsingUtilities.GetQuoteOneArgument(line);
            }
            catch (RegexMatchTimeoutException)
            {
                return(false);
            }

            if (!PathTracker.IsDirPathValid(path))
            {
                throw new InvalidPathException();
            }

            return(true);
        }
Exemple #2
0
        public override bool ValidateParams(string line)
        {
            // Checking if command line has only 1 param.
            try
            {
                if (!ParsingUtilities.HasOneParam(name, line))
                {
                    return(false);
                }
            }
            catch (RegexMatchTimeoutException)
            {
                return(false);
            }

            string filePathArg = ParsingUtilities.GetQuoteOneArgument(line);

            // Check if file exists.
            if (!PathTracker.IsFilePathValid(PathTracker.CombineRelativePath(filePathArg)))
            {
                throw new InvalidPathException("FILE_NOT_FOUND");
            }

            return(true);
        }
        public override bool ValidateParams(string line)
        {
            // Print command can have 1 option or 2 options.
            try
            {
                if (!(ParsingUtilities.HasOneParam(name, line) ||
                      ParsingUtilities.HasTwoParam(name, line)))
                {
                    return(false);
                }
            }
            catch (RegexMatchTimeoutException)
            {
                return(false);
            }

            string path;

            try
            {
                string[] arguments = ParsingUtilities.GetQuoteArguments(line);
                // User has not specified encoding.
                if (!ParsingUtilities.HasOneParam(name, line))
                {
                    // Trying to find specified encoding.
                    var encodingStr = arguments[1];
                    if (!EncodingUtilities.dictStrEncoding.ContainsKey(encodingStr))
                    {
                        throw new InvalidEncodingException();
                    }
                }

                path = arguments[0];
            }
            catch (RegexMatchTimeoutException)
            {
                return(false);
            }

            // Check if file exists.
            if (!PathTracker.IsFilePathValid(path))
            {
                throw new InvalidPathException("FILE_NOT_FOUND");
            }

            return(true);
        }