public void AddFile(string fullPath) { if (!IsExcluded(fullPath)) { var folder = FindFolder(Path.GetDirectoryName(fullPath) + "\\"); var sourceFile = FileSystemFile.FromPath(this, folder, fullPath.ToPlatformPath().NormalizePath()); SourceFiles.InsertSorted(sourceFile); if (folder != null) { if (folder.Location == Project.CurrentDirectory) { Project.Items.InsertSorted(sourceFile); sourceFile.Parent = Project; } else { folder.Items.InsertSorted(sourceFile); sourceFile.Parent = folder; } FileAdded?.Invoke(this, sourceFile); } } }
/// <summary> /// Add File without downloading it /// </summary> /// <param name="item">File to add in collection</param> public void Add(IFileObject item) { if (item.Uri == null) { throw new ArgumentNullException("Uri"); } if (string.IsNullOrWhiteSpace(item.Uri.AbsoluteUri)) { throw new ArgumentException("Uri path is not valid"); } if (_dict.ContainsKey(item.Uri.AbsoluteUri)) { throw new ArgumentException("Uri is alredy in the collection"); } FileAdding?.Invoke(this, new FileAddingArgs(item)); _dict.Add(item.Uri.AbsoluteUri, item); item.FileDownloaded += OnFileDownloaded; item.FileDownloading += OnFileDownloading; item.UriChange += OnUriChange; item.FileRemoved += OnFileRemoved; item.FileSaved += OnFileSaved; item.FileSaving += OnFileSaving; FileAdded?.Invoke(this, new FileAddedArgs(item)); }
private void OnFileAdded(string name) { if (FileAdded != null) { FileAdded.Invoke(name); } }
/* * Add the given content file. * Will notify the FileAdded event after adding. * If a file with the given name already exists and is deleted, * it is replaced with the given one. * If a file with the given name already exists and is not deleted, * it will not be replaced unless the "overwrite" parameter is set to true. */ public void Add(PackedFile file, bool overwrite = false) { if (containedFiles.ContainsKey(file.Name)) { PackedFile contained = null; foreach (var f in containedFiles) { if (f.Value.Name == file.Name) { contained = f.Value; break; } } if (contained.Deleted || overwrite) { containedFiles.Remove(file.Name); FileRemoved?.Invoke(contained); } else { // don't add the file return; } } containedFiles.Add(file.Name, file); file.IsAdded = true; file.Parent = this; FileAdded?.Invoke(file); }
private void HandleAdd() { if (CurrentView != null && CurrentView.NewAllowed && CurrentView.New()) { FileAdded?.Invoke(this, EventArgs.Empty); SetData(m_gameFile); } }
/// <summary> /// начинает контроль за заданной папкой /// </summary> /// <param name="path">путь к папке</param> public void StartControl(object path) { string _path = path as string; controlDirectorySize = DirSize(new DirectoryInfo(_path)); fileList = InitFileList(_path); directoryList = InitDirectoryList(_path); while (true) { if (controlDirectorySize != DirSize(new DirectoryInfo(_path))) // если размер папки изменился { if (!CheckDirectoryChange(_path)) // если в контролируемую директорию не было добавлено или удалено ПАПКУ { List <File> currentlist = InitFileList(_path); if (fileList.Count < currentlist.Count) //если файл был добавлен { foreach (var item in currentlist) { if (!ContainsItem(fileList, item)) { FileAdded.Invoke(item); if (Synchronaizer.IsDisableChangeFolder) { System.IO.File.Delete(item.Path); FileRemoved.Invoke(item); } } } } else if (fileList.Count > currentlist.Count) // если файл был удален { foreach (var item in fileList) { if (!ContainsItem(currentlist, item)) { FileRemoved.Invoke(item); } } } else // размер файла был изменен { for (int i = 0; i < currentlist.Count; i++) { if (fileList[i].Size != currentlist[i].Size) // дизнаемся размер которого файла было изменено { FileChanged.Invoke(fileList[i]); } } } controlDirectorySize = DirSize(new DirectoryInfo(_path)); fileList = InitFileList(_path); } } Thread.Sleep(CheckInterval); // интервал проверки } }
private void ReactOnFileChanges(object sender, FileSystemEventArgs e) { if (IsVideoAnalyzer.IsVideo(e.Name)) { LOGGER.Info($"Watcher found file '{e.FullPath}'"); FileAdded?.Invoke(e); } }
private void OnFileAdded(object sender, FileSystemEventArgs e) { if (_appConfigHelper.FileNameRegex.IsMatch(e.Name)) { FileAdded?.Invoke(this, new FileStoragePipelineEventArgs() { FilePath = e.FullPath }); } }
private void ExecuteIntegrations(string addedFilePath) { FileAdded?.Invoke(addedFilePath); var folder = Path.GetDirectoryName(addedFilePath); foreach (var integration in Configurations.Where(c => c.Folder == folder).Select(c => c.Integration)) { integration.Execute(addedFilePath); IntegrationExecuted?.Invoke(integration); } }
private void Watcher_Created(object sender, FileSystemEventArgs e) { string ext = Path.GetExtension(e.FullPath); if (ext.Length == 0) { FolderAdded?.Invoke(e.FullPath); } else if (PassesFilter(e.FullPath)) { FileAdded?.Invoke(e.FullPath); } }
/// <summary> /// Imports a file into the project at the specified path /// </summary> /// <param name="destinationPath">Desired project path of the file to import</param> /// <param name="filePath">Physical path of the file to import</param> /// <param name="fileType">Type of the file, or null to auto-detect the type on load</param> /// <param name="provider">Instance of the IO provider from which to get the file located at <paramref name="filePath"/>.</param> public virtual void AddExistingFileToPath(string destinationPath, string filePath, Type fileType, IFileSystem provider) { var fixedPath = FixPath(destinationPath); var relativePath = filePath.Replace(GetRootDirectory(), "").Replace("\\", "/").TrimStart("/".ToCharArray()); ProjectFileWrapper wrapper = new ProjectFileWrapper(this.Filename, relativePath); if (fileType != null) { wrapper.FileAssemblyQualifiedTypeName = fileType.AssemblyQualifiedName; } AddItem(destinationPath, wrapper); FileAdded?.Invoke(this, new ProjectFileAddedEventArgs { ProjectPath = Path.GetFileName(destinationPath), PhysicalPath = filePath }); }
private async Task PopulateFilesAsync(IProjectFolder folder) { await Task.Run(() => { var files = Directory.EnumerateFiles(folder.Location); files = files.Where(f => !IsExcluded(f)); foreach (var file in files) { var sourceFile = FileSystemFile.FromPath(this, folder, file.ToPlatformPath().NormalizePath()); SourceFiles.InsertSorted(sourceFile); folder.Items.InsertSorted(sourceFile); FileAdded?.Invoke(this, sourceFile); } }); }
public IProjectFile IncludeFile(string name) { var filePath = Path.Combine(FolderPath, name); if (!File.Exists(filePath)) { throw new ArgumentException("File does not exist. Cannot include not existent file."); } if (_files.Any(f => f.Name == name)) { throw new ArgumentException("File with the same name already exists in this folder."); } var newFile = new ProjectFile(filePath, this); _files.Add(newFile); FileAdded?.Invoke(this, new ProjectFileAddedEventArgs(newFile)); return(newFile); }
public IProjectFile AddFile(string name, Stream fileContent) { if (_files.Any(f => f.Name == name)) { throw new ArgumentException("File with the same name already exists in this folder."); } var filePath = Path.Combine(FolderPath, name); using (var fileStream = File.Create(filePath)) { fileContent.CopyTo(fileStream); } var newFile = new ProjectFile(filePath, this); _files.Add(newFile); FileAdded?.Invoke(this, new ProjectFileAddedEventArgs(newFile)); return(newFile); }
public void AddFile(string fullPath) { var folder = FindFolder(Path.GetDirectoryName(fullPath) + "\\"); var sourceFile = File.FromPath(this, folder, fullPath.ToPlatformPath()); SourceFiles.InsertSorted(sourceFile); if (folder.Location == Project.CurrentDirectory) { Project.Items.InsertSorted(sourceFile); sourceFile.Parent = Project; } else { folder.Items.InsertSorted(sourceFile); sourceFile.Parent = folder; } FileAdded?.Invoke(this, new EventArgs()); }
private void OnFileSystemEvent(object sender, FileSystemEventArgs e) { // ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault switch (e.ChangeType) { case WatcherChangeTypes.Created: FileAdded?.Invoke(this, e.FullPath); break; case WatcherChangeTypes.Deleted: FileRemoved?.Invoke(this, e.FullPath); break; case WatcherChangeTypes.Changed: FileRemoved?.Invoke(this, e.FullPath); if (File.Exists(e.FullPath)) { FileAdded?.Invoke(this, e.FullPath); } break; } }
protected virtual void OnFileAdded(FileAddedEventArgs e) { FileAdded?.Invoke(this, e); }
protected virtual void OnFileAdded(FileInfo file) { FileAdded?.Invoke(this, new FileInfoEventArgs(file)); }
//------------------------------------------------------------------------- protected virtual void OnFileAdded() { FileAdded?.Invoke(this, EventArgs.Empty); }
private void InvokeFileAdded(TreeFile file) { FileAdded?.Invoke(this, new TreeFileEventArgs(file)); }
/// <summary> /// Handles changed files, added files and files deleted in the directory /// </summary> private void HandleFileEvent() { isStopped = false; while (isRunning) { _waitHandle.WaitOne(); if (!isRunning) { break; } FileSystemEventArgs e; //Tries to take event from queue while (_fileHandlingQueue.TryDequeue(out e)) { if (!isRunning) { _fileHandlingQueue.Enqueue(e); break; } if (IgnoreHidden(e.FullPath)) { continue; } //If the event is not the deletion of a file, //this avoids handling directories snd unfinished files if (!e.ChangeType.Equals(WatcherChangeTypes.Deleted)) { //Checks if the event is called on a directory if (File.GetAttributes(e.FullPath).HasFlag(FileAttributes.Directory)) { continue; } //Checks if the file is done saving, //else it enqueues it again if (!WaitForFile(e.FullPath)) { _fileHandlingQueue.Enqueue(e); continue; } } //Handles create events, by checking if the event is //called on a new file or dublicate file with a new path. //If it is a new file, the file is added to the index, //else the new path to the file is added if (e.ChangeType.Equals(WatcherChangeTypes.Created)) { var eventFile = new IndexFile(e.FullPath); if (_index.ContainsKey(eventFile.GetHash())) { _index[eventFile.hash].AddPath(e.FullPath); } else { _index.Add(eventFile.GetHash(), eventFile); FileAdded?.Invoke(eventFile); } } //Handles changes to files, by removing old file, or the //path to the file if more paths exist, from index and //adding the new one. This is done, because the hash is changed else if (e.ChangeType.Equals(WatcherChangeTypes.Changed)) { bool fileRemoved = false; string oldHash = null; var eventFile = new IndexFile(e.FullPath); if (!_index.ContainsKey(eventFile.hash)) { foreach (KeyValuePair <string, IndexFile> pair in _index) { if (_index[pair.Key].paths.Contains(e.FullPath)) { if (_index[pair.Key].paths.Count > 1) { _index[pair.Key].paths.Remove(e.FullPath); oldHash = null; } else { oldHash = pair.Key; _index.Remove(pair.Key); } } } _index.Add(eventFile.hash, eventFile); } else { foreach (KeyValuePair <string, IndexFile> pair in _index) { if (_index[pair.Key].paths.Count > 1) { foreach (string path in _index[pair.Key].paths) { if (path == eventFile.paths[0] && !eventFile.Equals(_index[pair.Key])) { _index[pair.Key].paths.Remove(path); break; } } } else { foreach (string path in _index[pair.Key].paths) { if (path == eventFile.paths[0] && !eventFile.Equals(_index[pair.Key])) { _index.Remove(pair.Key); fileRemoved = true; } } } if (fileRemoved) { break; } } if (!_index[eventFile.hash].paths.Contains(eventFile.paths[0])) { _index[eventFile.hash].AddPath(eventFile.paths[0]); } } FileChanged?.Invoke(eventFile, oldHash); } //Handles delete events, by deleting file from index or path, //if file has multiple paths else if (e.ChangeType.Equals(WatcherChangeTypes.Deleted)) { foreach (KeyValuePair <string, IndexFile> pair in _index) { List <string> pathsToDelete = _index[pair.Key].paths.Where(p => p.Equals(e.FullPath) || p.StartsWith(e.FullPath)).ToList(); foreach (string path in pathsToDelete) { _index[pair.Key].paths.Remove(path); } } List <KeyValuePair <string, IndexFile> > filesToDelete = _index.Where(p => _index[p.Key].paths.Count == 0).ToList(); foreach (KeyValuePair <string, IndexFile> pair in filesToDelete) { FileDeleted.Invoke(pair.Key); _index.Remove(pair.Key); } } } _waitHandle.Reset(); } isStopped = true; }