Ejemplo n.º 1
0
        static async void OnEntryAdded(object o, SolutionItemEventArgs args)
        {
            if (args is SolutionItemChangeEventArgs && ((SolutionItemChangeEventArgs)args).Reloading)
            {
                return;
            }

            // handles addition of solutions and projects
            SolutionFolderItem parent = (SolutionFolderItem)args.SolutionItem.ParentFolder;

            if (parent == null)
            {
                return;
            }

            Repository repo = GetRepository(parent);

            if (repo == null)
            {
                return;
            }

            SolutionFolderItem entry       = args.SolutionItem;
            Repository         currentRepo = GetRepository(entry);

            if (currentRepo != null && currentRepo.VersionControlSystem != repo.VersionControlSystem)
            {
                // If the item is already under version control using a different version control system
                // don't add it to the parent repo.
                return;
            }

            string path = entry.BaseDirectory;

            // While we /could/ call repo.Add with `recursive = true', we don't
            // necessarily want to add files under the project/solution directory
            // that may not be a part of this project/solution.

            var files = new HashSet <string> {
                path
            };

            SolutionItemAddFiles(path, entry, files);

            if (entry is SolutionFolder && files.Count == 1)
            {
                return;
            }
            try {
                using (ProgressMonitor monitor = GetStatusMonitor()) {
                    foreach (var file in files)
                    {
                        var status = await repo.GetDirectoryVersionInfoAsync(file, false, false, monitor.CancellationToken);

                        foreach (var v in status)
                        {
                            if (!v.IsVersioned && files.Contains(v.LocalPath))
                            {
                                await repo.AddAsync(v.LocalPath, false, monitor);
                            }
                        }
                    }
                }
                if (entry is SolutionFolder && files.Count == 1)
                {
                    return;
                }

                NotifyFileStatusChanged(new FileUpdateEventArgs(repo, parent.BaseDirectory, true));
            } catch (OperationCanceledException) {
                return;
            } catch (Exception e) {
                LoggingService.LogInternalError(e);
            }
        }