private void OnFileSystemObjectCreated(object sender, FileSystemEventArgs e) { if (_monitoredFiles.ContainsKey(e.FullPath)) { _monitoredFiles[e.FullPath] = CreateFileDataObject(e.FullPath); } else if (_deletedFiles.Count > 0) { FileInfoCache created = new FileInfoCache(e.FullPath); foreach (FileInfoCache deleted in _deletedFiles) { if (deleted.CreationTime == created.CreationTime || deleted.Name == created.Name || deleted.Length == created.Length) { // We assume that a recently deleted file with the same size // and creation time of a monitored one is being moved. UpdateFileDataObject(deleted.FullName, created.FullName); _deletedFiles.Remove(deleted); break; } } } }
private FileInfoCache CreateFileDataObject(string path) { FileInfoCache file = new FileInfoCache(path); string queryString = @" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#> SELECT ?uri WHERE { ?uri a nfo:FileDataObject . ?uri nfo:fileUrl """ + file.Url.AbsoluteUri + @""" . } LIMIT 1"; SparqlQuery query = new SparqlQuery(queryString); ISparqlQueryResult result = _model.ExecuteQuery(query); BindingSet bindings = result.GetBindings().FirstOrDefault(); if (bindings == null) { FileDataObject f = _model.CreateResource <FileDataObject>(); f.CreationTime = file.CreationTime; f.LastAccessTime = file.LastAccessTime; f.LastModificationTime = file.LastWriteTime; f.Url = file.Url.AbsoluteUri; f.Commit(); _monitoredFileUris[file.Url] = f.Uri; Logger.LogInfo("Created {0}", file.FullName); } else { _monitoredFileUris[file.Url] = new Uri(bindings["uri"].ToString()); Logger.LogInfo("Updating {0}", file.FullName); } return(file); }
public void AddFile(string path) { _monitoredFiles[path] = new FileInfoCache(path); }