Exemple #1
0
 public static string[] GetSomeUrlsForHost(string host, Controls.UrlCollection Urls, int count = 0)
 {
     List<string> result = new List<string>();
     try
     {
         List<string> fullResult = new List<string>();
         fullResult.AddRange(
             Urls
                 .AsParallel()
                 .Where(url => Helper.IsWellFormedUriString(url.Value, UriKind.Absolute) && StringLikes((new Uri(url.Value)).Host, host))
                 .Select(i => i.Value).ToArray()
                 .OrderBy(i => i)
                 );
         if (count > 0 && count < fullResult.Count)
         {
             count = Math.Min(count, fullResult.Count);
             if (count > 0)
                 result.Add(fullResult.First());
             if (count > 1)
                 result.Add(fullResult.Last());
             if (count > 2)
             {
                 int step = (int)((float)fullResult.Count / (float)(count - 1));
                 for (int i = 1; i < count - 1; i++)
                     result.Add(fullResult[step * i]);
             }
         }
         else
             result.AddRange(fullResult);
     }
     catch (Exception ex)
     {
         Helpers.Old.Log.Add(ex, string.Format("Helper.GetSomeUrlsForHost(host:'{0}',count:'{1}')", host, count));
     }
     return result.OrderBy(i => i).ToArray();
 }