Example #1
0
        public void TestEmptyParametersShouldReturnTrue()
        {
            var theme      = String.Empty;
            var begin_date = String.Empty;
            var end_date   = String.Empty;

            var queryValidator = new QueryValidator();

            listOfExceptions = queryValidator.ValidateData(theme, begin_date, end_date);

            Assert.IsTrue(listOfExceptions.HasEmptyDataException(), "Should have an empty data exception");
        }
Example #2
0
        public void TestEndDateSoonerThanBeginDateShouldReturnTrue()
        {
            var theme      = "pruebaDates";
            var begin_date = "20180907";
            var end_date   = "20180903";

            var queryValidator = new QueryValidator();

            listOfExceptions = queryValidator.ValidateData(theme, begin_date, end_date);

            Assert.IsTrue(listOfExceptions.HasWrongDatesException(), "Should have a WrongDatesException");
        }
Example #3
0
        /// <summary>
        /// Записать результат в .xml // XmlSerializer
        /// </summary>
        /// <param name="exeptions"></param>
        public void WriteLog(List <IException> exeptions)
        {
            if (File.Exists(folderPath + "exceptions.xml"))
            {
                File.Delete(folderPath + "exceptions.xml");
            }

            ExceptionsList exceptionsList = new ExceptionsList(exeptions);

            using (TextWriter writer = new StreamWriter(folderPath + "exceptions.xml"))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ExceptionsList));
                serializer.Serialize(writer, exceptionsList);
            }
        }
Example #4
0
        public static void Parse(string code, string filePath, string prjPath, CodeParts parts, ExceptionsList errors,
                                 bool add = true)
        {
            foreach (Match match in Regex.Matches(code, "\\#include[ \\t]+([^\\s]+)", RegexOptions.Multiline))
            {
                string text     = Convert.ToString(match.Groups[1].Value);
                string fullPath = "";

                var type = text.Substring(0, 1);

                var dirs = Directory.GetDirectories(prjPath + "\\dependencies").ToList();
                if (Directory.Exists(prjPath + "\\pawno\\include"))
                {
                    dirs.Add(prjPath + "\\pawno\\include");
                }

                if (char.Parse(type) == (char)34)
                {
                    //Remove the quotes.
                    try
                    {
                        text = text.Remove(text.IndexOf((char)34), 1);
                        text = text.Remove(text.IndexOf((char)34), 1);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    fullPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filePath)), text);
                    AddExtension(ref fullPath);
                }
                else if (type == "<")
                {
                    //Remove the brackets.
                    try
                    {
                        text = text.Remove(text.IndexOf("<"), 1);
                        text = text.Remove(text.IndexOf(">"), 1);
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                    foreach (var dir in dirs)
                    {
                        string pth = Path.Combine(dir, text);
                        AddExtension(ref pth);
                        if (File.Exists(pth))
                        {
                            fullPath = pth;
                            break;
                        }
                    }
                }
                else
                {
                    foreach (var dir in dirs)
                    {
                        string pth = Path.Combine(dir, text);
                        AddExtension(ref pth);
                        if (File.Exists(pth))
                        {
                            fullPath = pth;
                            break;
                        }
                    }
                }

                try
                {
                    //Create a new codeparts object for the includes cause they are needed.
                    if (add)
                    {
                        //Check if was already parsed or not.
                        if (Parser.IsParsed(parts.RootInclude, fullPath))
                        {
                            continue;
                        }

                        //Else:
                        //Check if exists or not:
                        if (File.Exists(fullPath))
                        {
                            CodeParts part = new CodeParts
                            {
                                //Setup and add to list.
                                FilePath = fullPath
                            };
                            parts.AddInclude(part);

                            Parser prs = new Parser(part, File.ReadAllText(fullPath), fullPath, prjPath, true);
                            errors.ExceptionsList_Renamed.AddRange(prs.Errors.ExceptionsList_Renamed);
                        }
                        else
                        {
                            errors.ExceptionsList_Renamed.Add(
                                new IncludeNotFoundException(Path.GetFileNameWithoutExtension(text)));
                        }
                    }
                    else
                    {
                        try
                        {
                            //Here if the include is REMOVED, There is no need to parse it all again cause we already know that we just need to remove the whole include.
                            parts.RemoveIncludeByHash(GeneralFunctions.GetFileHash(fullPath));
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }

                    //Exceptions.
                }
                catch (DirectoryNotFoundException)
                {
                    errors.ExceptionsList_Renamed.Add(new IncludeNotFoundException(Path.GetFileNameWithoutExtension(text)));
                }
                catch (FileNotFoundException)
                {
                    errors.ExceptionsList_Renamed.Add(new IncludeNotFoundException(Path.GetFileNameWithoutExtension(text)));
                }
            }
        }
Example #5
0
 public PartialAssociationRulesException(ExceptionsList exc)
     : base(exc.ToString())
 {
     Exception = exc;
 }
Example #6
0
        public Parser(CodeParts codeParts, string code, string filePath, string projectPath, bool add,
                      bool isIfDefine = false)
        {
            // VBConversions Note: Non-static class variable initialization is below.  Class variables cannot be initially assigned non-static values in C#.
            Errors = new ExceptionsList();

            //Make sure then code is not nothing.
            if (code == null)
            {
                return;
            }

            //Get the name
            string name = Path.GetFileNameWithoutExtension(filePath);

            //Debug.
            if (isIfDefine == false)
            {
                Debug.WriteLine("Started Parser on the file: '" + name + "' Status: " + add);
            }

            //Remove singline comments.
            Cleaner.Parse(ref code, true, false, false, false);

            //Parse for pawndocs.
            PawnDoc.Parse(code, name, codeParts, add);

            //Remove multiline comments.
            Cleaner.Parse(ref code, false, true, false, false);

            //Parse for Enums.
            Enums.Parse(code, name, codeParts, add);

            //Now remove braces.
            Cleaner.Parse(ref code, false, false, true, false);

            if (add == false)
            {
                //Replace defines and macros.
                DefReplacer.Parse(code, name, codeParts, add);
            }

            //Parse for includes. (BEFORE REMOVING STRINGS)
            Includes.Parse(code, filePath, projectPath, codeParts, Errors, add);

            //Remove strings
            Cleaner.Parse(ref code, false, false, false, true);

            //Parse defines and macros.
            Defines.Parse(code, name, codeParts, add);

            if (add)
            {
                //Replace defines and macros.
                DefReplacer.Parse(code, name, codeParts, add);
            }

            //Now parse funcs.
            Functions.Parse(code, name, codeParts, add);

            //Parse global vars.
            GlobalVariables.Parse(code, name, codeParts, add);

            //Parse if defines.
            IfDefines.Parse(code, filePath, projectPath, ref codeParts, add);
        }