Пример #1
0
        /// <summary>
        /// Builds a hash of the information about word counts found in the page passed to the parser.
        /// </summary>
        /// <param name="wordsOnPage"></param>
        /// <returns>Dictionary<string, int></returns>
        public Dictionary <string, int> GetTextStats(List <string> wordsOnPage)
        {
            //This is designed this way so you can add other metrics without changing the ui.
            allWordsTally = AllWordsTally(wordsOnPage);

            statsDictionary.Add("Total Word Count", wordsOnPage.Count);
            statsDictionary.Add("Unique Word Count", allWordsTally.Count());

            allWordsTally.Remove("");

            int TopFreqCount = Int32.Parse(ConfigurationManager.AppSettings["Word-Frequency-Count"]);
            int rank         = 1;

            foreach (var kvp in allWordsTally.OrderByDescending(m => m.Value).Take(TopFreqCount))
            {
                statsDictionary.Add(string.Format("Word Rank {0} - {1}", rank, kvp.Key), kvp.Value);
                rank++;
            }
            updateProgressBarDelegate.Invoke(250);
            return(statsDictionary);
        }
Пример #2
0
        /// <summary>
        /// Downloads all of the imageUrls, and saves them to the destination folder
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="imageUrls"></param>
        /// <param name="sitename"></param>
        /// <returns></returns>
        public List <string> DownloadWithFilePaths(string destination, List <string> imageUrls, string sitename)
        {
            List <string> localPaths      = new List <string>();
            int           count           = imageUrls.Count;
            int           updateincrement = 500 / count;

            string localFileName = "";

            using (WebClient client = new WebClient())
            {
                foreach (string url in imageUrls)
                {
                    try
                    {
                        string tempUrl = url;
                        if (IsRelativePath(url))
                        {
                            tempUrl = GetSiteRoot(sitename) + url;
                        }

                        localFileName = Path.Combine(destination, GetImageName(url));
                        if (!File.Exists(localFileName))
                        {
                            client.DownloadFile(tempUrl, localFileName);
                        }

                        localPaths.Add(localFileName);
                        updateProgressBarDelegate.Invoke(updateincrement);
                    }
                    catch (Exception e)
                    {
                        log.Error(e.StackTrace);
                    }
                }
            }
            return(localPaths);
        }