public Hasher(string wildcard, string location, long size) : base() { this.Locations = new WildCardCollection(location); this.Wildcard = new WildCardCollection(wildcard); this.Size = size; ValidateRequest(); }
public Hasher(WildCardCollection wildcard, HashSize size, ILog logger) : base(logger) { this.Wildcard = wildcard; this.GetSize(size); ValidateRequest(); }
public Hasher(WildCardCollection wildcard, long size, ILog logger) : base(logger) { this.Wildcard = wildcard; this.Size = size; ValidateRequest(); }
private SearchBrain(WildCardCollection wildcards, ILog logger) { GetExtensions(wildcards); Rules = new SearchRules(); this.logger = logger; ParseList(); }
public Hasher(WildCardCollection wildcard, WildCardCollection location, long size) : base() { this.Locations = location; this.Wildcard = wildcard; this.Size = size; ValidateRequest(); }
/// <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); }
/// <summary> /// Parse a configuration file with the following structure into rules for hashing: /// </summary> /// <example> /// <Configuration> /// <Programs> /// <ProgHasher> /// <SearchList> /// <Music extensions=""> /// <HashFirst> /// <Location>...............</Location> /// </HashFirst> /// <HashAfter> /// <Location>...............</Location> /// </HashAfter> /// </Music> /// <Executable extensions=""> /// <HashFirst> /// <Location>...............</Location> /// </HashFirst> /// <HashAfter> /// <Location>...............</Location> /// </HashAfter> /// </Executable> /// </SearchList> /// </ProgHasher> /// </Programs> /// </Configuration> /// </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); } } }
/// <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); }
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>(); }
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; }
//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>(); }
//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; }
/// <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(); }
/// <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"); } } }
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); }
/// <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(); } }
public Rule[] GetRule(WildCardCollection wildcards) { GetExtensions(wildcards); return(Rules.GetRule(WildCards)); }
/// <summary> /// Ctor /// </summary> /// <param name="wildcards">this represents search keywords. eg:"autoexec.bat"</param> private SearchBrain(WildCardCollection wildcards) { GetExtensions(wildcards); Rules = new SearchRules(); ParseList(); }
/// <summary> /// ctor /// </summary> /// <param name="wildcards">wildcards</param> /// <param name="name"></param> public Rule(WildCardCollection wildcards, string name) { this.wildcards = wildcards; this.Name = name; }
public HashEventArgs(WildCardCollection wildcards) { this.WildCards = wildcards; }
public HashItemSearchEventArgs(WildCardCollection wildcard, String name) { this.WildCards = wildcard; this.Name = name; }