/// <summary> /// Check if the location in parameter are already in the file system tree of the current instance /// </summary> /// <param name="location">Location to test</param> /// <returns>true if the location to test is in fs tree, false otherwise</returns> public virtual bool Contain(DocumentLocation location) { string source = location.Location.ToUpperInvariant(); string target = this.Location.ToUpperInvariant(); string diff = source.Replace(target, string.Empty); return diff.Length > 0 && diff.Length < source.Length; }
public void Init() { discovery = new ParallelFolderDiscovery(); location = new DocumentLocation(); location.Location = Path.Combine(Environment.CurrentDirectory, "TestMaterial"); location.State = DiscoveryStates.NotExplored; }
public bool IntersectWith(DocumentLocation location) { foreach(var loc in _locations) { bool result = loc.Contain(location); if(result) { return true; } } return false; }
/// <summary> /// Explore a location and return individual documents /// </summary> /// <param name="location"></param> /// <returns>Document</returns> public virtual ICollection<DocumentIdentity> Discover(DocumentLocation location) { Contract.Assert(location != null); List<DocumentIdentity> documents = new List<DocumentIdentity>(); location.State = DiscoveryStates.Exploring; DirectoryInfo dir = new DirectoryInfo(location.Location); IEnumerable<FileInfo> files = dir.EnumerateFiles("*.*", SearchOption.AllDirectories); Parallel.ForEach(files, (FileInfo file) => { try { if (!file.Exists) { return; } DocumentIdentity identity = new DocumentIdentity(); identity.DocumentID = ComputeId(file.FullName); identity.Checksum = ComputeChecksum(file); identity.State = IndexationStates.NotIndexed; identity.FilePath = file.FullName; identity.LastIndexed = null; documents.Add(identity); } catch (IOException ex) { } catch (InvalidOperationException ex) { //Logger.Error("Checksum failed"); //Logger.Error(ex); } catch (UnauthorizedAccessException ex) { // Logger.Error("Not authorized to accces to" + file.FullName); // Logger.Error(ex); } }); location.LastDiscovered = DateTime.Now; location.State = DiscoveryStates.Explored; return documents; }
public LocationModel(DocumentLocation location) { _location = location; }
/// <summary> /// Add the selected path in the location collection and persist the document store instance /// </summary> private void AddLocationToModel() { DocumentLocation location = new DocumentLocation(); location.Location = lastSelectedPath; location.State = DiscoveryStates.NotExplored; bool canAdd = !StoreModel.Locations.Contains(location) && !StoreModel.IntersectWith(location); if (canAdd) { this.StoreModel.Locations.Add(location); this.OnSaveDocumentStore(); } }