コード例 #1
0
 public void AddRootDirectoryItem(RootDirectoryItem item)
 {
     if (!GitListDataContext.RootDirectoryItems.Contains(item))
     {
         GitListDataContext.RootDirectoryItems.Add(item);
         SaveRootDirectoryitems();
     }
 }
コード例 #2
0
 private void Generate()
 {
     var directory = Directory.Value;
     var root = new RootDirectoryItem
     {
         Path = directory,
         Name = Path.GetFileName(directory)
     };
     Traverse(directory, root);
     var json = JsonConvert.SerializeObject(root, Formatting.Indented);
     System.IO.File.WriteAllText(File.Value, json, Encoding.UTF8);
 }
コード例 #3
0
        public void ChangeRootBranch(RootDirectoryItem item)
        {
            if (item != null && item.RepositoryItems != null)
            {
                SetRootRefreshInProgress(item);

                new Thread(() =>
                {
                    item.RepositoryItems.ToList().ForEach(repo =>
                    {
                        if (repo.Branches.Contains(item.RootBranch) && repo.CurrentBranch != item.RootBranch)
                        {
                            repo.CurrentBranch = item.RootBranch;
                            ChangeBranch(repo);
                        }
                    });

                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    DispatchInvoker.InvokeBackground(() =>
                    {
                        item.RootBranch = null;
                        RefreshRepositories(item, false);
                    });
                }).Start();
            }
        }
コード例 #4
0
        private void OnChanged(object sender, FileSystemEventArgs e, RootDirectoryItem item)
        {
            if (GitListDataContext.Configuration.RefreshDetectionEnabled)
            {
                TimeSpan lastRefresh = (DateTime.Now - item.LastRefresh);

                var anyInProgress = item.RepositoryItems.ToList().Any(x => x.InProgress);

                if (lastRefresh.TotalMinutes >= ConfigurationLoader.refreshDetectionInterval && !item.Refreshing && !anyInProgress)
                {
                    RefreshRepositories(item, true);
                }
                else
                {
                }
            }
        }
コード例 #5
0
        private RootDirectoryItem DiscoverRepositoriesAndAddToList(string path, bool collapsed = false)
        {
            if (!Directory.Exists(path) || GitListDataContext.RootDirectoryItems.Any(x => x.Path == path))
            {
                return null;
            }

            var repositories = new GitManager().FindRepositories(path);
            var newRootItem = new RootDirectoryItem()
            {
                Path = path,
                RepositoryItems = repositories,
                LastRefresh = DateTime.Now,
                RepositoriesDetected = repositories.Count > 0,
                Collapsed = collapsed,
                RepositoryBranches = new ObservableCollection<string>()
            };

            var watcher = new FileSystemWatcher(newRootItem.Path);
            watcher.Changed += (o, args) => OnChanged(o, args, newRootItem);
            watcher.Created += (o, args) => OnChanged(o, args, newRootItem);
            watcher.Deleted += (o, args) => OnChanged(o, args, newRootItem);
            watcher.Renamed += (o, args) => OnChanged(o, args, newRootItem);
            watcher.IncludeSubdirectories = true;
            watcher.EnableRaisingEvents = true;

            AddRootDirectoryItem(newRootItem);

            //if (gitListDataContext.RootDirectoryItems.Count > 0 && gitListDataContext.RootDirectoryItems[0].RepositoryItems.Count > 0 && gitListDataContext.RootDirectoryItems[0].Collapsed == false)
            //{
            //    gitListDataContext.SelectedRepositoryItem = gitListDataContext.RootDirectoryItems[0].RepositoryItems[0];
            //    //gitListDataContext.Controllers.ConsoleController.ChangeRepository(gitListDataContext.RootDirectoryItems[0].RepositoryItems[0]);
            //}

            return newRootItem;
        }
コード例 #6
0
 public void SetRootRefreshInProgress(RootDirectoryItem item)
 {
     item.RepositoryItems.ToList().ForEach(x =>
     {
         x.InProgress = true;
         x.Modified = null;
         x.Changes = null;
         x.CommitsAheadBy = 0;
         x.CommitsBehindBy = 0;
         x.CommitLog = null;
         x.Message = null;
     });
 }
コード例 #7
0
        public void RemoveRootDirectoryItem(RootDirectoryItem item)
        {
            if (GitListDataContext.RootDirectoryItems.Contains(item))
            {
                GitListDataContext.RootDirectoryItems.Remove(item);
                if (GitListDataContext.SelectedRepositoryItem != null && GitListDataContext.SelectedRepositoryItem.Parent == item)
                {
                    GitListDataContext.SelectedRepositoryItem = null;
                }

                SaveRootDirectoryitems();
            }
        }
コード例 #8
0
        public void RefreshRepositories(RootDirectoryItem rootItem, bool eventTriggered)
        {
            if (rootItem == null)
            {
                return;
            }

            rootItem.LastRefresh = DateTime.Now;
            rootItem.Refreshing = true;

            SetRootRefreshInProgress(rootItem);

            if (!Directory.Exists(rootItem.Path))
            {
                RemoveRootDirectoryItem(rootItem);
                return;
            }

            new Thread(() =>
            {
                if (eventTriggered)
                {
                    Thread.Sleep(TimeSpan.FromMinutes(1));
                }

                DispatchInvoker.InvokeBackground(() =>
                {
                    rootItem.RepositoryBranches.Clear();
                });

                rootItem.RepositoryItems.ToList().ForEach(repo =>
                {
                    if (!Directory.Exists(repo.Path))
                    {
                        DispatchInvoker.InvokeBackground(() =>
                        {
                            rootItem.RepositoryItems.Remove(repo);
                            //item.RepositoryItems = new GitManager().FindRepositories(item.Path);
                        });
                        return;
                    }

                    var changesList = new ObservableCollection<string>();
                    new GitManager().Changes(repo).ForEach(changesList.Add);
                    var branchList = GetBranchList(repo);
                    var currentBranch = GetCurrentBranchName(repo);
                    var aheadCount = new GitManager().Aheadby(repo);
                    var behindCount = new GitManager().BehindBy(repo);

                    var commitLog = new ObservableCollection<string>();
                    new GitManager().CommitLog(repo).ForEach(commitLog.Add);

                    DispatchInvoker.InvokeBackground(() =>
                    {
                        branchList.ToList().ForEach(branch =>
                        {
                            if (!rootItem.RepositoryBranches.Contains(branch) && branch != "DETACHED HEAD")
                            {
                                rootItem.RepositoryBranches.Add(branch);
                            }
                        });

                        repo.Parent = rootItem;
                        repo.Modified = changesList.Count > 0;
                        repo.Changes = changesList;
                        repo.Branches = branchList;
                        repo.CurrentBranch = currentBranch;
                        repo.CommitsAheadBy = aheadCount;
                        repo.CommitsBehindBy = behindCount;
                        repo.CommitLog = commitLog;
                        repo.InProgress = false;
                        rootItem.Refreshing = false;

                    });
                });

                DispatchInvoker.InvokeBackground(() =>
                {
                    if (rootItem.RepositoryItems != null)
                    {
                        var sortedList = rootItem.RepositoryItems.OrderBy(x => x.CurrentBranch).ThenBy(x => x.Name).ToList();
                        rootItem.RepositoryItems.Clear();
                        sortedList.ForEach(x =>
                        {
                            rootItem.RepositoryItems.Add(x);
                        });
                    }
                });

            }).Start();
        }
コード例 #9
0
        public void FetchAndResetRootBranch(RootDirectoryItem item)
        {
            if (item != null && item.RepositoryItems != null)
            {
                SetRootRefreshInProgress(item);

                new Thread(() =>
                {
                    item.RepositoryItems.ToList().ForEach(Fetch);

                    DispatchInvoker.InvokeBackground(() => { RefreshRepositories(item, false); });
                }).Start();
            }
        }
コード例 #10
0
 public void CollapseRootDirectory(RootDirectoryItem item)
 {
     item.Collapsed = !item.Collapsed;
     SaveRootDirectoryitems();
 }