Ejemplo n.º 1
0
 /// <summary>Checks the black list and returns whether the item is new or not.</summary>
 /// <param name="itemType">Type of the item.</param>
 /// <param name="itemGuid">The item unique identifier.</param>
 /// <returns>Returns true if the item was not blacklisted, false otherwise</returns>
 public bool CheckBlackList(MDBCrawlerBlackListItemType itemType, BinaryGuid itemGuid)
 {
     lock (CrawlerBlackList)
     {
         MDBCrawlerBlackListItem item = CrawlerBlackList.TryGetStruct(
             Search.FieldEquals(nameof(MDBCrawlerBlackListItem.Type), itemType) &
             Search.FieldEquals(nameof(MDBCrawlerBlackListItem.Guid), itemGuid));
         //item already present?
         if (item.ID > 0)
         {
             //yes, is expired -> no = false
             if (DateTime.UtcNow < item.Expire)
             {
                 return(false);
             }
             //yes = true;
         }
         else
         {
             //new blacklist item
             CrawlerBlackList.Insert(new MDBCrawlerBlackListItem()
             {
                 Guid   = itemGuid,
                 Type   = itemType,
                 Expire = DateTime.UtcNow.AddDays(14),
             });
         }
         return(true);
     }
 }
Ejemplo n.º 2
0
 /// <summary>Removes all expired items from the blacklist.</summary>
 public void CleanBlackList()
 {
     CrawlerBlackList?.TryDelete(Search.FieldSmaller(nameof(MDBCrawlerBlackListItem.Expire), DateTime.UtcNow));
 }