/// <summary> /// Initializes a new instance of the <see cref="FileSearchEngine"/> class. /// </summary> /// <param name="dir"> /// The dir represents the starting point for the search started by <see cref="Search"/> method. /// </param> /// <param name="extension"> </param> /// <exception cref="Fbb.Exceptions.General.InvalidArgumentException"> /// </exception> public FileSearchEngine(IDirectoryDefinition dir, string extension) { if (dir == null) { throw new InvalidArgumentException("The argument 'dir' can not be null!"); } if (string.IsNullOrEmpty(dir.Path)) { throw new InvalidArgumentException("The argument 'dir.Path' can not be null or empty!"); } if (string.IsNullOrEmpty(extension)) { throw new InvalidArgumentException("The argument 'extension' can not be null or empty!"); } DirCount = 0; FileCount = 0; Dir = dir; Extension = extension; FileFoundDuringSearch = new List <string>(); ExcludeDirs = new List <IDirectoryDefinition>(); IncludeSubDirsInSearch = true; Log = Out.ZoneFactory(Ids.REGION_SEARCH, GetType().Name); }
/// <summary> /// Initializes a new instance of the <see cref="FileSearchEngine"/> class. /// </summary> /// <param name="dir"> /// The dir represents the starting point for the search started by <see cref="Search"/> method. /// </param> /// <param name="extension"> </param> /// <exception cref="Fbb.Exceptions.General.InvalidArgumentException"> /// </exception> public FileSearchEngine(IDirectoryDefinition dir, string extension) { if (dir == null) { throw new InvalidArgumentException("The argument 'dir' can not be null!"); } if (string.IsNullOrEmpty(dir.Path)) { throw new InvalidArgumentException("The argument 'dir.Path' can not be null or empty!"); } if (string.IsNullOrEmpty(extension)) { throw new InvalidArgumentException("The argument 'extension' can not be null or empty!"); } DirCount = 0; FileCount = 0; Dir = dir; Extension = extension; FileFoundDuringSearch = new List<string>(); ExcludeDirs = new List<IDirectoryDefinition>(); IncludeSubDirsInSearch = true; Log = Out.ZoneFactory(Ids.REGION_SEARCH, GetType().Name); }
public static IDirectoryDefinition ExcludedDirectoryDefinitionMapper(Model.ExcludedDirectory excludedDirectoryDefinition) { IDirectoryDefinition directory = null; try { directory = ConfigurationComponentFactory().ConfigurationFactory <IDirectoryDefinition>(typeof(IDirectoryDefinition)); } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Configuration proxy factory failure - unable to create an instance of " + typeof(IDirectoryDefinition) + "?", e); } try { directory.Enabled = excludedDirectoryDefinition.Enabled; directory.Path = excludedDirectoryDefinition.Path; } catch (Exception e) { throw new DataAccessComponentException(null, -1, "Mapping process failure?", e); } return(directory); }
public static XmlNode CreateDirectoryDefinitionXmlNode(XmlDocument doc, IDirectoryDefinition definition) { // <Directory Enabled="true" Path="c:\CLR\TFSPreview\Frameworks\CodeAnalysis\Mediator\obj"/> XmlNode fileNode = doc.CreateNode(XmlNodeType.Element, "Directory", null); XmlAttribute enabledAttrib = doc.CreateAttribute("Enabled"); XmlAttribute pathAttrib = doc.CreateAttribute("Path"); enabledAttrib.Value = definition.Enabled.ToString(); pathAttrib.Value = definition.Path; fileNode.Attributes.Append(enabledAttrib); fileNode.Attributes.Append(pathAttrib); return(fileNode); }
public ProjectDefinition() { UnderConstruction = true; RootDirectory = new DirectoryDefinition(); Directories = new List <IDirectoryDefinition>(); ExcludedDirectories = new List <IDirectoryDefinition>(); InvalidDirectories = new List <IDirectoryDefinition>(); Files = new List <IFileDefinition>(); ExcludedFiles = new List <IFileDefinition>(); InvalidFiles = new List <IFileDefinition>(); Categories = new Dictionary <int, ICategoryDefinition>(); UnderConstruction = false; }
public void ConfigurationFactory_AllSupportedTypes_ReturnsValidObject() { ConfigurationComponentFactory factory = ConfigurationComponentFactory.Instance; factory.InitializeComponentAccessPermissions(AppManager); Debug.Assert(factory != null, "proxy != null"); ILanguageDeclaration languageDeclaration = factory.ConfigurationFactory <ILanguageDeclaration>(typeof(ILanguageDeclaration)); IRuleDeclaration ruleDeclaration = factory.ConfigurationFactory <IRuleDeclaration>(typeof(IRuleDeclaration)); IProjectDefinition projectDefinition = factory.ConfigurationFactory <IProjectDefinition>(typeof(IProjectDefinition)); ICategoryDefinition categoryDefinition = factory.ConfigurationFactory <ICategoryDefinition>(typeof(ICategoryDefinition)); IRuleDefinition ruleDefinition = factory.ConfigurationFactory <IRuleDefinition>(typeof(IRuleDefinition)); IDirectoryDefinition directoryDefinition = factory.ConfigurationFactory <IDirectoryDefinition>(typeof(IDirectoryDefinition)); IFileDefinition fileDefinition = factory.ConfigurationFactory <IFileDefinition>(typeof(IFileDefinition)); Assert.IsNotNull(languageDeclaration); Assert.IsNotNull(ruleDeclaration); Assert.IsNotNull(projectDefinition); Assert.IsNotNull(categoryDefinition); Assert.IsNotNull(ruleDefinition); Assert.IsNotNull(directoryDefinition); Assert.IsNotNull(fileDefinition); }
/// <summary> /// The internal search method - remember that the method is reqursive. /// </summary> /// <param name="directoryDefinition"> /// The directoryDefinition is the starting point for each call to the internal search method. /// </param> /// <exception cref="SearchException"> /// </exception> private void SearchInternal(IDirectoryDefinition directoryDefinition) { string[] dirs = new string[0]; string[] files; #region Get directories try { if (!Directory.Exists(directoryDefinition.Path)) { return; } if (!directoryDefinition.Enabled) { return; } if (IncludeSubDirsInSearch) { dirs = Directory.GetDirectories(directoryDefinition.Path); DirCount += dirs.Length; } } catch (UnauthorizedAccessException uae) { Log.Info("Unable to access directory {0} due to UnauthorizedAccessException. \n\n{1}", directoryDefinition, BaseException.Format(this, -1, "Unable to access directory " + directoryDefinition, uae)); return; } catch (Exception exception) { string s = string.Format("Unable to retrieve directories from '{0}'.", directoryDefinition.Path); throw new SearchException(this, -1, s, exception); } #endregion #region Get files try { files = Directory.GetFiles(directoryDefinition.Path, Extension); FileCount += files.Length; } catch (Exception exception) { string s = string.Format("Unable to retrieve files from '{0}'.", directoryDefinition); throw new SearchException(this, -1, s, exception); } #endregion #region Handle the found directories foreach (string dir in dirs) { bool exclude = false; foreach (IDirectoryDefinition excludedDir in ExcludeDirs) { if (!excludedDir.Enabled) continue; if (string.Compare(excludedDir.Path, dir, StringComparison.OrdinalIgnoreCase) == 0) exclude = true; } if (!exclude) { // Not excluded - let's continue... IDirectoryDefinition dirDef = ProxyHome.Instance.RetrieveConfigurationFactory(EngineKeyKeeper.Instance.AccessKey).ConfigurationFactory<IDirectoryDefinition>(typeof(IDirectoryDefinition)); dirDef.Enabled = true; dirDef.Path = dir; SearchInternal(dirDef); } } #endregion #region Handle the found files foreach (string file in files) { FileFoundDuringSearch.Add(file); } #endregion }
/// <summary> /// The internal search method - remember that the method is reqursive. /// </summary> /// <param name="directoryDefinition"> /// The directoryDefinition is the starting point for each call to the internal search method. /// </param> /// <exception cref="SearchException"> /// </exception> private void SearchInternal(IDirectoryDefinition directoryDefinition) { string[] dirs = new string[0]; string[] files; #region Get directories try { if (!Directory.Exists(directoryDefinition.Path)) { return; } if (!directoryDefinition.Enabled) { return; } if (IncludeSubDirsInSearch) { dirs = Directory.GetDirectories(directoryDefinition.Path); DirCount += dirs.Length; } } catch (UnauthorizedAccessException uae) { Log.Info("Unable to access directory {0} due to UnauthorizedAccessException. \n\n{1}", directoryDefinition, BaseException.Format(this, -1, "Unable to access directory " + directoryDefinition, uae)); return; } catch (Exception exception) { string s = string.Format("Unable to retrieve directories from '{0}'.", directoryDefinition.Path); throw new SearchException(this, -1, s, exception); } #endregion #region Get files try { files = Directory.GetFiles(directoryDefinition.Path, Extension); FileCount += files.Length; } catch (Exception exception) { string s = string.Format("Unable to retrieve files from '{0}'.", directoryDefinition); throw new SearchException(this, -1, s, exception); } #endregion #region Handle the found directories foreach (string dir in dirs) { bool exclude = false; foreach (IDirectoryDefinition excludedDir in ExcludeDirs) { if (!excludedDir.Enabled) { continue; } if (string.Compare(excludedDir.Path, dir, StringComparison.OrdinalIgnoreCase) == 0) { exclude = true; } } if (!exclude) { // Not excluded - let's continue... IDirectoryDefinition dirDef = ProxyHome.Instance.RetrieveConfigurationFactory(EngineKeyKeeper.Instance.AccessKey).ConfigurationFactory <IDirectoryDefinition>(typeof(IDirectoryDefinition)); dirDef.Enabled = true; dirDef.Path = dir; SearchInternal(dirDef); } } #endregion #region Handle the found files foreach (string file in files) { FileFoundDuringSearch.Add(file); } #endregion }
public static XmlNode CreateDirectoryDefinitionXmlNode(XmlDocument doc, IDirectoryDefinition definition) { // <Directory Enabled="true" Path="c:\CLR\TFSPreview\Frameworks\CodeAnalysis\Mediator\obj"/> XmlNode fileNode = doc.CreateNode(XmlNodeType.Element, "Directory", null); XmlAttribute enabledAttrib = doc.CreateAttribute("Enabled"); XmlAttribute pathAttrib = doc.CreateAttribute("Path"); enabledAttrib.Value = definition.Enabled.ToString(); pathAttrib.Value = definition.Path; fileNode.Attributes.Append(enabledAttrib); fileNode.Attributes.Append(pathAttrib); return fileNode; }