//private void ProjectService_FileRenaming(object sender, SledProjectServiceFileEventArgs e) //{ // ISledDocument sd = e.File.SledDocument; // if (sd == null) // return; // if (!IsValidDocument(sd)) // return; // Remove(sd); //} //private void ProjectService_FileRenamed(object sender, SledProjectServiceFileEventArgs e) //{ // ISledDocument sd = e.File.SledDocument; // if (sd == null) // return; // if (!IsValidDocument(sd)) // return; // Add(sd); //} #endregion #region Member Methods private void Add(ISledDocument sd) { if (!IsValidDocument(sd)) { return; } sd.UriChanged += SledDocumentUriChanged; if (m_dict.ContainsKey(sd)) { return; } var watcher = new SledFileSystemWatcher { Tag = sd, Path = Path.GetDirectoryName(sd.Uri.LocalPath), Filter = Path.GetFileName(sd.Uri.LocalPath), NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Attributes, SynchronizingObject = m_mainForm }; watcher.Changed += WatcherChanged; watcher.EnableRaisingEvents = true; // Add to dictionary m_dict[sd] = watcher; m_dictFileStats[sd] = SledFileSystemFileStats.GetStats(sd.Uri.LocalPath); }
private void Enable(SledProjectFilesType project) { if (m_watcher == null) { return; } // Enable watching m_watcher.EnableRaisingEvents = true; // Refresh stats m_fileStats = SledFileSystemFileStats.GetStats(project.AbsolutePath); }
private bool Enable(ISledDocument sd) { // Check if item in the dictionary SledFileSystemWatcher watcher; if (!m_dict.TryGetValue(sd, out watcher)) { return(false); } watcher.EnableRaisingEvents = true; m_dictFileStats[sd] = SledFileSystemFileStats.GetStats(sd.Uri.LocalPath); // Successfully enabled return(true); }
private void Create(SledProjectFilesType project) { Cleanup(); var absPath = project.AbsolutePath; // Create new file watcher for the project m_watcher = new SledFileSystemWatcher { Tag = project, Path = Path.GetDirectoryName(absPath), Filter = Path.GetFileName(absPath), NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Attributes, SynchronizingObject = m_mainForm }; m_watcher.Changed += WatcherChanged; m_watcher.EnableRaisingEvents = true; // Get initial stats m_fileStats = SledFileSystemFileStats.GetStats(absPath); }
private void WatcherChanged(object sender, FileSystemEventArgs e) { if (m_bChanging) { return; } try { m_bChanging = true; var watcher = sender as SledFileSystemWatcher; if (watcher == null) { return; } if (watcher.Tag == null) { return; } var project = watcher.Tag as SledProjectFilesType; if (project == null) { return; } // Any existing stats on this file? var curFileStats = SledFileSystemFileStats.GetStats(project.AbsolutePath); if (!curFileStats.Valid) { SledOutDevice.OutLine( SledMessageType.Error, "Exception obtaining file " + "stats on file \"{0}\": {1}", project.AbsolutePath, curFileStats.Exception); return; } // Figure out which event to hit var change = SledFileSystemFileStats.Compare(m_fileStats, curFileStats); // Update m_fileStats = curFileStats; // No change made; don't fire any events if (change == SledFileSystemFileStatsChange.Nothing) { return; } // Fire appropriate event (change == SledFileSystemFileStatsChange.LastWrite ? FileChangedEvent : AttributeChangedEvent).Raise(this, new SledProjectWatcherServiceEventArgs(project.AbsolutePath)); } catch (Exception ex) { SledOutDevice.OutLine( SledMessageType.Error, "[Project Watcher] Exception in WatchChanged event: {0}", ex.Message); } finally { m_bChanging = false; } }
private void WatcherChanged(object sender, FileSystemEventArgs e) { if (m_bChanging) { return; } try { m_bChanging = true; var watcher = sender as SledFileSystemWatcher; if (watcher == null) { return; } if (watcher.Tag == null) { return; } var sd = watcher.Tag as ISledDocument; if (sd == null) { return; } // Any existing stats on this file? SledFileSystemFileStats fileStats; if (!m_dictFileStats.TryGetValue(sd, out fileStats)) { return; } var curFileStats = SledFileSystemFileStats.GetStats(sd.Uri.LocalPath); if (!curFileStats.Valid) { SledOutDevice.OutLine( SledMessageType.Error, "Exception obtaining file " + "stats on file \"{0}\": {1}", sd.Uri.LocalPath, curFileStats.Exception); return; } // Figure out which event to hit var change = SledFileSystemFileStats.Compare(fileStats, curFileStats); // Update m_dictFileStats[sd] = curFileStats; // No change made; don't fire any events if (change == SledFileSystemFileStatsChange.Nothing) { return; } // Fire appropriate event (change == SledFileSystemFileStatsChange.LastWrite ? FileChangedEvent : AttributeChangedEvent).Raise(this, new SledFileWatcherServiceEventArgs(sd)); } finally { m_bChanging = false; } }