Example #1
0
        /// <summary>
        /// Validate() is called to run the validation. No return type is needed since it logs any errors found, using the _reportList
        /// object set in the constructor.
        /// </summary>
        public void Validate()
        {
            try
            {
                if (!System.IO.File.Exists(_folderTreePathAndFile))
                {
                    _folderTreePathAndFile = _folderTreePathAndFile.Replace(@"\FolderTrees\", "\\");
                }
                if (!System.IO.File.Exists(_folderTreePathAndFile))
                {
                    _reportList.Add(new ReportMissingFile(ReportType.MissingFolder, _folderTreePathAndFile, "Folder Tree File missing", true));
                    return;
                }

                string path;
                var    file = new System.IO.StreamReader(_folderTreePathAndFile);
                while ((path = file.ReadLine()) != null)
                {
                    if (!System.IO.Directory.Exists(_root + '\\' + path) && _folderStatus == FolderStatus.Exists)
                    {
                        _reportList.Add(new ReportMissingFile(ReportType.MissingFolder, path, "Expected Path was not found", true));
                    }
                    if (System.IO.Directory.Exists(_root + '\\' + path) && _folderStatus == FolderStatus.DoesNotExist)
                    {
                        _reportList.Add(new ReportMissingFile(ReportType.UnexpectedFolder, path, "Unexpected Path was found", true));
                    }
                }
                file.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Could not open Folder Tree File " + _folderTreePathAndFile);
            }
        }
Example #2
0
        /// <summary>
        /// IsControllerActionValid() return Resolves, Fails and Untested to describe whether the controller action, defined by href
        /// (example: ~/PaymentReminder/LoanPaymentDate), can actually be matched up with a Razor page.
        /// </summary>
        /// <param name="href"></param>
        /// <param name="sourceFile"></param>
        /// <returns></returns>
        public PathResolves IsControllerActionValid(string href, string sourceFile)
        {
            // TODO: Eventually, use sourceFile to see if the link is to an Overlay or not.
            // TODO: What about errors when the file's found in both the Controller folder AND the Controller's Overlay folder ?

            // Direct calls to the Shared folder should never happen, so flag it as an error
            if (href.ToLower().IndexOf("shared") > -1)
            {
                _reportList.Add(new ReportTagError("BAD URL", ReportType.UrlRazor, sourceFile, "Faulty URL pointing to " + href + " found in " + sourceFile, false));
                return(PathResolves.Fails);
            }

            string razorFilename = CreateRazorFilename(href);

            if (razorFilename != null)
            {
                if (File.Exists(razorFilename))
                {
                    return(PathResolves.Resolves);
                }

                // The Razor file was  found in the Controller's root folder
                // So look for the Razor file in the Controller's Overlay folder
                string razorFilenameWithOverlay = razorFilename.Substring(0, razorFilename.LastIndexOf('\\')) + "\\Overlay\\" + razorFilename.Substring(razorFilename.LastIndexOf('\\') + 1);
                if (File.Exists(razorFilenameWithOverlay))
                {
                    return(PathResolves.Resolves);
                }
                return(PathResolves.Fails);
            }

            return(PathResolves.Untested);
        }