// ------------------------------------------------------------------------ // update file status of the watched dirty files // ------------------------------------------------------------------------ bool UpdateFileStatusDictionary(List <string> fileList) { bool updateUI = false; if (_bRebuildStatusCacheRequired) { return(false); } // now we will get HG status information for the remaining files if (!_bRebuildStatusCacheRequired && fileList.Count > 0) { Dictionary <string, char> fileStatusDictionary; SkipDirstate(true); if (HG.QueryFileStatus(fileList.ToArray(), out fileStatusDictionary)) { Trace.WriteLine("got status for watched files - count: " + fileStatusDictionary.Count.ToString()); lock (_fileStatusDictionary) { _fileStatusDictionary.Add(fileStatusDictionary); } } SkipDirstate(false); updateUI = true; } return(updateUI); }
// ------------------------------------------------------------------------ /// update given file status. // ------------------------------------------------------------------------ public void UpdateFileStatus(string[] files) { Dictionary <string, char> fileStatusDictionary; if (HG.QueryFileStatus(files, out fileStatusDictionary)) { _fileStatusDictionary.Add(fileStatusDictionary); } }
// ------------------------------------------------------------------------ // async proc to assimilate the directory watcher state dictionaries // ------------------------------------------------------------------------ void DirectoryStatusCheckerThread(object source, ElapsedEventArgs e) { // handle user and IDE commands first Queue <IHGWorkItem> workItemQueue = _workItemQueue.PopWorkItems(); if (workItemQueue.Count > 0) { List <string> ditryFilesList = new List <string>(); foreach (IHGWorkItem item in workItemQueue) { item.Do(this, ditryFilesList); } if (ditryFilesList.Count > 0) { Dictionary <string, char> fileStatusDictionary; if (HG.QueryFileStatus(ditryFilesList.ToArray(), out fileStatusDictionary)) { lock (_fileStatusDictionary) { _fileStatusDictionary.Add(fileStatusDictionary); } } } // update status icons FireStatusChanged(_context); } else if (!_IsSolutionBuilding) { // handle modified files list long numberOfControlledFiles = 0; lock (_fileStatusDictionary) { numberOfControlledFiles = System.Math.Max(1, _fileStatusDictionary.Count); } long numberOfChangedFiles = 0; double elapsedMS = 0; lock (_directoryWatcherMap) { numberOfChangedFiles = _directoryWatcherMap.GetNumberOfChangedFiles(); TimeSpan timeSpan = new TimeSpan(DateTime.Now.Ticks - _directoryWatcherMap.GetLatestChange().Ticks); elapsedMS = timeSpan.TotalMilliseconds; } if (_bRebuildStatusCacheRequired || numberOfChangedFiles > 200) { if (elapsedMS > _MinElapsedTimeForStatusCacheRebuildMS) { Trace.WriteLine("DoFullStatusUpdate (NumberOfChangedFiles: " + numberOfChangedFiles.ToString() + " )"); RebuildStatusCache(); // update status icons FireStatusChanged(_context); } } else if (numberOfChangedFiles > 0) { // min elapsed time before do anything if (elapsedMS > 2000) { Trace.WriteLine("UpdateDirtyFilesStatus (NumberOfChangedFiles: " + numberOfChangedFiles.ToString() + " )"); var fileList = PopDirtyWatcherFiles(); if (UpdateFileStatusDictionary(fileList)) { // update status icons - but only if a project file was changed bool bFireStatusChanged = false; lock (_FileToProjectCache) { foreach (string file in fileList) { object o; if (_FileToProjectCache.TryGetValue(file.ToLower(), out o)) { bFireStatusChanged = true; break; } } } if (bFireStatusChanged) { FireStatusChanged(_context); } } } } } _timerDirectoryStatusChecker.Enabled = true; }