Пример #1
0
 public Hasher(string wildcard, string location, long size) : base()
 {
     this.Locations = new WildCardCollection(location);
     this.Wildcard  = new WildCardCollection(wildcard);
     this.Size      = size;
     ValidateRequest();
 }
Пример #2
0
 public Hasher(WildCardCollection wildcard, HashSize size, ILog logger)
     : base(logger)
 {
     this.Wildcard = wildcard;
     this.GetSize(size);
     ValidateRequest();
 }
Пример #3
0
 public Hasher(WildCardCollection wildcard, long size, ILog logger)
     : base(logger)
 {
     this.Wildcard = wildcard;
     this.Size     = size;
     ValidateRequest();
 }
Пример #4
0
 private SearchBrain(WildCardCollection wildcards, ILog logger)
 {
     GetExtensions(wildcards);
     Rules       = new SearchRules();
     this.logger = logger;
     ParseList();
 }
Пример #5
0
 public Hasher(WildCardCollection wildcard, WildCardCollection location, long size) : base()
 {
     this.Locations = location;
     this.Wildcard  = wildcard;
     this.Size      = size;
     ValidateRequest();
 }
Пример #6
0
        /// <summary>
        /// Main Entry point
        /// </summary>
        /// <param name="args">arguments</param>
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Thread.CurrentThread.Name = "main";
            if (args.Length > 0)
            {
                hasher = new Hasher(args[0], ProgHasher.HashSize.Infinity, logger);
            }
            else
            {
                hasher = new Hasher(Console.ReadLine(), ProgHasher.HashSize.Infinity, logger);
            }

            try
            {
                hasher.ItemFound     += new HashItemFoundHandler(OnItemFound);
                hasher.HashCompleted += new HashCompletedHandler(SetResults);
                hasher.Wildcard.Type  = WildCardType.Extension;
                hasher.BeginHash();
                wildcard = hasher.Wildcard;
                ExecuteRunner();
                //ExecuteSearcher();
                hasher.EndHash();
                //hasher.EndSearch();
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
            }

            Console.Write("Press any key to exit . . . ");
            Console.ReadKey(true);
        }
Пример #7
0
        /// <summary>
        /// Parse a configuration file with the following structure into rules for hashing:
        /// </summary>
        /// <example>
        ///    &lt;Configuration&gt;
        ///		    &lt;Programs&gt;
        ///		        &lt;ProgHasher&gt;
        ///		            &lt;SearchList&gt;
        ///		                &lt;Music extensions=""&gt;
        ///		                   &lt;HashFirst&gt;
        ///		                        &lt;Location&gt;...............&lt;/Location&gt;
        ///		                   &lt;/HashFirst&gt;
        ///		                    &lt;HashAfter&gt;
        ///		                        &lt;Location&gt;...............&lt;/Location&gt;
        ///		                    &lt;/HashAfter&gt;
        ///		                &lt;/Music&gt;
        ///		                &lt;Executable extensions=""&gt;
        ///		                    &lt;HashFirst&gt;
        ///		                        &lt;Location&gt;...............&lt;/Location&gt;
        ///		                   &lt;/HashFirst&gt;
        ///		                    &lt;HashAfter&gt;
        ///		                        &lt;Location&gt;...............&lt;/Location&gt;
        ///		                    &lt;/HashAfter&gt;
        ///		                &lt;/Executable&gt;
        ///		            &lt;/SearchList&gt;
        ///		        &lt;/ProgHasher&gt;
        ///		    &lt;/Programs&gt;
        ///		 &lt;/Configuration&gt;
        /// </example>
        private void ParseList()
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(ConfigurationManager.ConfigLocation);
                XmlNodeList searchlist  = xDoc.SelectNodes("Configuration/Programs/ProgHasher/SearchList/*");
                XmlNodeList excludeList = xDoc.SelectNodes("Configuration/Programs/ProgHasher/ExclusionList/*");

                //Create exclusion list for the poller.
                List <Regex> exclusionList = new List <Regex>();
                foreach (XmlNode x in excludeList)
                {
                    Regex r = new Regex(x.InnerText, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);
                    exclusionList.Add(r);
                }
                SearchRules.ExclusionList.AddRange(exclusionList);

                //Start parsing the stuff.
                string[] hashes = new string[] { "HashFirst", "HashAfter" };
                foreach (XmlNode x in searchlist)
                {
                    Rule               newRule    = null;
                    string             extensions = x.Attributes["extensions"].Value;
                    WildCardCollection wildcards  = null;
                    if (extensions != null)
                    {
                        wildcards = new WildCardCollection(extensions);
                    }
                    newRule = new Rule(wildcards, x.Name);
                    foreach (string s in hashes)
                    {
                        string      xPathString = string.Format("Configuration/Programs/ProgHasher/SearchList/{0}/{1}//Location", x.Name, s);
                        XmlNodeList locations   = xDoc.SelectNodes(xPathString);
                        if (locations != null)
                        {
                            foreach (XmlNode x2 in locations)
                            {
                                int depth = 0;
                                int.TryParse(x2.Attributes["depth"].Value, out depth);
                                newRule.SetHash(s, x2.InnerText, depth);
                            }
                        }
                    }
                    if (logger != null)
                    {
                        logger.Info(string.Format("Adding newly created rule for: {0} of type: {1}", wildcards.Value, x.Name));
                    }
                    Rules.Add(wildcards, newRule);
                }
            }
            catch (System.Exception e)
            {
                if (logger != null)
                {
                    logger.Error(e);
                }
            }
        }
Пример #8
0
 /// <summary>
 /// Checks if a set of wildcards are already been searched for.
 /// </summary>
 /// <param name="wildcard"></param>
 /// <returns></returns>
 public bool IsActive(WildCardCollection wildcard)
 {
     if (this.wildcards.Contains(wildcard))
     {
         return(true);
     }
     return(false);
 }
Пример #9
0
 public HashEngine(TaskItem location, WildCardCollection names)
 {
     this.task      = location;
     this.location  = task.Name;
     this.names     = names;
     Files          = new System.Collections.Generic.List <string>();
     SubDirectories = new System.Collections.Generic.List <string>();
 }
Пример #10
0
 internal TaskPoller(WildCardCollection locations, WildCardCollection wildcards)
 {
     this.wildcards = wildcards;
     this.locations = locations;
     this.Events    = new ManualResetEvents();
     Poll           = new ProcessList();
     CompletedDirs  = new List <string>();
     Results        = new List <string>();
     useLocation    = true;
 }
Пример #11
0
 //public HashEngine(string location, WildCardCollection names, ManualResetEvent completed)
 public HashEngine(string location, WildCardCollection names)
 {
     //this.completed = completed;
     this.task     = new TaskItem(location);
     this.location = task.Name;
     this.names    = names;
     //this.IgnoreSubDirs = ignoreSubDirs;
     Files          = new System.Collections.Generic.List <string>();
     SubDirectories = new System.Collections.Generic.List <string>();
 }
Пример #12
0
        //private List<ManualResetEvent> subEvents = null;
        internal Task(TaskItem item, WildCardCollection names, long limit, ManualResetEvent completed)
        {
            this.location = item.Name;
            this.taskItem = item;
            this.names    = names;
            Limit         = limit;

            //this.processList = new ProcessList();
            //this.processList.Add(item);
            //this.FoundList = new List<string>();
            //this.subEvents = new List<ManualResetEvent>();

            this.DoneEvent = completed;
        }
Пример #13
0
 /// <summary>
 /// Default ctor
 /// </summary>
 /// <param name="wildcards"></param>
 internal TaskPoller(WildCardCollection wildcards, Rule[] rules, ILog logger)
 {
     this.logger = logger;
     Thread.CurrentThread.IsBackground = true;
     Thread.CurrentThread.Priority     = ThreadPriority.BelowNormal;
     this.Rules                 = rules;
     this.Events                = new ManualResetEvents();
     this.tmpEvents             = new ManualResetEvents();
     this.pollTimer             = new ProgTimer(TimerType.HashDelay);
     this.pollTimer.TimerFired += new HashTimerEventHandler(pollTimer_TimerFired);
     this.wildcards             = wildcards;
     Poll          = new ProcessList();
     CompletedDirs = new List <string>();
     Results       = new List <string>();
     CreateTasks();
 }
Пример #14
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");
         }
     }
 }
Пример #15
0
 public static WildCardCollection GetExtensions(WildCardCollection wildcards)
 {
     WildCards = new WildCardCollection();
     if (wildcards != null)
     {
         foreach (string s in wildcards)
         {
             try{
                 FileInfo fi = new FileInfo(s);
                 WildCards.Add(fi.Extension.Remove(0, 1));
             }
             catch
             {
                 string[] name = s.Split('.');
                 WildCards.Add(name[name.Length - 1]);
             }
         }
     }
     return(WildCards);
 }
Пример #16
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();
            }
        }
Пример #17
0
 public Rule[] GetRule(WildCardCollection wildcards)
 {
     GetExtensions(wildcards);
     return(Rules.GetRule(WildCards));
 }
Пример #18
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="wildcards">this represents search keywords. eg:"autoexec.bat"</param>
 private SearchBrain(WildCardCollection wildcards)
 {
     GetExtensions(wildcards);
     Rules = new SearchRules();
     ParseList();
 }
Пример #19
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="wildcards">wildcards</param>
 /// <param name="name"></param>
 public Rule(WildCardCollection wildcards, string name)
 {
     this.wildcards = wildcards;
     this.Name      = name;
 }
Пример #20
0
 public HashEventArgs(WildCardCollection wildcards)
 {
     this.WildCards = wildcards;
 }
Пример #21
0
 public HashItemSearchEventArgs(WildCardCollection wildcard, String name)
 {
     this.WildCards = wildcard;
     this.Name      = name;
 }