Exemple #1
0
        /// <summary>Private routine to build XDocument of URLs</summary>
        /// <param name="inputStream">Stream to read URL lines</param>
        /// <param name="urlChecker">Checker of read URL lines</param>
        /// <param name="logger">Wrong URL logger, may be null</param>
        /// <returns>XML document with URL's info</returns>
        private static XDocument BuildXDocumentRoutine(Stream inputStream, URLChecker urlChecker, TextWriter logger)
        {
            // Create XML document basement
            var declaration = new XDeclaration("1.0", "UTF-8", "yes");
            var document    = new XDocument(declaration, new XElement("urlAddresses"));

            // Read urls
            string url;
            var    streamReader = new StreamReader(inputStream);

            while ((url = streamReader.ReadLine()) != null)
            {
                // Check url and print log
                if (urlChecker.CheckURL(url))
                {
                    var urlElement = BuildURLElement(url);
                    document.Root.Add(urlElement);

                    if (logger != null)
                    {
                        logger.WriteLine("[VALID]: " + url);
                    }
                }
                else
                {
                    if (logger != null)
                    {
                        logger.WriteLine("[INVALID]: " + url);
                    }
                }
            }

            return(document);
        }
Exemple #2
0
 /// <summary>Public interface to build XDocument of URLs</summary>
 /// <param name="inputStream">Stream to read URL lines</param>
 /// <param name="urlChecker">Checker of read URL lines</param>
 /// <param name="logger">Wrong URL logger, may be null</param>
 /// <returns>XML document with URL's info</returns>
 public static XDocument BuildXDocument(Stream inputStream, URLChecker urlChecker, TextWriter logger)
 {
     // Check arguments for null
     if (inputStream != null && urlChecker != null)
     {
         // Check stream for readability
         if (inputStream.CanRead)
         {
             return(BuildXDocumentRoutine(inputStream, urlChecker, logger));
         }
         else
         {
             throw new ArgumentException();
         }
     }
     else
     {
         throw new ArgumentNullException();
     }
 }
Exemple #3
0
 /// <summary>Public interface to build XDocument of URLs without logging</summary>
 /// <param name="inputStream">Stream to read URL lines</param>
 /// <param name="urlChecker">Checker of read URL lines</param>
 /// <returns>XML document with URL's info</returns>
 public static XDocument BuildXDocument(Stream inputStream, URLChecker urlChecker)
 {
     return(BuildXDocument(inputStream, urlChecker, null));
 }