Exemplo n.º 1
0
 /// <summary>
 /// Event: occurs when an item is not found within the result.
 /// This is relevant when using the hashing feature within a product.
 /// </summary>
 /// <param name="o">o</param>
 /// <param name="e">e</param>
 public void OnItemNotFound(object o, HashItemSearchEventArgs e)
 {
     if (mode == HashMode.Hash)
     {
         if (logger != null)
         {
             logger.Info("Item was not found. Initiating priorityPoller to find it.");
         }
         bool isactive        = false;
         WildCardCollection w = new WildCardCollection(WildCardType.Extreme, e.Name);
         if (priorityRnr != null)
         {
             if (priorityPoller != null)
             {
                 isactive = priorityPoller.IsActive(w);
                 if (priorityRnr.IsBusy && !isactive)
                 {
                     int tries = 0;
                     while (priorityRnr.IsBusy && tries < 5)
                     {
                         priorityRnr.CancelAsync();
                         Thread.Sleep(2000); //wait a bit for the poller to stop.
                         tries++;
                     }
                 }
             }
         }
         if (!isactive && !priorityRnr.IsBusy)
         {
             //this.priorityPoller = new TaskPoller(w, brain.Rules.GetRule(w));
             this.priorityPoller = new TaskPoller(w, brain.GetRule(this.Wildcard), logger);
             this.priorityPoller.CompletedDirs  = poller.CompletedDirs;
             this.priorityPoller.HashItemFound += new HashItemFoundHandler(OnPriorityItemFound);
             this.priorityPoller.HashCompleted += new HashCompletedHandler(OnHashCompleted);
             this.priorityRnr.RunWorkerAsync();
         }
     }
     else
     {
         if (logger != null)
         {
             logger.Error("No Items found");
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Validate search requirements
 /// </summary>
 protected void ValidateRequest()
 {
     try{
         SearchBrain.List.MaxPerFolder = (int)Size;
         if (Size > MaxPerFolder)
         {
             if (logger != null)
             {
                 logger.Warn("Warning: Requiring a hash size greater than allowed");
             }
         }
         poller = new TaskPoller(this.Wildcard, brain.GetRule(this.Wildcard), logger);
         poller.HashPollCompleted += new HashPollCompletedHandler(this.OnPollCompleted);
         poller.HashItemFound     += new HashItemFoundHandler(this.OnItemFound);
         poller.HashCompleted     += new HashCompletedHandler(this.OnHashCompleted);
     }
     catch (System.Exception e)
     {
         if (logger != null)
         {
             logger.Error(e);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Start a search routine.
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="type"></param>
        public void BeginSearch(string keyword, WildCardType type)
        {
            mode = HashMode.Search;
            bool isactive        = false;
            WildCardCollection w = new WildCardCollection(type, keyword);

            if (priorityRnr != null && priorityPoller != null)
            {
                isactive = priorityPoller.IsActive(w);
                if (priorityRnr.IsBusy && !isactive)
                {
                    priorityRnr.CancelAsync();
                }
            }
            if (!isactive)
            {
                this.priorityPoller = new TaskPoller(w, brain.Rules.GetRule(w), logger);
                this.priorityPoller.HashItemFound         += new HashItemFoundHandler(OnPriorityItemFound);
                this.priorityPoller.HashCompleted         += new HashCompletedHandler(OnHashCompleted);
                this.priorityPoller.IgnoreDepthRestriction = true;
                this.priorityRnr.RunWorkerAsync();
                this.hashTimer.BeginTimer();
            }
        }