public async Task <GitFileStatusTracker> GetTrackerForPathAsync(string filename, bool setActiveTracker = false, bool createTracker = true)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                return(null);
            }

            GitFileStatusTracker repo = null;

            filename = filename.ToLower();

            //check out quick list to see if we have he file first.
            if (!_fileRepoLookup.TryGetValue(filename, out repo))
            {
                var basePath = await GetGitRepositoryAsync(filename);

                if (!string.IsNullOrWhiteSpace(basePath) && !_basePathRepoLookup.TryGetValue(basePath, out repo))
                {
                    repo = new GitFileStatusTracker(basePath);
                    repo.EnableRepositoryWatcher();
                    repo.FilesChanged     += Repo_FilesChanged;
                    repo.FileStatusUpdate += Repo_FileStatusUpdate;
                    repo.OnCommitChanged  += Repo_OnCommitChanged;
                    //repo.BranchChanged += Repo_BranchChanged;

                    //add our refrences so we can do a quick lookup later
                    _repositories.Add(repo);
                    _basePathRepoLookup.TryAdd(basePath, repo);
                }
                _fileRepoLookup.TryAdd(filename, repo);
            }


            if (repo == null)
            {
                return(ActiveTracker);
            }

            if (setActiveTracker)
            {
                ActiveTracker = repo;
            }

            return(repo);
        }
Esempio n. 2
0
        public GitFileStatusTracker GetTrackerForPath(string filename, bool setActiveTracker = false, bool createTracker = true)
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                return(null);
            }

            GitFileStatusTracker repo = null;
            var filePath = filename.ToLower();

            //check out quick list to see if we have he file first.
            if (!_fileRepoLookup.TryGetValue(filePath, out repo))
            {
                var basePath = GetGitRepository(filePath);
                if (createTracker &&
                    !string.IsNullOrWhiteSpace(basePath) && !_basePathRepoLookup.TryGetValue(basePath, out repo))
                {
                    repo = new GitFileStatusTracker(basePath);
                    repo.EnableRepositoryWatcher();
                    repo.FilesChanged     += Repo_FilesChanged;
                    repo.FileStatusUpdate += Repo_FileStatusUpdate;
                    //repo.BranchChanged += Repo_BranchChanged;

                    //add our refrences so we can do a quick lookup later
                    _repositories.Add(repo);
                    _basePathRepoLookup.TryAdd(basePath, repo);
                }
                _fileRepoLookup.TryAdd(filePath, repo);
            }


            //if (repo == null)
            //{
            //    return ActiveTracker;
            //}

            if (setActiveTracker && repo != null)
            {
                ActiveTracker = repo;
            }

            return(repo);
        }
        public async Task<GitFileStatusTracker> GetTrackerForPathAsync(string filename,bool setActiveTracker = false ,bool createTracker = true)
        {
            if (string.IsNullOrWhiteSpace(filename)) return null;

            GitFileStatusTracker repo = null;
            filename = filename.ToLower();

            //check out quick list to see if we have he file first. 
            if (!_fileRepoLookup.TryGetValue(filename, out repo))
            {
                var basePath = await GetGitRepositoryAsync(filename);
                if (!string.IsNullOrWhiteSpace(basePath) && !_basePathRepoLookup.TryGetValue(basePath, out repo))
                {
                    repo = new GitFileStatusTracker(basePath);
                    repo.EnableRepositoryWatcher();
                    repo.FilesChanged += Repo_FilesChanged;
                    repo.FileStatusUpdate += Repo_FileStatusUpdate;
                    //repo.BranchChanged += Repo_BranchChanged;

                    //add our refrences so we can do a quick lookup later
                    _repositories.Add(repo);
                    _basePathRepoLookup.TryAdd(basePath, repo);
                }
                _fileRepoLookup.TryAdd(filename, repo);
            }


            if (repo == null)
            {
                return ActiveTracker;
            }

            if (setActiveTracker)
            {
                ActiveTracker = repo;
            }

            return repo;
        }